aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2019-04-07 23:39:04 +0200
committerSven Gothel <[email protected]>2019-04-07 23:39:04 +0200
commit73233ce69919fc19c53ce8663c5b8cc05227f07e (patch)
treef2b6ccc1a14d7c387f33398a44ea4511d7ecb212
parent8efa4c7ba5ee8eb399d31a9884e45f743d4625ad (diff)
parent99a55c445211fea77af6ab61cbc6a6ec4fbdc9b9 (diff)
Merge branch 'v1.19' of git://repo.or.cz/openal-soft into v1.19v1.19
-rw-r--r--.gitignore10
-rw-r--r--.travis.yml66
-rw-r--r--Alc/ALc.c2799
-rw-r--r--Alc/ALu.c2490
-rw-r--r--Alc/alcRing.c401
-rw-r--r--Alc/alconfig.c (renamed from Alc/alcConfig.c)204
-rw-r--r--Alc/alconfig.h17
-rw-r--r--Alc/alstring.h44
-rw-r--r--Alc/ambdec.c566
-rw-r--r--Alc/ambdec.h46
-rw-r--r--Alc/backends/alsa.c306
-rw-r--r--Alc/backends/base.c187
-rw-r--r--Alc/backends/base.h62
-rw-r--r--Alc/backends/coreaudio.c586
-rw-r--r--Alc/backends/dsound.c372
-rw-r--r--Alc/backends/jack.c171
-rw-r--r--Alc/backends/loopback.c13
-rw-r--r--Alc/backends/null.c31
-rw-r--r--Alc/backends/opensl.c985
-rw-r--r--Alc/backends/oss.c541
-rw-r--r--Alc/backends/portaudio.c62
-rw-r--r--Alc/backends/pulseaudio.c414
-rw-r--r--Alc/backends/qsa.c415
-rw-r--r--Alc/backends/sdl2.c288
-rw-r--r--Alc/backends/sndio.c476
-rw-r--r--Alc/backends/solaris.c112
-rw-r--r--Alc/backends/wasapi.c (renamed from Alc/backends/mmdevapi.c)909
-rw-r--r--Alc/backends/wave.c123
-rw-r--r--Alc/backends/winmm.c199
-rw-r--r--Alc/bformatdec.c492
-rw-r--r--Alc/bformatdec.h57
-rw-r--r--Alc/bs2b.c57
-rw-r--r--Alc/bsinc.c981
-rw-r--r--Alc/compat.h25
-rw-r--r--Alc/converter.c468
-rw-r--r--Alc/converter.h55
-rw-r--r--Alc/cpu_caps.h15
-rw-r--r--Alc/effects/autowah.c321
-rw-r--r--Alc/effects/chorus.c494
-rw-r--r--Alc/effects/compressor.c220
-rw-r--r--Alc/effects/dedicated.c140
-rw-r--r--Alc/effects/distortion.c241
-rw-r--r--Alc/effects/echo.c243
-rw-r--r--Alc/effects/equalizer.c228
-rw-r--r--Alc/effects/flanger.c398
-rw-r--r--Alc/effects/fshifter.c329
-rw-r--r--Alc/effects/modulator.c261
-rw-r--r--Alc/effects/null.c113
-rw-r--r--Alc/effects/pshifter.c441
-rw-r--r--Alc/effects/reverb.c2433
-rw-r--r--Alc/filters/defs.h112
-rw-r--r--Alc/filters/filter.c129
-rw-r--r--Alc/filters/nfc.c426
-rw-r--r--Alc/filters/nfc.h49
-rw-r--r--Alc/filters/splitter.c109
-rw-r--r--Alc/filters/splitter.h40
-rw-r--r--Alc/fpu_modes.h34
-rw-r--r--Alc/helpers.c1431
-rw-r--r--Alc/hrtf.c1551
-rw-r--r--Alc/hrtf.h84
-rw-r--r--Alc/inprogext.h87
-rw-r--r--Alc/logging.h69
-rw-r--r--Alc/mastering.c543
-rw-r--r--Alc/mastering.h49
-rw-r--r--Alc/mixer.c638
-rw-r--r--Alc/mixer/defs.h119
-rw-r--r--Alc/mixer/hrtf_inc.c128
-rw-r--r--Alc/mixer/mixer_c.c169
-rw-r--r--Alc/mixer/mixer_neon.c283
-rw-r--r--Alc/mixer/mixer_sse.c250
-rw-r--r--Alc/mixer/mixer_sse2.c84
-rw-r--r--Alc/mixer/mixer_sse3.c0
-rw-r--r--Alc/mixer/mixer_sse41.c (renamed from Alc/mixer_sse2.c)38
-rw-r--r--Alc/mixer_c.c181
-rw-r--r--Alc/mixer_defs.h80
-rw-r--r--Alc/mixer_inc.c79
-rw-r--r--Alc/mixer_neon.c139
-rw-r--r--Alc/mixer_sse.c279
-rw-r--r--Alc/mixer_sse3.c162
-rw-r--r--Alc/mixer_sse41.c224
-rw-r--r--Alc/mixvoice.c762
-rw-r--r--Alc/panning.c1392
-rw-r--r--Alc/polymorphism.h105
-rw-r--r--Alc/ringbuffer.c295
-rw-r--r--Alc/ringbuffer.h77
-rw-r--r--Alc/uhjfilter.c120
-rw-r--r--Alc/uhjfilter.h49
-rw-r--r--Alc/vector.h99
-rw-r--r--CMakeLists.txt1212
-rw-r--r--COPYING60
-rw-r--r--ChangeLog214
-rw-r--r--OpenAL32/Include/alAuxEffectSlot.h148
-rw-r--r--OpenAL32/Include/alBuffer.h93
-rw-r--r--OpenAL32/Include/alEffect.h77
-rw-r--r--OpenAL32/Include/alError.h20
-rw-r--r--OpenAL32/Include/alFilter.h134
-rw-r--r--OpenAL32/Include/alListener.h52
-rw-r--r--OpenAL32/Include/alMain.h1015
-rw-r--r--OpenAL32/Include/alSource.h162
-rw-r--r--OpenAL32/Include/alThunk.h20
-rw-r--r--OpenAL32/Include/alu.h454
-rw-r--r--OpenAL32/Include/bs2b.h41
-rw-r--r--OpenAL32/Include/sample_cvt.h8
-rw-r--r--OpenAL32/alAuxEffectSlot.c620
-rw-r--r--OpenAL32/alBuffer.c1282
-rw-r--r--OpenAL32/alEffect.c301
-rw-r--r--OpenAL32/alError.c54
-rw-r--r--OpenAL32/alExtension.c23
-rw-r--r--OpenAL32/alFilter.c542
-rw-r--r--OpenAL32/alListener.c264
-rw-r--r--OpenAL32/alSource.c2529
-rw-r--r--OpenAL32/alState.c401
-rw-r--r--OpenAL32/alThunk.c103
-rw-r--r--OpenAL32/event.c127
-rw-r--r--OpenAL32/sample_cvt.c1113
-rw-r--r--README55
-rw-r--r--README.md61
-rw-r--r--alsoftrc.sample175
-rw-r--r--appveyor.yml19
-rw-r--r--cmake/CheckSharedFunctionExists.cmake4
-rw-r--r--cmake/FindDSound.cmake26
-rw-r--r--cmake/FindFFmpeg.cmake6
-rw-r--r--cmake/FindOSS.cmake14
-rw-r--r--cmake/FindSDL2.cmake20
-rw-r--r--cmake/FindWindowsSDK.cmake626
-rw-r--r--common/alcomplex.c92
-rw-r--r--common/alcomplex.h71
-rw-r--r--common/align.h (renamed from include/align.h)0
-rw-r--r--common/almalloc.c110
-rw-r--r--common/almalloc.h30
-rw-r--r--common/atomic.c3
-rw-r--r--common/atomic.h439
-rw-r--r--common/bool.h (renamed from include/bool.h)0
-rw-r--r--common/math_defs.h65
-rw-r--r--common/rwlock.c20
-rw-r--r--common/rwlock.h (renamed from include/rwlock.h)9
-rw-r--r--common/static_assert.h (renamed from include/static_assert.h)0
-rw-r--r--common/threads.c343
-rw-r--r--common/threads.h (renamed from include/threads.h)45
-rw-r--r--common/uintmap.c154
-rw-r--r--common/uintmap.h41
-rw-r--r--common/win_main_utf8.h97
-rw-r--r--config.h.in64
-rw-r--r--docs/3D7.1.txt82
-rw-r--r--docs/ambdec.txt189
-rw-r--r--docs/ambisonics.txt126
-rw-r--r--docs/env-vars.txt (renamed from env-vars.txt)10
-rw-r--r--docs/hrtf.txt84
-rw-r--r--examples/alffplay.c1533
-rw-r--r--examples/alffplay.cpp1915
-rw-r--r--examples/alhrtf.c154
-rw-r--r--examples/allatency.c100
-rw-r--r--examples/alloopback.c40
-rw-r--r--examples/almultireverb.c696
-rw-r--r--examples/alplay.c177
-rw-r--r--examples/alrecord.c394
-rw-r--r--examples/alreverb.c104
-rw-r--r--examples/alstream.c134
-rw-r--r--examples/altonegen.c99
-rw-r--r--examples/common/alhelpers.c273
-rw-r--r--examples/common/alhelpers.h36
-rw-r--r--examples/common/sdl_sound.c164
-rw-r--r--examples/common/sdl_sound.h43
-rw-r--r--hrtf.txt74
-rw-r--r--hrtf/default-44100.mhrbin53853 -> 80354 bytes
-rw-r--r--hrtf/default-48000.mhrbin53853 -> 80354 bytes
-rw-r--r--include/AL/alext.h78
-rw-r--r--include/atomic.h334
-rw-r--r--include/math_defs.h19
-rw-r--r--include/uintmap.h43
-rw-r--r--native-tools/CMakeLists.txt29
-rw-r--r--native-tools/bin2h.c100
-rw-r--r--native-tools/bsincgen.c367
-rw-r--r--openal.pc.in1
-rw-r--r--presets/3D7.1.ambdec43
-rw-r--r--presets/hexagon.ambdec51
-rw-r--r--presets/itu5.1-nocenter.ambdec46
-rw-r--r--presets/itu5.1.ambdec48
-rw-r--r--presets/presets.txt42
-rw-r--r--presets/rectangle.ambdec45
-rw-r--r--presets/square.ambdec45
-rw-r--r--router/al.c132
-rw-r--r--router/alc.c956
-rw-r--r--router/router.c537
-rw-r--r--router/router.h197
-rw-r--r--utils/CIAIR.def5860
-rw-r--r--utils/IRC_1005.def768
-rw-r--r--utils/MIT_KEMAR.def109
-rw-r--r--utils/alsoft-config/CMakeLists.txt61
-rw-r--r--utils/alsoft-config/mainwindow.cpp978
-rw-r--r--utils/alsoft-config/mainwindow.h32
-rw-r--r--utils/alsoft-config/mainwindow.ui1854
-rw-r--r--utils/bsincgen.c290
-rw-r--r--utils/getopt.c137
-rw-r--r--utils/getopt.h26
-rw-r--r--utils/makehrtf.c5002
-rw-r--r--utils/openal-info.c98
-rw-r--r--version.cmake11
-rw-r--r--version.h.in8
199 files changed, 44915 insertions, 24889 deletions
diff --git a/.gitignore b/.gitignore
index 9aa081c6..de57ef22 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,5 @@
-build
-winbuild
-win64build
-include/SLES
-include/sndio.h
-include/sys
+build*/
+winbuild/
+win64build/
openal-soft.kdev4
+.kdev4/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 00000000..426eef40
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,66 @@
+language: c
+matrix:
+ include:
+ - os: linux
+ dist: trusty
+ - os: linux
+ dist: trusty
+ env:
+ - BUILD_ANDROID=true
+ - os: osx
+sudo: required
+install:
+ - >
+ if [[ "${TRAVIS_OS_NAME}" == "linux" && -z "${BUILD_ANDROID}" ]]; then
+ # Install pulseaudio, portaudio, ALSA, JACK dependencies for
+ # corresponding backends.
+ # Install Qt5 dependency for alsoft-config.
+ sudo apt-get install -qq \
+ libpulse-dev \
+ portaudio19-dev \
+ libasound2-dev \
+ libjack-dev \
+ qtbase5-dev
+ fi
+ - >
+ if [[ "${TRAVIS_OS_NAME}" == "linux" && "${BUILD_ANDROID}" == "true" ]]; then
+ curl -o ~/android-ndk.zip https://dl.google.com/android/repository/android-ndk-r15-linux-x86_64.zip
+ unzip -q ~/android-ndk.zip -d ~ \
+ 'android-ndk-r15/build/cmake/*' \
+ 'android-ndk-r15/build/core/toolchains/arm-linux-androideabi-*/*' \
+ 'android-ndk-r15/platforms/android-14/arch-arm/*' \
+ 'android-ndk-r15/source.properties' \
+ 'android-ndk-r15/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/*' \
+ 'android-ndk-r15/sources/cxx-stl/gnu-libstdc++/4.9/include/*' \
+ 'android-ndk-r15/sysroot/*' \
+ 'android-ndk-r15/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/*' \
+ 'android-ndk-r15/toolchains/llvm/prebuilt/linux-x86_64/*'
+ fi
+script:
+ - >
+ if [[ "${TRAVIS_OS_NAME}" == "linux" && -z "${BUILD_ANDROID}" ]]; then
+ cmake \
+ -DALSOFT_REQUIRE_ALSA=ON \
+ -DALSOFT_REQUIRE_OSS=ON \
+ -DALSOFT_REQUIRE_PORTAUDIO=ON \
+ -DALSOFT_REQUIRE_PULSEAUDIO=ON \
+ -DALSOFT_REQUIRE_JACK=ON \
+ -DALSOFT_EMBED_HRTF_DATA=YES \
+ .
+ fi
+ - >
+ if [[ "${TRAVIS_OS_NAME}" == "linux" && "${BUILD_ANDROID}" == "true" ]]; then
+ cmake \
+ -DCMAKE_TOOLCHAIN_FILE=~/android-ndk-r15/build/cmake/android.toolchain.cmake \
+ -DALSOFT_REQUIRE_OPENSL=ON \
+ -DALSOFT_EMBED_HRTF_DATA=YES \
+ .
+ fi
+ - >
+ if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
+ cmake \
+ -DALSOFT_REQUIRE_COREAUDIO=ON \
+ -DALSOFT_EMBED_HRTF_DATA=YES \
+ .
+ fi
+ - make -j2
diff --git a/Alc/ALc.c b/Alc/ALc.c
index d6d23eba..8bf2e1da 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -20,6 +20,8 @@
#include "config.h"
+#include "version.h"
+
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
@@ -30,17 +32,24 @@
#include "alMain.h"
#include "alSource.h"
#include "alListener.h"
-#include "alThunk.h"
#include "alSource.h"
#include "alBuffer.h"
+#include "alFilter.h"
+#include "alEffect.h"
#include "alAuxEffectSlot.h"
#include "alError.h"
-#include "bs2b.h"
+#include "mastering.h"
+#include "bformatdec.h"
#include "alu.h"
+#include "alconfig.h"
+#include "ringbuffer.h"
+#include "fpu_modes.h"
+#include "cpu_caps.h"
#include "compat.h"
#include "threads.h"
#include "alstring.h"
+#include "almalloc.h"
#include "backends/base.h"
@@ -51,61 +60,58 @@
struct BackendInfo {
const char *name;
ALCbackendFactory* (*getFactory)(void);
- ALCboolean (*Init)(BackendFuncs*);
- void (*Deinit)(void);
- void (*Probe)(enum DevProbe);
- BackendFuncs Funcs;
};
-#define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
static struct BackendInfo BackendList[] = {
#ifdef HAVE_JACK
- { "jack", ALCjackBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
+ { "jack", ALCjackBackendFactory_getFactory },
#endif
#ifdef HAVE_PULSEAUDIO
- { "pulse", ALCpulseBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
+ { "pulse", ALCpulseBackendFactory_getFactory },
#endif
#ifdef HAVE_ALSA
- { "alsa", ALCalsaBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
+ { "alsa", ALCalsaBackendFactory_getFactory },
#endif
#ifdef HAVE_COREAUDIO
- { "core", NULL, alc_ca_init, alc_ca_deinit, alc_ca_probe, EmptyFuncs },
-#endif
-#ifdef HAVE_OSS
- { "oss", ALCossBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
+ { "core", ALCcoreAudioBackendFactory_getFactory },
#endif
#ifdef HAVE_SOLARIS
- { "solaris", ALCsolarisBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
+ { "solaris", ALCsolarisBackendFactory_getFactory },
#endif
#ifdef HAVE_SNDIO
- { "sndio", NULL, alc_sndio_init, alc_sndio_deinit, alc_sndio_probe, EmptyFuncs },
+ { "sndio", SndioBackendFactory_getFactory },
+#endif
+#ifdef HAVE_OSS
+ { "oss", ALCossBackendFactory_getFactory },
#endif
#ifdef HAVE_QSA
- { "qsa", NULL, alc_qsa_init, alc_qsa_deinit, alc_qsa_probe, EmptyFuncs },
+ { "qsa", ALCqsaBackendFactory_getFactory },
#endif
-#ifdef HAVE_MMDEVAPI
- { "mmdevapi", ALCmmdevBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
+#ifdef HAVE_WASAPI
+ { "wasapi", ALCwasapiBackendFactory_getFactory },
#endif
#ifdef HAVE_DSOUND
- { "dsound", ALCdsoundBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
+ { "dsound", ALCdsoundBackendFactory_getFactory },
#endif
#ifdef HAVE_WINMM
- { "winmm", ALCwinmmBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
+ { "winmm", ALCwinmmBackendFactory_getFactory },
#endif
#ifdef HAVE_PORTAUDIO
- { "port", ALCportBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
+ { "port", ALCportBackendFactory_getFactory },
#endif
#ifdef HAVE_OPENSL
- { "opensl", NULL, alc_opensl_init, alc_opensl_deinit, alc_opensl_probe, EmptyFuncs },
+ { "opensl", ALCopenslBackendFactory_getFactory },
+#endif
+#ifdef HAVE_SDL2
+ { "sdl2", ALCsdl2BackendFactory_getFactory },
#endif
- { "null", ALCnullBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
+ { "null", ALCnullBackendFactory_getFactory },
#ifdef HAVE_WAVE
- { "wave", ALCwaveBackendFactory_getFactory, NULL, NULL, NULL, EmptyFuncs },
+ { "wave", ALCwaveBackendFactory_getFactory },
#endif
-
- { NULL, NULL, NULL, NULL, NULL, EmptyFuncs }
};
+static ALsizei BackendListSize = COUNTOF(BackendList);
#undef EmptyFuncs
static struct BackendInfo PlaybackBackend;
@@ -115,18 +121,11 @@ static struct BackendInfo CaptureBackend;
/************************************************
* Functions, enums, and errors
************************************************/
-typedef struct ALCfunction {
+#define DECL(x) { #x, (ALCvoid*)(x) }
+static const struct {
const ALCchar *funcName;
ALCvoid *address;
-} ALCfunction;
-
-typedef struct ALCenums {
- const ALCchar *enumName;
- ALCenum value;
-} ALCenums;
-
-#define DECL(x) { #x, (ALCvoid*)(x) }
-static const ALCfunction alcFunctions[] = {
+} alcFunctions[] = {
DECL(alcCreateContext),
DECL(alcMakeContextCurrent),
DECL(alcProcessContext),
@@ -271,13 +270,6 @@ static const ALCfunction alcFunctions[] = {
DECL(alGetAuxiliaryEffectSlotf),
DECL(alGetAuxiliaryEffectSlotfv),
- DECL(alBufferSubDataSOFT),
-
- DECL(alBufferSamplesSOFT),
- DECL(alBufferSubSamplesSOFT),
- DECL(alGetBufferSamplesSOFT),
- DECL(alIsBufferFormatSupportedSOFT),
-
DECL(alDeferUpdatesSOFT),
DECL(alProcessUpdatesSOFT),
@@ -294,12 +286,25 @@ static const ALCfunction alcFunctions[] = {
DECL(alGetSource3i64SOFT),
DECL(alGetSourcei64vSOFT),
- { NULL, NULL }
+ DECL(alGetStringiSOFT),
+
+ DECL(alBufferStorageSOFT),
+ DECL(alMapBufferSOFT),
+ DECL(alUnmapBufferSOFT),
+ DECL(alFlushMappedBufferSOFT),
+
+ DECL(alEventControlSOFT),
+ DECL(alEventCallbackSOFT),
+ DECL(alGetPointerSOFT),
+ DECL(alGetPointervSOFT),
};
#undef DECL
#define DECL(x) { #x, (x) }
-static const ALCenums enumeration[] = {
+static const struct {
+ const ALCchar *enumName;
+ ALCenum value;
+} alcEnumerations[] = {
DECL(ALC_INVALID),
DECL(ALC_FALSE),
DECL(ALC_TRUE),
@@ -336,6 +341,7 @@ static const ALCenums enumeration[] = {
DECL(ALC_5POINT1_SOFT),
DECL(ALC_6POINT1_SOFT),
DECL(ALC_7POINT1_SOFT),
+ DECL(ALC_BFORMAT3D_SOFT),
DECL(ALC_BYTE_SOFT),
DECL(ALC_UNSIGNED_BYTE_SOFT),
@@ -358,6 +364,16 @@ static const ALCenums enumeration[] = {
DECL(ALC_HRTF_SPECIFIER_SOFT),
DECL(ALC_HRTF_ID_SOFT),
+ DECL(ALC_AMBISONIC_LAYOUT_SOFT),
+ DECL(ALC_AMBISONIC_SCALING_SOFT),
+ DECL(ALC_AMBISONIC_ORDER_SOFT),
+ DECL(ALC_ACN_SOFT),
+ DECL(ALC_FUMA_SOFT),
+ DECL(ALC_N3D_SOFT),
+ DECL(ALC_SN3D_SOFT),
+
+ DECL(ALC_OUTPUT_LIMITER_SOFT),
+
DECL(ALC_NO_ERROR),
DECL(ALC_INVALID_DEVICE),
DECL(ALC_INVALID_CONTEXT),
@@ -390,9 +406,7 @@ static const ALCenums enumeration[] = {
DECL(AL_MAX_DISTANCE),
DECL(AL_SEC_OFFSET),
DECL(AL_SAMPLE_OFFSET),
- DECL(AL_SAMPLE_RW_OFFSETS_SOFT),
DECL(AL_BYTE_OFFSET),
- DECL(AL_BYTE_RW_OFFSETS_SOFT),
DECL(AL_SOURCE_TYPE),
DECL(AL_STATIC),
DECL(AL_STREAMING),
@@ -460,27 +474,6 @@ static const ALCenums enumeration[] = {
DECL(AL_FORMAT_MONO_ALAW_EXT),
DECL(AL_FORMAT_STEREO_ALAW_EXT),
- DECL(AL_MONO8_SOFT),
- DECL(AL_MONO16_SOFT),
- DECL(AL_MONO32F_SOFT),
- DECL(AL_STEREO8_SOFT),
- DECL(AL_STEREO16_SOFT),
- DECL(AL_STEREO32F_SOFT),
- DECL(AL_QUAD8_SOFT),
- DECL(AL_QUAD16_SOFT),
- DECL(AL_QUAD32F_SOFT),
- DECL(AL_REAR8_SOFT),
- DECL(AL_REAR16_SOFT),
- DECL(AL_REAR32F_SOFT),
- DECL(AL_5POINT1_8_SOFT),
- DECL(AL_5POINT1_16_SOFT),
- DECL(AL_5POINT1_32F_SOFT),
- DECL(AL_6POINT1_8_SOFT),
- DECL(AL_6POINT1_16_SOFT),
- DECL(AL_6POINT1_32F_SOFT),
- DECL(AL_7POINT1_8_SOFT),
- DECL(AL_7POINT1_16_SOFT),
- DECL(AL_7POINT1_32F_SOFT),
DECL(AL_FORMAT_BFORMAT2D_8),
DECL(AL_FORMAT_BFORMAT2D_16),
DECL(AL_FORMAT_BFORMAT2D_FLOAT32),
@@ -490,36 +483,17 @@ static const ALCenums enumeration[] = {
DECL(AL_FORMAT_BFORMAT3D_FLOAT32),
DECL(AL_FORMAT_BFORMAT3D_MULAW),
- DECL(AL_MONO_SOFT),
- DECL(AL_STEREO_SOFT),
- DECL(AL_QUAD_SOFT),
- DECL(AL_REAR_SOFT),
- DECL(AL_5POINT1_SOFT),
- DECL(AL_6POINT1_SOFT),
- DECL(AL_7POINT1_SOFT),
-
- DECL(AL_BYTE_SOFT),
- DECL(AL_UNSIGNED_BYTE_SOFT),
- DECL(AL_SHORT_SOFT),
- DECL(AL_UNSIGNED_SHORT_SOFT),
- DECL(AL_INT_SOFT),
- DECL(AL_UNSIGNED_INT_SOFT),
- DECL(AL_FLOAT_SOFT),
- DECL(AL_DOUBLE_SOFT),
- DECL(AL_BYTE3_SOFT),
- DECL(AL_UNSIGNED_BYTE3_SOFT),
-
DECL(AL_FREQUENCY),
DECL(AL_BITS),
DECL(AL_CHANNELS),
DECL(AL_SIZE),
- DECL(AL_INTERNAL_FORMAT_SOFT),
- DECL(AL_BYTE_LENGTH_SOFT),
- DECL(AL_SAMPLE_LENGTH_SOFT),
- DECL(AL_SEC_LENGTH_SOFT),
DECL(AL_UNPACK_BLOCK_ALIGNMENT_SOFT),
DECL(AL_PACK_BLOCK_ALIGNMENT_SOFT),
+ DECL(AL_SOURCE_RADIUS),
+
+ DECL(AL_STEREO_ANGLES),
+
DECL(AL_UNUSED),
DECL(AL_PENDING),
DECL(AL_PROCESSED),
@@ -542,6 +516,7 @@ static const ALCenums enumeration[] = {
DECL(AL_SPEED_OF_SOUND),
DECL(AL_SOURCE_DISTANCE_MODEL),
DECL(AL_DEFERRED_UPDATES_SOFT),
+ DECL(AL_GAIN_LIMIT_SOFT),
DECL(AL_INVERSE_DISTANCE),
DECL(AL_INVERSE_DISTANCE_CLAMPED),
@@ -574,20 +549,23 @@ static const ALCenums enumeration[] = {
DECL(AL_EFFECT_DISTORTION),
DECL(AL_EFFECT_ECHO),
DECL(AL_EFFECT_FLANGER),
-#if 0
+ DECL(AL_EFFECT_PITCH_SHIFTER),
DECL(AL_EFFECT_FREQUENCY_SHIFTER),
+#if 0
DECL(AL_EFFECT_VOCAL_MORPHER),
- DECL(AL_EFFECT_PITCH_SHIFTER),
#endif
DECL(AL_EFFECT_RING_MODULATOR),
-#if 0
DECL(AL_EFFECT_AUTOWAH),
-#endif
DECL(AL_EFFECT_COMPRESSOR),
DECL(AL_EFFECT_EQUALIZER),
DECL(AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT),
DECL(AL_EFFECT_DEDICATED_DIALOGUE),
+ DECL(AL_EFFECTSLOT_EFFECT),
+ DECL(AL_EFFECTSLOT_GAIN),
+ DECL(AL_EFFECTSLOT_AUXILIARY_SEND_AUTO),
+ DECL(AL_EFFECTSLOT_NULL),
+
DECL(AL_EAXREVERB_DENSITY),
DECL(AL_EAXREVERB_DIFFUSION),
DECL(AL_EAXREVERB_GAIN),
@@ -652,16 +630,16 @@ static const ALCenums enumeration[] = {
DECL(AL_FLANGER_FEEDBACK),
DECL(AL_FLANGER_DELAY),
+ DECL(AL_FREQUENCY_SHIFTER_FREQUENCY),
+ DECL(AL_FREQUENCY_SHIFTER_LEFT_DIRECTION),
+ DECL(AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION),
+
DECL(AL_RING_MODULATOR_FREQUENCY),
DECL(AL_RING_MODULATOR_HIGHPASS_CUTOFF),
DECL(AL_RING_MODULATOR_WAVEFORM),
-#if 0
- DECL(AL_AUTOWAH_ATTACK_TIME),
- DECL(AL_AUTOWAH_PEAK_GAIN),
- DECL(AL_AUTOWAH_RELEASE_TIME),
- DECL(AL_AUTOWAH_RESONANCE),
-#endif
+ DECL(AL_PITCH_SHIFTER_COARSE_TUNE),
+ DECL(AL_PITCH_SHIFTER_FINE_TUNE),
DECL(AL_COMPRESSOR_ONOFF),
@@ -678,7 +656,31 @@ static const ALCenums enumeration[] = {
DECL(AL_DEDICATED_GAIN),
- { NULL, (ALCenum)0 }
+ DECL(AL_AUTOWAH_ATTACK_TIME),
+ DECL(AL_AUTOWAH_RELEASE_TIME),
+ DECL(AL_AUTOWAH_RESONANCE),
+ DECL(AL_AUTOWAH_PEAK_GAIN),
+
+ DECL(AL_NUM_RESAMPLERS_SOFT),
+ DECL(AL_DEFAULT_RESAMPLER_SOFT),
+ DECL(AL_SOURCE_RESAMPLER_SOFT),
+ DECL(AL_RESAMPLER_NAME_SOFT),
+
+ DECL(AL_SOURCE_SPATIALIZE_SOFT),
+ DECL(AL_AUTO_SOFT),
+
+ DECL(AL_MAP_READ_BIT_SOFT),
+ DECL(AL_MAP_WRITE_BIT_SOFT),
+ DECL(AL_MAP_PERSISTENT_BIT_SOFT),
+ DECL(AL_PRESERVE_DATA_BIT_SOFT),
+
+ DECL(AL_EVENT_CALLBACK_FUNCTION_SOFT),
+ DECL(AL_EVENT_CALLBACK_USER_PARAM_SOFT),
+ DECL(AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT),
+ DECL(AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT),
+ DECL(AL_EVENT_TYPE_ERROR_SOFT),
+ DECL(AL_EVENT_TYPE_PERFORMANCE_SOFT),
+ DECL(AL_EVENT_TYPE_DEPRECATED_SOFT),
};
#undef DECL
@@ -706,13 +708,35 @@ static ALCchar *alcCaptureDefaultDeviceSpecifier;
/* Default context extensions */
static const ALchar alExtList[] =
- "AL_EXT_ALAW AL_EXT_BFORMAT AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE "
- "AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS "
- "AL_EXT_MULAW AL_EXT_MULAW_BFORMAT AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET "
- "AL_EXT_source_distance_model AL_LOKI_quadriphonic AL_SOFT_block_alignment "
- "AL_SOFT_buffer_samples AL_SOFT_buffer_sub_data AL_SOFT_deferred_updates "
- "AL_SOFT_direct_channels AL_SOFT_loop_points AL_SOFT_MSADPCM "
- "AL_SOFT_source_latency AL_SOFT_source_length";
+ "AL_EXT_ALAW "
+ "AL_EXT_BFORMAT "
+ "AL_EXT_DOUBLE "
+ "AL_EXT_EXPONENT_DISTANCE "
+ "AL_EXT_FLOAT32 "
+ "AL_EXT_IMA4 "
+ "AL_EXT_LINEAR_DISTANCE "
+ "AL_EXT_MCFORMATS "
+ "AL_EXT_MULAW "
+ "AL_EXT_MULAW_BFORMAT "
+ "AL_EXT_MULAW_MCFORMATS "
+ "AL_EXT_OFFSET "
+ "AL_EXT_source_distance_model "
+ "AL_EXT_SOURCE_RADIUS "
+ "AL_EXT_STEREO_ANGLES "
+ "AL_LOKI_quadriphonic "
+ "AL_SOFT_block_alignment "
+ "AL_SOFT_deferred_updates "
+ "AL_SOFT_direct_channels "
+ "AL_SOFTX_events "
+ "AL_SOFTX_filter_gain_ex "
+ "AL_SOFT_gain_clamp_ex "
+ "AL_SOFT_loop_points "
+ "AL_SOFTX_map_buffer "
+ "AL_SOFT_MSADPCM "
+ "AL_SOFT_source_latency "
+ "AL_SOFT_source_length "
+ "AL_SOFT_source_resampler "
+ "AL_SOFT_source_spatialize";
static ATOMIC(ALCenum) LastNullDeviceError = ATOMIC_INIT_STATIC(ALC_NO_ERROR);
@@ -755,8 +779,8 @@ static const ALCchar alcNoDeviceExtList[] =
static const ALCchar alcExtensionList[] =
"ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
"ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX "
- "ALC_EXT_thread_local_context ALC_SOFTX_device_clock ALC_SOFT_HRTF "
- "ALC_SOFT_loopback ALC_SOFT_pause_device";
+ "ALC_EXT_thread_local_context ALC_SOFT_device_clock ALC_SOFT_HRTF "
+ "ALC_SOFT_loopback ALC_SOFT_output_limiter ALC_SOFT_pause_device";
static const ALCint alcMajorVersion = 1;
static const ALCint alcMinorVersion = 1;
@@ -772,13 +796,13 @@ static ATOMIC(ALCdevice*) DeviceList = ATOMIC_INIT_STATIC(NULL);
static almtx_t ListLock;
static inline void LockLists(void)
{
- int lockret = almtx_lock(&ListLock);
- assert(lockret == althrd_success);
+ int ret = almtx_lock(&ListLock);
+ assert(ret == althrd_success);
}
static inline void UnlockLists(void)
{
- int unlockret = almtx_unlock(&ListLock);
- assert(unlockret == althrd_success);
+ int ret = almtx_unlock(&ListLock);
+ assert(ret == althrd_success);
}
/************************************************
@@ -802,6 +826,7 @@ BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD reason, LPVOID lpReserved)
break;
case DLL_THREAD_DETACH:
+ althrd_thread_detach();
break;
case DLL_PROCESS_DETACH:
@@ -864,19 +889,21 @@ static void alc_init(void)
if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
ZScale *= -1.0f;
+ str = getenv("__ALSOFT_REVERB_IGNORES_SOUND_SPEED");
+ if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
+ OverrideReverbSpeedOfSound = AL_TRUE;
+
ret = altss_create(&LocalContext, ReleaseThreadCtx);
assert(ret == althrd_success);
ret = almtx_init(&ListLock, almtx_recursive);
assert(ret == althrd_success);
-
- ThunkInit();
}
static void alc_initconfig(void)
{
const char *devs, *str;
- ALuint capfilter;
+ int capfilter;
float valf;
int i, n;
@@ -896,10 +923,15 @@ static void alc_initconfig(void)
else ERR("Failed to open log file '%s'\n", str);
}
+ TRACE("Initializing library v%s-%s %s\n", ALSOFT_VERSION,
+ ALSOFT_GIT_COMMIT_HASH, ALSOFT_GIT_BRANCH);
{
char buf[1024] = "";
- int len = snprintf(buf, sizeof(buf), "%s", BackendList[0].name);
- for(i = 1;BackendList[i].name;i++)
+ int len = 0;
+
+ if(BackendListSize > 0)
+ len += snprintf(buf, sizeof(buf), "%s", BackendList[0].name);
+ for(i = 1;i < BackendListSize;i++)
len += snprintf(buf+len, sizeof(buf)-len, ", %s", BackendList[i].name);
TRACE("Supported backends: %s\n", buf);
}
@@ -975,6 +1007,7 @@ static void alc_initconfig(void)
#endif
ConfigValueInt(NULL, NULL, "rt-prio", &RTPrioLevel);
+ aluInit();
aluInitMixer();
str = getenv("ALSOFT_TRAP_ERROR");
@@ -999,8 +1032,6 @@ static void alc_initconfig(void)
if(ConfigValueFloat(NULL, "reverb", "boost", &valf))
ReverbBoost *= powf(10.0f, valf / 20.0f);
- EmulateEAXReverb = GetConfigValueBool(NULL, "reverb", "emulate-eax", AL_FALSE);
-
if(((devs=getenv("ALSOFT_DRIVERS")) && devs[0]) ||
ConfigValueStr(NULL, NULL, "drivers", &devs))
{
@@ -1029,26 +1060,32 @@ static void alc_initconfig(void)
len = (next ? ((size_t)(next-devs)) : strlen(devs));
while(len > 0 && isspace(devs[len-1]))
len--;
- for(n = i;BackendList[n].name;n++)
+#ifdef HAVE_WASAPI
+ /* HACK: For backwards compatibility, convert backend references of
+ * mmdevapi to wasapi. This should eventually be removed.
+ */
+ if(len == 8 && strncmp(devs, "mmdevapi", len) == 0)
+ {
+ devs = "wasapi";
+ len = 6;
+ }
+#endif
+ for(n = i;n < BackendListSize;n++)
{
if(len == strlen(BackendList[n].name) &&
strncmp(BackendList[n].name, devs, len) == 0)
{
if(delitem)
{
- do {
+ for(;n+1 < BackendListSize;n++)
BackendList[n] = BackendList[n+1];
- ++n;
- } while(BackendList[n].name);
+ BackendListSize--;
}
else
{
struct BackendInfo Bkp = BackendList[n];
- while(n > i)
- {
+ for(;n > i;n--)
BackendList[n] = BackendList[n-1];
- --n;
- }
BackendList[n] = Bkp;
i++;
@@ -1059,64 +1096,46 @@ static void alc_initconfig(void)
} while(next++);
if(endlist)
- {
- BackendList[i].name = NULL;
- BackendList[i].getFactory = NULL;
- BackendList[i].Init = NULL;
- BackendList[i].Deinit = NULL;
- BackendList[i].Probe = NULL;
- }
+ BackendListSize = i;
}
- for(i = 0;(BackendList[i].Init || BackendList[i].getFactory) && (!PlaybackBackend.name || !CaptureBackend.name);i++)
+ for(n = i = 0;i < BackendListSize && (!PlaybackBackend.name || !CaptureBackend.name);i++)
{
- if(BackendList[i].getFactory)
- {
- ALCbackendFactory *factory = BackendList[i].getFactory();
- if(!V0(factory,init)())
- {
- WARN("Failed to initialize backend \"%s\"\n", BackendList[i].name);
- continue;
- }
-
- TRACE("Initialized backend \"%s\"\n", BackendList[i].name);
- if(!PlaybackBackend.name && V(factory,querySupport)(ALCbackend_Playback))
- {
- PlaybackBackend = BackendList[i];
- TRACE("Added \"%s\" for playback\n", PlaybackBackend.name);
- }
- if(!CaptureBackend.name && V(factory,querySupport)(ALCbackend_Capture))
- {
- CaptureBackend = BackendList[i];
- TRACE("Added \"%s\" for capture\n", CaptureBackend.name);
- }
+ ALCbackendFactory *factory;
+ BackendList[n] = BackendList[i];
- continue;
- }
-
- if(!BackendList[i].Init(&BackendList[i].Funcs))
+ factory = BackendList[n].getFactory();
+ if(!V0(factory,init)())
{
- WARN("Failed to initialize backend \"%s\"\n", BackendList[i].name);
+ WARN("Failed to initialize backend \"%s\"\n", BackendList[n].name);
continue;
}
- TRACE("Initialized backend \"%s\"\n", BackendList[i].name);
- if(BackendList[i].Funcs.OpenPlayback && !PlaybackBackend.name)
+ TRACE("Initialized backend \"%s\"\n", BackendList[n].name);
+ if(!PlaybackBackend.name && V(factory,querySupport)(ALCbackend_Playback))
{
- PlaybackBackend = BackendList[i];
+ PlaybackBackend = BackendList[n];
TRACE("Added \"%s\" for playback\n", PlaybackBackend.name);
}
- if(BackendList[i].Funcs.OpenCapture && !CaptureBackend.name)
+ if(!CaptureBackend.name && V(factory,querySupport)(ALCbackend_Capture))
{
- CaptureBackend = BackendList[i];
+ CaptureBackend = BackendList[n];
TRACE("Added \"%s\" for capture\n", CaptureBackend.name);
}
+ n++;
}
+ BackendListSize = n;
+
{
ALCbackendFactory *factory = ALCloopbackFactory_getFactory();
V0(factory,init)();
}
+ if(!PlaybackBackend.name)
+ WARN("No playback backend available!\n");
+ if(!CaptureBackend.name)
+ WARN("No capture backend available!\n");
+
if(ConfigValueStr(NULL, NULL, "excludefx", &str))
{
size_t len;
@@ -1130,7 +1149,7 @@ static void alc_initconfig(void)
continue;
len = (next ? ((size_t)(next-str)) : strlen(str));
- for(n = 0;EffectList[n].name;n++)
+ for(n = 0;n < EFFECTLIST_SIZE;n++)
{
if(len == strlen(EffectList[n].name) &&
strncmp(EffectList[n].name, str, len) == 0)
@@ -1139,8 +1158,6 @@ static void alc_initconfig(void)
} while(next++);
}
- InitEffectFactoryMap();
-
InitEffect(&DefaultEffect);
str = getenv("ALSOFT_DEFAULT_REVERB");
if((str && str[0]) || ConfigValueStr(NULL, NULL, "default-reverb", &str))
@@ -1164,16 +1181,15 @@ static void alc_cleanup(void)
free(alcCaptureDefaultDeviceSpecifier);
alcCaptureDefaultDeviceSpecifier = NULL;
- if((dev=ATOMIC_EXCHANGE(ALCdevice*, &DeviceList, NULL)) != NULL)
+ if((dev=ATOMIC_EXCHANGE_PTR_SEQ(&DeviceList, NULL)) != NULL)
{
ALCuint num = 0;
do {
num++;
- } while((dev=dev->next) != NULL);
+ dev = ATOMIC_LOAD(&dev->next, almemory_order_relaxed);
+ } while(dev != NULL);
ERR("%u device%s not closed\n", num, (num>1)?"s":"");
}
-
- DeinitEffectFactoryMap();
}
static void alc_deinit_safe(void)
@@ -1183,13 +1199,14 @@ static void alc_deinit_safe(void)
FreeHrtfs();
FreeALConfig();
- ThunkExit();
almtx_destroy(&ListLock);
altss_delete(LocalContext);
if(LogFile != stderr)
fclose(LogFile);
LogFile = NULL;
+
+ althrd_deinit();
}
static void alc_deinit(void)
@@ -1201,15 +1218,10 @@ static void alc_deinit(void)
memset(&PlaybackBackend, 0, sizeof(PlaybackBackend));
memset(&CaptureBackend, 0, sizeof(CaptureBackend));
- for(i = 0;BackendList[i].Deinit || BackendList[i].getFactory;i++)
+ for(i = 0;i < BackendListSize;i++)
{
- if(!BackendList[i].getFactory)
- BackendList[i].Deinit();
- else
- {
- ALCbackendFactory *factory = BackendList[i].getFactory();
- V0(factory,deinit)();
- }
+ ALCbackendFactory *factory = BackendList[i].getFactory();
+ V0(factory,deinit)();
}
{
ALCbackendFactory *factory = ALCloopbackFactory_getFactory();
@@ -1228,14 +1240,12 @@ static void ProbeDevices(al_string *list, struct BackendInfo *backendinfo, enum
DO_INITCONFIG();
LockLists();
- al_string_clear(list);
+ alstr_clear(list);
- if(!backendinfo->getFactory)
- backendinfo->Probe(type);
- else
+ if(backendinfo->getFactory)
{
ALCbackendFactory *factory = backendinfo->getFactory();
- V(factory,probe)(type);
+ V(factory,probe)(type, list);
}
UnlockLists();
@@ -1245,17 +1255,6 @@ static void ProbeAllDevicesList(void)
static void ProbeCaptureDeviceList(void)
{ ProbeDevices(&alcCaptureDeviceList, &CaptureBackend, CAPTURE_DEVICE_PROBE); }
-static void AppendDevice(const ALCchar *name, al_string *devnames)
-{
- size_t len = strlen(name);
- if(len > 0)
- al_string_append_range(devnames, name, name+len+1);
-}
-void AppendAllDevicesList(const ALCchar *name)
-{ AppendDevice(name, &alcAllDevicesList); }
-void AppendCaptureDeviceList(const ALCchar *name)
-{ AppendDevice(name, &alcCaptureDeviceList); }
-
/************************************************
* Device format information
@@ -1285,13 +1284,13 @@ const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans)
case DevFmtX51Rear: return "5.1 Surround (Rear)";
case DevFmtX61: return "6.1 Surround";
case DevFmtX71: return "7.1 Surround";
- case DevFmtBFormat3D: return "B-Format 3D";
+ case DevFmtAmbi3D: return "Ambisonic 3D";
}
return "(unknown channels)";
}
-extern inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans, enum DevFmtType type);
-ALuint BytesFromDevFmt(enum DevFmtType type)
+extern inline ALsizei FrameSizeFromDevFmt(enum DevFmtChannels chans, enum DevFmtType type, ALsizei ambiorder);
+ALsizei BytesFromDevFmt(enum DevFmtType type)
{
switch(type)
{
@@ -1305,7 +1304,7 @@ ALuint BytesFromDevFmt(enum DevFmtType type)
}
return 0;
}
-ALuint ChannelsFromDevFmt(enum DevFmtChannels chans)
+ALsizei ChannelsFromDevFmt(enum DevFmtChannels chans, ALsizei ambiorder)
{
switch(chans)
{
@@ -1316,13 +1315,15 @@ ALuint ChannelsFromDevFmt(enum DevFmtChannels chans)
case DevFmtX51Rear: return 6;
case DevFmtX61: return 7;
case DevFmtX71: return 8;
- case DevFmtBFormat3D: return 4;
+ case DevFmtAmbi3D: return (ambiorder >= 3) ? 16 :
+ (ambiorder == 2) ? 9 :
+ (ambiorder == 1) ? 4 : 1;
}
return 0;
}
-DECL_CONST static ALboolean DecomposeDevFormat(ALenum format,
- enum DevFmtChannels *chans, enum DevFmtType *type)
+static ALboolean DecomposeDevFormat(ALenum format, enum DevFmtChannels *chans,
+ enum DevFmtType *type)
{
static const struct {
ALenum format;
@@ -1368,7 +1369,7 @@ DECL_CONST static ALboolean DecomposeDevFormat(ALenum format,
return AL_FALSE;
}
-DECL_CONST static ALCboolean IsValidALCType(ALCenum type)
+static ALCboolean IsValidALCType(ALCenum type)
{
switch(type)
{
@@ -1384,7 +1385,7 @@ DECL_CONST static ALCboolean IsValidALCType(ALCenum type)
return ALC_FALSE;
}
-DECL_CONST static ALCboolean IsValidALCChannels(ALCenum channels)
+static ALCboolean IsValidALCChannels(ALCenum channels)
{
switch(channels)
{
@@ -1394,34 +1395,38 @@ DECL_CONST static ALCboolean IsValidALCChannels(ALCenum channels)
case ALC_5POINT1_SOFT:
case ALC_6POINT1_SOFT:
case ALC_7POINT1_SOFT:
+ case ALC_BFORMAT3D_SOFT:
return ALC_TRUE;
}
return ALC_FALSE;
}
-
-/************************************************
- * Miscellaneous ALC helpers
- ************************************************/
-enum HrtfRequestMode {
- Hrtf_Default = 0,
- Hrtf_Enable = 1,
- Hrtf_Disable = 2,
-};
-
-extern inline void LockContext(ALCcontext *context);
-extern inline void UnlockContext(ALCcontext *context);
-
-void ALCdevice_Lock(ALCdevice *device)
+static ALCboolean IsValidAmbiLayout(ALCenum layout)
{
- V0(device->Backend,lock)();
+ switch(layout)
+ {
+ case ALC_ACN_SOFT:
+ case ALC_FUMA_SOFT:
+ return ALC_TRUE;
+ }
+ return ALC_FALSE;
}
-void ALCdevice_Unlock(ALCdevice *device)
+static ALCboolean IsValidAmbiScaling(ALCenum scaling)
{
- V0(device->Backend,unlock)();
+ switch(scaling)
+ {
+ case ALC_N3D_SOFT:
+ case ALC_SN3D_SOFT:
+ case ALC_FUMA_SOFT:
+ return ALC_TRUE;
+ }
+ return ALC_FALSE;
}
+/************************************************
+ * Miscellaneous ALC helpers
+ ************************************************/
/* SetDefaultWFXChannelOrder
*
@@ -1429,66 +1434,87 @@ void ALCdevice_Unlock(ALCdevice *device)
*/
void SetDefaultWFXChannelOrder(ALCdevice *device)
{
- ALuint i;
+ ALsizei i;
for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
- device->ChannelName[i] = InvalidChannel;
+ device->RealOut.ChannelName[i] = InvalidChannel;
switch(device->FmtChans)
{
case DevFmtMono:
- device->ChannelName[0] = FrontCenter;
+ device->RealOut.ChannelName[0] = FrontCenter;
break;
case DevFmtStereo:
- device->ChannelName[0] = FrontLeft;
- device->ChannelName[1] = FrontRight;
+ device->RealOut.ChannelName[0] = FrontLeft;
+ device->RealOut.ChannelName[1] = FrontRight;
break;
case DevFmtQuad:
- device->ChannelName[0] = FrontLeft;
- device->ChannelName[1] = FrontRight;
- device->ChannelName[2] = BackLeft;
- device->ChannelName[3] = BackRight;
+ device->RealOut.ChannelName[0] = FrontLeft;
+ device->RealOut.ChannelName[1] = FrontRight;
+ device->RealOut.ChannelName[2] = BackLeft;
+ device->RealOut.ChannelName[3] = BackRight;
break;
case DevFmtX51:
- device->ChannelName[0] = FrontLeft;
- device->ChannelName[1] = FrontRight;
- device->ChannelName[2] = FrontCenter;
- device->ChannelName[3] = LFE;
- device->ChannelName[4] = SideLeft;
- device->ChannelName[5] = SideRight;
+ device->RealOut.ChannelName[0] = FrontLeft;
+ device->RealOut.ChannelName[1] = FrontRight;
+ device->RealOut.ChannelName[2] = FrontCenter;
+ device->RealOut.ChannelName[3] = LFE;
+ device->RealOut.ChannelName[4] = SideLeft;
+ device->RealOut.ChannelName[5] = SideRight;
break;
case DevFmtX51Rear:
- device->ChannelName[0] = FrontLeft;
- device->ChannelName[1] = FrontRight;
- device->ChannelName[2] = FrontCenter;
- device->ChannelName[3] = LFE;
- device->ChannelName[4] = BackLeft;
- device->ChannelName[5] = BackRight;
+ device->RealOut.ChannelName[0] = FrontLeft;
+ device->RealOut.ChannelName[1] = FrontRight;
+ device->RealOut.ChannelName[2] = FrontCenter;
+ device->RealOut.ChannelName[3] = LFE;
+ device->RealOut.ChannelName[4] = BackLeft;
+ device->RealOut.ChannelName[5] = BackRight;
break;
case DevFmtX61:
- device->ChannelName[0] = FrontLeft;
- device->ChannelName[1] = FrontRight;
- device->ChannelName[2] = FrontCenter;
- device->ChannelName[3] = LFE;
- device->ChannelName[4] = BackCenter;
- device->ChannelName[5] = SideLeft;
- device->ChannelName[6] = SideRight;
+ device->RealOut.ChannelName[0] = FrontLeft;
+ device->RealOut.ChannelName[1] = FrontRight;
+ device->RealOut.ChannelName[2] = FrontCenter;
+ device->RealOut.ChannelName[3] = LFE;
+ device->RealOut.ChannelName[4] = BackCenter;
+ device->RealOut.ChannelName[5] = SideLeft;
+ device->RealOut.ChannelName[6] = SideRight;
break;
case DevFmtX71:
- device->ChannelName[0] = FrontLeft;
- device->ChannelName[1] = FrontRight;
- device->ChannelName[2] = FrontCenter;
- device->ChannelName[3] = LFE;
- device->ChannelName[4] = BackLeft;
- device->ChannelName[5] = BackRight;
- device->ChannelName[6] = SideLeft;
- device->ChannelName[7] = SideRight;
+ device->RealOut.ChannelName[0] = FrontLeft;
+ device->RealOut.ChannelName[1] = FrontRight;
+ device->RealOut.ChannelName[2] = FrontCenter;
+ device->RealOut.ChannelName[3] = LFE;
+ device->RealOut.ChannelName[4] = BackLeft;
+ device->RealOut.ChannelName[5] = BackRight;
+ device->RealOut.ChannelName[6] = SideLeft;
+ device->RealOut.ChannelName[7] = SideRight;
break;
- case DevFmtBFormat3D:
- device->ChannelName[0] = BFormatW;
- device->ChannelName[1] = BFormatX;
- device->ChannelName[2] = BFormatY;
- device->ChannelName[3] = BFormatZ;
+ case DevFmtAmbi3D:
+ device->RealOut.ChannelName[0] = Aux0;
+ if(device->AmbiOrder > 0)
+ {
+ device->RealOut.ChannelName[1] = Aux1;
+ device->RealOut.ChannelName[2] = Aux2;
+ device->RealOut.ChannelName[3] = Aux3;
+ }
+ if(device->AmbiOrder > 1)
+ {
+ device->RealOut.ChannelName[4] = Aux4;
+ device->RealOut.ChannelName[5] = Aux5;
+ device->RealOut.ChannelName[6] = Aux6;
+ device->RealOut.ChannelName[7] = Aux7;
+ device->RealOut.ChannelName[8] = Aux8;
+ }
+ if(device->AmbiOrder > 2)
+ {
+ device->RealOut.ChannelName[9] = Aux9;
+ device->RealOut.ChannelName[10] = Aux10;
+ device->RealOut.ChannelName[11] = Aux11;
+ device->RealOut.ChannelName[12] = Aux12;
+ device->RealOut.ChannelName[13] = Aux13;
+ device->RealOut.ChannelName[14] = Aux14;
+ device->RealOut.ChannelName[15] = Aux15;
+ }
break;
}
}
@@ -1499,30 +1525,30 @@ void SetDefaultWFXChannelOrder(ALCdevice *device)
*/
void SetDefaultChannelOrder(ALCdevice *device)
{
- ALuint i;
+ ALsizei i;
for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
- device->ChannelName[i] = InvalidChannel;
+ device->RealOut.ChannelName[i] = InvalidChannel;
switch(device->FmtChans)
{
case DevFmtX51Rear:
- device->ChannelName[0] = FrontLeft;
- device->ChannelName[1] = FrontRight;
- device->ChannelName[2] = BackLeft;
- device->ChannelName[3] = BackRight;
- device->ChannelName[4] = FrontCenter;
- device->ChannelName[5] = LFE;
+ device->RealOut.ChannelName[0] = FrontLeft;
+ device->RealOut.ChannelName[1] = FrontRight;
+ device->RealOut.ChannelName[2] = BackLeft;
+ device->RealOut.ChannelName[3] = BackRight;
+ device->RealOut.ChannelName[4] = FrontCenter;
+ device->RealOut.ChannelName[5] = LFE;
return;
case DevFmtX71:
- device->ChannelName[0] = FrontLeft;
- device->ChannelName[1] = FrontRight;
- device->ChannelName[2] = BackLeft;
- device->ChannelName[3] = BackRight;
- device->ChannelName[4] = FrontCenter;
- device->ChannelName[5] = LFE;
- device->ChannelName[6] = SideLeft;
- device->ChannelName[7] = SideRight;
+ device->RealOut.ChannelName[0] = FrontLeft;
+ device->RealOut.ChannelName[1] = FrontRight;
+ device->RealOut.ChannelName[2] = BackLeft;
+ device->RealOut.ChannelName[3] = BackRight;
+ device->RealOut.ChannelName[4] = FrontCenter;
+ device->RealOut.ChannelName[5] = LFE;
+ device->RealOut.ChannelName[6] = SideLeft;
+ device->RealOut.ChannelName[7] = SideRight;
return;
/* Same as WFX order */
@@ -1531,13 +1557,14 @@ void SetDefaultChannelOrder(ALCdevice *device)
case DevFmtQuad:
case DevFmtX51:
case DevFmtX61:
- case DevFmtBFormat3D:
+ case DevFmtAmbi3D:
SetDefaultWFXChannelOrder(device);
break;
}
}
-extern inline ALint GetChannelIdxByName(const ALCdevice *device, enum Channel chan);
+extern inline ALint GetChannelIndex(const enum Channel names[MAX_OUTPUT_CHANNELS], enum Channel chan);
+extern inline ALint GetChannelIdxByName(const RealMixParams *real, enum Channel chan);
/* ALCcontext_DeferUpdates
@@ -1548,28 +1575,7 @@ extern inline ALint GetChannelIdxByName(const ALCdevice *device, enum Channel ch
*/
void ALCcontext_DeferUpdates(ALCcontext *context)
{
- ALCdevice *device = context->Device;
- FPUCtl oldMode;
-
- SetMixerFPUMode(&oldMode);
-
- V0(device->Backend,lock)();
- if(!context->DeferUpdates)
- {
- context->DeferUpdates = AL_TRUE;
-
- /* Make sure all pending updates are performed */
- UpdateContextSources(context);
-#define UPDATE_SLOT(iter) do { \
- if(ATOMIC_EXCHANGE(ALenum, &(*iter)->NeedsUpdate, AL_FALSE)) \
- V((*iter)->EffectState,update)(device, *iter); \
-} while(0)
- VECTOR_FOR_EACH(ALeffectslot*, context->ActiveAuxSlots, UPDATE_SLOT);
-#undef UPDATE_SLOT
- }
- V0(device->Backend,unlock)();
-
- RestoreFPUMode(&oldMode);
+ ATOMIC_STORE_SEQ(&context->DeferUpdates, AL_TRUE);
}
/* ALCcontext_ProcessUpdates
@@ -1578,37 +1584,29 @@ void ALCcontext_DeferUpdates(ALCcontext *context)
*/
void ALCcontext_ProcessUpdates(ALCcontext *context)
{
- ALCdevice *device = context->Device;
-
- V0(device->Backend,lock)();
- if(context->DeferUpdates)
+ almtx_lock(&context->PropLock);
+ if(ATOMIC_EXCHANGE_SEQ(&context->DeferUpdates, AL_FALSE))
{
- ALsizei pos;
-
- context->DeferUpdates = AL_FALSE;
-
- LockUIntMapRead(&context->SourceMap);
- for(pos = 0;pos < context->SourceMap.size;pos++)
- {
- ALsource *Source = context->SourceMap.array[pos].value;
- ALenum new_state;
-
- if((Source->state == AL_PLAYING || Source->state == AL_PAUSED) &&
- Source->Offset >= 0.0)
- {
- WriteLock(&Source->queue_lock);
- ApplyOffset(Source);
- WriteUnlock(&Source->queue_lock);
- }
-
- new_state = Source->new_state;
- Source->new_state = AL_NONE;
- if(new_state)
- SetSourceState(Source, context, new_state);
- }
- UnlockUIntMapRead(&context->SourceMap);
+ /* Tell the mixer to stop applying updates, then wait for any active
+ * updating to finish, before providing updates.
+ */
+ ATOMIC_STORE_SEQ(&context->HoldUpdates, AL_TRUE);
+ while((ATOMIC_LOAD(&context->UpdateCount, almemory_order_acquire)&1) != 0)
+ althrd_yield();
+
+ if(!ATOMIC_FLAG_TEST_AND_SET(&context->PropsClean, almemory_order_acq_rel))
+ UpdateContextProps(context);
+ if(!ATOMIC_FLAG_TEST_AND_SET(&context->Listener->PropsClean, almemory_order_acq_rel))
+ UpdateListenerProps(context);
+ UpdateAllEffectSlotProps(context);
+ UpdateAllSourceProps(context);
+
+ /* Now with all updates declared, let the mixer continue applying them
+ * so they all happen at once.
+ */
+ ATOMIC_STORE_SEQ(&context->HoldUpdates, AL_FALSE);
}
- V0(device->Backend,unlock)();
+ almtx_unlock(&context->PropLock);
}
@@ -1618,6 +1616,7 @@ void ALCcontext_ProcessUpdates(ALCcontext *context)
*/
static void alcSetError(ALCdevice *device, ALCenum errorCode)
{
+ WARN("Error generated on device %p, code 0x%04x\n", device, errorCode);
if(TrapALCError)
{
#ifdef _WIN32
@@ -1630,22 +1629,32 @@ static void alcSetError(ALCdevice *device, ALCenum errorCode)
}
if(device)
- ATOMIC_STORE(&device->LastError, errorCode);
+ ATOMIC_STORE_SEQ(&device->LastError, errorCode);
else
- ATOMIC_STORE(&LastNullDeviceError, errorCode);
+ ATOMIC_STORE_SEQ(&LastNullDeviceError, errorCode);
}
+static struct Compressor *CreateDeviceLimiter(const ALCdevice *device, const ALfloat threshold)
+{
+ return CompressorInit(device->RealOut.NumChannels, device->Frequency,
+ AL_TRUE, AL_TRUE, AL_TRUE, AL_TRUE, AL_TRUE, 0.001f, 0.002f,
+ 0.0f, 0.0f, threshold, INFINITY, 0.0f, 0.020f, 0.200f);
+}
+
/* UpdateClockBase
*
* Updates the device's base clock time with however many samples have been
* done. This is used so frequency changes on the device don't cause the time
- * to jump forward or back.
+ * to jump forward or back. Must not be called while the device is running/
+ * mixing.
*/
static inline void UpdateClockBase(ALCdevice *device)
{
+ IncrementRef(&device->MixCount);
device->ClockBase += device->SamplesDone * DEVICE_CLOCK_RES / device->Frequency;
device->SamplesDone = 0;
+ IncrementRef(&device->MixCount);
}
/* UpdateDeviceParams
@@ -1655,30 +1664,32 @@ static inline void UpdateClockBase(ALCdevice *device)
*/
static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
{
- ALCcontext *context;
- enum HrtfRequestMode hrtf_appreq = Hrtf_Default;
enum HrtfRequestMode hrtf_userreq = Hrtf_Default;
+ enum HrtfRequestMode hrtf_appreq = Hrtf_Default;
+ ALCenum gainLimiter = device->LimiterState;
+ const ALsizei old_sends = device->NumAuxSends;
+ ALsizei new_sends = device->NumAuxSends;
enum DevFmtChannels oldChans;
enum DevFmtType oldType;
- ALCuint oldFreq;
- FPUCtl oldMode;
+ ALboolean update_failed;
ALCsizei hrtf_id = -1;
+ ALCcontext *context;
+ ALCuint oldFreq;
size_t size;
+ ALCsizei i;
+ int val;
// Check for attributes
if(device->Type == Loopback)
{
- enum {
- GotFreq = 1<<0,
- GotChans = 1<<1,
- GotType = 1<<2,
- GotAll = GotFreq|GotChans|GotType
- };
- ALCuint freq, numMono, numStereo, numSends;
- enum DevFmtChannels schans;
- enum DevFmtType stype;
- ALCuint attrIdx = 0;
- ALCint gotFmt = 0;
+ ALCsizei numMono, numStereo, numSends;
+ ALCenum alayout = AL_NONE;
+ ALCenum ascale = AL_NONE;
+ ALCenum schans = AL_NONE;
+ ALCenum stype = AL_NONE;
+ ALCsizei attrIdx = 0;
+ ALCsizei aorder = 0;
+ ALCuint freq = 0;
if(!attrList)
{
@@ -1688,75 +1699,113 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
numMono = device->NumMonoSources;
numStereo = device->NumStereoSources;
- numSends = device->NumAuxSends;
- schans = device->FmtChans;
- stype = device->FmtType;
- freq = device->Frequency;
+ numSends = old_sends;
+#define TRACE_ATTR(a, v) TRACE("Loopback %s = %d\n", #a, v)
while(attrList[attrIdx])
{
- if(attrList[attrIdx] == ALC_FORMAT_CHANNELS_SOFT)
+ switch(attrList[attrIdx])
{
- ALCint val = attrList[attrIdx + 1];
- if(!IsValidALCChannels(val) || !ChannelsFromDevFmt(val))
- return ALC_INVALID_VALUE;
- schans = val;
- gotFmt |= GotChans;
- }
+ case ALC_FORMAT_CHANNELS_SOFT:
+ schans = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_FORMAT_CHANNELS_SOFT, schans);
+ if(!IsValidALCChannels(schans))
+ return ALC_INVALID_VALUE;
+ break;
- if(attrList[attrIdx] == ALC_FORMAT_TYPE_SOFT)
- {
- ALCint val = attrList[attrIdx + 1];
- if(!IsValidALCType(val) || !BytesFromDevFmt(val))
- return ALC_INVALID_VALUE;
- stype = val;
- gotFmt |= GotType;
- }
+ case ALC_FORMAT_TYPE_SOFT:
+ stype = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_FORMAT_TYPE_SOFT, stype);
+ if(!IsValidALCType(stype))
+ return ALC_INVALID_VALUE;
+ break;
- if(attrList[attrIdx] == ALC_FREQUENCY)
- {
- freq = attrList[attrIdx + 1];
- if(freq < MIN_OUTPUT_RATE)
- return ALC_INVALID_VALUE;
- gotFmt |= GotFreq;
- }
+ case ALC_FREQUENCY:
+ freq = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_FREQUENCY, freq);
+ if(freq < MIN_OUTPUT_RATE)
+ return ALC_INVALID_VALUE;
+ break;
- if(attrList[attrIdx] == ALC_STEREO_SOURCES)
- {
- numStereo = attrList[attrIdx + 1];
- if(numStereo > device->MaxNoOfSources)
- numStereo = device->MaxNoOfSources;
+ case ALC_AMBISONIC_LAYOUT_SOFT:
+ alayout = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_AMBISONIC_LAYOUT_SOFT, alayout);
+ if(!IsValidAmbiLayout(alayout))
+ return ALC_INVALID_VALUE;
+ break;
- numMono = device->MaxNoOfSources - numStereo;
- }
+ case ALC_AMBISONIC_SCALING_SOFT:
+ ascale = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_AMBISONIC_SCALING_SOFT, ascale);
+ if(!IsValidAmbiScaling(ascale))
+ return ALC_INVALID_VALUE;
+ break;
- if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS)
- numSends = attrList[attrIdx + 1];
+ case ALC_AMBISONIC_ORDER_SOFT:
+ aorder = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_AMBISONIC_ORDER_SOFT, aorder);
+ if(aorder < 1 || aorder > MAX_AMBI_ORDER)
+ return ALC_INVALID_VALUE;
+ break;
- if(attrList[attrIdx] == ALC_HRTF_SOFT)
- {
- if(attrList[attrIdx + 1] == ALC_FALSE)
- hrtf_appreq = Hrtf_Disable;
- else if(attrList[attrIdx + 1] == ALC_TRUE)
- hrtf_appreq = Hrtf_Enable;
- else
- hrtf_appreq = Hrtf_Default;
- }
+ case ALC_MONO_SOURCES:
+ numMono = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_MONO_SOURCES, numMono);
+ numMono = maxi(numMono, 0);
+ break;
+
+ case ALC_STEREO_SOURCES:
+ numStereo = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_STEREO_SOURCES, numStereo);
+ numStereo = maxi(numStereo, 0);
+ break;
+
+ case ALC_MAX_AUXILIARY_SENDS:
+ numSends = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_MAX_AUXILIARY_SENDS, numSends);
+ numSends = clampi(numSends, 0, MAX_SENDS);
+ break;
+
+ case ALC_HRTF_SOFT:
+ TRACE_ATTR(ALC_HRTF_SOFT, attrList[attrIdx + 1]);
+ if(attrList[attrIdx + 1] == ALC_FALSE)
+ hrtf_appreq = Hrtf_Disable;
+ else if(attrList[attrIdx + 1] == ALC_TRUE)
+ hrtf_appreq = Hrtf_Enable;
+ else
+ hrtf_appreq = Hrtf_Default;
+ break;
- if(attrList[attrIdx] == ALC_HRTF_ID_SOFT)
- hrtf_id = attrList[attrIdx + 1];
+ case ALC_HRTF_ID_SOFT:
+ hrtf_id = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_HRTF_ID_SOFT, hrtf_id);
+ break;
+
+ case ALC_OUTPUT_LIMITER_SOFT:
+ gainLimiter = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_OUTPUT_LIMITER_SOFT, gainLimiter);
+ break;
+
+ default:
+ TRACE("Loopback 0x%04X = %d (0x%x)\n", attrList[attrIdx],
+ attrList[attrIdx + 1], attrList[attrIdx + 1]);
+ break;
+ }
attrIdx += 2;
}
+#undef TRACE_ATTR
- if(gotFmt != GotAll)
+ if(!schans || !stype || !freq)
{
WARN("Missing format for loopback device\n");
return ALC_INVALID_VALUE;
}
-
- ConfigValueUInt(NULL, NULL, "sends", &numSends);
- numSends = minu(MAX_SENDS, numSends);
+ if(schans == ALC_BFORMAT3D_SOFT && (!alayout || !ascale || !aorder))
+ {
+ WARN("Missing ambisonic info for loopback device\n");
+ return ALC_INVALID_VALUE;
+ }
if((device->Flags&DEVICE_RUNNING))
V0(device->Backend,stop)();
@@ -1767,14 +1816,40 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
device->Frequency = freq;
device->FmtChans = schans;
device->FmtType = stype;
+ if(schans == ALC_BFORMAT3D_SOFT)
+ {
+ device->AmbiOrder = aorder;
+ device->AmbiLayout = alayout;
+ device->AmbiScale = ascale;
+ }
+
+ if(numMono > INT_MAX-numStereo)
+ numMono = INT_MAX-numStereo;
+ numMono += numStereo;
+ if(ConfigValueInt(NULL, NULL, "sources", &numMono))
+ {
+ if(numMono <= 0)
+ numMono = 256;
+ }
+ else
+ numMono = maxi(numMono, 256);
+ numStereo = mini(numStereo, numMono);
+ numMono -= numStereo;
+ device->SourcesMax = numMono + numStereo;
+
device->NumMonoSources = numMono;
device->NumStereoSources = numStereo;
- device->NumAuxSends = numSends;
+
+ if(ConfigValueInt(NULL, NULL, "sends", &new_sends))
+ new_sends = mini(numSends, clampi(new_sends, 0, MAX_SENDS));
+ else
+ new_sends = numSends;
}
else if(attrList && attrList[0])
{
- ALCuint freq, numMono, numStereo, numSends;
- ALCuint attrIdx = 0;
+ ALCsizei numMono, numStereo, numSends;
+ ALCsizei attrIdx = 0;
+ ALCuint freq;
/* If a context is already running on the device, stop playback so the
* device attributes can be updated. */
@@ -1782,55 +1857,75 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
V0(device->Backend,stop)();
device->Flags &= ~DEVICE_RUNNING;
+ UpdateClockBase(device);
+
freq = device->Frequency;
numMono = device->NumMonoSources;
numStereo = device->NumStereoSources;
- numSends = device->NumAuxSends;
+ numSends = old_sends;
+#define TRACE_ATTR(a, v) TRACE("%s = %d\n", #a, v)
while(attrList[attrIdx])
{
- if(attrList[attrIdx] == ALC_FREQUENCY)
+ switch(attrList[attrIdx])
{
- freq = attrList[attrIdx + 1];
- device->Flags |= DEVICE_FREQUENCY_REQUEST;
- }
+ case ALC_FREQUENCY:
+ freq = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_FREQUENCY, freq);
+ device->Flags |= DEVICE_FREQUENCY_REQUEST;
+ break;
- if(attrList[attrIdx] == ALC_STEREO_SOURCES)
- {
- numStereo = attrList[attrIdx + 1];
- if(numStereo > device->MaxNoOfSources)
- numStereo = device->MaxNoOfSources;
+ case ALC_MONO_SOURCES:
+ numMono = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_MONO_SOURCES, numMono);
+ numMono = maxi(numMono, 0);
+ break;
- numMono = device->MaxNoOfSources - numStereo;
- }
+ case ALC_STEREO_SOURCES:
+ numStereo = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_STEREO_SOURCES, numStereo);
+ numStereo = maxi(numStereo, 0);
+ break;
- if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS)
- numSends = attrList[attrIdx + 1];
+ case ALC_MAX_AUXILIARY_SENDS:
+ numSends = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_MAX_AUXILIARY_SENDS, numSends);
+ numSends = clampi(numSends, 0, MAX_SENDS);
+ break;
- if(attrList[attrIdx] == ALC_HRTF_SOFT)
- {
- if(attrList[attrIdx + 1] == ALC_FALSE)
- hrtf_appreq = Hrtf_Disable;
- else if(attrList[attrIdx + 1] == ALC_TRUE)
- hrtf_appreq = Hrtf_Enable;
- else
- hrtf_appreq = Hrtf_Default;
- }
+ case ALC_HRTF_SOFT:
+ TRACE_ATTR(ALC_HRTF_SOFT, attrList[attrIdx + 1]);
+ if(attrList[attrIdx + 1] == ALC_FALSE)
+ hrtf_appreq = Hrtf_Disable;
+ else if(attrList[attrIdx + 1] == ALC_TRUE)
+ hrtf_appreq = Hrtf_Enable;
+ else
+ hrtf_appreq = Hrtf_Default;
+ break;
+
+ case ALC_HRTF_ID_SOFT:
+ hrtf_id = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_HRTF_ID_SOFT, hrtf_id);
+ break;
+
+ case ALC_OUTPUT_LIMITER_SOFT:
+ gainLimiter = attrList[attrIdx + 1];
+ TRACE_ATTR(ALC_OUTPUT_LIMITER_SOFT, gainLimiter);
+ break;
- if(attrList[attrIdx] == ALC_HRTF_ID_SOFT)
- hrtf_id = attrList[attrIdx + 1];
+ default:
+ TRACE("0x%04X = %d (0x%x)\n", attrList[attrIdx],
+ attrList[attrIdx + 1], attrList[attrIdx + 1]);
+ break;
+ }
attrIdx += 2;
}
+#undef TRACE_ATTR
- ConfigValueUInt(al_string_get_cstr(device->DeviceName), NULL, "frequency", &freq);
+ ConfigValueUInt(alstr_get_cstr(device->DeviceName), NULL, "frequency", &freq);
freq = maxu(freq, MIN_OUTPUT_RATE);
- ConfigValueUInt(al_string_get_cstr(device->DeviceName), NULL, "sends", &numSends);
- numSends = minu(MAX_SENDS, numSends);
-
- UpdateClockBase(device);
-
device->UpdateSize = (ALuint64)device->UpdateSize * freq /
device->Frequency;
/* SSE and Neon do best with the update size being a multiple of 4 */
@@ -1838,24 +1933,67 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
device->UpdateSize = (device->UpdateSize+3)&~3;
device->Frequency = freq;
+
+ if(numMono > INT_MAX-numStereo)
+ numMono = INT_MAX-numStereo;
+ numMono += numStereo;
+ if(ConfigValueInt(alstr_get_cstr(device->DeviceName), NULL, "sources", &numMono))
+ {
+ if(numMono <= 0)
+ numMono = 256;
+ }
+ else
+ numMono = maxi(numMono, 256);
+ numStereo = mini(numStereo, numMono);
+ numMono -= numStereo;
+ device->SourcesMax = numMono + numStereo;
+
device->NumMonoSources = numMono;
device->NumStereoSources = numStereo;
- device->NumAuxSends = numSends;
+
+ if(ConfigValueInt(alstr_get_cstr(device->DeviceName), NULL, "sends", &new_sends))
+ new_sends = mini(numSends, clampi(new_sends, 0, MAX_SENDS));
+ else
+ new_sends = numSends;
}
if((device->Flags&DEVICE_RUNNING))
return ALC_NO_ERROR;
- al_free(device->DryBuffer);
- device->DryBuffer = NULL;
+ al_free(device->Uhj_Encoder);
+ device->Uhj_Encoder = NULL;
+
+ al_free(device->Bs2b);
+ device->Bs2b = NULL;
+
+ al_free(device->ChannelDelay[0].Buffer);
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ {
+ device->ChannelDelay[i].Length = 0;
+ device->ChannelDelay[i].Buffer = NULL;
+ }
+
+ al_free(device->Dry.Buffer);
+ device->Dry.Buffer = NULL;
+ device->Dry.NumChannels = 0;
+ device->FOAOut.Buffer = NULL;
+ device->FOAOut.NumChannels = 0;
+ device->RealOut.Buffer = NULL;
+ device->RealOut.NumChannels = 0;
UpdateClockBase(device);
+ device->FixedLatency = 0;
+
+ device->DitherSeed = DITHER_RNG_SEED;
- device->Hrtf_Status = ALC_HRTF_DISABLED_SOFT;
+ /*************************************************************************
+ * Update device format request if HRTF is requested
+ */
+ device->HrtfStatus = ALC_HRTF_DISABLED_SOFT;
if(device->Type != Loopback)
{
const char *hrtf;
- if(ConfigValueStr(al_string_get_cstr(device->DeviceName), NULL, "hrtf", &hrtf))
+ if(ConfigValueStr(alstr_get_cstr(device->DeviceName), NULL, "hrtf", &hrtf))
{
if(strcasecmp(hrtf, "true") == 0)
hrtf_userreq = Hrtf_Enable;
@@ -1867,56 +2005,36 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
if(hrtf_userreq == Hrtf_Enable || (hrtf_userreq != Hrtf_Disable && hrtf_appreq == Hrtf_Enable))
{
- if(VECTOR_SIZE(device->Hrtf_List) == 0)
+ struct Hrtf *hrtf = NULL;
+ if(VECTOR_SIZE(device->HrtfList) == 0)
{
- VECTOR_DEINIT(device->Hrtf_List);
- device->Hrtf_List = EnumerateHrtf(device->DeviceName);
+ VECTOR_DEINIT(device->HrtfList);
+ device->HrtfList = EnumerateHrtf(device->DeviceName);
}
- if(VECTOR_SIZE(device->Hrtf_List) > 0)
+ if(VECTOR_SIZE(device->HrtfList) > 0)
{
- device->FmtChans = DevFmtStereo;
- if(hrtf_id >= 0 && (size_t)hrtf_id < VECTOR_SIZE(device->Hrtf_List))
- device->Frequency = GetHrtfSampleRate(VECTOR_ELEM(device->Hrtf_List, hrtf_id).hrtf);
+ if(hrtf_id >= 0 && (size_t)hrtf_id < VECTOR_SIZE(device->HrtfList))
+ hrtf = GetLoadedHrtf(VECTOR_ELEM(device->HrtfList, hrtf_id).hrtf);
else
- device->Frequency = GetHrtfSampleRate(VECTOR_ELEM(device->Hrtf_List, 0).hrtf);
- device->Flags |= DEVICE_CHANNELS_REQUEST | DEVICE_FREQUENCY_REQUEST;
- }
- else
- {
- hrtf_userreq = hrtf_appreq = Hrtf_Default;
- device->Hrtf_Status = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
+ hrtf = GetLoadedHrtf(VECTOR_ELEM(device->HrtfList, 0).hrtf);
}
- }
- }
- else if(hrtf_appreq == Hrtf_Enable)
- {
- size_t i;
- /* Loopback device. We don't need to match to a specific HRTF entry
- * here. If the requested ID matches, we'll pick that later, if not,
- * we'll try to auto-select one anyway. */
- if(device->FmtChans != DevFmtStereo)
- i = VECTOR_SIZE(device->Hrtf_List);
- else
- {
- if(VECTOR_SIZE(device->Hrtf_List) == 0)
+
+ if(hrtf)
{
- VECTOR_DEINIT(device->Hrtf_List);
- device->Hrtf_List = EnumerateHrtf(device->DeviceName);
+ device->FmtChans = DevFmtStereo;
+ device->Frequency = hrtf->sampleRate;
+ device->Flags |= DEVICE_CHANNELS_REQUEST | DEVICE_FREQUENCY_REQUEST;
+ if(device->HrtfHandle)
+ Hrtf_DecRef(device->HrtfHandle);
+ device->HrtfHandle = hrtf;
}
- for(i = 0;i < VECTOR_SIZE(device->Hrtf_List);i++)
+ else
{
- const struct Hrtf *hrtf = VECTOR_ELEM(device->Hrtf_List, i).hrtf;
- if(GetHrtfSampleRate(hrtf) == device->Frequency)
- break;
+ hrtf_userreq = Hrtf_Default;
+ hrtf_appreq = Hrtf_Disable;
+ device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
}
}
- if(i == VECTOR_SIZE(device->Hrtf_List))
- {
- ERR("Requested format not HRTF compatible: %s, %uhz\n",
- DevFmtChannelsString(device->FmtChans), device->Frequency);
- hrtf_appreq = Hrtf_Default;
- device->Hrtf_Status = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
- }
}
oldFreq = device->Frequency;
@@ -1951,11 +2069,6 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
device->Flags &= ~DEVICE_FREQUENCY_REQUEST;
}
- TRACE("Post-reset: %s, %s, %uhz, %u update size x%d\n",
- DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType),
- device->Frequency, device->UpdateSize, device->NumUpdates
- );
-
if((device->UpdateSize&3) != 0)
{
if((CPUCapFlags&CPU_CAP_SSE))
@@ -1964,230 +2077,278 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
WARN("NEON performs best with multiple of 4 update sizes (%u)\n", device->UpdateSize);
}
- device->Hrtf = NULL;
- device->Hrtf_Mode = DisabledHrtf;
- al_string_clear(&device->Hrtf_Name);
- if(device->FmtChans != DevFmtStereo)
+ TRACE("Post-reset: %s, %s, %uhz, %u update size x%d\n",
+ DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType),
+ device->Frequency, device->UpdateSize, device->NumUpdates
+ );
+
+ aluInitRenderer(device, hrtf_id, hrtf_appreq, hrtf_userreq);
+ TRACE("Channel config, Dry: %d, FOA: %d, Real: %d\n", device->Dry.NumChannels,
+ device->FOAOut.NumChannels, device->RealOut.NumChannels);
+
+ /* Allocate extra channels for any post-filter output. */
+ size = (device->Dry.NumChannels + device->FOAOut.NumChannels +
+ device->RealOut.NumChannels)*sizeof(device->Dry.Buffer[0]);
+
+ TRACE("Allocating "SZFMT" channels, "SZFMT" bytes\n", size/sizeof(device->Dry.Buffer[0]), size);
+ device->Dry.Buffer = al_calloc(16, size);
+ if(!device->Dry.Buffer)
{
- if(hrtf_appreq == Hrtf_Enable)
- device->Hrtf_Status = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
+ ERR("Failed to allocate "SZFMT" bytes for mix buffer\n", size);
+ return ALC_INVALID_DEVICE;
+ }
- free(device->Bs2b);
- device->Bs2b = NULL;
+ if(device->RealOut.NumChannels != 0)
+ device->RealOut.Buffer = device->Dry.Buffer + device->Dry.NumChannels +
+ device->FOAOut.NumChannels;
+ else
+ {
+ device->RealOut.Buffer = device->Dry.Buffer;
+ device->RealOut.NumChannels = device->Dry.NumChannels;
}
+
+ if(device->FOAOut.NumChannels != 0)
+ device->FOAOut.Buffer = device->Dry.Buffer + device->Dry.NumChannels;
else
{
- bool headphones = device->IsHeadphones;
- enum HrtfMode hrtf_mode = FullHrtf;
- ALCenum hrtf_status = device->Hrtf_Status;
- const char *mode;
- int bs2blevel;
- int usehrtf;
+ device->FOAOut.Buffer = device->Dry.Buffer;
+ device->FOAOut.NumChannels = device->Dry.NumChannels;
+ }
- if(device->Type != Loopback)
- {
- if(ConfigValueStr(al_string_get_cstr(device->DeviceName), NULL, "stereo-mode", &mode))
- {
- if(strcasecmp(mode, "headphones") == 0)
- headphones = true;
- else if(strcasecmp(mode, "speakers") == 0)
- headphones = false;
- else if(strcasecmp(mode, "auto") != 0)
- ERR("Unexpected stereo-mode: %s\n", mode);
- }
+ device->NumAuxSends = new_sends;
+ TRACE("Max sources: %d (%d + %d), effect slots: %d, sends: %d\n",
+ device->SourcesMax, device->NumMonoSources, device->NumStereoSources,
+ device->AuxiliaryEffectSlotMax, device->NumAuxSends);
- if(ConfigValueStr(al_string_get_cstr(device->DeviceName), NULL, "hrtf-mode", &mode))
+ device->DitherDepth = 0.0f;
+ if(GetConfigValueBool(alstr_get_cstr(device->DeviceName), NULL, "dither", 1))
+ {
+ ALint depth = 0;
+ ConfigValueInt(alstr_get_cstr(device->DeviceName), NULL, "dither-depth", &depth);
+ if(depth <= 0)
+ {
+ switch(device->FmtType)
{
- if(strcasecmp(mode, "full") == 0)
- hrtf_mode = FullHrtf;
- else if(strcasecmp(mode, "basic") == 0)
- hrtf_mode = BasicHrtf;
- else
- ERR("Unexpected hrtf-mode: %s\n", mode);
+ case DevFmtByte:
+ case DevFmtUByte:
+ depth = 8;
+ break;
+ case DevFmtShort:
+ case DevFmtUShort:
+ depth = 16;
+ break;
+ case DevFmtInt:
+ case DevFmtUInt:
+ case DevFmtFloat:
+ break;
}
}
-
- if(hrtf_userreq == Hrtf_Default)
- {
- usehrtf = (headphones && hrtf_appreq != Hrtf_Disable) ||
- (hrtf_appreq == Hrtf_Enable);
- if(headphones && hrtf_appreq != Hrtf_Disable)
- hrtf_status = ALC_HRTF_HEADPHONES_DETECTED_SOFT;
- else if(usehrtf)
- hrtf_status = ALC_HRTF_ENABLED_SOFT;
- }
- else
+ if(depth > 0)
{
- usehrtf = (hrtf_userreq == Hrtf_Enable);
- if(!usehrtf)
- hrtf_status = ALC_HRTF_DENIED_SOFT;
- else
- hrtf_status = ALC_HRTF_REQUIRED_SOFT;
+ depth = clampi(depth, 2, 24);
+ device->DitherDepth = powf(2.0f, (ALfloat)(depth-1));
}
-
- if(!usehrtf)
- device->Hrtf_Status = hrtf_status;
- else
+ }
+ if(!(device->DitherDepth > 0.0f))
+ TRACE("Dithering disabled\n");
+ else
+ TRACE("Dithering enabled (%g-bit, %g)\n", log2f(device->DitherDepth)+1.0f,
+ device->DitherDepth);
+
+ device->LimiterState = gainLimiter;
+ if(ConfigValueBool(alstr_get_cstr(device->DeviceName), NULL, "output-limiter", &val))
+ gainLimiter = val ? ALC_TRUE : ALC_FALSE;
+
+ /* Valid values for gainLimiter are ALC_DONT_CARE_SOFT, ALC_TRUE, and
+ * ALC_FALSE. For ALC_DONT_CARE_SOFT, use the limiter for integer-based
+ * output (where samples must be clamped), and don't for floating-point
+ * (which can take unclamped samples).
+ */
+ if(gainLimiter == ALC_DONT_CARE_SOFT)
+ {
+ switch(device->FmtType)
{
- size_t i;
-
- device->Hrtf_Status = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
- if(VECTOR_SIZE(device->Hrtf_List) == 0)
- {
- VECTOR_DEINIT(device->Hrtf_List);
- device->Hrtf_List = EnumerateHrtf(device->DeviceName);
- }
-
- if(hrtf_id >= 0 && (size_t)hrtf_id < VECTOR_SIZE(device->Hrtf_List))
- {
- const HrtfEntry *entry = &VECTOR_ELEM(device->Hrtf_List, hrtf_id);
- if(GetHrtfSampleRate(entry->hrtf) == device->Frequency)
- {
- device->Hrtf = entry->hrtf;
- al_string_copy(&device->Hrtf_Name, entry->name);
- }
- }
- if(!device->Hrtf)
- {
- for(i = 0;i < VECTOR_SIZE(device->Hrtf_List);i++)
- {
- const HrtfEntry *entry = &VECTOR_ELEM(device->Hrtf_List, i);
- if(GetHrtfSampleRate(entry->hrtf) == device->Frequency)
- {
- device->Hrtf = entry->hrtf;
- al_string_copy(&device->Hrtf_Name, entry->name);
- break;
- }
- }
- }
+ case DevFmtByte:
+ case DevFmtUByte:
+ case DevFmtShort:
+ case DevFmtUShort:
+ case DevFmtInt:
+ case DevFmtUInt:
+ gainLimiter = ALC_TRUE;
+ break;
+ case DevFmtFloat:
+ gainLimiter = ALC_FALSE;
+ break;
}
- if(device->Hrtf)
+ }
+ if(gainLimiter != ALC_FALSE)
+ {
+ ALfloat thrshld = 1.0f;
+ switch(device->FmtType)
{
- device->Hrtf_Mode = hrtf_mode;
- device->Hrtf_Status = hrtf_status;
- TRACE("HRTF enabled, \"%s\"\n", al_string_get_cstr(device->Hrtf_Name));
- free(device->Bs2b);
- device->Bs2b = NULL;
+ case DevFmtByte:
+ case DevFmtUByte:
+ thrshld = 127.0f / 128.0f;
+ break;
+ case DevFmtShort:
+ case DevFmtUShort:
+ thrshld = 32767.0f / 32768.0f;
+ break;
+ case DevFmtInt:
+ case DevFmtUInt:
+ case DevFmtFloat:
+ break;
}
- else
- {
- TRACE("HRTF disabled\n");
+ if(device->DitherDepth > 0.0f)
+ thrshld -= 1.0f / device->DitherDepth;
- bs2blevel = ((headphones && hrtf_appreq != Hrtf_Disable) ||
- (hrtf_appreq == Hrtf_Enable)) ? 5 : 0;
- if(device->Type != Loopback)
- ConfigValueInt(al_string_get_cstr(device->DeviceName), NULL, "cf_level", &bs2blevel);
- if(bs2blevel > 0 && bs2blevel <= 6)
- {
- if(!device->Bs2b)
- {
- device->Bs2b = calloc(1, sizeof(*device->Bs2b));
- bs2b_clear(device->Bs2b);
- }
- bs2b_set_params(device->Bs2b, bs2blevel, device->Frequency);
- TRACE("BS2B enabled\n");
- }
- else
- {
- free(device->Bs2b);
- device->Bs2b = NULL;
- TRACE("BS2B disabled\n");
- }
- }
+ al_free(device->Limiter);
+ device->Limiter = CreateDeviceLimiter(device, log10f(thrshld) * 20.0f);
+ device->FixedLatency += (ALuint)(GetCompressorLookAhead(device->Limiter) *
+ DEVICE_CLOCK_RES / device->Frequency);
}
-
- aluInitPanning(device);
-
- /* With HRTF, allocate two extra channels for the post-filter output. */
- size = sizeof(device->DryBuffer[0]) * (device->NumChannels + (device->Hrtf ? 2 : 0));
- device->DryBuffer = al_calloc(16, size);
- if(!device->DryBuffer)
+ else
{
- ERR("Failed to allocate "SZFMT" bytes for mix buffer\n", size);
- return ALC_INVALID_DEVICE;
+ al_free(device->Limiter);
+ device->Limiter = NULL;
}
+ TRACE("Output limiter %s\n", device->Limiter ? "enabled" : "disabled");
- SetMixerFPUMode(&oldMode);
- V0(device->Backend,lock)();
- context = ATOMIC_LOAD(&device->ContextList);
+ aluSelectPostProcess(device);
+
+ TRACE("Fixed device latency: %uns\n", device->FixedLatency);
+
+ /* Need to delay returning failure until replacement Send arrays have been
+ * allocated with the appropriate size.
+ */
+ update_failed = AL_FALSE;
+ START_MIXER_MODE();
+ context = ATOMIC_LOAD_SEQ(&device->ContextList);
while(context)
{
+ SourceSubList *sublist, *subend;
+ struct ALvoiceProps *vprops;
ALsizei pos;
- ATOMIC_STORE(&context->UpdateSources, AL_FALSE);
- LockUIntMapRead(&context->EffectSlotMap);
- for(pos = 0;pos < context->EffectSlotMap.size;pos++)
+ if(context->DefaultSlot)
{
- ALeffectslot *slot = context->EffectSlotMap.array[pos].value;
+ ALeffectslot *slot = context->DefaultSlot;
+ ALeffectState *state = slot->Effect.State;
- if(V(slot->EffectState,deviceUpdate)(device) == AL_FALSE)
- {
- UnlockUIntMapRead(&context->EffectSlotMap);
- V0(device->Backend,unlock)();
- RestoreFPUMode(&oldMode);
- return ALC_INVALID_DEVICE;
- }
- ATOMIC_STORE(&slot->NeedsUpdate, AL_FALSE);
- V(slot->EffectState,update)(device, slot);
+ state->OutBuffer = device->Dry.Buffer;
+ state->OutChannels = device->Dry.NumChannels;
+ if(V(state,deviceUpdate)(device) == AL_FALSE)
+ update_failed = AL_TRUE;
+ else
+ UpdateEffectSlotProps(slot, context);
+ }
+
+ almtx_lock(&context->PropLock);
+ almtx_lock(&context->EffectSlotLock);
+ for(pos = 0;pos < (ALsizei)VECTOR_SIZE(context->EffectSlotList);pos++)
+ {
+ ALeffectslot *slot = VECTOR_ELEM(context->EffectSlotList, pos);
+ ALeffectState *state = slot->Effect.State;
+
+ state->OutBuffer = device->Dry.Buffer;
+ state->OutChannels = device->Dry.NumChannels;
+ if(V(state,deviceUpdate)(device) == AL_FALSE)
+ update_failed = AL_TRUE;
+ else
+ UpdateEffectSlotProps(slot, context);
}
- UnlockUIntMapRead(&context->EffectSlotMap);
+ almtx_unlock(&context->EffectSlotLock);
- LockUIntMapRead(&context->SourceMap);
- for(pos = 0;pos < context->SourceMap.size;pos++)
+ almtx_lock(&context->SourceLock);
+ sublist = VECTOR_BEGIN(context->SourceList);
+ subend = VECTOR_END(context->SourceList);
+ for(;sublist != subend;++sublist)
{
- ALsource *source = context->SourceMap.array[pos].value;
- ALuint s = device->NumAuxSends;
- while(s < MAX_SENDS)
+ ALuint64 usemask = ~sublist->FreeMask;
+ while(usemask)
{
- if(source->Send[s].Slot)
- DecrementRef(&source->Send[s].Slot->ref);
- source->Send[s].Slot = NULL;
- source->Send[s].Gain = 1.0f;
- source->Send[s].GainHF = 1.0f;
- s++;
+ ALsizei idx = CTZ64(usemask);
+ ALsource *source = sublist->Sources + idx;
+
+ usemask &= ~(U64(1) << idx);
+
+ if(old_sends != device->NumAuxSends)
+ {
+ ALvoid *sends = al_calloc(16, device->NumAuxSends*sizeof(source->Send[0]));
+ ALsizei s;
+
+ memcpy(sends, source->Send,
+ mini(device->NumAuxSends, old_sends)*sizeof(source->Send[0])
+ );
+ for(s = device->NumAuxSends;s < old_sends;s++)
+ {
+ if(source->Send[s].Slot)
+ DecrementRef(&source->Send[s].Slot->ref);
+ source->Send[s].Slot = NULL;
+ }
+ al_free(source->Send);
+ source->Send = sends;
+ for(s = old_sends;s < device->NumAuxSends;s++)
+ {
+ source->Send[s].Slot = NULL;
+ source->Send[s].Gain = 1.0f;
+ source->Send[s].GainHF = 1.0f;
+ source->Send[s].HFReference = LOWPASSFREQREF;
+ source->Send[s].GainLF = 1.0f;
+ source->Send[s].LFReference = HIGHPASSFREQREF;
+ }
+ }
+
+ ATOMIC_FLAG_CLEAR(&source->PropsClean, almemory_order_release);
}
- ATOMIC_STORE(&source->NeedsUpdate, AL_TRUE);
}
- UnlockUIntMapRead(&context->SourceMap);
+ /* Clear any pre-existing voice property structs, in case the number of
+ * auxiliary sends is changing. Active sources will have updates
+ * respecified in UpdateAllSourceProps.
+ */
+ vprops = ATOMIC_EXCHANGE_PTR(&context->FreeVoiceProps, NULL, almemory_order_acq_rel);
+ while(vprops)
+ {
+ struct ALvoiceProps *next = ATOMIC_LOAD(&vprops->next, almemory_order_relaxed);
+ al_free(vprops);
+ vprops = next;
+ }
+
+ AllocateVoices(context, context->MaxVoices, old_sends);
for(pos = 0;pos < context->VoiceCount;pos++)
{
- ALvoice *voice = &context->Voices[pos];
- ALsource *source = voice->Source;
- ALuint s = device->NumAuxSends;
+ ALvoice *voice = context->Voices[pos];
- while(s < MAX_SENDS)
- {
- voice->Send[s].Moving = AL_FALSE;
- voice->Send[s].Counter = 0;
- s++;
- }
+ al_free(ATOMIC_EXCHANGE_PTR(&voice->Update, NULL, almemory_order_acq_rel));
+
+ if(ATOMIC_LOAD(&voice->Source, almemory_order_acquire) == NULL)
+ continue;
- if(source)
+ if(device->AvgSpeakerDist > 0.0f)
{
- ATOMIC_STORE(&source->NeedsUpdate, AL_FALSE);
- voice->Update(voice, source, context);
+ /* Reinitialize the NFC filters for new parameters. */
+ ALfloat w1 = SPEEDOFSOUNDMETRESPERSEC /
+ (device->AvgSpeakerDist * device->Frequency);
+ for(i = 0;i < voice->NumChannels;i++)
+ NfcFilterCreate(&voice->Direct.Params[i].NFCtrlFilter, 0.0f, w1);
}
}
+ almtx_unlock(&context->SourceLock);
- context = context->next;
- }
- if(device->DefaultSlot)
- {
- ALeffectslot *slot = device->DefaultSlot;
+ ATOMIC_FLAG_TEST_AND_SET(&context->PropsClean, almemory_order_release);
+ UpdateContextProps(context);
+ ATOMIC_FLAG_TEST_AND_SET(&context->Listener->PropsClean, almemory_order_release);
+ UpdateListenerProps(context);
+ UpdateAllSourceProps(context);
+ almtx_unlock(&context->PropLock);
- if(V(slot->EffectState,deviceUpdate)(device) == AL_FALSE)
- {
- V0(device->Backend,unlock)();
- RestoreFPUMode(&oldMode);
- return ALC_INVALID_DEVICE;
- }
- ATOMIC_STORE(&slot->NeedsUpdate, AL_FALSE);
- V(slot->EffectState,update)(device, slot);
+ context = ATOMIC_LOAD(&context->next, almemory_order_relaxed);
}
- V0(device->Backend,unlock)();
- RestoreFPUMode(&oldMode);
+ END_MIXER_MODE();
+ if(update_failed)
+ return ALC_INVALID_DEVICE;
if(!(device->Flags&DEVICE_PAUSED))
{
@@ -2199,6 +2360,73 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
return ALC_NO_ERROR;
}
+
+static void InitDevice(ALCdevice *device, enum DeviceType type)
+{
+ ALsizei i;
+
+ InitRef(&device->ref, 1);
+ ATOMIC_INIT(&device->Connected, ALC_TRUE);
+ device->Type = type;
+ ATOMIC_INIT(&device->LastError, ALC_NO_ERROR);
+
+ device->Flags = 0;
+ device->Render_Mode = NormalRender;
+ device->AvgSpeakerDist = 0.0f;
+ device->LimiterState = ALC_DONT_CARE_SOFT;
+
+ ATOMIC_INIT(&device->ContextList, NULL);
+
+ device->ClockBase = 0;
+ device->SamplesDone = 0;
+ device->FixedLatency = 0;
+
+ device->SourcesMax = 0;
+ device->AuxiliaryEffectSlotMax = 0;
+ device->NumAuxSends = 0;
+
+ device->Dry.Buffer = NULL;
+ device->Dry.NumChannels = 0;
+ device->FOAOut.Buffer = NULL;
+ device->FOAOut.NumChannels = 0;
+ device->RealOut.Buffer = NULL;
+ device->RealOut.NumChannels = 0;
+
+ AL_STRING_INIT(device->DeviceName);
+
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ {
+ device->ChannelDelay[i].Gain = 1.0f;
+ device->ChannelDelay[i].Length = 0;
+ device->ChannelDelay[i].Buffer = NULL;
+ }
+
+ AL_STRING_INIT(device->HrtfName);
+ VECTOR_INIT(device->HrtfList);
+ device->HrtfHandle = NULL;
+ device->Hrtf = NULL;
+ device->Bs2b = NULL;
+ device->Uhj_Encoder = NULL;
+ device->AmbiDecoder = NULL;
+ device->AmbiUp = NULL;
+ device->Stablizer = NULL;
+ device->Limiter = NULL;
+
+ VECTOR_INIT(device->BufferList);
+ almtx_init(&device->BufferLock, almtx_plain);
+
+ VECTOR_INIT(device->EffectList);
+ almtx_init(&device->EffectLock, almtx_plain);
+
+ VECTOR_INIT(device->FilterList);
+ almtx_init(&device->FilterLock, almtx_plain);
+
+ almtx_init(&device->BackendLock, almtx_plain);
+ device->Backend = NULL;
+
+ ATOMIC_INIT(&device->next, NULL);
+}
+
/* FreeDevice
*
* Frees the device structure, and destroys any objects the app failed to
@@ -2206,50 +2434,77 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
*/
static ALCvoid FreeDevice(ALCdevice *device)
{
+ ALsizei i;
+
TRACE("%p\n", device);
- V0(device->Backend,close)();
- DELETE_OBJ(device->Backend);
+ if(device->Backend)
+ DELETE_OBJ(device->Backend);
device->Backend = NULL;
- if(device->DefaultSlot)
- {
- ALeffectState *state = device->DefaultSlot->EffectState;
- device->DefaultSlot = NULL;
- DELETE_OBJ(state);
- }
+ almtx_destroy(&device->BackendLock);
+
+ ReleaseALBuffers(device);
+#define FREE_BUFFERSUBLIST(x) al_free((x)->Buffers)
+ VECTOR_FOR_EACH(BufferSubList, device->BufferList, FREE_BUFFERSUBLIST);
+#undef FREE_BUFFERSUBLIST
+ VECTOR_DEINIT(device->BufferList);
+ almtx_destroy(&device->BufferLock);
+
+ ReleaseALEffects(device);
+#define FREE_EFFECTSUBLIST(x) al_free((x)->Effects)
+ VECTOR_FOR_EACH(EffectSubList, device->EffectList, FREE_EFFECTSUBLIST);
+#undef FREE_EFFECTSUBLIST
+ VECTOR_DEINIT(device->EffectList);
+ almtx_destroy(&device->EffectLock);
+
+ ReleaseALFilters(device);
+#define FREE_FILTERSUBLIST(x) al_free((x)->Filters)
+ VECTOR_FOR_EACH(FilterSubList, device->FilterList, FREE_FILTERSUBLIST);
+#undef FREE_FILTERSUBLIST
+ VECTOR_DEINIT(device->FilterList);
+ almtx_destroy(&device->FilterLock);
+
+ AL_STRING_DEINIT(device->HrtfName);
+ FreeHrtfList(&device->HrtfList);
+ if(device->HrtfHandle)
+ Hrtf_DecRef(device->HrtfHandle);
+ device->HrtfHandle = NULL;
+ al_free(device->Hrtf);
+ device->Hrtf = NULL;
- if(device->BufferMap.size > 0)
- {
- WARN("(%p) Deleting %d Buffer(s)\n", device, device->BufferMap.size);
- ReleaseALBuffers(device);
- }
- ResetUIntMap(&device->BufferMap);
+ al_free(device->Bs2b);
+ device->Bs2b = NULL;
- if(device->EffectMap.size > 0)
- {
- WARN("(%p) Deleting %d Effect(s)\n", device, device->EffectMap.size);
- ReleaseALEffects(device);
- }
- ResetUIntMap(&device->EffectMap);
+ al_free(device->Uhj_Encoder);
+ device->Uhj_Encoder = NULL;
- if(device->FilterMap.size > 0)
- {
- WARN("(%p) Deleting %d Filter(s)\n", device, device->FilterMap.size);
- ReleaseALFilters(device);
- }
- ResetUIntMap(&device->FilterMap);
+ bformatdec_free(&device->AmbiDecoder);
+ ambiup_free(&device->AmbiUp);
- AL_STRING_DEINIT(device->Hrtf_Name);
- FreeHrtfList(&device->Hrtf_List);
+ al_free(device->Stablizer);
+ device->Stablizer = NULL;
- free(device->Bs2b);
- device->Bs2b = NULL;
+ al_free(device->Limiter);
+ device->Limiter = NULL;
+
+ al_free(device->ChannelDelay[0].Buffer);
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ {
+ device->ChannelDelay[i].Gain = 1.0f;
+ device->ChannelDelay[i].Length = 0;
+ device->ChannelDelay[i].Buffer = NULL;
+ }
AL_STRING_DEINIT(device->DeviceName);
- al_free(device->DryBuffer);
- device->DryBuffer = NULL;
+ al_free(device->Dry.Buffer);
+ device->Dry.Buffer = NULL;
+ device->Dry.NumChannels = 0;
+ device->FOAOut.Buffer = NULL;
+ device->FOAOut.NumChannels = 0;
+ device->RealOut.Buffer = NULL;
+ device->RealOut.NumChannels = 0;
al_free(device);
}
@@ -2279,7 +2534,7 @@ static ALCboolean VerifyDevice(ALCdevice **device)
ALCdevice *tmpDevice;
LockLists();
- tmpDevice = ATOMIC_LOAD(&DeviceList);
+ tmpDevice = ATOMIC_LOAD_SEQ(&DeviceList);
while(tmpDevice)
{
if(tmpDevice == *device)
@@ -2288,7 +2543,7 @@ static ALCboolean VerifyDevice(ALCdevice **device)
UnlockLists();
return ALC_TRUE;
}
- tmpDevice = tmpDevice->next;
+ tmpDevice = ATOMIC_LOAD(&tmpDevice->next, almemory_order_relaxed);
}
UnlockLists();
@@ -2304,30 +2559,50 @@ static ALCboolean VerifyDevice(ALCdevice **device)
static ALvoid InitContext(ALCcontext *Context)
{
ALlistener *listener = Context->Listener;
+ struct ALeffectslotArray *auxslots;
+
//Initialise listener
listener->Gain = 1.0f;
- listener->MetersPerUnit = 1.0f;
- aluVectorSet(&listener->Position, 0.0f, 0.0f, 0.0f, 1.0f);
- aluVectorSet(&listener->Velocity, 0.0f, 0.0f, 0.0f, 0.0f);
+ listener->Position[0] = 0.0f;
+ listener->Position[1] = 0.0f;
+ listener->Position[2] = 0.0f;
+ listener->Velocity[0] = 0.0f;
+ listener->Velocity[1] = 0.0f;
+ listener->Velocity[2] = 0.0f;
listener->Forward[0] = 0.0f;
listener->Forward[1] = 0.0f;
listener->Forward[2] = -1.0f;
listener->Up[0] = 0.0f;
listener->Up[1] = 1.0f;
listener->Up[2] = 0.0f;
- aluMatrixdSet(&listener->Params.Matrix,
- 1.0, 0.0, 0.0, 0.0,
- 0.0, 1.0, 0.0, 0.0,
- 0.0, 0.0, 1.0, 0.0,
- 0.0, 0.0, 0.0, 1.0
- );
- aluVectorSet(&listener->Params.Velocity, 0.0f, 0.0f, 0.0f, 0.0f);
+ ATOMIC_FLAG_TEST_AND_SET(&listener->PropsClean, almemory_order_relaxed);
+
+ ATOMIC_INIT(&listener->Update, NULL);
//Validate Context
+ InitRef(&Context->UpdateCount, 0);
+ ATOMIC_INIT(&Context->HoldUpdates, AL_FALSE);
+ Context->GainBoost = 1.0f;
+ almtx_init(&Context->PropLock, almtx_plain);
ATOMIC_INIT(&Context->LastError, AL_NO_ERROR);
- ATOMIC_INIT(&Context->UpdateSources, AL_FALSE);
- InitUIntMap(&Context->SourceMap, Context->Device->MaxNoOfSources);
- InitUIntMap(&Context->EffectSlotMap, Context->Device->AuxiliaryEffectSlotMax);
+ VECTOR_INIT(Context->SourceList);
+ Context->NumSources = 0;
+ almtx_init(&Context->SourceLock, almtx_plain);
+ VECTOR_INIT(Context->EffectSlotList);
+ almtx_init(&Context->EffectSlotLock, almtx_plain);
+
+ if(Context->DefaultSlot)
+ {
+ auxslots = al_calloc(DEF_ALIGN, FAM_SIZE(struct ALeffectslotArray, slot, 1));
+ auxslots->count = 1;
+ auxslots->slot[0] = Context->DefaultSlot;
+ }
+ else
+ {
+ auxslots = al_calloc(DEF_ALIGN, sizeof(struct ALeffectslotArray));
+ auxslots->count = 0;
+ }
+ ATOMIC_INIT(&Context->ActiveAuxSlots, auxslots);
//Set globals
Context->DistanceModel = DefaultDistanceModel;
@@ -2335,9 +2610,40 @@ static ALvoid InitContext(ALCcontext *Context)
Context->DopplerFactor = 1.0f;
Context->DopplerVelocity = 1.0f;
Context->SpeedOfSound = SPEEDOFSOUNDMETRESPERSEC;
- Context->DeferUpdates = AL_FALSE;
+ Context->MetersPerUnit = AL_DEFAULT_METERS_PER_UNIT;
+ ATOMIC_FLAG_TEST_AND_SET(&Context->PropsClean, almemory_order_relaxed);
+ ATOMIC_INIT(&Context->DeferUpdates, AL_FALSE);
+ alsem_init(&Context->EventSem, 0);
+ Context->AsyncEvents = NULL;
+ ATOMIC_INIT(&Context->EnabledEvts, 0);
+ almtx_init(&Context->EventCbLock, almtx_plain);
+ Context->EventCb = NULL;
+ Context->EventParam = NULL;
+
+ ATOMIC_INIT(&Context->Update, NULL);
+ ATOMIC_INIT(&Context->FreeContextProps, NULL);
+ ATOMIC_INIT(&Context->FreeListenerProps, NULL);
+ ATOMIC_INIT(&Context->FreeVoiceProps, NULL);
+ ATOMIC_INIT(&Context->FreeEffectslotProps, NULL);
Context->ExtensionList = alExtList;
+
+
+ listener->Params.Matrix = IdentityMatrixf;
+ aluVectorSet(&listener->Params.Velocity, 0.0f, 0.0f, 0.0f, 0.0f);
+ listener->Params.Gain = listener->Gain;
+ listener->Params.MetersPerUnit = Context->MetersPerUnit;
+ listener->Params.DopplerFactor = Context->DopplerFactor;
+ listener->Params.SpeedOfSound = Context->SpeedOfSound * Context->DopplerVelocity;
+ listener->Params.ReverbSpeedOfSound = listener->Params.SpeedOfSound *
+ listener->Params.MetersPerUnit;
+ listener->Params.SourceDistanceModel = Context->SourceDistanceModel;
+ listener->Params.DistanceModel = Context->DistanceModel;
+
+
+ Context->AsyncEvents = ll_ringbuffer_create(63, sizeof(AsyncEvent), false);
+ if(althrd_create(&Context->EventThread, EventThread, Context) != althrd_success)
+ ERR("Failed to start event thread! Expect problems.\n");
}
@@ -2348,28 +2654,111 @@ static ALvoid InitContext(ALCcontext *Context)
*/
static void FreeContext(ALCcontext *context)
{
+ ALlistener *listener = context->Listener;
+ struct ALeffectslotArray *auxslots;
+ struct ALeffectslotProps *eprops;
+ struct ALlistenerProps *lprops;
+ struct ALcontextProps *cprops;
+ struct ALvoiceProps *vprops;
+ size_t count;
+ ALsizei i;
+
TRACE("%p\n", context);
- if(context->SourceMap.size > 0)
+ if((cprops=ATOMIC_LOAD(&context->Update, almemory_order_acquire)) != NULL)
+ {
+ TRACE("Freed unapplied context update %p\n", cprops);
+ al_free(cprops);
+ }
+
+ count = 0;
+ cprops = ATOMIC_LOAD(&context->FreeContextProps, almemory_order_acquire);
+ while(cprops)
+ {
+ struct ALcontextProps *next = ATOMIC_LOAD(&cprops->next, almemory_order_acquire);
+ al_free(cprops);
+ cprops = next;
+ ++count;
+ }
+ TRACE("Freed "SZFMT" context property object%s\n", count, (count==1)?"":"s");
+
+ if(context->DefaultSlot)
{
- WARN("(%p) Deleting %d Source(s)\n", context, context->SourceMap.size);
- ReleaseALSources(context);
+ DeinitEffectSlot(context->DefaultSlot);
+ context->DefaultSlot = NULL;
}
- ResetUIntMap(&context->SourceMap);
- if(context->EffectSlotMap.size > 0)
+ auxslots = ATOMIC_EXCHANGE_PTR(&context->ActiveAuxSlots, NULL, almemory_order_relaxed);
+ al_free(auxslots);
+
+ ReleaseALSources(context);
+#define FREE_SOURCESUBLIST(x) al_free((x)->Sources)
+ VECTOR_FOR_EACH(SourceSubList, context->SourceList, FREE_SOURCESUBLIST);
+#undef FREE_SOURCESUBLIST
+ VECTOR_DEINIT(context->SourceList);
+ context->NumSources = 0;
+ almtx_destroy(&context->SourceLock);
+
+ count = 0;
+ eprops = ATOMIC_LOAD(&context->FreeEffectslotProps, almemory_order_relaxed);
+ while(eprops)
+ {
+ struct ALeffectslotProps *next = ATOMIC_LOAD(&eprops->next, almemory_order_relaxed);
+ if(eprops->State) ALeffectState_DecRef(eprops->State);
+ al_free(eprops);
+ eprops = next;
+ ++count;
+ }
+ TRACE("Freed "SZFMT" AuxiliaryEffectSlot property object%s\n", count, (count==1)?"":"s");
+
+ ReleaseALAuxiliaryEffectSlots(context);
+#define FREE_EFFECTSLOTPTR(x) al_free(*(x))
+ VECTOR_FOR_EACH(ALeffectslotPtr, context->EffectSlotList, FREE_EFFECTSLOTPTR);
+#undef FREE_EFFECTSLOTPTR
+ VECTOR_DEINIT(context->EffectSlotList);
+ almtx_destroy(&context->EffectSlotLock);
+
+ count = 0;
+ vprops = ATOMIC_LOAD(&context->FreeVoiceProps, almemory_order_relaxed);
+ while(vprops)
{
- WARN("(%p) Deleting %d AuxiliaryEffectSlot(s)\n", context, context->EffectSlotMap.size);
- ReleaseALAuxiliaryEffectSlots(context);
+ struct ALvoiceProps *next = ATOMIC_LOAD(&vprops->next, almemory_order_relaxed);
+ al_free(vprops);
+ vprops = next;
+ ++count;
}
- ResetUIntMap(&context->EffectSlotMap);
+ TRACE("Freed "SZFMT" voice property object%s\n", count, (count==1)?"":"s");
+ for(i = 0;i < context->VoiceCount;i++)
+ DeinitVoice(context->Voices[i]);
al_free(context->Voices);
context->Voices = NULL;
context->VoiceCount = 0;
context->MaxVoices = 0;
- VECTOR_DEINIT(context->ActiveAuxSlots);
+ if((lprops=ATOMIC_LOAD(&listener->Update, almemory_order_acquire)) != NULL)
+ {
+ TRACE("Freed unapplied listener update %p\n", lprops);
+ al_free(lprops);
+ }
+ count = 0;
+ lprops = ATOMIC_LOAD(&context->FreeListenerProps, almemory_order_acquire);
+ while(lprops)
+ {
+ struct ALlistenerProps *next = ATOMIC_LOAD(&lprops->next, almemory_order_acquire);
+ al_free(lprops);
+ lprops = next;
+ ++count;
+ }
+ TRACE("Freed "SZFMT" listener property object%s\n", count, (count==1)?"":"s");
+
+ almtx_destroy(&context->EventCbLock);
+ alsem_destroy(&context->EventSem);
+
+ ll_ringbuffer_free(context->AsyncEvents);
+ context->AsyncEvents = NULL;
+
+ almtx_destroy(&context->PropLock);
ALCdevice_DecRef(context->Device);
context->Device = NULL;
@@ -2382,12 +2771,14 @@ static void FreeContext(ALCcontext *context)
/* ReleaseContext
*
* Removes the context reference from the given device and removes it from
- * being current on the running thread or globally.
+ * being current on the running thread or globally. Returns true if other
+ * contexts still exist on the device.
*/
-static void ReleaseContext(ALCcontext *context, ALCdevice *device)
+static bool ReleaseContext(ALCcontext *context, ALCdevice *device)
{
- ALCcontext *nextctx;
- ALCcontext *origctx;
+ static const AsyncEvent kill_evt = ASYNC_EVENT(EventType_KillThread);
+ ALCcontext *origctx, *newhead;
+ bool ret = true;
if(altss_get(LocalContext) == context)
{
@@ -2397,44 +2788,60 @@ static void ReleaseContext(ALCcontext *context, ALCdevice *device)
}
origctx = context;
- if(ATOMIC_COMPARE_EXCHANGE_STRONG(ALCcontext*, &GlobalContext, &origctx, NULL))
+ if(ATOMIC_COMPARE_EXCHANGE_PTR_STRONG_SEQ(&GlobalContext, &origctx, NULL))
ALCcontext_DecRef(context);
- ALCdevice_Lock(device);
+ V0(device->Backend,lock)();
origctx = context;
- nextctx = context->next;
- if(!ATOMIC_COMPARE_EXCHANGE_STRONG(ALCcontext*, &device->ContextList, &origctx, nextctx))
+ newhead = ATOMIC_LOAD(&context->next, almemory_order_relaxed);
+ if(!ATOMIC_COMPARE_EXCHANGE_PTR_STRONG_SEQ(&device->ContextList, &origctx, newhead))
{
ALCcontext *list;
do {
+ /* origctx is what the desired context failed to match. Try
+ * swapping out the next one in the list.
+ */
list = origctx;
origctx = context;
- } while(!COMPARE_EXCHANGE(&list->next, &origctx, nextctx));
+ } while(!ATOMIC_COMPARE_EXCHANGE_PTR_STRONG_SEQ(&list->next, &origctx, newhead));
}
- ALCdevice_Unlock(device);
+ else
+ ret = !!newhead;
+ V0(device->Backend,unlock)();
+
+ /* Make sure the context is finished and no longer processing in the mixer
+ * before sending the message queue kill event. The backend's lock does
+ * this, although waiting for a non-odd mix count would work too.
+ */
+
+ while(ll_ringbuffer_write(context->AsyncEvents, (const char*)&kill_evt, 1) == 0)
+ althrd_yield();
+ alsem_post(&context->EventSem);
+ althrd_join(context->EventThread, NULL);
ALCcontext_DecRef(context);
+ return ret;
}
-void ALCcontext_IncRef(ALCcontext *context)
+static void ALCcontext_IncRef(ALCcontext *context)
{
- uint ref;
- ref = IncrementRef(&context->ref);
+ uint ref = IncrementRef(&context->ref);
TRACEREF("%p increasing refcount to %u\n", context, ref);
}
void ALCcontext_DecRef(ALCcontext *context)
{
- uint ref;
- ref = DecrementRef(&context->ref);
+ uint ref = DecrementRef(&context->ref);
TRACEREF("%p decreasing refcount to %u\n", context, ref);
if(ref == 0) FreeContext(context);
}
static void ReleaseThreadCtx(void *ptr)
{
- WARN("%p current for thread being destroyed\n", ptr);
- ALCcontext_DecRef(ptr);
+ ALCcontext *context = ptr;
+ uint ref = DecrementRef(&context->ref);
+ TRACEREF("%p decreasing refcount to %u\n", context, ref);
+ ERR("Context %p current for thread being destroyed, possible leak!\n", context);
}
/* VerifyContext
@@ -2446,10 +2853,10 @@ static ALCboolean VerifyContext(ALCcontext **context)
ALCdevice *dev;
LockLists();
- dev = ATOMIC_LOAD(&DeviceList);
+ dev = ATOMIC_LOAD_SEQ(&DeviceList);
while(dev)
{
- ALCcontext *ctx = ATOMIC_LOAD(&dev->ContextList);
+ ALCcontext *ctx = ATOMIC_LOAD(&dev->ContextList, almemory_order_acquire);
while(ctx)
{
if(ctx == *context)
@@ -2458,9 +2865,9 @@ static ALCboolean VerifyContext(ALCcontext **context)
UnlockLists();
return ALC_TRUE;
}
- ctx = ctx->next;
+ ctx = ATOMIC_LOAD(&ctx->next, almemory_order_relaxed);
}
- dev = dev->next;
+ dev = ATOMIC_LOAD(&dev->next, almemory_order_relaxed);
}
UnlockLists();
@@ -2484,7 +2891,7 @@ ALCcontext *GetContextRef(void)
else
{
LockLists();
- context = ATOMIC_LOAD(&GlobalContext);
+ context = ATOMIC_LOAD_SEQ(&GlobalContext);
if(context)
ALCcontext_IncRef(context);
UnlockLists();
@@ -2494,6 +2901,91 @@ ALCcontext *GetContextRef(void)
}
+void AllocateVoices(ALCcontext *context, ALsizei num_voices, ALsizei old_sends)
+{
+ ALCdevice *device = context->Device;
+ ALsizei num_sends = device->NumAuxSends;
+ struct ALvoiceProps *props;
+ size_t sizeof_props;
+ size_t sizeof_voice;
+ ALvoice **voices;
+ ALvoice *voice;
+ ALsizei v = 0;
+ size_t size;
+
+ if(num_voices == context->MaxVoices && num_sends == old_sends)
+ return;
+
+ /* Allocate the voice pointers, voices, and the voices' stored source
+ * property set (including the dynamically-sized Send[] array) in one
+ * chunk.
+ */
+ sizeof_voice = RoundUp(FAM_SIZE(ALvoice, Send, num_sends), 16);
+ sizeof_props = RoundUp(FAM_SIZE(struct ALvoiceProps, Send, num_sends), 16);
+ size = sizeof(ALvoice*) + sizeof_voice + sizeof_props;
+
+ voices = al_calloc(16, RoundUp(size*num_voices, 16));
+ /* The voice and property objects are stored interleaved since they're
+ * paired together.
+ */
+ voice = (ALvoice*)((char*)voices + RoundUp(num_voices*sizeof(ALvoice*), 16));
+ props = (struct ALvoiceProps*)((char*)voice + sizeof_voice);
+
+ if(context->Voices)
+ {
+ const ALsizei v_count = mini(context->VoiceCount, num_voices);
+ const ALsizei s_count = mini(old_sends, num_sends);
+
+ for(;v < v_count;v++)
+ {
+ ALvoice *old_voice = context->Voices[v];
+ ALsizei i;
+
+ /* Copy the old voice data and source property set to the new
+ * storage.
+ */
+ *voice = *old_voice;
+ for(i = 0;i < s_count;i++)
+ voice->Send[i] = old_voice->Send[i];
+ *props = *(old_voice->Props);
+ for(i = 0;i < s_count;i++)
+ props->Send[i] = old_voice->Props->Send[i];
+
+ /* Set this voice's property set pointer and voice reference. */
+ voice->Props = props;
+ voices[v] = voice;
+
+ /* Increment pointers to the next storage space. */
+ voice = (ALvoice*)((char*)props + sizeof_props);
+ props = (struct ALvoiceProps*)((char*)voice + sizeof_voice);
+ }
+ /* Deinit any left over voices that weren't copied over to the new
+ * array. NOTE: If this does anything, v equals num_voices and
+ * num_voices is less than VoiceCount, so the following loop won't do
+ * anything.
+ */
+ for(;v < context->VoiceCount;v++)
+ DeinitVoice(context->Voices[v]);
+ }
+ /* Finish setting the voices' property set pointers and references. */
+ for(;v < num_voices;v++)
+ {
+ ATOMIC_INIT(&voice->Update, NULL);
+
+ voice->Props = props;
+ voices[v] = voice;
+
+ voice = (ALvoice*)((char*)props + sizeof_props);
+ props = (struct ALvoiceProps*)((char*)voice + sizeof_voice);
+ }
+
+ al_free(context->Voices);
+ context->Voices = voices;
+ context->MaxVoices = num_voices;
+ context->VoiceCount = mini(context->VoiceCount, num_voices);
+}
+
+
/************************************************
* Standard ALC functions
************************************************/
@@ -2508,11 +3000,11 @@ ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
if(VerifyDevice(&device))
{
- errorCode = ATOMIC_EXCHANGE(ALCenum, &device->LastError, ALC_NO_ERROR);
+ errorCode = ATOMIC_EXCHANGE_SEQ(&device->LastError, ALC_NO_ERROR);
ALCdevice_DecRef(device);
}
else
- errorCode = ATOMIC_EXCHANGE(ALCenum, &LastNullDeviceError, ALC_NO_ERROR);
+ errorCode = ATOMIC_EXCHANGE_SEQ(&LastNullDeviceError, ALC_NO_ERROR);
return errorCode;
}
@@ -2596,26 +3088,26 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *Device, ALCenum para
case ALC_ALL_DEVICES_SPECIFIER:
if(VerifyDevice(&Device))
{
- value = al_string_get_cstr(Device->DeviceName);
+ value = alstr_get_cstr(Device->DeviceName);
ALCdevice_DecRef(Device);
}
else
{
ProbeAllDevicesList();
- value = al_string_get_cstr(alcAllDevicesList);
+ value = alstr_get_cstr(alcAllDevicesList);
}
break;
case ALC_CAPTURE_DEVICE_SPECIFIER:
if(VerifyDevice(&Device))
{
- value = al_string_get_cstr(Device->DeviceName);
+ value = alstr_get_cstr(Device->DeviceName);
ALCdevice_DecRef(Device);
}
else
{
ProbeCaptureDeviceList();
- value = al_string_get_cstr(alcCaptureDeviceList);
+ value = alstr_get_cstr(alcCaptureDeviceList);
}
break;
@@ -2625,13 +3117,13 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *Device, ALCenum para
break;
case ALC_DEFAULT_ALL_DEVICES_SPECIFIER:
- if(al_string_empty(alcAllDevicesList))
+ if(alstr_empty(alcAllDevicesList))
ProbeAllDevicesList();
VerifyDevice(&Device);
free(alcDefaultAllDevicesSpecifier);
- alcDefaultAllDevicesSpecifier = strdup(al_string_get_cstr(alcAllDevicesList));
+ alcDefaultAllDevicesSpecifier = strdup(alstr_get_cstr(alcAllDevicesList));
if(!alcDefaultAllDevicesSpecifier)
alcSetError(Device, ALC_OUT_OF_MEMORY);
@@ -2640,13 +3132,13 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *Device, ALCenum para
break;
case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER:
- if(al_string_empty(alcCaptureDeviceList))
+ if(alstr_empty(alcCaptureDeviceList))
ProbeCaptureDeviceList();
VerifyDevice(&Device);
free(alcCaptureDefaultDeviceSpecifier);
- alcCaptureDefaultDeviceSpecifier = strdup(al_string_get_cstr(alcCaptureDeviceList));
+ alcCaptureDefaultDeviceSpecifier = strdup(alstr_get_cstr(alcCaptureDeviceList));
if(!alcCaptureDefaultDeviceSpecifier)
alcSetError(Device, ALC_OUT_OF_MEMORY);
@@ -2669,9 +3161,9 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *Device, ALCenum para
alcSetError(NULL, ALC_INVALID_DEVICE);
else
{
- LockLists();
- value = (Device->Hrtf ? al_string_get_cstr(Device->Hrtf_Name) : "");
- UnlockLists();
+ almtx_lock(&Device->BackendLock);
+ value = (Device->HrtfHandle ? alstr_get_cstr(Device->HrtfName) : "");
+ almtx_unlock(&Device->BackendLock);
ALCdevice_DecRef(Device);
}
break;
@@ -2687,6 +3179,15 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *Device, ALCenum para
}
+static inline ALCsizei NumAttrsForDevice(ALCdevice *device)
+{
+ if(device->Type == Capture) return 9;
+ if(device->Type != Loopback) return 29;
+ if(device->FmtChans == DevFmtAmbi3D)
+ return 35;
+ return 29;
+}
+
static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALCint *values)
{
ALCsizei i;
@@ -2718,6 +3219,10 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC
case ALC_CAPTURE_SAMPLES:
case ALC_FORMAT_CHANNELS_SOFT:
case ALC_FORMAT_TYPE_SOFT:
+ case ALC_AMBISONIC_LAYOUT_SOFT:
+ case ALC_AMBISONIC_SCALING_SOFT:
+ case ALC_AMBISONIC_ORDER_SOFT:
+ case ALC_MAX_AMBISONIC_ORDER_SOFT:
alcSetError(NULL, ALC_INVALID_DEVICE);
return 0;
@@ -2732,14 +3237,47 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC
{
switch(param)
{
+ case ALC_ATTRIBUTES_SIZE:
+ values[0] = NumAttrsForDevice(device);
+ return 1;
+
+ case ALC_ALL_ATTRIBUTES:
+ if(size < NumAttrsForDevice(device))
+ {
+ alcSetError(device, ALC_INVALID_VALUE);
+ return 0;
+ }
+
+ i = 0;
+ almtx_lock(&device->BackendLock);
+ values[i++] = ALC_MAJOR_VERSION;
+ values[i++] = alcMajorVersion;
+ values[i++] = ALC_MINOR_VERSION;
+ values[i++] = alcMinorVersion;
+ values[i++] = ALC_CAPTURE_SAMPLES;
+ values[i++] = V0(device->Backend,availableSamples)();
+ values[i++] = ALC_CONNECTED;
+ values[i++] = ATOMIC_LOAD(&device->Connected, almemory_order_relaxed);
+ almtx_unlock(&device->BackendLock);
+
+ values[i++] = 0;
+ return i;
+
+ case ALC_MAJOR_VERSION:
+ values[0] = alcMajorVersion;
+ return 1;
+ case ALC_MINOR_VERSION:
+ values[0] = alcMinorVersion;
+ return 1;
+
case ALC_CAPTURE_SAMPLES:
- V0(device->Backend,lock)();
+ almtx_lock(&device->BackendLock);
values[0] = V0(device->Backend,availableSamples)();
- V0(device->Backend,unlock)();
+ almtx_unlock(&device->BackendLock);
return 1;
case ALC_CONNECTED:
- values[0] = device->Connected;
+ values[0] = ATOMIC_LOAD(&device->Connected, almemory_order_acquire);
return 1;
default:
@@ -2752,37 +3290,30 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC
/* render device */
switch(param)
{
- case ALC_MAJOR_VERSION:
- values[0] = alcMajorVersion;
- return 1;
-
- case ALC_MINOR_VERSION:
- values[0] = alcMinorVersion;
- return 1;
-
- case ALC_EFX_MAJOR_VERSION:
- values[0] = alcEFXMajorVersion;
- return 1;
-
- case ALC_EFX_MINOR_VERSION:
- values[0] = alcEFXMinorVersion;
- return 1;
-
case ALC_ATTRIBUTES_SIZE:
- values[0] = 17;
+ values[0] = NumAttrsForDevice(device);
return 1;
case ALC_ALL_ATTRIBUTES:
- if(size < 17)
+ if(size < NumAttrsForDevice(device))
{
alcSetError(device, ALC_INVALID_VALUE);
return 0;
}
i = 0;
+ almtx_lock(&device->BackendLock);
+ values[i++] = ALC_MAJOR_VERSION;
+ values[i++] = alcMajorVersion;
+ values[i++] = ALC_MINOR_VERSION;
+ values[i++] = alcMinorVersion;
+ values[i++] = ALC_EFX_MAJOR_VERSION;
+ values[i++] = alcEFXMajorVersion;
+ values[i++] = ALC_EFX_MINOR_VERSION;
+ values[i++] = alcEFXMinorVersion;
+
values[i++] = ALC_FREQUENCY;
values[i++] = device->Frequency;
-
if(device->Type != Loopback)
{
values[i++] = ALC_REFRESH;
@@ -2793,6 +3324,18 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC
}
else
{
+ if(device->FmtChans == DevFmtAmbi3D)
+ {
+ values[i++] = ALC_AMBISONIC_LAYOUT_SOFT;
+ values[i++] = device->AmbiLayout;
+
+ values[i++] = ALC_AMBISONIC_SCALING_SOFT;
+ values[i++] = device->AmbiScale;
+
+ values[i++] = ALC_AMBISONIC_ORDER_SOFT;
+ values[i++] = device->AmbiOrder;
+ }
+
values[i++] = ALC_FORMAT_CHANNELS_SOFT;
values[i++] = device->FmtChans;
@@ -2810,14 +3353,37 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC
values[i++] = device->NumAuxSends;
values[i++] = ALC_HRTF_SOFT;
- values[i++] = (device->Hrtf ? ALC_TRUE : ALC_FALSE);
+ values[i++] = (device->HrtfHandle ? ALC_TRUE : ALC_FALSE);
values[i++] = ALC_HRTF_STATUS_SOFT;
- values[i++] = device->Hrtf_Status;
+ values[i++] = device->HrtfStatus;
+
+ values[i++] = ALC_OUTPUT_LIMITER_SOFT;
+ values[i++] = device->Limiter ? ALC_TRUE : ALC_FALSE;
+
+ values[i++] = ALC_MAX_AMBISONIC_ORDER_SOFT;
+ values[i++] = MAX_AMBI_ORDER;
+ almtx_unlock(&device->BackendLock);
values[i++] = 0;
return i;
+ case ALC_MAJOR_VERSION:
+ values[0] = alcMajorVersion;
+ return 1;
+
+ case ALC_MINOR_VERSION:
+ values[0] = alcMinorVersion;
+ return 1;
+
+ case ALC_EFX_MAJOR_VERSION:
+ values[0] = alcEFXMajorVersion;
+ return 1;
+
+ case ALC_EFX_MINOR_VERSION:
+ values[0] = alcEFXMinorVersion;
+ return 1;
+
case ALC_FREQUENCY:
values[0] = device->Frequency;
return 1;
@@ -2828,7 +3394,9 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC
alcSetError(device, ALC_INVALID_DEVICE);
return 0;
}
+ almtx_lock(&device->BackendLock);
values[0] = device->Frequency / device->UpdateSize;
+ almtx_unlock(&device->BackendLock);
return 1;
case ALC_SYNC:
@@ -2858,6 +3426,33 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC
values[0] = device->FmtType;
return 1;
+ case ALC_AMBISONIC_LAYOUT_SOFT:
+ if(device->Type != Loopback || device->FmtChans != DevFmtAmbi3D)
+ {
+ alcSetError(device, ALC_INVALID_DEVICE);
+ return 0;
+ }
+ values[0] = device->AmbiLayout;
+ return 1;
+
+ case ALC_AMBISONIC_SCALING_SOFT:
+ if(device->Type != Loopback || device->FmtChans != DevFmtAmbi3D)
+ {
+ alcSetError(device, ALC_INVALID_DEVICE);
+ return 0;
+ }
+ values[0] = device->AmbiScale;
+ return 1;
+
+ case ALC_AMBISONIC_ORDER_SOFT:
+ if(device->Type != Loopback || device->FmtChans != DevFmtAmbi3D)
+ {
+ alcSetError(device, ALC_INVALID_DEVICE);
+ return 0;
+ }
+ values[0] = device->AmbiOrder;
+ return 1;
+
case ALC_MONO_SOURCES:
values[0] = device->NumMonoSources;
return 1;
@@ -2871,21 +3466,31 @@ static ALCsizei GetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALC
return 1;
case ALC_CONNECTED:
- values[0] = device->Connected;
+ values[0] = ATOMIC_LOAD(&device->Connected, almemory_order_acquire);
return 1;
case ALC_HRTF_SOFT:
- values[0] = (device->Hrtf ? ALC_TRUE : ALC_FALSE);
+ values[0] = (device->HrtfHandle ? ALC_TRUE : ALC_FALSE);
return 1;
case ALC_HRTF_STATUS_SOFT:
- values[0] = device->Hrtf_Status;
+ values[0] = device->HrtfStatus;
return 1;
case ALC_NUM_HRTF_SPECIFIERS_SOFT:
- FreeHrtfList(&device->Hrtf_List);
- device->Hrtf_List = EnumerateHrtf(device->DeviceName);
- values[0] = (ALCint)VECTOR_SIZE(device->Hrtf_List);
+ almtx_lock(&device->BackendLock);
+ FreeHrtfList(&device->HrtfList);
+ device->HrtfList = EnumerateHrtf(device->DeviceName);
+ values[0] = (ALCint)VECTOR_SIZE(device->HrtfList);
+ almtx_unlock(&device->BackendLock);
+ return 1;
+
+ case ALC_OUTPUT_LIMITER_SOFT:
+ values[0] = device->Limiter ? ALC_TRUE : ALC_FALSE;
+ return 1;
+
+ case ALC_MAX_AMBISONIC_ORDER_SOFT:
+ values[0] = MAX_AMBI_ORDER;
return 1;
default:
@@ -2927,20 +3532,24 @@ ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname,
}
else /* render device */
{
+ ClockLatency clock;
+ ALuint64 basecount;
+ ALuint samplecount;
+ ALuint refcount;
+
switch(pname)
{
case ALC_ATTRIBUTES_SIZE:
- *values = 19;
+ *values = NumAttrsForDevice(device)+4;
break;
case ALC_ALL_ATTRIBUTES:
- if(size < 19)
+ if(size < NumAttrsForDevice(device)+4)
alcSetError(device, ALC_INVALID_VALUE);
else
{
- int i = 0;
-
- V0(device->Backend,lock)();
+ i = 0;
+ almtx_lock(&device->BackendLock);
values[i++] = ALC_FREQUENCY;
values[i++] = device->Frequency;
@@ -2954,6 +3563,18 @@ ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname,
}
else
{
+ if(device->FmtChans == DevFmtAmbi3D)
+ {
+ values[i++] = ALC_AMBISONIC_LAYOUT_SOFT;
+ values[i++] = device->AmbiLayout;
+
+ values[i++] = ALC_AMBISONIC_SCALING_SOFT;
+ values[i++] = device->AmbiScale;
+
+ values[i++] = ALC_AMBISONIC_ORDER_SOFT;
+ values[i++] = device->AmbiOrder;
+ }
+
values[i++] = ALC_FORMAT_CHANNELS_SOFT;
values[i++] = device->FmtChans;
@@ -2971,25 +3592,56 @@ ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname,
values[i++] = device->NumAuxSends;
values[i++] = ALC_HRTF_SOFT;
- values[i++] = (device->Hrtf ? ALC_TRUE : ALC_FALSE);
+ values[i++] = (device->HrtfHandle ? ALC_TRUE : ALC_FALSE);
values[i++] = ALC_HRTF_STATUS_SOFT;
- values[i++] = device->Hrtf_Status;
+ values[i++] = device->HrtfStatus;
+
+ values[i++] = ALC_OUTPUT_LIMITER_SOFT;
+ values[i++] = device->Limiter ? ALC_TRUE : ALC_FALSE;
+ clock = GetClockLatency(device);
values[i++] = ALC_DEVICE_CLOCK_SOFT;
- values[i++] = device->ClockBase +
- (device->SamplesDone * DEVICE_CLOCK_RES / device->Frequency);
+ values[i++] = clock.ClockTime;
+
+ values[i++] = ALC_DEVICE_LATENCY_SOFT;
+ values[i++] = clock.Latency;
+ almtx_unlock(&device->BackendLock);
values[i++] = 0;
- V0(device->Backend,unlock)();
}
break;
case ALC_DEVICE_CLOCK_SOFT:
- V0(device->Backend,lock)();
- *values = device->ClockBase +
- (device->SamplesDone * DEVICE_CLOCK_RES / device->Frequency);
- V0(device->Backend,unlock)();
+ almtx_lock(&device->BackendLock);
+ do {
+ while(((refcount=ReadRef(&device->MixCount))&1) != 0)
+ althrd_yield();
+ basecount = device->ClockBase;
+ samplecount = device->SamplesDone;
+ } while(refcount != ReadRef(&device->MixCount));
+ *values = basecount + (samplecount*DEVICE_CLOCK_RES/device->Frequency);
+ almtx_unlock(&device->BackendLock);
+ break;
+
+ case ALC_DEVICE_LATENCY_SOFT:
+ almtx_lock(&device->BackendLock);
+ clock = GetClockLatency(device);
+ almtx_unlock(&device->BackendLock);
+ *values = clock.Latency;
+ break;
+
+ case ALC_DEVICE_CLOCK_LATENCY_SOFT:
+ if(size < 2)
+ alcSetError(device, ALC_INVALID_VALUE);
+ else
+ {
+ almtx_lock(&device->BackendLock);
+ clock = GetClockLatency(device);
+ almtx_unlock(&device->BackendLock);
+ values[0] = clock.ClockTime;
+ values[1] = clock.Latency;
+ }
break;
default:
@@ -3060,10 +3712,15 @@ ALC_API ALCvoid* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar
}
else
{
- ALsizei i = 0;
- while(alcFunctions[i].funcName && strcmp(alcFunctions[i].funcName, funcName) != 0)
- i++;
- ptr = alcFunctions[i].address;
+ size_t i = 0;
+ for(i = 0;i < COUNTOF(alcFunctions);i++)
+ {
+ if(strcmp(alcFunctions[i].funcName, funcName) == 0)
+ {
+ ptr = alcFunctions[i].address;
+ break;
+ }
+ }
}
return ptr;
@@ -3086,10 +3743,15 @@ ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *e
}
else
{
- ALsizei i = 0;
- while(enumeration[i].enumName && strcmp(enumeration[i].enumName, enumName) != 0)
- i++;
- val = enumeration[i].value;
+ size_t i = 0;
+ for(i = 0;i < COUNTOF(alcEnumerations);i++)
+ {
+ if(strcmp(alcEnumerations[i].enumName, enumName) == 0)
+ {
+ val = alcEnumerations[i].value;
+ break;
+ }
+ }
}
return val;
@@ -3103,81 +3765,116 @@ ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *e
ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrList)
{
ALCcontext *ALContext;
+ ALfloat valf;
ALCenum err;
+ /* Explicitly hold the list lock while taking the BackendLock in case the
+ * device is asynchronously destropyed, to ensure this new context is
+ * properly cleaned up after being made.
+ */
LockLists();
- if(!VerifyDevice(&device) || device->Type == Capture || !device->Connected)
+ if(!VerifyDevice(&device) || device->Type == Capture ||
+ !ATOMIC_LOAD(&device->Connected, almemory_order_relaxed))
{
UnlockLists();
alcSetError(device, ALC_INVALID_DEVICE);
if(device) ALCdevice_DecRef(device);
return NULL;
}
+ almtx_lock(&device->BackendLock);
+ UnlockLists();
+
+ ATOMIC_STORE_SEQ(&device->LastError, ALC_NO_ERROR);
+
+ if(device->Type == Playback && DefaultEffect.type != AL_EFFECT_NULL)
+ ALContext = al_calloc(16, sizeof(ALCcontext)+sizeof(ALlistener)+sizeof(ALeffectslot));
+ else
+ ALContext = al_calloc(16, sizeof(ALCcontext)+sizeof(ALlistener));
+ if(!ALContext)
+ {
+ almtx_unlock(&device->BackendLock);
+
+ alcSetError(device, ALC_OUT_OF_MEMORY);
+ ALCdevice_DecRef(device);
+ return NULL;
+ }
+
+ InitRef(&ALContext->ref, 1);
+ ALContext->Listener = (ALlistener*)ALContext->_listener_mem;
+ ALContext->DefaultSlot = NULL;
- ATOMIC_STORE(&device->LastError, ALC_NO_ERROR);
+ ALContext->Voices = NULL;
+ ALContext->VoiceCount = 0;
+ ALContext->MaxVoices = 0;
+ ATOMIC_INIT(&ALContext->ActiveAuxSlots, NULL);
+ ALContext->Device = device;
+ ATOMIC_INIT(&ALContext->next, NULL);
if((err=UpdateDeviceParams(device, attrList)) != ALC_NO_ERROR)
{
- UnlockLists();
+ almtx_unlock(&device->BackendLock);
+
+ al_free(ALContext);
+ ALContext = NULL;
+
alcSetError(device, err);
if(err == ALC_INVALID_DEVICE)
{
V0(device->Backend,lock)();
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Device update failure");
V0(device->Backend,unlock)();
}
ALCdevice_DecRef(device);
return NULL;
}
+ AllocateVoices(ALContext, 256, device->NumAuxSends);
- ALContext = al_calloc(16, sizeof(ALCcontext)+sizeof(ALlistener));
- if(ALContext)
- {
- InitRef(&ALContext->ref, 1);
- ALContext->Listener = (ALlistener*)ALContext->_listener_mem;
-
- VECTOR_INIT(ALContext->ActiveAuxSlots);
-
- ALContext->VoiceCount = 0;
- ALContext->MaxVoices = 256;
- ALContext->Voices = al_calloc(16, ALContext->MaxVoices * sizeof(ALContext->Voices[0]));
- }
- if(!ALContext || !ALContext->Voices)
+ if(DefaultEffect.type != AL_EFFECT_NULL && device->Type == Playback)
{
- if(!ATOMIC_LOAD(&device->ContextList))
+ ALContext->DefaultSlot = (ALeffectslot*)(ALContext->_listener_mem + sizeof(ALlistener));
+ if(InitEffectSlot(ALContext->DefaultSlot) == AL_NO_ERROR)
+ aluInitEffectPanning(ALContext->DefaultSlot);
+ else
{
- V0(device->Backend,stop)();
- device->Flags &= ~DEVICE_RUNNING;
+ ALContext->DefaultSlot = NULL;
+ ERR("Failed to initialize the default effect slot\n");
}
- UnlockLists();
-
- if(ALContext)
- {
- al_free(ALContext->Voices);
- ALContext->Voices = NULL;
+ }
- VECTOR_DEINIT(ALContext->ActiveAuxSlots);
+ ALCdevice_IncRef(ALContext->Device);
+ InitContext(ALContext);
- al_free(ALContext);
- ALContext = NULL;
+ if(ConfigValueFloat(alstr_get_cstr(device->DeviceName), NULL, "volume-adjust", &valf))
+ {
+ if(!isfinite(valf))
+ ERR("volume-adjust must be finite: %f\n", valf);
+ else
+ {
+ ALfloat db = clampf(valf, -24.0f, 24.0f);
+ if(db != valf)
+ WARN("volume-adjust clamped: %f, range: +/-%f\n", valf, 24.0f);
+ ALContext->GainBoost = powf(10.0f, db/20.0f);
+ TRACE("volume-adjust gain: %f\n", ALContext->GainBoost);
}
-
- alcSetError(device, ALC_OUT_OF_MEMORY);
- ALCdevice_DecRef(device);
- return NULL;
}
-
- ALContext->Device = device;
- ALCdevice_IncRef(device);
- InitContext(ALContext);
+ UpdateListenerProps(ALContext);
{
- ALCcontext *head = ATOMIC_LOAD(&device->ContextList);
+ ALCcontext *head = ATOMIC_LOAD_SEQ(&device->ContextList);
do {
- ALContext->next = head;
- } while(!ATOMIC_COMPARE_EXCHANGE_WEAK(ALCcontext*, &device->ContextList, &head, ALContext));
+ ATOMIC_STORE(&ALContext->next, head, almemory_order_relaxed);
+ } while(ATOMIC_COMPARE_EXCHANGE_PTR_WEAK_SEQ(&device->ContextList, &head,
+ ALContext) == 0);
+ }
+ almtx_unlock(&device->BackendLock);
+
+ if(ALContext->DefaultSlot)
+ {
+ if(InitializeEffect(ALContext, ALContext->DefaultSlot, &DefaultEffect) == AL_NO_ERROR)
+ UpdateEffectSlotProps(ALContext->DefaultSlot, ALContext);
+ else
+ ERR("Failed to initialize the default effect\n");
}
- UnlockLists();
ALCdevice_DecRef(device);
@@ -3194,18 +3891,27 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
ALCdevice *Device;
LockLists();
- /* alcGetContextsDevice sets an error for invalid contexts */
- Device = alcGetContextsDevice(context);
+ if(!VerifyContext(&context))
+ {
+ UnlockLists();
+ alcSetError(NULL, ALC_INVALID_CONTEXT);
+ return;
+ }
+
+ Device = context->Device;
if(Device)
{
- ReleaseContext(context, Device);
- if(!ATOMIC_LOAD(&Device->ContextList))
+ almtx_lock(&Device->BackendLock);
+ if(!ReleaseContext(context, Device))
{
V0(Device->Backend,stop)();
Device->Flags &= ~DEVICE_RUNNING;
}
+ almtx_unlock(&Device->BackendLock);
}
UnlockLists();
+
+ ALCcontext_DecRef(context);
}
@@ -3216,7 +3922,7 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void)
{
ALCcontext *Context = altss_get(LocalContext);
- if(!Context) Context = ATOMIC_LOAD(&GlobalContext);
+ if(!Context) Context = ATOMIC_LOAD_SEQ(&GlobalContext);
return Context;
}
@@ -3244,7 +3950,7 @@ ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
return ALC_FALSE;
}
/* context's reference count is already incremented */
- context = ATOMIC_EXCHANGE(ALCcontext*, &GlobalContext, context);
+ context = ATOMIC_EXCHANGE_PTR_SEQ(&GlobalContext, context);
if(context) ALCcontext_DecRef(context);
if((context=altss_get(LocalContext)) != NULL)
@@ -3305,6 +4011,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *Context)
*/
ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
{
+ ALCbackendFactory *factory;
const ALCchar *fmt;
ALCdevice *device;
ALCenum err;
@@ -3329,7 +4036,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
))
deviceName = NULL;
- device = al_calloc(16, sizeof(ALCdevice)+sizeof(ALeffectslot));
+ device = al_calloc(16, sizeof(ALCdevice));
if(!device)
{
alcSetError(NULL, ALC_OUT_OF_MEMORY);
@@ -3337,69 +4044,40 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
}
//Validate device
- InitRef(&device->ref, 1);
- device->Connected = ALC_TRUE;
- device->Type = Playback;
- ATOMIC_INIT(&device->LastError, ALC_NO_ERROR);
-
- device->Flags = 0;
- device->Bs2b = NULL;
- VECTOR_INIT(device->Hrtf_List);
- AL_STRING_INIT(device->Hrtf_Name);
- device->Hrtf_Mode = DisabledHrtf;
- AL_STRING_INIT(device->DeviceName);
- device->DryBuffer = NULL;
-
- ATOMIC_INIT(&device->ContextList, NULL);
-
- device->ClockBase = 0;
- device->SamplesDone = 0;
-
- device->MaxNoOfSources = 256;
- device->AuxiliaryEffectSlotMax = 4;
- device->NumAuxSends = MAX_SENDS;
-
- InitUIntMap(&device->BufferMap, ~0);
- InitUIntMap(&device->EffectMap, ~0);
- InitUIntMap(&device->FilterMap, ~0);
+ InitDevice(device, Playback);
//Set output format
device->FmtChans = DevFmtChannelsDefault;
device->FmtType = DevFmtTypeDefault;
device->Frequency = DEFAULT_OUTPUT_RATE;
device->IsHeadphones = AL_FALSE;
- device->NumUpdates = 4;
+ device->AmbiLayout = AmbiLayout_Default;
+ device->AmbiScale = AmbiNorm_Default;
+ device->LimiterState = ALC_TRUE;
+ device->NumUpdates = 3;
device->UpdateSize = 1024;
- if(!PlaybackBackend.getFactory)
- device->Backend = create_backend_wrapper(device, &PlaybackBackend.Funcs,
- ALCbackend_Playback);
- else
- {
- ALCbackendFactory *factory = PlaybackBackend.getFactory();
- device->Backend = V(factory,createBackend)(device, ALCbackend_Playback);
- }
- if(!device->Backend)
- {
- al_free(device);
- alcSetError(NULL, ALC_OUT_OF_MEMORY);
- return NULL;
- }
-
+ device->SourcesMax = 256;
+ device->AuxiliaryEffectSlotMax = 64;
+ device->NumAuxSends = DEFAULT_SENDS;
if(ConfigValueStr(deviceName, NULL, "channels", &fmt))
{
static const struct {
const char name[16];
enum DevFmtChannels chans;
+ ALsizei order;
} chanlist[] = {
- { "mono", DevFmtMono },
- { "stereo", DevFmtStereo },
- { "quad", DevFmtQuad },
- { "surround51", DevFmtX51 },
- { "surround61", DevFmtX61 },
- { "surround71", DevFmtX71 },
- { "surround51rear", DevFmtX51Rear },
+ { "mono", DevFmtMono, 0 },
+ { "stereo", DevFmtStereo, 0 },
+ { "quad", DevFmtQuad, 0 },
+ { "surround51", DevFmtX51, 0 },
+ { "surround61", DevFmtX61, 0 },
+ { "surround71", DevFmtX71, 0 },
+ { "surround51rear", DevFmtX51Rear, 0 },
+ { "ambi1", DevFmtAmbi3D, 1 },
+ { "ambi2", DevFmtAmbi3D, 2 },
+ { "ambi3", DevFmtAmbi3D, 3 },
};
size_t i;
@@ -3408,6 +4086,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
if(strcasecmp(chanlist[i].name, fmt) == 0)
{
device->FmtChans = chanlist[i].chans;
+ device->AmbiOrder = chanlist[i].order;
device->Flags |= DEVICE_CHANNELS_REQUEST;
break;
}
@@ -3460,52 +4139,67 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
if((CPUCapFlags&(CPU_CAP_SSE|CPU_CAP_NEON)) != 0)
device->UpdateSize = (device->UpdateSize+3)&~3;
- ConfigValueUInt(deviceName, NULL, "sources", &device->MaxNoOfSources);
- if(device->MaxNoOfSources == 0) device->MaxNoOfSources = 256;
+ ConfigValueUInt(deviceName, NULL, "sources", &device->SourcesMax);
+ if(device->SourcesMax == 0) device->SourcesMax = 256;
ConfigValueUInt(deviceName, NULL, "slots", &device->AuxiliaryEffectSlotMax);
- if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 4;
+ if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 64;
+ else device->AuxiliaryEffectSlotMax = minu(device->AuxiliaryEffectSlotMax, INT_MAX);
- ConfigValueUInt(deviceName, NULL, "sends", &device->NumAuxSends);
- if(device->NumAuxSends > MAX_SENDS) device->NumAuxSends = MAX_SENDS;
+ if(ConfigValueInt(deviceName, NULL, "sends", &device->NumAuxSends))
+ device->NumAuxSends = clampi(
+ DEFAULT_SENDS, 0, clampi(device->NumAuxSends, 0, MAX_SENDS)
+ );
device->NumStereoSources = 1;
- device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
+ device->NumMonoSources = device->SourcesMax - device->NumStereoSources;
+
+ factory = PlaybackBackend.getFactory();
+ device->Backend = V(factory,createBackend)(device, ALCbackend_Playback);
+ if(!device->Backend)
+ {
+ FreeDevice(device);
+ alcSetError(NULL, ALC_OUT_OF_MEMORY);
+ return NULL;
+ }
// Find a playback device to open
if((err=V(device->Backend,open)(deviceName)) != ALC_NO_ERROR)
{
- DELETE_OBJ(device->Backend);
- al_free(device);
+ FreeDevice(device);
alcSetError(NULL, err);
return NULL;
}
- if(DefaultEffect.type != AL_EFFECT_NULL)
+ if(ConfigValueStr(alstr_get_cstr(device->DeviceName), NULL, "ambi-format", &fmt))
{
- device->DefaultSlot = (ALeffectslot*)device->_slot_mem;
- if(InitEffectSlot(device->DefaultSlot) != AL_NO_ERROR)
+ if(strcasecmp(fmt, "fuma") == 0)
{
- device->DefaultSlot = NULL;
- ERR("Failed to initialize the default effect slot\n");
+ device->AmbiLayout = AmbiLayout_FuMa;
+ device->AmbiScale = AmbiNorm_FuMa;
}
- else if(InitializeEffect(device, device->DefaultSlot, &DefaultEffect) != AL_NO_ERROR)
+ else if(strcasecmp(fmt, "acn+sn3d") == 0)
{
- ALeffectState *state = device->DefaultSlot->EffectState;
- device->DefaultSlot = NULL;
- DELETE_OBJ(state);
- ERR("Failed to initialize the default effect\n");
+ device->AmbiLayout = AmbiLayout_ACN;
+ device->AmbiScale = AmbiNorm_SN3D;
+ }
+ else if(strcasecmp(fmt, "acn+n3d") == 0)
+ {
+ device->AmbiLayout = AmbiLayout_ACN;
+ device->AmbiScale = AmbiNorm_N3D;
}
+ else
+ ERR("Unsupported ambi-format: %s\n", fmt);
}
{
- ALCdevice *head = ATOMIC_LOAD(&DeviceList);
+ ALCdevice *head = ATOMIC_LOAD_SEQ(&DeviceList);
do {
- device->next = head;
- } while(!ATOMIC_COMPARE_EXCHANGE_WEAK(ALCdevice*, &DeviceList, &head, device));
+ ATOMIC_STORE(&device->next, head, almemory_order_relaxed);
+ } while(!ATOMIC_COMPARE_EXCHANGE_PTR_WEAK_SEQ(&DeviceList, &head, device));
}
- TRACE("Created device %p, \"%s\"\n", device, al_string_get_cstr(device->DeviceName));
+ TRACE("Created device %p, \"%s\"\n", device, alstr_get_cstr(device->DeviceName));
return device;
}
@@ -3515,37 +4209,40 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
*/
ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device)
{
- ALCdevice *list, *origdev, *nextdev;
+ ALCdevice *iter, *origdev, *nextdev;
ALCcontext *ctx;
LockLists();
- list = ATOMIC_LOAD(&DeviceList);
+ iter = ATOMIC_LOAD_SEQ(&DeviceList);
do {
- if(list == device)
+ if(iter == device)
break;
- } while((list=list->next) != NULL);
- if(!list || list->Type == Capture)
+ iter = ATOMIC_LOAD(&iter->next, almemory_order_relaxed);
+ } while(iter != NULL);
+ if(!iter || iter->Type == Capture)
{
- alcSetError(list, ALC_INVALID_DEVICE);
+ alcSetError(iter, ALC_INVALID_DEVICE);
UnlockLists();
return ALC_FALSE;
}
+ almtx_lock(&device->BackendLock);
origdev = device;
- nextdev = device->next;
- if(!ATOMIC_COMPARE_EXCHANGE_STRONG(ALCdevice*, &DeviceList, &origdev, nextdev))
+ nextdev = ATOMIC_LOAD(&device->next, almemory_order_relaxed);
+ if(!ATOMIC_COMPARE_EXCHANGE_PTR_STRONG_SEQ(&DeviceList, &origdev, nextdev))
{
+ ALCdevice *list;
do {
list = origdev;
origdev = device;
- } while(!COMPARE_EXCHANGE(&list->next, &origdev, nextdev));
+ } while(!ATOMIC_COMPARE_EXCHANGE_PTR_STRONG_SEQ(&list->next, &origdev, nextdev));
}
UnlockLists();
- ctx = ATOMIC_LOAD(&device->ContextList);
+ ctx = ATOMIC_LOAD_SEQ(&device->ContextList);
while(ctx != NULL)
{
- ALCcontext *next = ctx->next;
+ ALCcontext *next = ATOMIC_LOAD(&ctx->next, almemory_order_relaxed);
WARN("Releasing context %p\n", ctx);
ReleaseContext(ctx, device);
ctx = next;
@@ -3553,6 +4250,7 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device)
if((device->Flags&DEVICE_RUNNING))
V0(device->Backend,stop)();
device->Flags &= ~DEVICE_RUNNING;
+ almtx_unlock(&device->BackendLock);
ALCdevice_DecRef(device);
@@ -3565,6 +4263,7 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device)
************************************************/
ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, ALCuint frequency, ALCenum format, ALCsizei samples)
{
+ ALCbackendFactory *factory;
ALCdevice *device = NULL;
ALCenum err;
@@ -3593,96 +4292,93 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
}
//Validate device
- InitRef(&device->ref, 1);
- device->Connected = ALC_TRUE;
- device->Type = Capture;
-
- VECTOR_INIT(device->Hrtf_List);
- AL_STRING_INIT(device->Hrtf_Name);
-
- AL_STRING_INIT(device->DeviceName);
- device->DryBuffer = NULL;
+ InitDevice(device, Capture);
- InitUIntMap(&device->BufferMap, ~0);
- InitUIntMap(&device->EffectMap, ~0);
- InitUIntMap(&device->FilterMap, ~0);
-
- if(!CaptureBackend.getFactory)
- device->Backend = create_backend_wrapper(device, &CaptureBackend.Funcs,
- ALCbackend_Capture);
- else
- {
- ALCbackendFactory *factory = CaptureBackend.getFactory();
- device->Backend = V(factory,createBackend)(device, ALCbackend_Capture);
- }
- if(!device->Backend)
- {
- al_free(device);
- alcSetError(NULL, ALC_OUT_OF_MEMORY);
- return NULL;
- }
-
- device->Flags |= DEVICE_FREQUENCY_REQUEST;
device->Frequency = frequency;
+ device->Flags |= DEVICE_FREQUENCY_REQUEST;
- device->Flags |= DEVICE_CHANNELS_REQUEST | DEVICE_SAMPLE_TYPE_REQUEST;
if(DecomposeDevFormat(format, &device->FmtChans, &device->FmtType) == AL_FALSE)
{
- al_free(device);
+ FreeDevice(device);
alcSetError(NULL, ALC_INVALID_ENUM);
return NULL;
}
+ device->Flags |= DEVICE_CHANNELS_REQUEST | DEVICE_SAMPLE_TYPE_REQUEST;
device->IsHeadphones = AL_FALSE;
+ device->AmbiOrder = 0;
+ device->AmbiLayout = AmbiLayout_Default;
+ device->AmbiScale = AmbiNorm_Default;
device->UpdateSize = samples;
device->NumUpdates = 1;
+ factory = CaptureBackend.getFactory();
+ device->Backend = V(factory,createBackend)(device, ALCbackend_Capture);
+ if(!device->Backend)
+ {
+ FreeDevice(device);
+ alcSetError(NULL, ALC_OUT_OF_MEMORY);
+ return NULL;
+ }
+
+ TRACE("Capture format: %s, %s, %uhz, %u update size x%d\n",
+ DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType),
+ device->Frequency, device->UpdateSize, device->NumUpdates
+ );
if((err=V(device->Backend,open)(deviceName)) != ALC_NO_ERROR)
{
- al_free(device);
+ FreeDevice(device);
alcSetError(NULL, err);
return NULL;
}
{
- ALCdevice *head = ATOMIC_LOAD(&DeviceList);
+ ALCdevice *head = ATOMIC_LOAD_SEQ(&DeviceList);
do {
- device->next = head;
- } while(!ATOMIC_COMPARE_EXCHANGE_WEAK(ALCdevice*, &DeviceList, &head, device));
+ ATOMIC_STORE(&device->next, head, almemory_order_relaxed);
+ } while(!ATOMIC_COMPARE_EXCHANGE_PTR_WEAK_SEQ(&DeviceList, &head, device));
}
- TRACE("Created device %p, \"%s\"\n", device, al_string_get_cstr(device->DeviceName));
+ TRACE("Created device %p, \"%s\"\n", device, alstr_get_cstr(device->DeviceName));
return device;
}
ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *device)
{
- ALCdevice *list, *next, *nextdev;
+ ALCdevice *iter, *origdev, *nextdev;
LockLists();
- list = ATOMIC_LOAD(&DeviceList);
+ iter = ATOMIC_LOAD_SEQ(&DeviceList);
do {
- if(list == device)
+ if(iter == device)
break;
- } while((list=list->next) != NULL);
- if(!list || list->Type != Capture)
+ iter = ATOMIC_LOAD(&iter->next, almemory_order_relaxed);
+ } while(iter != NULL);
+ if(!iter || iter->Type != Capture)
{
- alcSetError(list, ALC_INVALID_DEVICE);
+ alcSetError(iter, ALC_INVALID_DEVICE);
UnlockLists();
return ALC_FALSE;
}
- next = device;
- nextdev = device->next;
- if(!ATOMIC_COMPARE_EXCHANGE_STRONG(ALCdevice*, &DeviceList, &next, nextdev))
+ origdev = device;
+ nextdev = ATOMIC_LOAD(&device->next, almemory_order_relaxed);
+ if(!ATOMIC_COMPARE_EXCHANGE_PTR_STRONG_SEQ(&DeviceList, &origdev, nextdev))
{
+ ALCdevice *list;
do {
- list = next;
- next = device;
- } while(!COMPARE_EXCHANGE(&list->next, &next, nextdev));
+ list = origdev;
+ origdev = device;
+ } while(!ATOMIC_COMPARE_EXCHANGE_PTR_STRONG_SEQ(&list->next, &origdev, nextdev));
}
UnlockLists();
+ almtx_lock(&device->BackendLock);
+ if((device->Flags&DEVICE_RUNNING))
+ V0(device->Backend,stop)();
+ device->Flags &= ~DEVICE_RUNNING;
+ almtx_unlock(&device->BackendLock);
+
ALCdevice_DecRef(device);
return ALC_TRUE;
@@ -3694,8 +4390,8 @@ ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
alcSetError(device, ALC_INVALID_DEVICE);
else
{
- V0(device->Backend,lock)();
- if(!device->Connected)
+ almtx_lock(&device->BackendLock);
+ if(!ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
alcSetError(device, ALC_INVALID_DEVICE);
else if(!(device->Flags&DEVICE_RUNNING))
{
@@ -3703,11 +4399,11 @@ ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
device->Flags |= DEVICE_RUNNING;
else
{
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Device start failure");
alcSetError(device, ALC_INVALID_DEVICE);
}
}
- V0(device->Backend,unlock)();
+ almtx_unlock(&device->BackendLock);
}
if(device) ALCdevice_DecRef(device);
@@ -3719,11 +4415,11 @@ ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
alcSetError(device, ALC_INVALID_DEVICE);
else
{
- V0(device->Backend,lock)();
+ almtx_lock(&device->BackendLock);
if((device->Flags&DEVICE_RUNNING))
V0(device->Backend,stop)();
device->Flags &= ~DEVICE_RUNNING;
- V0(device->Backend,unlock)();
+ almtx_unlock(&device->BackendLock);
}
if(device) ALCdevice_DecRef(device);
@@ -3737,10 +4433,10 @@ ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer,
{
ALCenum err = ALC_INVALID_VALUE;
- V0(device->Backend,lock)();
+ almtx_lock(&device->BackendLock);
if(samples >= 0 && V0(device->Backend,availableSamples)() >= (ALCuint)samples)
err = V(device->Backend,captureSamples)(buffer, samples);
- V0(device->Backend,unlock)();
+ almtx_unlock(&device->BackendLock);
if(err != ALC_NO_ERROR)
alcSetError(device, err);
@@ -3779,40 +4475,11 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
}
//Validate device
- InitRef(&device->ref, 1);
- device->Connected = ALC_TRUE;
- device->Type = Loopback;
- ATOMIC_INIT(&device->LastError, ALC_NO_ERROR);
-
- device->Flags = 0;
- VECTOR_INIT(device->Hrtf_List);
- AL_STRING_INIT(device->Hrtf_Name);
- device->Bs2b = NULL;
- device->Hrtf_Mode = DisabledHrtf;
- AL_STRING_INIT(device->DeviceName);
- device->DryBuffer = NULL;
-
- ATOMIC_INIT(&device->ContextList, NULL);
-
- device->ClockBase = 0;
- device->SamplesDone = 0;
-
- device->MaxNoOfSources = 256;
- device->AuxiliaryEffectSlotMax = 4;
- device->NumAuxSends = MAX_SENDS;
+ InitDevice(device, Loopback);
- InitUIntMap(&device->BufferMap, ~0);
- InitUIntMap(&device->EffectMap, ~0);
- InitUIntMap(&device->FilterMap, ~0);
-
- factory = ALCloopbackFactory_getFactory();
- device->Backend = V(factory,createBackend)(device, ALCbackend_Loopback);
- if(!device->Backend)
- {
- al_free(device);
- alcSetError(NULL, ALC_OUT_OF_MEMORY);
- return NULL;
- }
+ device->SourcesMax = 256;
+ device->AuxiliaryEffectSlotMax = 64;
+ device->NumAuxSends = DEFAULT_SENDS;
//Set output format
device->NumUpdates = 0;
@@ -3822,27 +4489,41 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
device->FmtChans = DevFmtChannelsDefault;
device->FmtType = DevFmtTypeDefault;
device->IsHeadphones = AL_FALSE;
+ device->AmbiLayout = AmbiLayout_Default;
+ device->AmbiScale = AmbiNorm_Default;
- ConfigValueUInt(NULL, NULL, "sources", &device->MaxNoOfSources);
- if(device->MaxNoOfSources == 0) device->MaxNoOfSources = 256;
+ ConfigValueUInt(NULL, NULL, "sources", &device->SourcesMax);
+ if(device->SourcesMax == 0) device->SourcesMax = 256;
ConfigValueUInt(NULL, NULL, "slots", &device->AuxiliaryEffectSlotMax);
- if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 4;
+ if(device->AuxiliaryEffectSlotMax == 0) device->AuxiliaryEffectSlotMax = 64;
+ else device->AuxiliaryEffectSlotMax = minu(device->AuxiliaryEffectSlotMax, INT_MAX);
- ConfigValueUInt(NULL, NULL, "sends", &device->NumAuxSends);
- if(device->NumAuxSends > MAX_SENDS) device->NumAuxSends = MAX_SENDS;
+ if(ConfigValueInt(NULL, NULL, "sends", &device->NumAuxSends))
+ device->NumAuxSends = clampi(
+ DEFAULT_SENDS, 0, clampi(device->NumAuxSends, 0, MAX_SENDS)
+ );
device->NumStereoSources = 1;
- device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
+ device->NumMonoSources = device->SourcesMax - device->NumStereoSources;
+
+ factory = ALCloopbackFactory_getFactory();
+ device->Backend = V(factory,createBackend)(device, ALCbackend_Loopback);
+ if(!device->Backend)
+ {
+ al_free(device);
+ alcSetError(NULL, ALC_OUT_OF_MEMORY);
+ return NULL;
+ }
// Open the "backend"
V(device->Backend,open)("Loopback");
{
- ALCdevice *head = ATOMIC_LOAD(&DeviceList);
+ ALCdevice *head = ATOMIC_LOAD_SEQ(&DeviceList);
do {
- device->next = head;
- } while(!ATOMIC_COMPARE_EXCHANGE_WEAK(ALCdevice*, &DeviceList, &head, device));
+ ATOMIC_STORE(&device->next, head, almemory_order_relaxed);
+ } while(!ATOMIC_COMPARE_EXCHANGE_PTR_WEAK_SEQ(&DeviceList, &head, device));
}
TRACE("Created device %p\n", device);
@@ -3863,9 +4544,7 @@ ALC_API ALCboolean ALC_APIENTRY alcIsRenderFormatSupportedSOFT(ALCdevice *device
alcSetError(device, ALC_INVALID_VALUE);
else
{
- if(IsValidALCType(type) && BytesFromDevFmt(type) > 0 &&
- IsValidALCChannels(channels) && ChannelsFromDevFmt(channels) > 0 &&
- freq >= MIN_OUTPUT_RATE)
+ if(IsValidALCType(type) && IsValidALCChannels(channels) && freq >= MIN_OUTPUT_RATE)
ret = ALC_TRUE;
}
if(device) ALCdevice_DecRef(device);
@@ -3885,7 +4564,11 @@ FORCE_ALIGN ALC_API void ALC_APIENTRY alcRenderSamplesSOFT(ALCdevice *device, AL
else if(samples < 0 || (samples > 0 && buffer == NULL))
alcSetError(device, ALC_INVALID_VALUE);
else
+ {
+ V0(device->Backend,lock)();
aluMixData(device, buffer, samples);
+ V0(device->Backend,unlock)();
+ }
if(device) ALCdevice_DecRef(device);
}
@@ -3904,12 +4587,12 @@ ALC_API void ALC_APIENTRY alcDevicePauseSOFT(ALCdevice *device)
alcSetError(device, ALC_INVALID_DEVICE);
else
{
- LockLists();
+ almtx_lock(&device->BackendLock);
if((device->Flags&DEVICE_RUNNING))
V0(device->Backend,stop)();
device->Flags &= ~DEVICE_RUNNING;
device->Flags |= DEVICE_PAUSED;
- UnlockLists();
+ almtx_unlock(&device->BackendLock);
}
if(device) ALCdevice_DecRef(device);
}
@@ -3924,24 +4607,24 @@ ALC_API void ALC_APIENTRY alcDeviceResumeSOFT(ALCdevice *device)
alcSetError(device, ALC_INVALID_DEVICE);
else
{
- LockLists();
+ almtx_lock(&device->BackendLock);
if((device->Flags&DEVICE_PAUSED))
{
device->Flags &= ~DEVICE_PAUSED;
- if(ATOMIC_LOAD(&device->ContextList) != NULL)
+ if(ATOMIC_LOAD_SEQ(&device->ContextList) != NULL)
{
if(V0(device->Backend,start)() != ALC_FALSE)
device->Flags |= DEVICE_RUNNING;
else
{
- alcSetError(device, ALC_INVALID_DEVICE);
V0(device->Backend,lock)();
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Device start failure");
V0(device->Backend,unlock)();
+ alcSetError(device, ALC_INVALID_DEVICE);
}
}
}
- UnlockLists();
+ almtx_unlock(&device->BackendLock);
}
if(device) ALCdevice_DecRef(device);
}
@@ -3964,8 +4647,8 @@ ALC_API const ALCchar* ALC_APIENTRY alcGetStringiSOFT(ALCdevice *device, ALCenum
else switch(paramName)
{
case ALC_HRTF_SPECIFIER_SOFT:
- if(index >= 0 && (size_t)index < VECTOR_SIZE(device->Hrtf_List))
- str = al_string_get_cstr(VECTOR_ELEM(device->Hrtf_List, index).name);
+ if(index >= 0 && (size_t)index < VECTOR_SIZE(device->HrtfList))
+ str = alstr_get_cstr(VECTOR_ELEM(device->HrtfList, index).name);
else
alcSetError(device, ALC_INVALID_VALUE);
break;
@@ -3988,28 +4671,32 @@ ALC_API ALCboolean ALC_APIENTRY alcResetDeviceSOFT(ALCdevice *device, const ALCi
ALCenum err;
LockLists();
- if(!VerifyDevice(&device) || device->Type == Capture || !device->Connected)
+ if(!VerifyDevice(&device) || device->Type == Capture ||
+ !ATOMIC_LOAD(&device->Connected, almemory_order_relaxed))
{
UnlockLists();
alcSetError(device, ALC_INVALID_DEVICE);
if(device) ALCdevice_DecRef(device);
return ALC_FALSE;
}
+ almtx_lock(&device->BackendLock);
+ UnlockLists();
+
+ err = UpdateDeviceParams(device, attribs);
+ almtx_unlock(&device->BackendLock);
- if((err=UpdateDeviceParams(device, attribs)) != ALC_NO_ERROR)
+ if(err != ALC_NO_ERROR)
{
- UnlockLists();
alcSetError(device, err);
if(err == ALC_INVALID_DEVICE)
{
V0(device->Backend,lock)();
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Device start failure");
V0(device->Backend,unlock)();
}
ALCdevice_DecRef(device);
return ALC_FALSE;
}
- UnlockLists();
ALCdevice_DecRef(device);
return ALC_TRUE;
diff --git a/Alc/ALu.c b/Alc/ALu.c
index 91c2aa7f..03abb116 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -34,25 +34,21 @@
#include "alu.h"
#include "bs2b.h"
#include "hrtf.h"
+#include "mastering.h"
+#include "uhjfilter.h"
+#include "bformatdec.h"
#include "static_assert.h"
+#include "ringbuffer.h"
+#include "filters/splitter.h"
-#include "mixer_defs.h"
+#include "mixer/defs.h"
+#include "fpu_modes.h"
+#include "cpu_caps.h"
+#include "bsinc_inc.h"
#include "backends/base.h"
-struct ChanMap {
- enum Channel channel;
- ALfloat angle;
- ALfloat elevation;
-};
-
-/* Cone scalar */
-ALfloat ConeScale = 1.0f;
-
-/* Localized Z scalar for mono sources */
-ALfloat ZScale = 1.0f;
-
extern inline ALfloat minf(ALfloat a, ALfloat b);
extern inline ALfloat maxf(ALfloat a, ALfloat b);
extern inline ALfloat clampf(ALfloat val, ALfloat min, ALfloat max);
@@ -77,9 +73,12 @@ extern inline ALuint64 minu64(ALuint64 a, ALuint64 b);
extern inline ALuint64 maxu64(ALuint64 a, ALuint64 b);
extern inline ALuint64 clampu64(ALuint64 val, ALuint64 min, ALuint64 max);
+extern inline size_t minz(size_t a, size_t b);
+extern inline size_t maxz(size_t a, size_t b);
+extern inline size_t clampz(size_t val, size_t min, size_t max);
+
extern inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu);
-extern inline ALfloat resample_fir4(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALuint frac);
-extern inline ALfloat resample_fir8(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALfloat val4, ALfloat val5, ALfloat val6, ALfloat val7, ALuint frac);
+extern inline ALfloat cubic(ALfloat val1, ALfloat val2, ALfloat val3, ALfloat val4, ALfloat mu);
extern inline void aluVectorSet(aluVector *restrict vector, ALfloat x, ALfloat y, ALfloat z, ALfloat w);
@@ -91,50 +90,69 @@ extern inline void aluMatrixfSet(aluMatrixf *matrix,
ALfloat m20, ALfloat m21, ALfloat m22, ALfloat m23,
ALfloat m30, ALfloat m31, ALfloat m32, ALfloat m33);
-extern inline void aluMatrixdSetRow(aluMatrixd *matrix, ALuint row,
- ALdouble m0, ALdouble m1, ALdouble m2, ALdouble m3);
-extern inline void aluMatrixdSet(aluMatrixd *matrix,
- ALdouble m00, ALdouble m01, ALdouble m02, ALdouble m03,
- ALdouble m10, ALdouble m11, ALdouble m12, ALdouble m13,
- ALdouble m20, ALdouble m21, ALdouble m22, ALdouble m23,
- ALdouble m30, ALdouble m31, ALdouble m32, ALdouble m33);
+/* Cone scalar */
+ALfloat ConeScale = 1.0f;
+
+/* Localized Z scalar for mono sources */
+ALfloat ZScale = 1.0f;
+
+/* Force default speed of sound for distance-related reverb decay. */
+ALboolean OverrideReverbSpeedOfSound = AL_FALSE;
+
+const aluMatrixf IdentityMatrixf = {{
+ { 1.0f, 0.0f, 0.0f, 0.0f },
+ { 0.0f, 1.0f, 0.0f, 0.0f },
+ { 0.0f, 0.0f, 1.0f, 0.0f },
+ { 0.0f, 0.0f, 0.0f, 1.0f },
+}};
-/* NOTE: HRTF is set up a bit special in the device. By default, the device's
- * DryBuffer, NumChannels, ChannelName, and Channel fields correspond to the
- * output mixing format, and the DryBuffer is then converted and written to the
- * backend's audio buffer.
- *
- * With HRTF, these fields correspond to a virtual format (typically B-Format),
- * and the actual output is stored in DryBuffer[NumChannels] for the left
- * channel and DryBuffer[NumChannels+1] for the right. As a final output step,
- * the virtual channels will have HRTF applied and written to the actual
- * output. Things like effects and B-Format decoding will want to write to the
- * virtual channels so that they can be mixed with HRTF in full 3D.
- *
- * Sources that get mixed using HRTF directly (or that want to skip HRTF
- * completely) will need to offset the output buffer so that they skip the
- * virtual output and write to the actual output channels. This is the reason
- * you'll see
- *
- * voice->Direct.OutBuffer += voice->Direct.OutChannels;
- * voice->Direct.OutChannels = 2;
- *
- * at various points in the code where HRTF is explicitly used or bypassed.
- */
-static inline HrtfMixerFunc SelectHrtfMixer(void)
+static void ClearArray(ALfloat f[MAX_OUTPUT_CHANNELS])
+{
+ size_t i;
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ f[i] = 0.0f;
+}
+
+struct ChanMap {
+ enum Channel channel;
+ ALfloat angle;
+ ALfloat elevation;
+};
+
+static HrtfDirectMixerFunc MixDirectHrtf = MixDirectHrtf_C;
+
+
+void DeinitVoice(ALvoice *voice)
+{
+ al_free(ATOMIC_EXCHANGE_PTR_SEQ(&voice->Update, NULL));
+}
+
+
+static inline HrtfDirectMixerFunc SelectHrtfMixer(void)
{
-#ifdef HAVE_SSE
- if((CPUCapFlags&CPU_CAP_SSE))
- return MixHrtf_SSE;
-#endif
#ifdef HAVE_NEON
if((CPUCapFlags&CPU_CAP_NEON))
- return MixHrtf_Neon;
+ return MixDirectHrtf_Neon;
+#endif
+#ifdef HAVE_SSE
+ if((CPUCapFlags&CPU_CAP_SSE))
+ return MixDirectHrtf_SSE;
#endif
- return MixHrtf_C;
+ return MixDirectHrtf_C;
+}
+
+
+/* This RNG method was created based on the math found in opusdec. It's quick,
+ * and starting with a seed value of 22222, is suitable for generating
+ * whitenoise.
+ */
+static inline ALuint dither_rng(ALuint *seed)
+{
+ *seed = (*seed * 96314165) + 907633515;
+ return *seed;
}
@@ -150,1337 +168,1646 @@ static inline ALfloat aluDotproduct(const aluVector *vec1, const aluVector *vec2
return vec1->v[0]*vec2->v[0] + vec1->v[1]*vec2->v[1] + vec1->v[2]*vec2->v[2];
}
-static inline ALfloat aluNormalize(ALfloat *vec)
+static ALfloat aluNormalize(ALfloat *vec)
{
ALfloat length = sqrtf(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]);
- if(length > 0.0f)
+ if(length > FLT_EPSILON)
{
ALfloat inv_length = 1.0f/length;
vec[0] *= inv_length;
vec[1] *= inv_length;
vec[2] *= inv_length;
+ return length;
}
- return length;
+ vec[0] = vec[1] = vec[2] = 0.0f;
+ return 0.0f;
}
+static void aluMatrixfFloat3(ALfloat *vec, ALfloat w, const aluMatrixf *mtx)
+{
+ ALfloat v[4] = { vec[0], vec[1], vec[2], w };
-static inline void aluCrossproductd(const ALdouble *inVector1, const ALdouble *inVector2, ALdouble *outVector)
+ vec[0] = v[0]*mtx->m[0][0] + v[1]*mtx->m[1][0] + v[2]*mtx->m[2][0] + v[3]*mtx->m[3][0];
+ vec[1] = v[0]*mtx->m[0][1] + v[1]*mtx->m[1][1] + v[2]*mtx->m[2][1] + v[3]*mtx->m[3][1];
+ vec[2] = v[0]*mtx->m[0][2] + v[1]*mtx->m[1][2] + v[2]*mtx->m[2][2] + v[3]*mtx->m[3][2];
+}
+
+static aluVector aluMatrixfVector(const aluMatrixf *mtx, const aluVector *vec)
{
- outVector[0] = inVector1[1]*inVector2[2] - inVector1[2]*inVector2[1];
- outVector[1] = inVector1[2]*inVector2[0] - inVector1[0]*inVector2[2];
- outVector[2] = inVector1[0]*inVector2[1] - inVector1[1]*inVector2[0];
+ aluVector v;
+ v.v[0] = vec->v[0]*mtx->m[0][0] + vec->v[1]*mtx->m[1][0] + vec->v[2]*mtx->m[2][0] + vec->v[3]*mtx->m[3][0];
+ v.v[1] = vec->v[0]*mtx->m[0][1] + vec->v[1]*mtx->m[1][1] + vec->v[2]*mtx->m[2][1] + vec->v[3]*mtx->m[3][1];
+ v.v[2] = vec->v[0]*mtx->m[0][2] + vec->v[1]*mtx->m[1][2] + vec->v[2]*mtx->m[2][2] + vec->v[3]*mtx->m[3][2];
+ v.v[3] = vec->v[0]*mtx->m[0][3] + vec->v[1]*mtx->m[1][3] + vec->v[2]*mtx->m[2][3] + vec->v[3]*mtx->m[3][3];
+ return v;
+}
+
+
+void aluInit(void)
+{
+ MixDirectHrtf = SelectHrtfMixer();
}
-static inline ALdouble aluNormalized(ALdouble *vec)
+
+static void SendSourceStoppedEvent(ALCcontext *context, ALuint id)
{
- ALdouble length = sqrt(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]);
- if(length > 0.0)
+ AsyncEvent evt = ASYNC_EVENT(EventType_SourceStateChange);
+ ALbitfieldSOFT enabledevt;
+ size_t strpos;
+ ALuint scale;
+
+ enabledevt = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_acquire);
+ if(!(enabledevt&EventType_SourceStateChange)) return;
+
+ evt.u.user.type = AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT;
+ evt.u.user.id = id;
+ evt.u.user.param = AL_STOPPED;
+
+ /* Normally snprintf would be used, but this is called from the mixer and
+ * that function's not real-time safe, so we have to construct it manually.
+ */
+ strcpy(evt.u.user.msg, "Source ID "); strpos = 10;
+ scale = 1000000000;
+ while(scale > 0 && scale > id)
+ scale /= 10;
+ while(scale > 0)
{
- ALdouble inv_length = 1.0/length;
- vec[0] *= inv_length;
- vec[1] *= inv_length;
- vec[2] *= inv_length;
+ evt.u.user.msg[strpos++] = '0' + ((id/scale)%10);
+ scale /= 10;
}
- return length;
+ strcpy(evt.u.user.msg+strpos, " state changed to AL_STOPPED");
+
+ if(ll_ringbuffer_write(context->AsyncEvents, (const char*)&evt, 1) == 1)
+ alsem_post(&context->EventSem);
}
-static inline ALvoid aluMatrixdFloat3(ALfloat *vec, ALfloat w, const aluMatrixd *mtx)
+
+static void ProcessHrtf(ALCdevice *device, ALsizei SamplesToDo)
{
- ALdouble v[4] = { vec[0], vec[1], vec[2], w };
+ DirectHrtfState *state;
+ int lidx, ridx;
+ ALsizei c;
+
+ if(device->AmbiUp)
+ ambiup_process(device->AmbiUp,
+ device->Dry.Buffer, device->Dry.NumChannels, device->FOAOut.Buffer,
+ SamplesToDo
+ );
- vec[0] = (ALfloat)(v[0]*mtx->m[0][0] + v[1]*mtx->m[1][0] + v[2]*mtx->m[2][0] + v[3]*mtx->m[3][0]);
- vec[1] = (ALfloat)(v[0]*mtx->m[0][1] + v[1]*mtx->m[1][1] + v[2]*mtx->m[2][1] + v[3]*mtx->m[3][1]);
- vec[2] = (ALfloat)(v[0]*mtx->m[0][2] + v[1]*mtx->m[1][2] + v[2]*mtx->m[2][2] + v[3]*mtx->m[3][2]);
+ lidx = GetChannelIdxByName(&device->RealOut, FrontLeft);
+ ridx = GetChannelIdxByName(&device->RealOut, FrontRight);
+ assert(lidx != -1 && ridx != -1);
+
+ state = device->Hrtf;
+ for(c = 0;c < device->Dry.NumChannels;c++)
+ {
+ MixDirectHrtf(device->RealOut.Buffer[lidx], device->RealOut.Buffer[ridx],
+ device->Dry.Buffer[c], state->Offset, state->IrSize,
+ state->Chan[c].Coeffs, state->Chan[c].Values, SamplesToDo
+ );
+ }
+ state->Offset += SamplesToDo;
}
-static inline ALvoid aluMatrixdDouble3(ALdouble *vec, ALdouble w, const aluMatrixd *mtx)
+static void ProcessAmbiDec(ALCdevice *device, ALsizei SamplesToDo)
{
- ALdouble v[4] = { vec[0], vec[1], vec[2], w };
+ if(device->Dry.Buffer != device->FOAOut.Buffer)
+ bformatdec_upSample(device->AmbiDecoder,
+ device->Dry.Buffer, device->FOAOut.Buffer, device->FOAOut.NumChannels,
+ SamplesToDo
+ );
+ bformatdec_process(device->AmbiDecoder,
+ device->RealOut.Buffer, device->RealOut.NumChannels, device->Dry.Buffer,
+ SamplesToDo
+ );
+}
- vec[0] = v[0]*mtx->m[0][0] + v[1]*mtx->m[1][0] + v[2]*mtx->m[2][0] + v[3]*mtx->m[3][0];
- vec[1] = v[0]*mtx->m[0][1] + v[1]*mtx->m[1][1] + v[2]*mtx->m[2][1] + v[3]*mtx->m[3][1];
- vec[2] = v[0]*mtx->m[0][2] + v[1]*mtx->m[1][2] + v[2]*mtx->m[2][2] + v[3]*mtx->m[3][2];
+static void ProcessAmbiUp(ALCdevice *device, ALsizei SamplesToDo)
+{
+ ambiup_process(device->AmbiUp,
+ device->RealOut.Buffer, device->RealOut.NumChannels, device->FOAOut.Buffer,
+ SamplesToDo
+ );
}
-static inline aluVector aluMatrixdVector(const aluMatrixd *mtx, const aluVector *vec)
+static void ProcessUhj(ALCdevice *device, ALsizei SamplesToDo)
{
- aluVector v;
- v.v[0] = (ALfloat)(vec->v[0]*mtx->m[0][0] + vec->v[1]*mtx->m[1][0] + vec->v[2]*mtx->m[2][0] + vec->v[3]*mtx->m[3][0]);
- v.v[1] = (ALfloat)(vec->v[0]*mtx->m[0][1] + vec->v[1]*mtx->m[1][1] + vec->v[2]*mtx->m[2][1] + vec->v[3]*mtx->m[3][1]);
- v.v[2] = (ALfloat)(vec->v[0]*mtx->m[0][2] + vec->v[1]*mtx->m[1][2] + vec->v[2]*mtx->m[2][2] + vec->v[3]*mtx->m[3][2]);
- v.v[3] = (ALfloat)(vec->v[0]*mtx->m[0][3] + vec->v[1]*mtx->m[1][3] + vec->v[2]*mtx->m[2][3] + vec->v[3]*mtx->m[3][3]);
- return v;
+ int lidx = GetChannelIdxByName(&device->RealOut, FrontLeft);
+ int ridx = GetChannelIdxByName(&device->RealOut, FrontRight);
+ assert(lidx != -1 && ridx != -1);
+
+ /* Encode to stereo-compatible 2-channel UHJ output. */
+ EncodeUhj2(device->Uhj_Encoder,
+ device->RealOut.Buffer[lidx], device->RealOut.Buffer[ridx],
+ device->Dry.Buffer, SamplesToDo
+ );
+}
+
+static void ProcessBs2b(ALCdevice *device, ALsizei SamplesToDo)
+{
+ int lidx = GetChannelIdxByName(&device->RealOut, FrontLeft);
+ int ridx = GetChannelIdxByName(&device->RealOut, FrontRight);
+ assert(lidx != -1 && ridx != -1);
+
+ /* Apply binaural/crossfeed filter */
+ bs2b_cross_feed(device->Bs2b, device->RealOut.Buffer[lidx],
+ device->RealOut.Buffer[ridx], SamplesToDo);
}
+void aluSelectPostProcess(ALCdevice *device)
+{
+ if(device->HrtfHandle)
+ device->PostProcess = ProcessHrtf;
+ else if(device->AmbiDecoder)
+ device->PostProcess = ProcessAmbiDec;
+ else if(device->AmbiUp)
+ device->PostProcess = ProcessAmbiUp;
+ else if(device->Uhj_Encoder)
+ device->PostProcess = ProcessUhj;
+ else if(device->Bs2b)
+ device->PostProcess = ProcessBs2b;
+ else
+ device->PostProcess = NULL;
+}
-/* Prepares the interpolator for a given rate (determined by increment). A
- * result of AL_FALSE indicates that the filter output will completely cut
- * the input signal.
+
+/* Prepares the interpolator for a given rate (determined by increment).
*
* With a bit of work, and a trade of memory for CPU cost, this could be
* modified for use with an interpolated increment for buttery-smooth pitch
* changes.
*/
-static ALboolean BsincPrepare(const ALuint increment, BsincState *state)
+void BsincPrepare(const ALuint increment, BsincState *state, const BSincTable *table)
{
- static const ALfloat scaleBase = 1.510578918e-01f, scaleRange = 1.177936623e+00f;
- static const ALuint m[BSINC_SCALE_COUNT] = { 24, 24, 24, 24, 24, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 12 };
- static const ALuint to[4][BSINC_SCALE_COUNT] =
- {
- { 0, 24, 408, 792, 1176, 1560, 1944, 2328, 2648, 2968, 3288, 3544, 3800, 4056, 4248, 4440 },
- { 4632, 5016, 5400, 5784, 6168, 6552, 6936, 7320, 7640, 7960, 8280, 8536, 8792, 9048, 9240, 0 },
- { 0, 9432, 9816, 10200, 10584, 10968, 11352, 11736, 12056, 12376, 12696, 12952, 13208, 13464, 13656, 13848 },
- { 14040, 14424, 14808, 15192, 15576, 15960, 16344, 16728, 17048, 17368, 17688, 17944, 18200, 18456, 18648, 0 }
- };
- static const ALuint tm[2][BSINC_SCALE_COUNT] =
- {
- { 0, 24, 24, 24, 24, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 12 },
- { 24, 24, 24, 24, 24, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 0 }
- };
- ALfloat sf;
- ALuint si, pi;
- ALboolean uncut = AL_TRUE;
+ ALfloat sf = 0.0f;
+ ALsizei si = BSINC_SCALE_COUNT-1;
if(increment > FRACTIONONE)
{
sf = (ALfloat)FRACTIONONE / increment;
- if(sf < scaleBase)
- {
- /* Signal has been completely cut. The return result can be used
- * to skip the filter (and output zeros) as an optimization.
- */
- sf = 0.0f;
- si = 0;
- uncut = AL_FALSE;
- }
- else
- {
- sf = (BSINC_SCALE_COUNT - 1) * (sf - scaleBase) * scaleRange;
- si = fastf2u(sf);
- /* The interpolation factor is fit to this diagonally-symmetric
- * curve to reduce the transition ripple caused by interpolating
- * different scales of the sinc function.
- */
- sf = 1.0f - cosf(asinf(sf - si));
- }
- }
- else
- {
- sf = 0.0f;
- si = BSINC_SCALE_COUNT - 1;
+ sf = maxf(0.0f, (BSINC_SCALE_COUNT-1) * (sf-table->scaleBase) * table->scaleRange);
+ si = float2int(sf);
+ /* The interpolation factor is fit to this diagonally-symmetric curve
+ * to reduce the transition ripple caused by interpolating different
+ * scales of the sinc function.
+ */
+ sf = 1.0f - cosf(asinf(sf - si));
}
state->sf = sf;
- state->m = m[si];
- state->l = -(ALint)((m[si] / 2) - 1);
- /* The CPU cost of this table re-mapping could be traded for the memory
- * cost of a complete table map (1024 elements large).
- */
- for(pi = 0;pi < BSINC_PHASE_COUNT;pi++)
- {
- state->coeffs[pi].filter = &bsincTab[to[0][si] + tm[0][si]*pi];
- state->coeffs[pi].scDelta = &bsincTab[to[1][si] + tm[1][si]*pi];
- state->coeffs[pi].phDelta = &bsincTab[to[2][si] + tm[0][si]*pi];
- state->coeffs[pi].spDelta = &bsincTab[to[3][si] + tm[1][si]*pi];
- }
- return uncut;
+ state->m = table->m[si];
+ state->l = (state->m/2) - 1;
+ state->filter = table->Tab + table->filterOffset[si];
}
-/* Calculates the fade time from the changes in gain and listener to source
- * angle between updates. The result is a the time, in seconds, for the
- * transition to complete.
- */
-static ALfloat CalcFadeTime(ALfloat oldGain, ALfloat newGain, const aluVector *olddir, const aluVector *newdir)
+static bool CalcContextParams(ALCcontext *Context)
{
- ALfloat gainChange, angleChange, change;
+ ALlistener *Listener = Context->Listener;
+ struct ALcontextProps *props;
- /* Calculate the normalized dB gain change. */
- newGain = maxf(newGain, 0.0001f);
- oldGain = maxf(oldGain, 0.0001f);
- gainChange = fabsf(log10f(newGain / oldGain) / log10f(0.0001f));
+ props = ATOMIC_EXCHANGE_PTR(&Context->Update, NULL, almemory_order_acq_rel);
+ if(!props) return false;
- /* Calculate the angle change only when there is enough gain to notice it. */
- angleChange = 0.0f;
- if(gainChange > 0.0001f || newGain > 0.0001f)
- {
- /* No angle change when the directions are equal or degenerate (when
- * both have zero length).
- */
- if(newdir->v[0] != olddir->v[0] || newdir->v[1] != olddir->v[1] || newdir->v[2] != olddir->v[2])
- {
- ALfloat dotp = aluDotproduct(olddir, newdir);
- angleChange = acosf(clampf(dotp, -1.0f, 1.0f)) / F_PI;
- }
- }
-
- /* Use the largest of the two changes, and apply a significance shaping
- * function to it. The result is then scaled to cover a 15ms transition
- * range.
- */
- change = maxf(angleChange * 25.0f, gainChange) * 2.0f;
- return minf(change, 1.0f) * 0.015f;
-}
+ Listener->Params.MetersPerUnit = props->MetersPerUnit;
+ Listener->Params.DopplerFactor = props->DopplerFactor;
+ Listener->Params.SpeedOfSound = props->SpeedOfSound * props->DopplerVelocity;
+ if(!OverrideReverbSpeedOfSound)
+ Listener->Params.ReverbSpeedOfSound = Listener->Params.SpeedOfSound *
+ Listener->Params.MetersPerUnit;
-static void UpdateDryStepping(DirectParams *params, ALuint num_chans, ALuint steps)
-{
- ALfloat delta;
- ALuint i, j;
-
- if(steps < 2)
- {
- for(i = 0;i < num_chans;i++)
- {
- MixGains *gains = params->Gains[i];
- for(j = 0;j < params->OutChannels;j++)
- {
- gains[j].Current = gains[j].Target;
- gains[j].Step = 0.0f;
- }
- }
- params->Counter = 0;
- return;
- }
+ Listener->Params.SourceDistanceModel = props->SourceDistanceModel;
+ Listener->Params.DistanceModel = props->DistanceModel;
- delta = 1.0f / (ALfloat)steps;
- for(i = 0;i < num_chans;i++)
- {
- MixGains *gains = params->Gains[i];
- for(j = 0;j < params->OutChannels;j++)
- {
- ALfloat diff = gains[j].Target - gains[j].Current;
- if(fabsf(diff) >= GAIN_SILENCE_THRESHOLD)
- gains[j].Step = diff * delta;
- else
- {
- gains[j].Current = gains[j].Target;
- gains[j].Step = 0.0f;
- }
- }
- }
- params->Counter = steps;
+ ATOMIC_REPLACE_HEAD(struct ALcontextProps*, &Context->FreeContextProps, props);
+ return true;
}
-static void UpdateWetStepping(SendParams *params, ALuint num_chans, ALuint steps)
+static bool CalcListenerParams(ALCcontext *Context)
{
- ALfloat delta;
- ALuint i;
+ ALlistener *Listener = Context->Listener;
+ ALfloat N[3], V[3], U[3], P[3];
+ struct ALlistenerProps *props;
+ aluVector vel;
- if(steps < 2)
- {
- for(i = 0;i < num_chans;i++)
- {
- params->Gains[i].Current = params->Gains[i].Target;
- params->Gains[i].Step = 0.0f;
- }
- params->Counter = 0;
- return;
- }
-
- delta = 1.0f / (ALfloat)steps;
- for(i = 0;i < num_chans;i++)
- {
- ALfloat diff = params->Gains[i].Target - params->Gains[i].Current;
- if(fabsf(diff) >= GAIN_SILENCE_THRESHOLD)
- params->Gains[i].Step = diff * delta;
- else
- {
- params->Gains[i].Current = params->Gains[i].Target;
- params->Gains[i].Step = 0.0f;
- }
- }
- params->Counter = steps;
-}
-
-
-static ALvoid CalcListenerParams(ALlistener *Listener)
-{
- ALdouble N[3], V[3], U[3], P[3];
+ props = ATOMIC_EXCHANGE_PTR(&Listener->Update, NULL, almemory_order_acq_rel);
+ if(!props) return false;
/* AT then UP */
- N[0] = Listener->Forward[0];
- N[1] = Listener->Forward[1];
- N[2] = Listener->Forward[2];
- aluNormalized(N);
- V[0] = Listener->Up[0];
- V[1] = Listener->Up[1];
- V[2] = Listener->Up[2];
- aluNormalized(V);
+ N[0] = props->Forward[0];
+ N[1] = props->Forward[1];
+ N[2] = props->Forward[2];
+ aluNormalize(N);
+ V[0] = props->Up[0];
+ V[1] = props->Up[1];
+ V[2] = props->Up[2];
+ aluNormalize(V);
/* Build and normalize right-vector */
- aluCrossproductd(N, V, U);
- aluNormalized(U);
+ aluCrossproduct(N, V, U);
+ aluNormalize(U);
- aluMatrixdSet(&Listener->Params.Matrix,
+ aluMatrixfSet(&Listener->Params.Matrix,
U[0], V[0], -N[0], 0.0,
U[1], V[1], -N[1], 0.0,
U[2], V[2], -N[2], 0.0,
0.0, 0.0, 0.0, 1.0
);
- P[0] = Listener->Position.v[0];
- P[1] = Listener->Position.v[1];
- P[2] = Listener->Position.v[2];
- aluMatrixdDouble3(P, 1.0, &Listener->Params.Matrix);
- aluMatrixdSetRow(&Listener->Params.Matrix, 3, -P[0], -P[1], -P[2], 1.0f);
+ P[0] = props->Position[0];
+ P[1] = props->Position[1];
+ P[2] = props->Position[2];
+ aluMatrixfFloat3(P, 1.0, &Listener->Params.Matrix);
+ aluMatrixfSetRow(&Listener->Params.Matrix, 3, -P[0], -P[1], -P[2], 1.0f);
- Listener->Params.Velocity = aluMatrixdVector(&Listener->Params.Matrix, &Listener->Velocity);
-}
+ aluVectorSet(&vel, props->Velocity[0], props->Velocity[1], props->Velocity[2], 0.0f);
+ Listener->Params.Velocity = aluMatrixfVector(&Listener->Params.Matrix, &vel);
-ALvoid CalcNonAttnSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCcontext *ALContext)
-{
- static const struct ChanMap MonoMap[1] = {
- { FrontCenter, 0.0f, 0.0f }
- }, StereoMap[2] = {
- { FrontLeft, DEG2RAD(-30.0f), DEG2RAD(0.0f) },
- { FrontRight, DEG2RAD( 30.0f), DEG2RAD(0.0f) }
- }, StereoWideMap[2] = {
- { FrontLeft, DEG2RAD(-90.0f), DEG2RAD(0.0f) },
- { FrontRight, DEG2RAD( 90.0f), DEG2RAD(0.0f) }
- }, RearMap[2] = {
- { BackLeft, DEG2RAD(-150.0f), DEG2RAD(0.0f) },
- { BackRight, DEG2RAD( 150.0f), DEG2RAD(0.0f) }
- }, QuadMap[4] = {
- { FrontLeft, DEG2RAD( -45.0f), DEG2RAD(0.0f) },
- { FrontRight, DEG2RAD( 45.0f), DEG2RAD(0.0f) },
- { BackLeft, DEG2RAD(-135.0f), DEG2RAD(0.0f) },
- { BackRight, DEG2RAD( 135.0f), DEG2RAD(0.0f) }
- }, X51Map[6] = {
- { FrontLeft, DEG2RAD( -30.0f), DEG2RAD(0.0f) },
- { FrontRight, DEG2RAD( 30.0f), DEG2RAD(0.0f) },
- { FrontCenter, DEG2RAD( 0.0f), DEG2RAD(0.0f) },
- { LFE, 0.0f, 0.0f },
- { SideLeft, DEG2RAD(-110.0f), DEG2RAD(0.0f) },
- { SideRight, DEG2RAD( 110.0f), DEG2RAD(0.0f) }
- }, X61Map[7] = {
- { FrontLeft, DEG2RAD(-30.0f), DEG2RAD(0.0f) },
- { FrontRight, DEG2RAD( 30.0f), DEG2RAD(0.0f) },
- { FrontCenter, DEG2RAD( 0.0f), DEG2RAD(0.0f) },
- { LFE, 0.0f, 0.0f },
- { BackCenter, DEG2RAD(180.0f), DEG2RAD(0.0f) },
- { SideLeft, DEG2RAD(-90.0f), DEG2RAD(0.0f) },
- { SideRight, DEG2RAD( 90.0f), DEG2RAD(0.0f) }
- }, X71Map[8] = {
- { FrontLeft, DEG2RAD( -30.0f), DEG2RAD(0.0f) },
- { FrontRight, DEG2RAD( 30.0f), DEG2RAD(0.0f) },
- { FrontCenter, DEG2RAD( 0.0f), DEG2RAD(0.0f) },
- { LFE, 0.0f, 0.0f },
- { BackLeft, DEG2RAD(-150.0f), DEG2RAD(0.0f) },
- { BackRight, DEG2RAD( 150.0f), DEG2RAD(0.0f) },
- { SideLeft, DEG2RAD( -90.0f), DEG2RAD(0.0f) },
- { SideRight, DEG2RAD( 90.0f), DEG2RAD(0.0f) }
- };
+ Listener->Params.Gain = props->Gain * Context->GainBoost;
- ALCdevice *Device = ALContext->Device;
- ALfloat SourceVolume,ListenerGain,MinVolume,MaxVolume;
- ALbufferlistitem *BufferListItem;
- enum FmtChannels Channels;
- ALfloat DryGain, DryGainHF, DryGainLF;
- ALfloat WetGain[MAX_SENDS];
- ALfloat WetGainHF[MAX_SENDS];
- ALfloat WetGainLF[MAX_SENDS];
- ALuint NumSends, Frequency;
- ALboolean Relative;
- const struct ChanMap *chans = NULL;
- ALuint num_channels = 0;
- ALboolean DirectChannels;
- ALboolean isbformat = AL_FALSE;
- ALfloat Pitch;
- ALuint i, j, c;
-
- /* Get device properties */
- NumSends = Device->NumAuxSends;
- Frequency = Device->Frequency;
+ ATOMIC_REPLACE_HEAD(struct ALlistenerProps*, &Context->FreeListenerProps, props);
+ return true;
+}
- /* Get listener properties */
- ListenerGain = ALContext->Listener->Gain;
+static bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool force)
+{
+ struct ALeffectslotProps *props;
+ ALeffectState *state;
- /* Get source properties */
- SourceVolume = ALSource->Gain;
- MinVolume = ALSource->MinGain;
- MaxVolume = ALSource->MaxGain;
- Pitch = ALSource->Pitch;
- Relative = ALSource->HeadRelative;
- DirectChannels = ALSource->DirectChannels;
+ props = ATOMIC_EXCHANGE_PTR(&slot->Update, NULL, almemory_order_acq_rel);
+ if(!props && !force) return false;
- voice->Direct.OutBuffer = Device->DryBuffer;
- voice->Direct.OutChannels = Device->NumChannels;
- for(i = 0;i < NumSends;i++)
+ if(props)
{
- ALeffectslot *Slot = ALSource->Send[i].Slot;
- if(!Slot && i == 0)
- Slot = Device->DefaultSlot;
- if(!Slot || Slot->EffectType == AL_EFFECT_NULL)
- voice->Send[i].OutBuffer = NULL;
+ slot->Params.Gain = props->Gain;
+ slot->Params.AuxSendAuto = props->AuxSendAuto;
+ slot->Params.EffectType = props->Type;
+ slot->Params.EffectProps = props->Props;
+ if(IsReverbEffect(props->Type))
+ {
+ slot->Params.RoomRolloff = props->Props.Reverb.RoomRolloffFactor;
+ slot->Params.DecayTime = props->Props.Reverb.DecayTime;
+ slot->Params.DecayLFRatio = props->Props.Reverb.DecayLFRatio;
+ slot->Params.DecayHFRatio = props->Props.Reverb.DecayHFRatio;
+ slot->Params.DecayHFLimit = props->Props.Reverb.DecayHFLimit;
+ slot->Params.AirAbsorptionGainHF = props->Props.Reverb.AirAbsorptionGainHF;
+ }
else
- voice->Send[i].OutBuffer = Slot->WetBuffer;
- }
+ {
+ slot->Params.RoomRolloff = 0.0f;
+ slot->Params.DecayTime = 0.0f;
+ slot->Params.DecayLFRatio = 0.0f;
+ slot->Params.DecayHFRatio = 0.0f;
+ slot->Params.DecayHFLimit = AL_FALSE;
+ slot->Params.AirAbsorptionGainHF = 1.0f;
+ }
- /* Calculate the stepping value */
- Channels = FmtMono;
- BufferListItem = ATOMIC_LOAD(&ALSource->queue);
- while(BufferListItem != NULL)
- {
- ALbuffer *ALBuffer;
- if((ALBuffer=BufferListItem->buffer) != NULL)
+ state = props->State;
+
+ if(state == slot->Params.EffectState)
{
- Pitch = Pitch * ALBuffer->Frequency / Frequency;
- if(Pitch > (ALfloat)MAX_PITCH)
- voice->Step = MAX_PITCH<<FRACTIONBITS;
- else
- voice->Step = maxi(fastf2i(Pitch*FRACTIONONE + 0.5f), 1);
- BsincPrepare(voice->Step, &voice->SincState);
+ /* If the effect state is the same as current, we can decrement its
+ * count safely to remove it from the update object (it can't reach
+ * 0 refs since the current params also hold a reference).
+ */
+ DecrementRef(&state->Ref);
+ props->State = NULL;
+ }
+ else
+ {
+ /* Otherwise, replace it and send off the old one with a release
+ * event.
+ */
+ AsyncEvent evt = ASYNC_EVENT(EventType_ReleaseEffectState);
+ evt.u.EffectState = slot->Params.EffectState;
- Channels = ALBuffer->FmtChannels;
- break;
+ slot->Params.EffectState = state;
+ props->State = NULL;
+
+ if(LIKELY(ll_ringbuffer_write(context->AsyncEvents, (const char*)&evt, 1) != 0))
+ alsem_post(&context->EventSem);
+ else
+ {
+ /* If writing the event failed, the queue was probably full.
+ * Store the old state in the property object where it can
+ * eventually be cleaned up sometime later (not ideal, but
+ * better than blocking or leaking).
+ */
+ props->State = evt.u.EffectState;
+ }
}
- BufferListItem = BufferListItem->next;
- }
- /* Calculate gains */
- DryGain = clampf(SourceVolume, MinVolume, MaxVolume);
- DryGain *= ALSource->Direct.Gain * ListenerGain;
- DryGainHF = ALSource->Direct.GainHF;
- DryGainLF = ALSource->Direct.GainLF;
- for(i = 0;i < NumSends;i++)
- {
- WetGain[i] = clampf(SourceVolume, MinVolume, MaxVolume);
- WetGain[i] *= ALSource->Send[i].Gain * ListenerGain;
- WetGainHF[i] = ALSource->Send[i].GainHF;
- WetGainLF[i] = ALSource->Send[i].GainLF;
+ ATOMIC_REPLACE_HEAD(struct ALeffectslotProps*, &context->FreeEffectslotProps, props);
}
+ else
+ state = slot->Params.EffectState;
+
+ V(state,update)(context, slot, &slot->Params.EffectProps);
+ return true;
+}
+
+
+static const struct ChanMap MonoMap[1] = {
+ { FrontCenter, 0.0f, 0.0f }
+}, RearMap[2] = {
+ { BackLeft, DEG2RAD(-150.0f), DEG2RAD(0.0f) },
+ { BackRight, DEG2RAD( 150.0f), DEG2RAD(0.0f) }
+}, QuadMap[4] = {
+ { FrontLeft, DEG2RAD( -45.0f), DEG2RAD(0.0f) },
+ { FrontRight, DEG2RAD( 45.0f), DEG2RAD(0.0f) },
+ { BackLeft, DEG2RAD(-135.0f), DEG2RAD(0.0f) },
+ { BackRight, DEG2RAD( 135.0f), DEG2RAD(0.0f) }
+}, X51Map[6] = {
+ { FrontLeft, DEG2RAD( -30.0f), DEG2RAD(0.0f) },
+ { FrontRight, DEG2RAD( 30.0f), DEG2RAD(0.0f) },
+ { FrontCenter, DEG2RAD( 0.0f), DEG2RAD(0.0f) },
+ { LFE, 0.0f, 0.0f },
+ { SideLeft, DEG2RAD(-110.0f), DEG2RAD(0.0f) },
+ { SideRight, DEG2RAD( 110.0f), DEG2RAD(0.0f) }
+}, X61Map[7] = {
+ { FrontLeft, DEG2RAD(-30.0f), DEG2RAD(0.0f) },
+ { FrontRight, DEG2RAD( 30.0f), DEG2RAD(0.0f) },
+ { FrontCenter, DEG2RAD( 0.0f), DEG2RAD(0.0f) },
+ { LFE, 0.0f, 0.0f },
+ { BackCenter, DEG2RAD(180.0f), DEG2RAD(0.0f) },
+ { SideLeft, DEG2RAD(-90.0f), DEG2RAD(0.0f) },
+ { SideRight, DEG2RAD( 90.0f), DEG2RAD(0.0f) }
+}, X71Map[8] = {
+ { FrontLeft, DEG2RAD( -30.0f), DEG2RAD(0.0f) },
+ { FrontRight, DEG2RAD( 30.0f), DEG2RAD(0.0f) },
+ { FrontCenter, DEG2RAD( 0.0f), DEG2RAD(0.0f) },
+ { LFE, 0.0f, 0.0f },
+ { BackLeft, DEG2RAD(-150.0f), DEG2RAD(0.0f) },
+ { BackRight, DEG2RAD( 150.0f), DEG2RAD(0.0f) },
+ { SideLeft, DEG2RAD( -90.0f), DEG2RAD(0.0f) },
+ { SideRight, DEG2RAD( 90.0f), DEG2RAD(0.0f) }
+};
+
+static void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev,
+ const ALfloat Distance, const ALfloat Spread,
+ const ALfloat DryGain, const ALfloat DryGainHF,
+ const ALfloat DryGainLF, const ALfloat *WetGain,
+ const ALfloat *WetGainLF, const ALfloat *WetGainHF,
+ ALeffectslot **SendSlots, const ALbuffer *Buffer,
+ const struct ALvoiceProps *props, const ALlistener *Listener,
+ const ALCdevice *Device)
+{
+ struct ChanMap StereoMap[2] = {
+ { FrontLeft, DEG2RAD(-30.0f), DEG2RAD(0.0f) },
+ { FrontRight, DEG2RAD( 30.0f), DEG2RAD(0.0f) }
+ };
+ bool DirectChannels = props->DirectChannels;
+ const ALsizei NumSends = Device->NumAuxSends;
+ const ALuint Frequency = Device->Frequency;
+ const struct ChanMap *chans = NULL;
+ ALsizei num_channels = 0;
+ bool isbformat = false;
+ ALfloat downmix_gain = 1.0f;
+ ALsizei c, i;
- switch(Channels)
+ switch(Buffer->FmtChannels)
{
case FmtMono:
chans = MonoMap;
num_channels = 1;
+ /* Mono buffers are never played direct. */
+ DirectChannels = false;
break;
case FmtStereo:
- /* HACK: Place the stereo channels at +/-90 degrees when using non-
- * HRTF stereo output. This helps reduce the "monoization" caused
- * by them panning towards the center. */
- if(Device->FmtChans == DevFmtStereo && !Device->Hrtf)
- chans = StereoWideMap;
- else
- chans = StereoMap;
+ /* Convert counter-clockwise to clockwise. */
+ StereoMap[0].angle = -props->StereoPan[0];
+ StereoMap[1].angle = -props->StereoPan[1];
+
+ chans = StereoMap;
num_channels = 2;
+ downmix_gain = 1.0f / 2.0f;
break;
case FmtRear:
chans = RearMap;
num_channels = 2;
+ downmix_gain = 1.0f / 2.0f;
break;
case FmtQuad:
chans = QuadMap;
num_channels = 4;
+ downmix_gain = 1.0f / 4.0f;
break;
case FmtX51:
chans = X51Map;
num_channels = 6;
+ /* NOTE: Excludes LFE. */
+ downmix_gain = 1.0f / 5.0f;
break;
case FmtX61:
chans = X61Map;
num_channels = 7;
+ /* NOTE: Excludes LFE. */
+ downmix_gain = 1.0f / 6.0f;
break;
case FmtX71:
chans = X71Map;
num_channels = 8;
+ /* NOTE: Excludes LFE. */
+ downmix_gain = 1.0f / 7.0f;
break;
case FmtBFormat2D:
num_channels = 3;
- isbformat = AL_TRUE;
- DirectChannels = AL_FALSE;
+ isbformat = true;
+ DirectChannels = false;
break;
case FmtBFormat3D:
num_channels = 4;
- isbformat = AL_TRUE;
- DirectChannels = AL_FALSE;
+ isbformat = true;
+ DirectChannels = false;
break;
}
+ for(c = 0;c < num_channels;c++)
+ {
+ memset(&voice->Direct.Params[c].Hrtf.Target, 0,
+ sizeof(voice->Direct.Params[c].Hrtf.Target));
+ ClearArray(voice->Direct.Params[c].Gains.Target);
+ }
+ for(i = 0;i < NumSends;i++)
+ {
+ for(c = 0;c < num_channels;c++)
+ ClearArray(voice->Send[i].Params[c].Gains.Target);
+ }
+
+ voice->Flags &= ~(VOICE_HAS_HRTF | VOICE_HAS_NFC);
if(isbformat)
{
- ALfloat N[3], V[3], U[3];
- aluMatrixf matrix;
- ALfloat scale;
-
- /* AT then UP */
- N[0] = ALSource->Orientation[0][0];
- N[1] = ALSource->Orientation[0][1];
- N[2] = ALSource->Orientation[0][2];
- aluNormalize(N);
- V[0] = ALSource->Orientation[1][0];
- V[1] = ALSource->Orientation[1][1];
- V[2] = ALSource->Orientation[1][2];
- aluNormalize(V);
- if(!Relative)
+ /* Special handling for B-Format sources. */
+
+ if(Distance > FLT_EPSILON)
+ {
+ /* Panning a B-Format sound toward some direction is easy. Just pan
+ * the first (W) channel as a normal mono sound and silence the
+ * others.
+ */
+ ALfloat coeffs[MAX_AMBI_COEFFS];
+
+ if(Device->AvgSpeakerDist > 0.0f)
+ {
+ ALfloat mdist = Distance * Listener->Params.MetersPerUnit;
+ ALfloat w0 = SPEEDOFSOUNDMETRESPERSEC /
+ (mdist * (ALfloat)Device->Frequency);
+ ALfloat w1 = SPEEDOFSOUNDMETRESPERSEC /
+ (Device->AvgSpeakerDist * (ALfloat)Device->Frequency);
+ /* Clamp w0 for really close distances, to prevent excessive
+ * bass.
+ */
+ w0 = minf(w0, w1*4.0f);
+
+ /* Only need to adjust the first channel of a B-Format source. */
+ NfcFilterAdjust(&voice->Direct.Params[0].NFCtrlFilter, w0);
+
+ for(i = 0;i < MAX_AMBI_ORDER+1;i++)
+ voice->Direct.ChannelsPerOrder[i] = Device->NumChannelsPerOrder[i];
+ voice->Flags |= VOICE_HAS_NFC;
+ }
+
+ /* A scalar of 1.5 for plain stereo results in +/-60 degrees being
+ * moved to +/-90 degrees for direct right and left speaker
+ * responses.
+ */
+ CalcAngleCoeffs((Device->Render_Mode==StereoPair) ? ScaleAzimuthFront(Azi, 1.5f) : Azi,
+ Elev, Spread, coeffs);
+
+ /* NOTE: W needs to be scaled by sqrt(2) due to FuMa normalization. */
+ ComputePanGains(&Device->Dry, coeffs, DryGain*SQRTF_2,
+ voice->Direct.Params[0].Gains.Target);
+ for(i = 0;i < NumSends;i++)
+ {
+ const ALeffectslot *Slot = SendSlots[i];
+ if(Slot)
+ ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels, coeffs,
+ WetGain[i]*SQRTF_2, voice->Send[i].Params[0].Gains.Target
+ );
+ }
+ }
+ else
+ {
+ /* Local B-Format sources have their XYZ channels rotated according
+ * to the orientation.
+ */
+ ALfloat N[3], V[3], U[3];
+ aluMatrixf matrix;
+
+ if(Device->AvgSpeakerDist > 0.0f)
+ {
+ /* NOTE: The NFCtrlFilters were created with a w0 of 0, which
+ * is what we want for FOA input. The first channel may have
+ * been previously re-adjusted if panned, so reset it.
+ */
+ NfcFilterAdjust(&voice->Direct.Params[0].NFCtrlFilter, 0.0f);
+
+ voice->Direct.ChannelsPerOrder[0] = 1;
+ voice->Direct.ChannelsPerOrder[1] = mini(voice->Direct.Channels-1, 3);
+ for(i = 2;i < MAX_AMBI_ORDER+1;i++)
+ voice->Direct.ChannelsPerOrder[i] = 0;
+ voice->Flags |= VOICE_HAS_NFC;
+ }
+
+ /* AT then UP */
+ N[0] = props->Orientation[0][0];
+ N[1] = props->Orientation[0][1];
+ N[2] = props->Orientation[0][2];
+ aluNormalize(N);
+ V[0] = props->Orientation[1][0];
+ V[1] = props->Orientation[1][1];
+ V[2] = props->Orientation[1][2];
+ aluNormalize(V);
+ if(!props->HeadRelative)
+ {
+ const aluMatrixf *lmatrix = &Listener->Params.Matrix;
+ aluMatrixfFloat3(N, 0.0f, lmatrix);
+ aluMatrixfFloat3(V, 0.0f, lmatrix);
+ }
+ /* Build and normalize right-vector */
+ aluCrossproduct(N, V, U);
+ aluNormalize(U);
+
+ /* Build a rotate + conversion matrix (FuMa -> ACN+N3D). NOTE: This
+ * matrix is transposed, for the inputs to align on the rows and
+ * outputs on the columns.
+ */
+ aluMatrixfSet(&matrix,
+ // ACN0 ACN1 ACN2 ACN3
+ SQRTF_2, 0.0f, 0.0f, 0.0f, // Ambi W
+ 0.0f, -N[0]*SQRTF_3, N[1]*SQRTF_3, -N[2]*SQRTF_3, // Ambi X
+ 0.0f, U[0]*SQRTF_3, -U[1]*SQRTF_3, U[2]*SQRTF_3, // Ambi Y
+ 0.0f, -V[0]*SQRTF_3, V[1]*SQRTF_3, -V[2]*SQRTF_3 // Ambi Z
+ );
+
+ voice->Direct.Buffer = Device->FOAOut.Buffer;
+ voice->Direct.Channels = Device->FOAOut.NumChannels;
+ for(c = 0;c < num_channels;c++)
+ ComputePanGains(&Device->FOAOut, matrix.m[c], DryGain,
+ voice->Direct.Params[c].Gains.Target);
+ for(i = 0;i < NumSends;i++)
+ {
+ const ALeffectslot *Slot = SendSlots[i];
+ if(Slot)
+ {
+ for(c = 0;c < num_channels;c++)
+ ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels,
+ matrix.m[c], WetGain[i], voice->Send[i].Params[c].Gains.Target
+ );
+ }
+ }
+ }
+ }
+ else if(DirectChannels)
+ {
+ /* Direct source channels always play local. Skip the virtual channels
+ * and write inputs to the matching real outputs.
+ */
+ voice->Direct.Buffer = Device->RealOut.Buffer;
+ voice->Direct.Channels = Device->RealOut.NumChannels;
+
+ for(c = 0;c < num_channels;c++)
{
- const aluMatrixd *lmatrix = &ALContext->Listener->Params.Matrix;
- aluMatrixdFloat3(N, 0.0f, lmatrix);
- aluMatrixdFloat3(V, 0.0f, lmatrix);
+ int idx = GetChannelIdxByName(&Device->RealOut, chans[c].channel);
+ if(idx != -1) voice->Direct.Params[c].Gains.Target[idx] = DryGain;
}
- /* Build and normalize right-vector */
- aluCrossproduct(N, V, U);
- aluNormalize(U);
-
- /* Build a rotate + conversion matrix (B-Format -> N3D), and include
- * scaling for first-order content. */
- scale = Device->AmbiScale * 1.732050808f;
- aluMatrixfSet(&matrix,
- 1.414213562f, 0.0f, 0.0f, 0.0f,
- 0.0f, -N[0]*scale, N[1]*scale, -N[2]*scale,
- 0.0f, U[0]*scale, -U[1]*scale, U[2]*scale,
- 0.0f, -V[0]*scale, V[1]*scale, -V[2]*scale
- );
+ /* Auxiliary sends still use normal channel panning since they mix to
+ * B-Format, which can't channel-match.
+ */
for(c = 0;c < num_channels;c++)
{
- MixGains *gains = voice->Direct.Gains[c];
- ALfloat Target[MAX_OUTPUT_CHANNELS];
+ ALfloat coeffs[MAX_AMBI_COEFFS];
+ CalcAngleCoeffs(chans[c].angle, chans[c].elevation, 0.0f, coeffs);
- ComputeBFormatGains(Device, matrix.m[c], DryGain, Target);
- for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
- gains[i].Target = Target[i];
+ for(i = 0;i < NumSends;i++)
+ {
+ const ALeffectslot *Slot = SendSlots[i];
+ if(Slot)
+ ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels,
+ coeffs, WetGain[i], voice->Send[i].Params[c].Gains.Target
+ );
+ }
}
- UpdateDryStepping(&voice->Direct, num_channels, (voice->Direct.Moving ? 64 : 0));
- voice->Direct.Moving = AL_TRUE;
-
- voice->IsHrtf = AL_FALSE;
+ }
+ else if(Device->Render_Mode == HrtfRender)
+ {
+ /* Full HRTF rendering. Skip the virtual channels and render to the
+ * real outputs.
+ */
+ voice->Direct.Buffer = Device->RealOut.Buffer;
+ voice->Direct.Channels = Device->RealOut.NumChannels;
- for(i = 0;i < NumSends;i++)
+ if(Distance > FLT_EPSILON)
{
- /* Only the first channel of B-Format buffers (W) goes to auxiliary
- * sends. It also needs to be scaled by sqrt(2) to account for the
- * signal being scaled by sqrt(1/2).
+ ALfloat coeffs[MAX_AMBI_COEFFS];
+
+ /* Get the HRIR coefficients and delays just once, for the given
+ * source direction.
*/
- voice->Send[i].Gains[0].Target = WetGain[i] * 1.414213562f;
+ GetHrtfCoeffs(Device->HrtfHandle, Elev, Azi, Spread,
+ voice->Direct.Params[0].Hrtf.Target.Coeffs,
+ voice->Direct.Params[0].Hrtf.Target.Delay);
+ voice->Direct.Params[0].Hrtf.Target.Gain = DryGain * downmix_gain;
+
+ /* Remaining channels use the same results as the first. */
for(c = 1;c < num_channels;c++)
- voice->Send[i].Gains[c].Target = 0.0f;
- UpdateWetStepping(&voice->Send[i], num_channels, (voice->Send[i].Moving ? 64 : 0));
- voice->Send[i].Moving = AL_TRUE;
+ {
+ /* Skip LFE */
+ if(chans[c].channel != LFE)
+ voice->Direct.Params[c].Hrtf.Target = voice->Direct.Params[0].Hrtf.Target;
+ }
+
+ /* Calculate the directional coefficients once, which apply to all
+ * input channels of the source sends.
+ */
+ CalcAngleCoeffs(Azi, Elev, Spread, coeffs);
+
+ for(i = 0;i < NumSends;i++)
+ {
+ const ALeffectslot *Slot = SendSlots[i];
+ if(Slot)
+ for(c = 0;c < num_channels;c++)
+ {
+ /* Skip LFE */
+ if(chans[c].channel != LFE)
+ ComputePanningGainsBF(Slot->ChanMap,
+ Slot->NumChannels, coeffs, WetGain[i] * downmix_gain,
+ voice->Send[i].Params[c].Gains.Target
+ );
+ }
+ }
}
- }
- else
- {
- if(DirectChannels)
+ else
{
- if(Device->Hrtf)
+ /* Local sources on HRTF play with each channel panned to its
+ * relative location around the listener, providing "virtual
+ * speaker" responses.
+ */
+ for(c = 0;c < num_channels;c++)
{
- /* DirectChannels with HRTF enabled. Skip the virtual channels
- * and write FrontLeft and FrontRight inputs to the first and
- * second outputs.
- */
- voice->Direct.OutBuffer += voice->Direct.OutChannels;
- voice->Direct.OutChannels = 2;
- for(c = 0;c < num_channels;c++)
+ ALfloat coeffs[MAX_AMBI_COEFFS];
+
+ if(chans[c].channel == LFE)
{
- MixGains *gains = voice->Direct.Gains[c];
+ /* Skip LFE */
+ continue;
+ }
- for(j = 0;j < MAX_OUTPUT_CHANNELS;j++)
- gains[j].Target = 0.0f;
+ /* Get the HRIR coefficients and delays for this channel
+ * position.
+ */
+ GetHrtfCoeffs(Device->HrtfHandle,
+ chans[c].elevation, chans[c].angle, Spread,
+ voice->Direct.Params[c].Hrtf.Target.Coeffs,
+ voice->Direct.Params[c].Hrtf.Target.Delay
+ );
+ voice->Direct.Params[c].Hrtf.Target.Gain = DryGain;
- if(chans[c].channel == FrontLeft)
- gains[0].Target = DryGain;
- else if(chans[c].channel == FrontRight)
- gains[1].Target = DryGain;
+ /* Normal panning for auxiliary sends. */
+ CalcAngleCoeffs(chans[c].angle, chans[c].elevation, Spread, coeffs);
+
+ for(i = 0;i < NumSends;i++)
+ {
+ const ALeffectslot *Slot = SendSlots[i];
+ if(Slot)
+ ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels,
+ coeffs, WetGain[i], voice->Send[i].Params[c].Gains.Target
+ );
}
}
- else for(c = 0;c < num_channels;c++)
+ }
+
+ voice->Flags |= VOICE_HAS_HRTF;
+ }
+ else
+ {
+ /* Non-HRTF rendering. Use normal panning to the output. */
+
+ if(Distance > FLT_EPSILON)
+ {
+ ALfloat coeffs[MAX_AMBI_COEFFS];
+ ALfloat w0 = 0.0f;
+
+ /* Calculate NFC filter coefficient if needed. */
+ if(Device->AvgSpeakerDist > 0.0f)
{
- MixGains *gains = voice->Direct.Gains[c];
- int idx;
+ ALfloat mdist = Distance * Listener->Params.MetersPerUnit;
+ ALfloat w1 = SPEEDOFSOUNDMETRESPERSEC /
+ (Device->AvgSpeakerDist * (ALfloat)Device->Frequency);
+ w0 = SPEEDOFSOUNDMETRESPERSEC /
+ (mdist * (ALfloat)Device->Frequency);
+ /* Clamp w0 for really close distances, to prevent excessive
+ * bass.
+ */
+ w0 = minf(w0, w1*4.0f);
- for(j = 0;j < MAX_OUTPUT_CHANNELS;j++)
- gains[j].Target = 0.0f;
- if((idx=GetChannelIdxByName(Device, chans[c].channel)) != -1)
- gains[idx].Target = DryGain;
+ /* Adjust NFC filters. */
+ for(c = 0;c < num_channels;c++)
+ NfcFilterAdjust(&voice->Direct.Params[c].NFCtrlFilter, w0);
+
+ for(i = 0;i < MAX_AMBI_ORDER+1;i++)
+ voice->Direct.ChannelsPerOrder[i] = Device->NumChannelsPerOrder[i];
+ voice->Flags |= VOICE_HAS_NFC;
}
- UpdateDryStepping(&voice->Direct, num_channels, (voice->Direct.Moving ? 64 : 0));
- voice->Direct.Moving = AL_TRUE;
- voice->IsHrtf = AL_FALSE;
- }
- else if(Device->Hrtf_Mode == FullHrtf)
- {
- /* Full HRTF rendering. Skip the virtual channels and render each
- * input channel to the real outputs.
+ /* Calculate the directional coefficients once, which apply to all
+ * input channels.
*/
- voice->Direct.OutBuffer += voice->Direct.OutChannels;
- voice->Direct.OutChannels = 2;
+ CalcAngleCoeffs((Device->Render_Mode==StereoPair) ? ScaleAzimuthFront(Azi, 1.5f) : Azi,
+ Elev, Spread, coeffs);
+
for(c = 0;c < num_channels;c++)
{
+ /* Special-case LFE */
if(chans[c].channel == LFE)
{
- /* Skip LFE */
- voice->Direct.Hrtf[c].Params.Delay[0] = 0;
- voice->Direct.Hrtf[c].Params.Delay[1] = 0;
- for(i = 0;i < HRIR_LENGTH;i++)
+ if(Device->Dry.Buffer == Device->RealOut.Buffer)
{
- voice->Direct.Hrtf[c].Params.Coeffs[i][0] = 0.0f;
- voice->Direct.Hrtf[c].Params.Coeffs[i][1] = 0.0f;
+ int idx = GetChannelIdxByName(&Device->RealOut, chans[c].channel);
+ if(idx != -1) voice->Direct.Params[c].Gains.Target[idx] = DryGain;
}
+ continue;
}
- else
- {
- /* Get the static HRIR coefficients and delays for this
- * channel. */
- GetLerpedHrtfCoeffs(Device->Hrtf,
- chans[c].elevation, chans[c].angle, 1.0f, DryGain,
- voice->Direct.Hrtf[c].Params.Coeffs,
- voice->Direct.Hrtf[c].Params.Delay
- );
- }
+
+ ComputePanGains(&Device->Dry, coeffs, DryGain * downmix_gain,
+ voice->Direct.Params[c].Gains.Target);
}
- voice->Direct.Counter = 0;
- voice->Direct.Moving = AL_TRUE;
- voice->IsHrtf = AL_TRUE;
+ for(i = 0;i < NumSends;i++)
+ {
+ const ALeffectslot *Slot = SendSlots[i];
+ if(Slot)
+ for(c = 0;c < num_channels;c++)
+ {
+ /* Skip LFE */
+ if(chans[c].channel != LFE)
+ ComputePanningGainsBF(Slot->ChanMap,
+ Slot->NumChannels, coeffs, WetGain[i] * downmix_gain,
+ voice->Send[i].Params[c].Gains.Target
+ );
+ }
+ }
}
else
{
- /* Basic or no HRTF rendering. Use normal panning to the output. */
+ ALfloat w0 = 0.0f;
+
+ if(Device->AvgSpeakerDist > 0.0f)
+ {
+ /* If the source distance is 0, set w0 to w1 to act as a pass-
+ * through. We still want to pass the signal through the
+ * filters so they keep an appropriate history, in case the
+ * source moves away from the listener.
+ */
+ w0 = SPEEDOFSOUNDMETRESPERSEC /
+ (Device->AvgSpeakerDist * (ALfloat)Device->Frequency);
+
+ for(c = 0;c < num_channels;c++)
+ NfcFilterAdjust(&voice->Direct.Params[c].NFCtrlFilter, w0);
+
+ for(i = 0;i < MAX_AMBI_ORDER+1;i++)
+ voice->Direct.ChannelsPerOrder[i] = Device->NumChannelsPerOrder[i];
+ voice->Flags |= VOICE_HAS_NFC;
+ }
+
for(c = 0;c < num_channels;c++)
{
- MixGains *gains = voice->Direct.Gains[c];
- ALfloat Target[MAX_OUTPUT_CHANNELS];
+ ALfloat coeffs[MAX_AMBI_COEFFS];
/* Special-case LFE */
if(chans[c].channel == LFE)
{
- int idx;
- for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
- gains[i].Target = 0.0f;
- if((idx=GetChannelIdxByName(Device, chans[c].channel)) != -1)
- gains[idx].Target = DryGain;
+ if(Device->Dry.Buffer == Device->RealOut.Buffer)
+ {
+ int idx = GetChannelIdxByName(&Device->RealOut, chans[c].channel);
+ if(idx != -1) voice->Direct.Params[c].Gains.Target[idx] = DryGain;
+ }
continue;
}
- ComputeAngleGains(Device, chans[c].angle, chans[c].elevation, DryGain, Target);
- for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
- gains[i].Target = Target[i];
- }
- UpdateDryStepping(&voice->Direct, num_channels, (voice->Direct.Moving ? 64 : 0));
- voice->Direct.Moving = AL_TRUE;
+ CalcAngleCoeffs(
+ (Device->Render_Mode==StereoPair) ? ScaleAzimuthFront(chans[c].angle, 3.0f)
+ : chans[c].angle,
+ chans[c].elevation, Spread, coeffs
+ );
- voice->IsHrtf = AL_FALSE;
- }
- for(i = 0;i < NumSends;i++)
- {
- for(c = 0;c < num_channels;c++)
- voice->Send[i].Gains[c].Target = WetGain[i];
- UpdateWetStepping(&voice->Send[i], num_channels, (voice->Send[i].Moving ? 64 : 0));
- voice->Send[i].Moving = AL_TRUE;
+ ComputePanGains(&Device->Dry, coeffs, DryGain,
+ voice->Direct.Params[c].Gains.Target);
+ for(i = 0;i < NumSends;i++)
+ {
+ const ALeffectslot *Slot = SendSlots[i];
+ if(Slot)
+ ComputePanningGainsBF(Slot->ChanMap, Slot->NumChannels,
+ coeffs, WetGain[i], voice->Send[i].Params[c].Gains.Target
+ );
+ }
+ }
}
}
{
- ALfloat hfscale = ALSource->Direct.HFReference / Frequency;
- ALfloat lfscale = ALSource->Direct.LFReference / Frequency;
- DryGainHF = maxf(DryGainHF, 0.0001f);
- DryGainLF = maxf(DryGainLF, 0.0001f);
- for(c = 0;c < num_channels;c++)
+ ALfloat hfScale = props->Direct.HFReference / Frequency;
+ ALfloat lfScale = props->Direct.LFReference / Frequency;
+ ALfloat gainHF = maxf(DryGainHF, 0.001f); /* Limit -60dB */
+ ALfloat gainLF = maxf(DryGainLF, 0.001f);
+
+ voice->Direct.FilterType = AF_None;
+ if(gainHF != 1.0f) voice->Direct.FilterType |= AF_LowPass;
+ if(gainLF != 1.0f) voice->Direct.FilterType |= AF_HighPass;
+ BiquadFilter_setParams(
+ &voice->Direct.Params[0].LowPass, BiquadType_HighShelf,
+ gainHF, hfScale, calc_rcpQ_from_slope(gainHF, 1.0f)
+ );
+ BiquadFilter_setParams(
+ &voice->Direct.Params[0].HighPass, BiquadType_LowShelf,
+ gainLF, lfScale, calc_rcpQ_from_slope(gainLF, 1.0f)
+ );
+ for(c = 1;c < num_channels;c++)
{
- voice->Direct.Filters[c].ActiveType = AF_None;
- if(DryGainHF != 1.0f) voice->Direct.Filters[c].ActiveType |= AF_LowPass;
- if(DryGainLF != 1.0f) voice->Direct.Filters[c].ActiveType |= AF_HighPass;
- ALfilterState_setParams(
- &voice->Direct.Filters[c].LowPass, ALfilterType_HighShelf,
- DryGainHF, hfscale, calc_rcpQ_from_slope(DryGainHF, 0.75f)
- );
- ALfilterState_setParams(
- &voice->Direct.Filters[c].HighPass, ALfilterType_LowShelf,
- DryGainLF, lfscale, calc_rcpQ_from_slope(DryGainLF, 0.75f)
- );
+ BiquadFilter_copyParams(&voice->Direct.Params[c].LowPass,
+ &voice->Direct.Params[0].LowPass);
+ BiquadFilter_copyParams(&voice->Direct.Params[c].HighPass,
+ &voice->Direct.Params[0].HighPass);
}
}
for(i = 0;i < NumSends;i++)
{
- ALfloat hfscale = ALSource->Send[i].HFReference / Frequency;
- ALfloat lfscale = ALSource->Send[i].LFReference / Frequency;
- WetGainHF[i] = maxf(WetGainHF[i], 0.0001f);
- WetGainLF[i] = maxf(WetGainLF[i], 0.0001f);
- for(c = 0;c < num_channels;c++)
+ ALfloat hfScale = props->Send[i].HFReference / Frequency;
+ ALfloat lfScale = props->Send[i].LFReference / Frequency;
+ ALfloat gainHF = maxf(WetGainHF[i], 0.001f);
+ ALfloat gainLF = maxf(WetGainLF[i], 0.001f);
+
+ voice->Send[i].FilterType = AF_None;
+ if(gainHF != 1.0f) voice->Send[i].FilterType |= AF_LowPass;
+ if(gainLF != 1.0f) voice->Send[i].FilterType |= AF_HighPass;
+ BiquadFilter_setParams(
+ &voice->Send[i].Params[0].LowPass, BiquadType_HighShelf,
+ gainHF, hfScale, calc_rcpQ_from_slope(gainHF, 1.0f)
+ );
+ BiquadFilter_setParams(
+ &voice->Send[i].Params[0].HighPass, BiquadType_LowShelf,
+ gainLF, lfScale, calc_rcpQ_from_slope(gainLF, 1.0f)
+ );
+ for(c = 1;c < num_channels;c++)
{
- voice->Send[i].Filters[c].ActiveType = AF_None;
- if(WetGainHF[i] != 1.0f) voice->Send[i].Filters[c].ActiveType |= AF_LowPass;
- if(WetGainLF[i] != 1.0f) voice->Send[i].Filters[c].ActiveType |= AF_HighPass;
- ALfilterState_setParams(
- &voice->Send[i].Filters[c].LowPass, ALfilterType_HighShelf,
- WetGainHF[i], hfscale, calc_rcpQ_from_slope(WetGainHF[i], 0.75f)
- );
- ALfilterState_setParams(
- &voice->Send[i].Filters[c].HighPass, ALfilterType_LowShelf,
- WetGainLF[i], lfscale, calc_rcpQ_from_slope(WetGainLF[i], 0.75f)
- );
+ BiquadFilter_copyParams(&voice->Send[i].Params[c].LowPass,
+ &voice->Send[i].Params[0].LowPass);
+ BiquadFilter_copyParams(&voice->Send[i].Params[c].HighPass,
+ &voice->Send[i].Params[0].HighPass);
}
}
}
-ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCcontext *ALContext)
+static void CalcNonAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *props, const ALbuffer *ALBuffer, const ALCcontext *ALContext)
{
- ALCdevice *Device = ALContext->Device;
- aluVector Position, Velocity, Direction, SourceToListener;
- ALfloat InnerAngle,OuterAngle,Angle,Distance,ClampedDist;
- ALfloat MinVolume,MaxVolume,MinDist,MaxDist,Rolloff;
- ALfloat ConeVolume,ConeHF,SourceVolume,ListenerGain;
- ALfloat DopplerFactor, SpeedOfSound;
- ALfloat AirAbsorptionFactor;
- ALfloat RoomAirAbsorption[MAX_SENDS];
- ALbufferlistitem *BufferListItem;
- ALfloat Attenuation;
- ALfloat RoomAttenuation[MAX_SENDS];
- ALfloat MetersPerUnit;
- ALfloat RoomRolloffBase;
- ALfloat RoomRolloff[MAX_SENDS];
- ALfloat DecayDistance[MAX_SENDS];
- ALfloat DryGain;
- ALfloat DryGainHF;
- ALfloat DryGainLF;
- ALboolean DryGainHFAuto;
+ const ALCdevice *Device = ALContext->Device;
+ const ALlistener *Listener = ALContext->Listener;
+ ALfloat DryGain, DryGainHF, DryGainLF;
ALfloat WetGain[MAX_SENDS];
ALfloat WetGainHF[MAX_SENDS];
ALfloat WetGainLF[MAX_SENDS];
- ALboolean WetGainAuto;
- ALboolean WetGainHFAuto;
+ ALeffectslot *SendSlots[MAX_SENDS];
ALfloat Pitch;
- ALuint Frequency;
- ALint NumSends;
- ALint i, j;
+ ALsizei i;
- DryGainHF = 1.0f;
- DryGainLF = 1.0f;
- for(i = 0;i < MAX_SENDS;i++)
+ voice->Direct.Buffer = Device->Dry.Buffer;
+ voice->Direct.Channels = Device->Dry.NumChannels;
+ for(i = 0;i < Device->NumAuxSends;i++)
{
- WetGainHF[i] = 1.0f;
- WetGainLF[i] = 1.0f;
+ SendSlots[i] = props->Send[i].Slot;
+ if(!SendSlots[i] && i == 0)
+ SendSlots[i] = ALContext->DefaultSlot;
+ if(!SendSlots[i] || SendSlots[i]->Params.EffectType == AL_EFFECT_NULL)
+ {
+ SendSlots[i] = NULL;
+ voice->Send[i].Buffer = NULL;
+ voice->Send[i].Channels = 0;
+ }
+ else
+ {
+ voice->Send[i].Buffer = SendSlots[i]->WetBuffer;
+ voice->Send[i].Channels = SendSlots[i]->NumChannels;
+ }
}
- /* Get context/device properties */
- DopplerFactor = ALContext->DopplerFactor * ALSource->DopplerFactor;
- SpeedOfSound = ALContext->SpeedOfSound * ALContext->DopplerVelocity;
- NumSends = Device->NumAuxSends;
- Frequency = Device->Frequency;
-
- /* Get listener properties */
- ListenerGain = ALContext->Listener->Gain;
- MetersPerUnit = ALContext->Listener->MetersPerUnit;
-
- /* Get source properties */
- SourceVolume = ALSource->Gain;
- MinVolume = ALSource->MinGain;
- MaxVolume = ALSource->MaxGain;
- Pitch = ALSource->Pitch;
- Position = ALSource->Position;
- Direction = ALSource->Direction;
- Velocity = ALSource->Velocity;
- MinDist = ALSource->RefDistance;
- MaxDist = ALSource->MaxDistance;
- Rolloff = ALSource->RollOffFactor;
- InnerAngle = ALSource->InnerAngle;
- OuterAngle = ALSource->OuterAngle;
- AirAbsorptionFactor = ALSource->AirAbsorptionFactor;
- DryGainHFAuto = ALSource->DryGainHFAuto;
- WetGainAuto = ALSource->WetGainAuto;
- WetGainHFAuto = ALSource->WetGainHFAuto;
- RoomRolloffBase = ALSource->RoomRolloffFactor;
-
- voice->Direct.OutBuffer = Device->DryBuffer;
- voice->Direct.OutChannels = Device->NumChannels;
- for(i = 0;i < NumSends;i++)
+ /* Calculate the stepping value */
+ Pitch = (ALfloat)ALBuffer->Frequency/(ALfloat)Device->Frequency * props->Pitch;
+ if(Pitch > (ALfloat)MAX_PITCH)
+ voice->Step = MAX_PITCH<<FRACTIONBITS;
+ else
+ voice->Step = maxi(fastf2i(Pitch * FRACTIONONE), 1);
+ if(props->Resampler == BSinc24Resampler)
+ BsincPrepare(voice->Step, &voice->ResampleState.bsinc, &bsinc24);
+ else if(props->Resampler == BSinc12Resampler)
+ BsincPrepare(voice->Step, &voice->ResampleState.bsinc, &bsinc12);
+ voice->Resampler = SelectResampler(props->Resampler);
+
+ /* Calculate gains */
+ DryGain = clampf(props->Gain, props->MinGain, props->MaxGain);
+ DryGain *= props->Direct.Gain * Listener->Params.Gain;
+ DryGain = minf(DryGain, GAIN_MIX_MAX);
+ DryGainHF = props->Direct.GainHF;
+ DryGainLF = props->Direct.GainLF;
+ for(i = 0;i < Device->NumAuxSends;i++)
{
- ALeffectslot *Slot = ALSource->Send[i].Slot;
+ WetGain[i] = clampf(props->Gain, props->MinGain, props->MaxGain);
+ WetGain[i] *= props->Send[i].Gain * Listener->Params.Gain;
+ WetGain[i] = minf(WetGain[i], GAIN_MIX_MAX);
+ WetGainHF[i] = props->Send[i].GainHF;
+ WetGainLF[i] = props->Send[i].GainLF;
+ }
+
+ CalcPanningAndFilters(voice, 0.0f, 0.0f, 0.0f, 0.0f, DryGain, DryGainHF, DryGainLF, WetGain,
+ WetGainLF, WetGainHF, SendSlots, ALBuffer, props, Listener, Device);
+}
- if(!Slot && i == 0)
- Slot = Device->DefaultSlot;
- if(!Slot || Slot->EffectType == AL_EFFECT_NULL)
+static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *props, const ALbuffer *ALBuffer, const ALCcontext *ALContext)
+{
+ const ALCdevice *Device = ALContext->Device;
+ const ALlistener *Listener = ALContext->Listener;
+ const ALsizei NumSends = Device->NumAuxSends;
+ aluVector Position, Velocity, Direction, SourceToListener;
+ ALfloat Distance, ClampedDist, DopplerFactor;
+ ALeffectslot *SendSlots[MAX_SENDS];
+ ALfloat RoomRolloff[MAX_SENDS];
+ ALfloat DecayDistance[MAX_SENDS];
+ ALfloat DecayLFDistance[MAX_SENDS];
+ ALfloat DecayHFDistance[MAX_SENDS];
+ ALfloat DryGain, DryGainHF, DryGainLF;
+ ALfloat WetGain[MAX_SENDS];
+ ALfloat WetGainHF[MAX_SENDS];
+ ALfloat WetGainLF[MAX_SENDS];
+ bool directional;
+ ALfloat ev, az;
+ ALfloat spread;
+ ALfloat Pitch;
+ ALint i;
+
+ /* Set mixing buffers and get send parameters. */
+ voice->Direct.Buffer = Device->Dry.Buffer;
+ voice->Direct.Channels = Device->Dry.NumChannels;
+ for(i = 0;i < NumSends;i++)
+ {
+ SendSlots[i] = props->Send[i].Slot;
+ if(!SendSlots[i] && i == 0)
+ SendSlots[i] = ALContext->DefaultSlot;
+ if(!SendSlots[i] || SendSlots[i]->Params.EffectType == AL_EFFECT_NULL)
{
- Slot = NULL;
+ SendSlots[i] = NULL;
RoomRolloff[i] = 0.0f;
DecayDistance[i] = 0.0f;
- RoomAirAbsorption[i] = 1.0f;
+ DecayLFDistance[i] = 0.0f;
+ DecayHFDistance[i] = 0.0f;
}
- else if(Slot->AuxSendAuto)
+ else if(SendSlots[i]->Params.AuxSendAuto)
{
- RoomRolloff[i] = RoomRolloffBase;
- if(IsReverbEffect(Slot->EffectType))
- {
- RoomRolloff[i] += Slot->EffectProps.Reverb.RoomRolloffFactor;
- DecayDistance[i] = Slot->EffectProps.Reverb.DecayTime *
- SPEEDOFSOUNDMETRESPERSEC;
- RoomAirAbsorption[i] = Slot->EffectProps.Reverb.AirAbsorptionGainHF;
- }
- else
+ RoomRolloff[i] = SendSlots[i]->Params.RoomRolloff + props->RoomRolloffFactor;
+ /* Calculate the distances to where this effect's decay reaches
+ * -60dB.
+ */
+ DecayDistance[i] = SendSlots[i]->Params.DecayTime *
+ Listener->Params.ReverbSpeedOfSound;
+ DecayLFDistance[i] = DecayDistance[i] * SendSlots[i]->Params.DecayLFRatio;
+ DecayHFDistance[i] = DecayDistance[i] * SendSlots[i]->Params.DecayHFRatio;
+ if(SendSlots[i]->Params.DecayHFLimit)
{
- DecayDistance[i] = 0.0f;
- RoomAirAbsorption[i] = 1.0f;
+ ALfloat airAbsorption = SendSlots[i]->Params.AirAbsorptionGainHF;
+ if(airAbsorption < 1.0f)
+ {
+ /* Calculate the distance to where this effect's air
+ * absorption reaches -60dB, and limit the effect's HF
+ * decay distance (so it doesn't take any longer to decay
+ * than the air would allow).
+ */
+ ALfloat absorb_dist = log10f(REVERB_DECAY_GAIN) / log10f(airAbsorption);
+ DecayHFDistance[i] = minf(absorb_dist, DecayHFDistance[i]);
+ }
}
}
else
{
/* If the slot's auxiliary send auto is off, the data sent to the
* effect slot is the same as the dry path, sans filter effects */
- RoomRolloff[i] = Rolloff;
+ RoomRolloff[i] = props->RolloffFactor;
DecayDistance[i] = 0.0f;
- RoomAirAbsorption[i] = AIRABSORBGAINHF;
+ DecayLFDistance[i] = 0.0f;
+ DecayHFDistance[i] = 0.0f;
}
- if(!Slot || Slot->EffectType == AL_EFFECT_NULL)
- voice->Send[i].OutBuffer = NULL;
+ if(!SendSlots[i])
+ {
+ voice->Send[i].Buffer = NULL;
+ voice->Send[i].Channels = 0;
+ }
else
- voice->Send[i].OutBuffer = Slot->WetBuffer;
+ {
+ voice->Send[i].Buffer = SendSlots[i]->WetBuffer;
+ voice->Send[i].Channels = SendSlots[i]->NumChannels;
+ }
}
/* Transform source to listener space (convert to head relative) */
- if(ALSource->HeadRelative == AL_FALSE)
+ aluVectorSet(&Position, props->Position[0], props->Position[1], props->Position[2], 1.0f);
+ aluVectorSet(&Direction, props->Direction[0], props->Direction[1], props->Direction[2], 0.0f);
+ aluVectorSet(&Velocity, props->Velocity[0], props->Velocity[1], props->Velocity[2], 0.0f);
+ if(props->HeadRelative == AL_FALSE)
{
- const aluMatrixd *Matrix = &ALContext->Listener->Params.Matrix;
+ const aluMatrixf *Matrix = &Listener->Params.Matrix;
/* Transform source vectors */
- Position = aluMatrixdVector(Matrix, &Position);
- Velocity = aluMatrixdVector(Matrix, &Velocity);
- Direction = aluMatrixdVector(Matrix, &Direction);
+ Position = aluMatrixfVector(Matrix, &Position);
+ Velocity = aluMatrixfVector(Matrix, &Velocity);
+ Direction = aluMatrixfVector(Matrix, &Direction);
}
else
{
- const aluVector *lvelocity = &ALContext->Listener->Params.Velocity;
+ const aluVector *lvelocity = &Listener->Params.Velocity;
/* Offset the source velocity to be relative of the listener velocity */
Velocity.v[0] += lvelocity->v[0];
Velocity.v[1] += lvelocity->v[1];
Velocity.v[2] += lvelocity->v[2];
}
- aluNormalize(Direction.v);
+ directional = aluNormalize(Direction.v) > 0.0f;
SourceToListener.v[0] = -Position.v[0];
SourceToListener.v[1] = -Position.v[1];
SourceToListener.v[2] = -Position.v[2];
SourceToListener.v[3] = 0.0f;
Distance = aluNormalize(SourceToListener.v);
+ /* Initial source gain */
+ DryGain = props->Gain;
+ DryGainHF = 1.0f;
+ DryGainLF = 1.0f;
+ for(i = 0;i < NumSends;i++)
+ {
+ WetGain[i] = props->Gain;
+ WetGainHF[i] = 1.0f;
+ WetGainLF[i] = 1.0f;
+ }
+
/* Calculate distance attenuation */
ClampedDist = Distance;
- Attenuation = 1.0f;
- for(i = 0;i < NumSends;i++)
- RoomAttenuation[i] = 1.0f;
- switch(ALContext->SourceDistanceModel ? ALSource->DistanceModel :
- ALContext->DistanceModel)
+ switch(Listener->Params.SourceDistanceModel ?
+ props->DistanceModel : Listener->Params.DistanceModel)
{
case InverseDistanceClamped:
- ClampedDist = clampf(ClampedDist, MinDist, MaxDist);
- if(MaxDist < MinDist)
+ ClampedDist = clampf(ClampedDist, props->RefDistance, props->MaxDistance);
+ if(props->MaxDistance < props->RefDistance)
break;
/*fall-through*/
case InverseDistance:
- if(MinDist > 0.0f)
+ if(!(props->RefDistance > 0.0f))
+ ClampedDist = props->RefDistance;
+ else
{
- ALfloat dist = lerp(MinDist, ClampedDist, Rolloff);
- if(dist > 0.0f) Attenuation = MinDist / dist;
+ ALfloat dist = lerp(props->RefDistance, ClampedDist, props->RolloffFactor);
+ if(dist > 0.0f) DryGain *= props->RefDistance / dist;
for(i = 0;i < NumSends;i++)
{
- dist = lerp(MinDist, ClampedDist, RoomRolloff[i]);
- if(dist > 0.0f) RoomAttenuation[i] = MinDist / dist;
+ dist = lerp(props->RefDistance, ClampedDist, RoomRolloff[i]);
+ if(dist > 0.0f) WetGain[i] *= props->RefDistance / dist;
}
}
break;
case LinearDistanceClamped:
- ClampedDist = clampf(ClampedDist, MinDist, MaxDist);
- if(MaxDist < MinDist)
+ ClampedDist = clampf(ClampedDist, props->RefDistance, props->MaxDistance);
+ if(props->MaxDistance < props->RefDistance)
break;
/*fall-through*/
case LinearDistance:
- if(MaxDist != MinDist)
+ if(!(props->MaxDistance != props->RefDistance))
+ ClampedDist = props->RefDistance;
+ else
{
- Attenuation = 1.0f - (Rolloff*(ClampedDist-MinDist)/(MaxDist - MinDist));
- Attenuation = maxf(Attenuation, 0.0f);
+ ALfloat attn = props->RolloffFactor * (ClampedDist-props->RefDistance) /
+ (props->MaxDistance-props->RefDistance);
+ DryGain *= maxf(1.0f - attn, 0.0f);
for(i = 0;i < NumSends;i++)
{
- RoomAttenuation[i] = 1.0f - (RoomRolloff[i]*(ClampedDist-MinDist)/(MaxDist - MinDist));
- RoomAttenuation[i] = maxf(RoomAttenuation[i], 0.0f);
+ attn = RoomRolloff[i] * (ClampedDist-props->RefDistance) /
+ (props->MaxDistance-props->RefDistance);
+ WetGain[i] *= maxf(1.0f - attn, 0.0f);
}
}
break;
case ExponentDistanceClamped:
- ClampedDist = clampf(ClampedDist, MinDist, MaxDist);
- if(MaxDist < MinDist)
+ ClampedDist = clampf(ClampedDist, props->RefDistance, props->MaxDistance);
+ if(props->MaxDistance < props->RefDistance)
break;
/*fall-through*/
case ExponentDistance:
- if(ClampedDist > 0.0f && MinDist > 0.0f)
+ if(!(ClampedDist > 0.0f && props->RefDistance > 0.0f))
+ ClampedDist = props->RefDistance;
+ else
{
- Attenuation = powf(ClampedDist/MinDist, -Rolloff);
+ DryGain *= powf(ClampedDist/props->RefDistance, -props->RolloffFactor);
for(i = 0;i < NumSends;i++)
- RoomAttenuation[i] = powf(ClampedDist/MinDist, -RoomRolloff[i]);
+ WetGain[i] *= powf(ClampedDist/props->RefDistance, -RoomRolloff[i]);
}
break;
case DisableDistance:
- ClampedDist = MinDist;
+ ClampedDist = props->RefDistance;
break;
}
- /* Source Gain + Attenuation */
- DryGain = SourceVolume * Attenuation;
- for(i = 0;i < NumSends;i++)
- WetGain[i] = SourceVolume * RoomAttenuation[i];
-
- /* Distance-based air absorption */
- if(AirAbsorptionFactor > 0.0f && ClampedDist > MinDist)
+ /* Calculate directional soundcones */
+ if(directional && props->InnerAngle < 360.0f)
{
- ALfloat meters = (ClampedDist-MinDist) * MetersPerUnit;
- DryGainHF *= powf(AIRABSORBGAINHF, AirAbsorptionFactor*meters);
- for(i = 0;i < NumSends;i++)
- WetGainHF[i] *= powf(RoomAirAbsorption[i], AirAbsorptionFactor*meters);
- }
+ ALfloat ConeVolume;
+ ALfloat ConeHF;
+ ALfloat Angle;
- if(WetGainAuto)
- {
- ALfloat ApparentDist = 1.0f/maxf(Attenuation, 0.00001f) - 1.0f;
-
- /* Apply a decay-time transformation to the wet path, based on the
- * attenuation of the dry path.
- *
- * Using the apparent distance, based on the distance attenuation, the
- * initial decay of the reverb effect is calculated and applied to the
- * wet path.
- */
- for(i = 0;i < NumSends;i++)
+ Angle = acosf(aluDotproduct(&Direction, &SourceToListener));
+ Angle = RAD2DEG(Angle * ConeScale * 2.0f);
+ if(!(Angle > props->InnerAngle))
{
- if(DecayDistance[i] > 0.0f)
- WetGain[i] *= powf(0.001f/*-60dB*/, ApparentDist/DecayDistance[i]);
+ ConeVolume = 1.0f;
+ ConeHF = 1.0f;
+ }
+ else if(Angle < props->OuterAngle)
+ {
+ ALfloat scale = ( Angle-props->InnerAngle) /
+ (props->OuterAngle-props->InnerAngle);
+ ConeVolume = lerp(1.0f, props->OuterGain, scale);
+ ConeHF = lerp(1.0f, props->OuterGainHF, scale);
+ }
+ else
+ {
+ ConeVolume = props->OuterGain;
+ ConeHF = props->OuterGainHF;
}
- }
-
- /* Calculate directional soundcones */
- Angle = RAD2DEG(acosf(aluDotproduct(&Direction, &SourceToListener)) * ConeScale) * 2.0f;
- if(Angle > InnerAngle && Angle <= OuterAngle)
- {
- ALfloat scale = (Angle-InnerAngle) / (OuterAngle-InnerAngle);
- ConeVolume = lerp(1.0f, ALSource->OuterGain, scale);
- ConeHF = lerp(1.0f, ALSource->OuterGainHF, scale);
- }
- else if(Angle > OuterAngle)
- {
- ConeVolume = ALSource->OuterGain;
- ConeHF = ALSource->OuterGainHF;
- }
- else
- {
- ConeVolume = 1.0f;
- ConeHF = 1.0f;
- }
- DryGain *= ConeVolume;
- if(WetGainAuto)
- {
- for(i = 0;i < NumSends;i++)
- WetGain[i] *= ConeVolume;
- }
- if(DryGainHFAuto)
- DryGainHF *= ConeHF;
- if(WetGainHFAuto)
- {
- for(i = 0;i < NumSends;i++)
- WetGainHF[i] *= ConeHF;
+ DryGain *= ConeVolume;
+ if(props->DryGainHFAuto)
+ DryGainHF *= ConeHF;
+ if(props->WetGainAuto)
+ {
+ for(i = 0;i < NumSends;i++)
+ WetGain[i] *= ConeVolume;
+ }
+ if(props->WetGainHFAuto)
+ {
+ for(i = 0;i < NumSends;i++)
+ WetGainHF[i] *= ConeHF;
+ }
}
- /* Clamp to Min/Max Gain */
- DryGain = clampf(DryGain, MinVolume, MaxVolume);
- for(i = 0;i < NumSends;i++)
- WetGain[i] = clampf(WetGain[i], MinVolume, MaxVolume);
-
/* Apply gain and frequency filters */
- DryGain *= ALSource->Direct.Gain * ListenerGain;
- DryGainHF *= ALSource->Direct.GainHF;
- DryGainLF *= ALSource->Direct.GainLF;
+ DryGain = clampf(DryGain, props->MinGain, props->MaxGain);
+ DryGain = minf(DryGain*props->Direct.Gain*Listener->Params.Gain, GAIN_MIX_MAX);
+ DryGainHF *= props->Direct.GainHF;
+ DryGainLF *= props->Direct.GainLF;
for(i = 0;i < NumSends;i++)
{
- WetGain[i] *= ALSource->Send[i].Gain * ListenerGain;
- WetGainHF[i] *= ALSource->Send[i].GainHF;
- WetGainLF[i] *= ALSource->Send[i].GainLF;
+ WetGain[i] = clampf(WetGain[i], props->MinGain, props->MaxGain);
+ WetGain[i] = minf(WetGain[i]*props->Send[i].Gain*Listener->Params.Gain, GAIN_MIX_MAX);
+ WetGainHF[i] *= props->Send[i].GainHF;
+ WetGainLF[i] *= props->Send[i].GainLF;
}
- /* Calculate velocity-based doppler effect */
- if(DopplerFactor > 0.0f)
+ /* Distance-based air absorption and initial send decay. */
+ if(ClampedDist > props->RefDistance && props->RolloffFactor > 0.0f)
{
- const aluVector *lvelocity = &ALContext->Listener->Params.Velocity;
- ALfloat VSS, VLS;
-
- if(SpeedOfSound < 1.0f)
+ ALfloat meters_base = (ClampedDist-props->RefDistance) * props->RolloffFactor *
+ Listener->Params.MetersPerUnit;
+ if(props->AirAbsorptionFactor > 0.0f)
{
- DopplerFactor *= 1.0f/SpeedOfSound;
- SpeedOfSound = 1.0f;
+ ALfloat hfattn = powf(AIRABSORBGAINHF, meters_base * props->AirAbsorptionFactor);
+ DryGainHF *= hfattn;
+ for(i = 0;i < NumSends;i++)
+ WetGainHF[i] *= hfattn;
}
- VSS = aluDotproduct(&Velocity, &SourceToListener) * DopplerFactor;
- VLS = aluDotproduct(lvelocity, &SourceToListener) * DopplerFactor;
-
- Pitch *= clampf(SpeedOfSound-VLS, 1.0f, SpeedOfSound*2.0f - 1.0f) /
- clampf(SpeedOfSound-VSS, 1.0f, SpeedOfSound*2.0f - 1.0f);
- }
-
- BufferListItem = ATOMIC_LOAD(&ALSource->queue);
- while(BufferListItem != NULL)
- {
- ALbuffer *ALBuffer;
- if((ALBuffer=BufferListItem->buffer) != NULL)
+ if(props->WetGainAuto)
{
- /* Calculate fixed-point stepping value, based on the pitch, buffer
- * frequency, and output frequency. */
- Pitch = Pitch * ALBuffer->Frequency / Frequency;
- if(Pitch > (ALfloat)MAX_PITCH)
- voice->Step = MAX_PITCH<<FRACTIONBITS;
- else
- voice->Step = maxi(fastf2i(Pitch*FRACTIONONE + 0.5f), 1);
- BsincPrepare(voice->Step, &voice->SincState);
+ /* Apply a decay-time transformation to the wet path, based on the
+ * source distance in meters. The initial decay of the reverb
+ * effect is calculated and applied to the wet path.
+ */
+ for(i = 0;i < NumSends;i++)
+ {
+ ALfloat gain, gainhf, gainlf;
- break;
+ if(!(DecayDistance[i] > 0.0f))
+ continue;
+
+ gain = powf(REVERB_DECAY_GAIN, meters_base/DecayDistance[i]);
+ WetGain[i] *= gain;
+ /* Yes, the wet path's air absorption is applied with
+ * WetGainAuto on, rather than WetGainHFAuto.
+ */
+ if(gain > 0.0f)
+ {
+ gainhf = powf(REVERB_DECAY_GAIN, meters_base/DecayHFDistance[i]);
+ WetGainHF[i] *= minf(gainhf / gain, 1.0f);
+ gainlf = powf(REVERB_DECAY_GAIN, meters_base/DecayLFDistance[i]);
+ WetGainLF[i] *= minf(gainlf / gain, 1.0f);
+ }
+ }
}
- BufferListItem = BufferListItem->next;
}
- if(Device->Hrtf_Mode == FullHrtf)
+
+ /* Initial source pitch */
+ Pitch = props->Pitch;
+
+ /* Calculate velocity-based doppler effect */
+ DopplerFactor = props->DopplerFactor * Listener->Params.DopplerFactor;
+ if(DopplerFactor > 0.0f)
{
- /* Full HRTF rendering. Skip the virtual channels and render to the
- * real outputs.
- */
- aluVector dir = {{ 0.0f, 0.0f, -1.0f, 0.0f }};
- ALfloat ev = 0.0f, az = 0.0f;
- ALfloat radius = ALSource->Radius;
- ALfloat dirfact = 1.0f;
+ const aluVector *lvelocity = &Listener->Params.Velocity;
+ const ALfloat SpeedOfSound = Listener->Params.SpeedOfSound;
+ ALfloat vss, vls;
- voice->Direct.OutBuffer += voice->Direct.OutChannels;
- voice->Direct.OutChannels = 2;
+ vss = aluDotproduct(&Velocity, &SourceToListener) * DopplerFactor;
+ vls = aluDotproduct(lvelocity, &SourceToListener) * DopplerFactor;
- if(Distance > FLT_EPSILON)
+ if(!(vls < SpeedOfSound))
{
- dir.v[0] = -SourceToListener.v[0];
- dir.v[1] = -SourceToListener.v[1];
- dir.v[2] = -SourceToListener.v[2] * ZScale;
-
- /* Calculate elevation and azimuth only when the source is not at
- * the listener. This prevents +0 and -0 Z from producing
- * inconsistent panning. Also, clamp Y in case FP precision errors
- * cause it to land outside of -1..+1. */
- ev = asinf(clampf(dir.v[1], -1.0f, 1.0f));
- az = atan2f(dir.v[0], -dir.v[2]);
- }
- if(radius > 0.0f)
- {
- if(radius >= Distance)
- dirfact *= Distance / radius * 0.5f;
- else
- dirfact *= 1.0f - (asinf(radius / Distance) / F_PI);
+ /* Listener moving away from the source at the speed of sound.
+ * Sound waves can't catch it.
+ */
+ Pitch = 0.0f;
}
-
- /* Check to see if the HRIR is already moving. */
- if(voice->Direct.Moving)
+ else if(!(vss < SpeedOfSound))
{
- ALfloat delta;
- delta = CalcFadeTime(voice->Direct.LastGain, DryGain,
- &voice->Direct.LastDir, &dir);
- /* If the delta is large enough, get the moving HRIR target
- * coefficients, target delays, steppping values, and counter.
+ /* Source moving toward the listener at the speed of sound. Sound
+ * waves bunch up to extreme frequencies.
*/
- if(delta > 0.000015f)
- {
- ALuint counter = GetMovingHrtfCoeffs(Device->Hrtf,
- ev, az, dirfact, DryGain, delta, voice->Direct.Counter,
- voice->Direct.Hrtf[0].Params.Coeffs, voice->Direct.Hrtf[0].Params.Delay,
- voice->Direct.Hrtf[0].Params.CoeffStep, voice->Direct.Hrtf[0].Params.DelayStep
- );
- voice->Direct.Counter = counter;
- voice->Direct.LastGain = DryGain;
- voice->Direct.LastDir = dir;
- }
+ Pitch = HUGE_VALF;
}
else
{
- /* Get the initial (static) HRIR coefficients and delays. */
- GetLerpedHrtfCoeffs(Device->Hrtf, ev, az, dirfact, DryGain,
- voice->Direct.Hrtf[0].Params.Coeffs,
- voice->Direct.Hrtf[0].Params.Delay);
- voice->Direct.Counter = 0;
- voice->Direct.Moving = AL_TRUE;
- voice->Direct.LastGain = DryGain;
- voice->Direct.LastDir = dir;
+ /* Source and listener movement is nominal. Calculate the proper
+ * doppler shift.
+ */
+ Pitch *= (SpeedOfSound-vls) / (SpeedOfSound-vss);
}
-
- voice->IsHrtf = AL_TRUE;
}
+
+ /* Adjust pitch based on the buffer and output frequencies, and calculate
+ * fixed-point stepping value.
+ */
+ Pitch *= (ALfloat)ALBuffer->Frequency/(ALfloat)Device->Frequency;
+ if(Pitch > (ALfloat)MAX_PITCH)
+ voice->Step = MAX_PITCH<<FRACTIONBITS;
else
+ voice->Step = maxi(fastf2i(Pitch * FRACTIONONE), 1);
+ if(props->Resampler == BSinc24Resampler)
+ BsincPrepare(voice->Step, &voice->ResampleState.bsinc, &bsinc24);
+ else if(props->Resampler == BSinc12Resampler)
+ BsincPrepare(voice->Step, &voice->ResampleState.bsinc, &bsinc12);
+ voice->Resampler = SelectResampler(props->Resampler);
+
+ if(Distance > 0.0f)
{
- /* Basic or no HRTF rendering. Use normal panning to the output. */
- MixGains *gains = voice->Direct.Gains[0];
- ALfloat dir[3] = { 0.0f, 0.0f, -1.0f };
- ALfloat radius = ALSource->Radius;
- ALfloat Target[MAX_OUTPUT_CHANNELS];
+ /* Clamp Y, in case rounding errors caused it to end up outside of
+ * -1...+1.
+ */
+ ev = asinf(clampf(-SourceToListener.v[1], -1.0f, 1.0f));
+ /* Double negation on Z cancels out; negate once for changing source-
+ * to-listener to listener-to-source, and again for right-handed coords
+ * with -Z in front.
+ */
+ az = atan2f(-SourceToListener.v[0], SourceToListener.v[2]*ZScale);
+ }
+ else
+ ev = az = 0.0f;
- /* Get the localized direction, and compute panned gains. */
- if(Distance > FLT_EPSILON)
- {
- dir[0] = -SourceToListener.v[0];
- dir[1] = -SourceToListener.v[1];
- dir[2] = -SourceToListener.v[2] * ZScale;
- }
- if(radius > 0.0f)
- {
- ALfloat dirfact;
- if(radius >= Distance)
- dirfact = Distance / radius * 0.5f;
- else
- dirfact = 1.0f - (asinf(radius / Distance) / F_PI);
- dir[0] *= dirfact;
- dir[1] *= dirfact;
- dir[2] *= dirfact;
- }
- ComputeDirectionalGains(Device, dir, DryGain, Target);
+ if(props->Radius > Distance)
+ spread = F_TAU - Distance/props->Radius*F_PI;
+ else if(Distance > 0.0f)
+ spread = asinf(props->Radius / Distance) * 2.0f;
+ else
+ spread = 0.0f;
+
+ CalcPanningAndFilters(voice, az, ev, Distance, spread, DryGain, DryGainHF, DryGainLF, WetGain,
+ WetGainLF, WetGainHF, SendSlots, ALBuffer, props, Listener, Device);
+}
- for(j = 0;j < MAX_OUTPUT_CHANNELS;j++)
- gains[j].Target = Target[j];
- UpdateDryStepping(&voice->Direct, 1, (voice->Direct.Moving ? 64 : 0));
- voice->Direct.Moving = AL_TRUE;
+static void CalcSourceParams(ALvoice *voice, ALCcontext *context, bool force)
+{
+ ALbufferlistitem *BufferListItem;
+ struct ALvoiceProps *props;
- voice->IsHrtf = AL_FALSE;
- }
- for(i = 0;i < NumSends;i++)
- {
- voice->Send[i].Gains[0].Target = WetGain[i];
- UpdateWetStepping(&voice->Send[i], 1, (voice->Send[i].Moving ? 64 : 0));
- voice->Send[i].Moving = AL_TRUE;
- }
+ props = ATOMIC_EXCHANGE_PTR(&voice->Update, NULL, almemory_order_acq_rel);
+ if(!props && !force) return;
+ if(props)
{
- ALfloat hfscale = ALSource->Direct.HFReference / Frequency;
- ALfloat lfscale = ALSource->Direct.LFReference / Frequency;
- DryGainHF = maxf(DryGainHF, 0.0001f);
- DryGainLF = maxf(DryGainLF, 0.0001f);
- voice->Direct.Filters[0].ActiveType = AF_None;
- if(DryGainHF != 1.0f) voice->Direct.Filters[0].ActiveType |= AF_LowPass;
- if(DryGainLF != 1.0f) voice->Direct.Filters[0].ActiveType |= AF_HighPass;
- ALfilterState_setParams(
- &voice->Direct.Filters[0].LowPass, ALfilterType_HighShelf,
- DryGainHF, hfscale, calc_rcpQ_from_slope(DryGainHF, 0.75f)
- );
- ALfilterState_setParams(
- &voice->Direct.Filters[0].HighPass, ALfilterType_LowShelf,
- DryGainLF, lfscale, calc_rcpQ_from_slope(DryGainLF, 0.75f)
+ memcpy(voice->Props, props,
+ FAM_SIZE(struct ALvoiceProps, Send, context->Device->NumAuxSends)
);
+
+ ATOMIC_REPLACE_HEAD(struct ALvoiceProps*, &context->FreeVoiceProps, props);
}
- for(i = 0;i < NumSends;i++)
+ props = voice->Props;
+
+ BufferListItem = ATOMIC_LOAD(&voice->current_buffer, almemory_order_relaxed);
+ while(BufferListItem != NULL)
{
- ALfloat hfscale = ALSource->Send[i].HFReference / Frequency;
- ALfloat lfscale = ALSource->Send[i].LFReference / Frequency;
- WetGainHF[i] = maxf(WetGainHF[i], 0.0001f);
- WetGainLF[i] = maxf(WetGainLF[i], 0.0001f);
- voice->Send[i].Filters[0].ActiveType = AF_None;
- if(WetGainHF[i] != 1.0f) voice->Send[i].Filters[0].ActiveType |= AF_LowPass;
- if(WetGainLF[i] != 1.0f) voice->Send[i].Filters[0].ActiveType |= AF_HighPass;
- ALfilterState_setParams(
- &voice->Send[i].Filters[0].LowPass, ALfilterType_HighShelf,
- WetGainHF[i], hfscale, calc_rcpQ_from_slope(WetGainHF[i], 0.75f)
- );
- ALfilterState_setParams(
- &voice->Send[i].Filters[0].HighPass, ALfilterType_LowShelf,
- WetGainLF[i], lfscale, calc_rcpQ_from_slope(WetGainLF[i], 0.75f)
- );
+ const ALbuffer *buffer = NULL;
+ ALsizei i = 0;
+ while(!buffer && i < BufferListItem->num_buffers)
+ buffer = BufferListItem->buffers[i];
+ if(LIKELY(buffer))
+ {
+ if(props->SpatializeMode == SpatializeOn ||
+ (props->SpatializeMode == SpatializeAuto && buffer->FmtChannels == FmtMono))
+ CalcAttnSourceParams(voice, props, buffer, context);
+ else
+ CalcNonAttnSourceParams(voice, props, buffer, context);
+ break;
+ }
+ BufferListItem = ATOMIC_LOAD(&BufferListItem->next, almemory_order_acquire);
}
}
-void UpdateContextSources(ALCcontext *ctx)
+static void ProcessParamUpdates(ALCcontext *ctx, const struct ALeffectslotArray *slots)
{
- ALvoice *voice, *voice_end;
+ ALvoice **voice, **voice_end;
ALsource *source;
+ ALsizei i;
- if(ATOMIC_EXCHANGE(ALenum, &ctx->UpdateSources, AL_FALSE))
+ IncrementRef(&ctx->UpdateCount);
+ if(!ATOMIC_LOAD(&ctx->HoldUpdates, almemory_order_acquire))
{
- CalcListenerParams(ctx->Listener);
+ bool cforce = CalcContextParams(ctx);
+ bool force = CalcListenerParams(ctx) | cforce;
+ for(i = 0;i < slots->count;i++)
+ force |= CalcEffectSlotParams(slots->slot[i], ctx, cforce);
voice = ctx->Voices;
voice_end = voice + ctx->VoiceCount;
for(;voice != voice_end;++voice)
{
- if(!(source=voice->Source)) continue;
- if(source->state != AL_PLAYING && source->state != AL_PAUSED)
- voice->Source = NULL;
- else
- {
- ATOMIC_STORE(&source->NeedsUpdate, AL_FALSE);
- voice->Update(voice, source, ctx);
- }
+ source = ATOMIC_LOAD(&(*voice)->Source, almemory_order_acquire);
+ if(source) CalcSourceParams(*voice, ctx, force);
}
}
- else
+ IncrementRef(&ctx->UpdateCount);
+}
+
+
+static void ApplyStablizer(FrontStablizer *Stablizer, ALfloat (*restrict Buffer)[BUFFERSIZE],
+ int lidx, int ridx, int cidx, ALsizei SamplesToDo,
+ ALsizei NumChannels)
+{
+ ALfloat (*restrict lsplit)[BUFFERSIZE] = ASSUME_ALIGNED(Stablizer->LSplit, 16);
+ ALfloat (*restrict rsplit)[BUFFERSIZE] = ASSUME_ALIGNED(Stablizer->RSplit, 16);
+ ALsizei i;
+
+ /* Apply an all-pass to all channels, except the front-left and front-
+ * right, so they maintain the same relative phase.
+ */
+ for(i = 0;i < NumChannels;i++)
{
- voice = ctx->Voices;
- voice_end = voice + ctx->VoiceCount;
- for(;voice != voice_end;++voice)
+ if(i == lidx || i == ridx)
+ continue;
+ splitterap_process(&Stablizer->APFilter[i], Buffer[i], SamplesToDo);
+ }
+
+ bandsplit_process(&Stablizer->LFilter, lsplit[1], lsplit[0], Buffer[lidx], SamplesToDo);
+ bandsplit_process(&Stablizer->RFilter, rsplit[1], rsplit[0], Buffer[ridx], SamplesToDo);
+
+ for(i = 0;i < SamplesToDo;i++)
+ {
+ ALfloat lfsum, hfsum;
+ ALfloat m, s, c;
+
+ lfsum = lsplit[0][i] + rsplit[0][i];
+ hfsum = lsplit[1][i] + rsplit[1][i];
+ s = lsplit[0][i] + lsplit[1][i] - rsplit[0][i] - rsplit[1][i];
+
+ /* This pans the separate low- and high-frequency sums between being on
+ * the center channel and the left/right channels. The low-frequency
+ * sum is 1/3rd toward center (2/3rds on left/right) and the high-
+ * frequency sum is 1/4th toward center (3/4ths on left/right). These
+ * values can be tweaked.
+ */
+ m = lfsum*cosf(1.0f/3.0f * F_PI_2) + hfsum*cosf(1.0f/4.0f * F_PI_2);
+ c = lfsum*sinf(1.0f/3.0f * F_PI_2) + hfsum*sinf(1.0f/4.0f * F_PI_2);
+
+ /* The generated center channel signal adds to the existing signal,
+ * while the modified left and right channels replace.
+ */
+ Buffer[lidx][i] = (m + s) * 0.5f;
+ Buffer[ridx][i] = (m - s) * 0.5f;
+ Buffer[cidx][i] += c * 0.5f;
+ }
+}
+
+static void ApplyDistanceComp(ALfloat (*restrict Samples)[BUFFERSIZE], DistanceComp *distcomp,
+ ALfloat *restrict Values, ALsizei SamplesToDo, ALsizei numchans)
+{
+ ALsizei i, c;
+
+ Values = ASSUME_ALIGNED(Values, 16);
+ for(c = 0;c < numchans;c++)
+ {
+ ALfloat *restrict inout = ASSUME_ALIGNED(Samples[c], 16);
+ const ALfloat gain = distcomp[c].Gain;
+ const ALsizei base = distcomp[c].Length;
+ ALfloat *restrict distbuf = ASSUME_ALIGNED(distcomp[c].Buffer, 16);
+
+ if(base == 0)
{
- if(!(source=voice->Source)) continue;
- if(source->state != AL_PLAYING && source->state != AL_PAUSED)
- voice->Source = NULL;
- else if(ATOMIC_EXCHANGE(ALenum, &source->NeedsUpdate, AL_FALSE))
- voice->Update(voice, source, ctx);
+ if(gain < 1.0f)
+ {
+ for(i = 0;i < SamplesToDo;i++)
+ inout[i] *= gain;
+ }
+ continue;
}
+
+ if(LIKELY(SamplesToDo >= base))
+ {
+ for(i = 0;i < base;i++)
+ Values[i] = distbuf[i];
+ for(;i < SamplesToDo;i++)
+ Values[i] = inout[i-base];
+ memcpy(distbuf, &inout[SamplesToDo-base], base*sizeof(ALfloat));
+ }
+ else
+ {
+ for(i = 0;i < SamplesToDo;i++)
+ Values[i] = distbuf[i];
+ memmove(distbuf, distbuf+SamplesToDo, (base-SamplesToDo)*sizeof(ALfloat));
+ memcpy(distbuf+base-SamplesToDo, inout, SamplesToDo*sizeof(ALfloat));
+ }
+ for(i = 0;i < SamplesToDo;i++)
+ inout[i] = Values[i]*gain;
}
}
-
-/* Specialized function to clamp to [-1, +1] with only one branch. This also
- * converts NaN to 0. */
-static inline ALfloat aluClampf(ALfloat val)
+static void ApplyDither(ALfloat (*restrict Samples)[BUFFERSIZE], ALuint *dither_seed,
+ const ALfloat quant_scale, const ALsizei SamplesToDo,
+ const ALsizei numchans)
{
- if(fabsf(val) <= 1.0f) return val;
- return (ALfloat)((0.0f < val) - (val < 0.0f));
+ const ALfloat invscale = 1.0f / quant_scale;
+ ALuint seed = *dither_seed;
+ ALsizei c, i;
+
+ ASSUME(numchans > 0);
+ ASSUME(SamplesToDo > 0);
+
+ /* Dithering. Step 1, generate whitenoise (uniform distribution of random
+ * values between -1 and +1). Step 2 is to add the noise to the samples,
+ * before rounding and after scaling up to the desired quantization depth.
+ */
+ for(c = 0;c < numchans;c++)
+ {
+ ALfloat *restrict samples = Samples[c];
+ for(i = 0;i < SamplesToDo;i++)
+ {
+ ALfloat val = samples[i] * quant_scale;
+ ALuint rng0 = dither_rng(&seed);
+ ALuint rng1 = dither_rng(&seed);
+ val += (ALfloat)(rng0*(1.0/UINT_MAX) - rng1*(1.0/UINT_MAX));
+ samples[i] = fast_roundf(val) * invscale;
+ }
+ }
+ *dither_seed = seed;
}
-static inline ALfloat aluF2F(ALfloat val)
-{ return val; }
-static inline ALint aluF2I(ALfloat val)
+static inline ALfloat Conv_ALfloat(ALfloat val)
+{ return val; }
+static inline ALint Conv_ALint(ALfloat val)
{
- /* Floats only have a 24-bit mantissa, so [-16777215, +16777215] is the max
- * integer range normalized floats can be safely converted to.
+ /* Floats have a 23-bit mantissa. There is an implied 1 bit in the mantissa
+ * along with the sign bit, giving 25 bits total, so [-16777216, +16777216]
+ * is the max value a normalized float can be scaled to before losing
+ * precision.
*/
- return fastf2i(aluClampf(val)*16777215.0f)<<7;
+ return fastf2i(clampf(val*16777216.0f, -16777216.0f, 16777215.0f))<<7;
}
-static inline ALuint aluF2UI(ALfloat val)
-{ return aluF2I(val)+2147483648u; }
-
-static inline ALshort aluF2S(ALfloat val)
-{ return fastf2i(aluClampf(val)*32767.0f); }
-static inline ALushort aluF2US(ALfloat val)
-{ return aluF2S(val)+32768; }
-
-static inline ALbyte aluF2B(ALfloat val)
-{ return fastf2i(aluClampf(val)*127.0f); }
-static inline ALubyte aluF2UB(ALfloat val)
-{ return aluF2B(val)+128; }
-
-#define DECL_TEMPLATE(T, func) \
-static void Write_##T(ALfloatBUFFERSIZE *InBuffer, ALvoid *OutBuffer, \
- ALuint SamplesToDo, ALuint numchans) \
+static inline ALshort Conv_ALshort(ALfloat val)
+{ return fastf2i(clampf(val*32768.0f, -32768.0f, 32767.0f)); }
+static inline ALbyte Conv_ALbyte(ALfloat val)
+{ return fastf2i(clampf(val*128.0f, -128.0f, 127.0f)); }
+
+/* Define unsigned output variations. */
+#define DECL_TEMPLATE(T, func, O) \
+static inline T Conv_##T(ALfloat val) { return func(val)+O; }
+
+DECL_TEMPLATE(ALubyte, Conv_ALbyte, 128)
+DECL_TEMPLATE(ALushort, Conv_ALshort, 32768)
+DECL_TEMPLATE(ALuint, Conv_ALint, 2147483648u)
+
+#undef DECL_TEMPLATE
+
+#define DECL_TEMPLATE(T, A) \
+static void Write##A(const ALfloat (*restrict InBuffer)[BUFFERSIZE], \
+ ALvoid *OutBuffer, ALsizei Offset, ALsizei SamplesToDo, \
+ ALsizei numchans) \
{ \
- ALuint i, j; \
+ ALsizei i, j; \
+ \
+ ASSUME(numchans > 0); \
+ ASSUME(SamplesToDo > 0); \
+ \
for(j = 0;j < numchans;j++) \
{ \
- const ALfloat *in = InBuffer[j]; \
- T *restrict out = (T*)OutBuffer + j; \
+ const ALfloat *restrict in = ASSUME_ALIGNED(InBuffer[j], 16); \
+ T *restrict out = (T*)OutBuffer + Offset*numchans + j; \
+ \
for(i = 0;i < SamplesToDo;i++) \
- out[i*numchans] = func(in[i]); \
+ out[i*numchans] = Conv_##T(in[i]); \
} \
}
-DECL_TEMPLATE(ALfloat, aluF2F)
-DECL_TEMPLATE(ALuint, aluF2UI)
-DECL_TEMPLATE(ALint, aluF2I)
-DECL_TEMPLATE(ALushort, aluF2US)
-DECL_TEMPLATE(ALshort, aluF2S)
-DECL_TEMPLATE(ALubyte, aluF2UB)
-DECL_TEMPLATE(ALbyte, aluF2B)
+DECL_TEMPLATE(ALfloat, F32)
+DECL_TEMPLATE(ALuint, UI32)
+DECL_TEMPLATE(ALint, I32)
+DECL_TEMPLATE(ALushort, UI16)
+DECL_TEMPLATE(ALshort, I16)
+DECL_TEMPLATE(ALubyte, UI8)
+DECL_TEMPLATE(ALbyte, I8)
#undef DECL_TEMPLATE
-ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
+void aluMixData(ALCdevice *device, ALvoid *OutBuffer, ALsizei NumSamples)
{
- ALuint SamplesToDo;
- ALvoice *voice, *voice_end;
- ALeffectslot *slot;
- ALsource *source;
+ ALsizei SamplesToDo;
+ ALsizei SamplesDone;
ALCcontext *ctx;
- FPUCtl oldMode;
- ALuint i, c;
+ ALsizei i, c;
- SetMixerFPUMode(&oldMode);
-
- while(size > 0)
+ START_MIXER_MODE();
+ for(SamplesDone = 0;SamplesDone < NumSamples;)
{
- ALfloat (*OutBuffer)[BUFFERSIZE];
- ALuint OutChannels;
+ SamplesToDo = mini(NumSamples-SamplesDone, BUFFERSIZE);
+ for(c = 0;c < device->Dry.NumChannels;c++)
+ memset(device->Dry.Buffer[c], 0, SamplesToDo*sizeof(ALfloat));
+ if(device->Dry.Buffer != device->FOAOut.Buffer)
+ for(c = 0;c < device->FOAOut.NumChannels;c++)
+ memset(device->FOAOut.Buffer[c], 0, SamplesToDo*sizeof(ALfloat));
+ if(device->Dry.Buffer != device->RealOut.Buffer)
+ for(c = 0;c < device->RealOut.NumChannels;c++)
+ memset(device->RealOut.Buffer[c], 0, SamplesToDo*sizeof(ALfloat));
IncrementRef(&device->MixCount);
- OutBuffer = device->DryBuffer;
- OutChannels = device->NumChannels;
-
- SamplesToDo = minu(size, BUFFERSIZE);
- for(c = 0;c < OutChannels;c++)
- memset(OutBuffer[c], 0, SamplesToDo*sizeof(ALfloat));
- if(device->Hrtf)
+ ctx = ATOMIC_LOAD(&device->ContextList, almemory_order_acquire);
+ while(ctx)
{
- /* Set OutBuffer/OutChannels to correspond to the actual output
- * with HRTF. Make sure to clear them too. */
- OutBuffer += OutChannels;
- OutChannels = 2;
- for(c = 0;c < OutChannels;c++)
- memset(OutBuffer[c], 0, SamplesToDo*sizeof(ALfloat));
- }
+ const struct ALeffectslotArray *auxslots;
- V0(device->Backend,lock)();
-
- if((slot=device->DefaultSlot) != NULL)
- {
- if(ATOMIC_EXCHANGE(ALenum, &slot->NeedsUpdate, AL_FALSE))
- V(slot->EffectState,update)(device, slot);
- memset(slot->WetBuffer[0], 0, SamplesToDo*sizeof(ALfloat));
- }
+ auxslots = ATOMIC_LOAD(&ctx->ActiveAuxSlots, almemory_order_acquire);
+ ProcessParamUpdates(ctx, auxslots);
- ctx = ATOMIC_LOAD(&device->ContextList);
- while(ctx)
- {
- if(!ctx->DeferUpdates)
- {
- UpdateContextSources(ctx);
-#define UPDATE_SLOT(iter) do { \
- if(ATOMIC_EXCHANGE(ALenum, &(*iter)->NeedsUpdate, AL_FALSE)) \
- V((*iter)->EffectState,update)(device, *iter); \
- memset((*iter)->WetBuffer[0], 0, SamplesToDo*sizeof(ALfloat)); \
-} while(0)
- VECTOR_FOR_EACH(ALeffectslot*, ctx->ActiveAuxSlots, UPDATE_SLOT);
-#undef UPDATE_SLOT
- }
- else
+ for(i = 0;i < auxslots->count;i++)
{
-#define CLEAR_WET_BUFFER(iter) memset((*iter)->WetBuffer[0], 0, SamplesToDo*sizeof(ALfloat))
- VECTOR_FOR_EACH(ALeffectslot*, ctx->ActiveAuxSlots, CLEAR_WET_BUFFER);
-#undef CLEAR_WET_BUFFER
+ ALeffectslot *slot = auxslots->slot[i];
+ for(c = 0;c < slot->NumChannels;c++)
+ memset(slot->WetBuffer[c], 0, SamplesToDo*sizeof(ALfloat));
}
/* source processing */
- voice = ctx->Voices;
- voice_end = voice + ctx->VoiceCount;
- for(;voice != voice_end;++voice)
+ for(i = 0;i < ctx->VoiceCount;i++)
{
- source = voice->Source;
- if(source && source->state == AL_PLAYING)
- MixSource(voice, source, device, SamplesToDo);
+ ALvoice *voice = ctx->Voices[i];
+ ALsource *source = ATOMIC_LOAD(&voice->Source, almemory_order_acquire);
+ if(source && ATOMIC_LOAD(&voice->Playing, almemory_order_relaxed) &&
+ voice->Step > 0)
+ {
+ if(!MixSource(voice, source->id, ctx, SamplesToDo))
+ {
+ ATOMIC_STORE(&voice->Source, NULL, almemory_order_relaxed);
+ ATOMIC_STORE(&voice->Playing, false, almemory_order_release);
+ SendSourceStoppedEvent(ctx, source->id);
+ }
+ }
}
/* effect slot processing */
-#define PROCESS_SLOT(iter) V((*iter)->EffectState,process)( \
- SamplesToDo, (*iter)->WetBuffer[0], device->DryBuffer, device->NumChannels \
-);
- VECTOR_FOR_EACH(ALeffectslot*, ctx->ActiveAuxSlots, PROCESS_SLOT);
-#undef PROCESS_SLOT
+ for(i = 0;i < auxslots->count;i++)
+ {
+ const ALeffectslot *slot = auxslots->slot[i];
+ ALeffectState *state = slot->Params.EffectState;
+ V(state,process)(SamplesToDo, slot->WetBuffer, state->OutBuffer,
+ state->OutChannels);
+ }
- ctx = ctx->next;
+ ctx = ATOMIC_LOAD(&ctx->next, almemory_order_relaxed);
}
- if((slot=device->DefaultSlot) != NULL)
- V(slot->EffectState,process)(
- SamplesToDo, slot->WetBuffer[0], device->DryBuffer, device->NumChannels
- );
-
/* Increment the clock time. Every second's worth of samples is
* converted and added to clock base so that large sample counts don't
* overflow during conversion. This also guarantees an exact, stable
@@ -1488,104 +1815,109 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
device->SamplesDone += SamplesToDo;
device->ClockBase += (device->SamplesDone/device->Frequency) * DEVICE_CLOCK_RES;
device->SamplesDone %= device->Frequency;
- V0(device->Backend,unlock)();
+ IncrementRef(&device->MixCount);
- if(device->Hrtf)
- {
- HrtfMixerFunc HrtfMix = SelectHrtfMixer();
- ALuint irsize = GetHrtfIrSize(device->Hrtf);
- for(c = 0;c < device->NumChannels;c++)
- HrtfMix(OutBuffer, device->DryBuffer[c], 0, device->Hrtf_Offset,
- 0, irsize, &device->Hrtf_Params[c], &device->Hrtf_State[c],
- SamplesToDo
- );
- device->Hrtf_Offset += SamplesToDo;
- }
- else if(device->Bs2b)
+ /* Apply post-process for finalizing the Dry mix to the RealOut
+ * (Ambisonic decode, UHJ encode, etc).
+ */
+ if(LIKELY(device->PostProcess))
+ device->PostProcess(device, SamplesToDo);
+
+ if(device->Stablizer)
{
- /* Apply binaural/crossfeed filter */
- for(i = 0;i < SamplesToDo;i++)
- {
- float samples[2];
- samples[0] = device->DryBuffer[0][i];
- samples[1] = device->DryBuffer[1][i];
- bs2b_cross_feed(device->Bs2b, samples);
- device->DryBuffer[0][i] = samples[0];
- device->DryBuffer[1][i] = samples[1];
- }
+ int lidx = GetChannelIdxByName(&device->RealOut, FrontLeft);
+ int ridx = GetChannelIdxByName(&device->RealOut, FrontRight);
+ int cidx = GetChannelIdxByName(&device->RealOut, FrontCenter);
+ assert(lidx >= 0 && ridx >= 0 && cidx >= 0);
+
+ ApplyStablizer(device->Stablizer, device->RealOut.Buffer, lidx, ridx, cidx,
+ SamplesToDo, device->RealOut.NumChannels);
}
- if(buffer)
+ ApplyDistanceComp(device->RealOut.Buffer, device->ChannelDelay, device->TempBuffer[0],
+ SamplesToDo, device->RealOut.NumChannels);
+
+ if(device->Limiter)
+ ApplyCompression(device->Limiter, SamplesToDo, device->RealOut.Buffer);
+
+ if(device->DitherDepth > 0.0f)
+ ApplyDither(device->RealOut.Buffer, &device->DitherSeed, device->DitherDepth,
+ SamplesToDo, device->RealOut.NumChannels);
+
+ if(LIKELY(OutBuffer))
{
-#define WRITE(T, a, b, c, d) do { \
- Write_##T((a), (b), (c), (d)); \
- buffer = (T*)buffer + (c)*(d); \
-} while(0)
+ ALfloat (*Buffer)[BUFFERSIZE] = device->RealOut.Buffer;
+ ALsizei Channels = device->RealOut.NumChannels;
+
switch(device->FmtType)
{
- case DevFmtByte:
- WRITE(ALbyte, OutBuffer, buffer, SamplesToDo, OutChannels);
- break;
- case DevFmtUByte:
- WRITE(ALubyte, OutBuffer, buffer, SamplesToDo, OutChannels);
- break;
- case DevFmtShort:
- WRITE(ALshort, OutBuffer, buffer, SamplesToDo, OutChannels);
- break;
- case DevFmtUShort:
- WRITE(ALushort, OutBuffer, buffer, SamplesToDo, OutChannels);
- break;
- case DevFmtInt:
- WRITE(ALint, OutBuffer, buffer, SamplesToDo, OutChannels);
- break;
- case DevFmtUInt:
- WRITE(ALuint, OutBuffer, buffer, SamplesToDo, OutChannels);
- break;
- case DevFmtFloat:
- WRITE(ALfloat, OutBuffer, buffer, SamplesToDo, OutChannels);
- break;
+#define HANDLE_WRITE(T, S) case T: \
+ Write##S(Buffer, OutBuffer, SamplesDone, SamplesToDo, Channels); break;
+ HANDLE_WRITE(DevFmtByte, I8)
+ HANDLE_WRITE(DevFmtUByte, UI8)
+ HANDLE_WRITE(DevFmtShort, I16)
+ HANDLE_WRITE(DevFmtUShort, UI16)
+ HANDLE_WRITE(DevFmtInt, I32)
+ HANDLE_WRITE(DevFmtUInt, UI32)
+ HANDLE_WRITE(DevFmtFloat, F32)
+#undef HANDLE_WRITE
}
-#undef WRITE
}
- size -= SamplesToDo;
- IncrementRef(&device->MixCount);
+ SamplesDone += SamplesToDo;
}
-
- RestoreFPUMode(&oldMode);
+ END_MIXER_MODE();
}
-ALvoid aluHandleDisconnect(ALCdevice *device)
+void aluHandleDisconnect(ALCdevice *device, const char *msg, ...)
{
- ALCcontext *Context;
+ AsyncEvent evt = ASYNC_EVENT(EventType_Disconnected);
+ ALCcontext *ctx;
+ va_list args;
+ int msglen;
+
+ if(!ATOMIC_EXCHANGE(&device->Connected, AL_FALSE, almemory_order_acq_rel))
+ return;
+
+ evt.u.user.type = AL_EVENT_TYPE_DISCONNECTED_SOFT;
+ evt.u.user.id = 0;
+ evt.u.user.param = 0;
- device->Connected = ALC_FALSE;
+ va_start(args, msg);
+ msglen = vsnprintf(evt.u.user.msg, sizeof(evt.u.user.msg), msg, args);
+ va_end(args);
- Context = ATOMIC_LOAD(&device->ContextList);
- while(Context)
+ if(msglen < 0 || (size_t)msglen >= sizeof(evt.u.user.msg))
+ evt.u.user.msg[sizeof(evt.u.user.msg)-1] = 0;
+
+ ctx = ATOMIC_LOAD_SEQ(&device->ContextList);
+ while(ctx)
{
- ALvoice *voice, *voice_end;
+ ALbitfieldSOFT enabledevt = ATOMIC_LOAD(&ctx->EnabledEvts, almemory_order_acquire);
+ ALsizei i;
+
+ if((enabledevt&EventType_Disconnected) &&
+ ll_ringbuffer_write(ctx->AsyncEvents, (const char*)&evt, 1) == 1)
+ alsem_post(&ctx->EventSem);
- voice = Context->Voices;
- voice_end = voice + Context->VoiceCount;
- while(voice != voice_end)
+ for(i = 0;i < ctx->VoiceCount;i++)
{
- ALsource *source = voice->Source;
- voice->Source = NULL;
+ ALvoice *voice = ctx->Voices[i];
+ ALsource *source;
- if(source && source->state == AL_PLAYING)
+ source = ATOMIC_EXCHANGE_PTR(&voice->Source, NULL, almemory_order_relaxed);
+ if(source && ATOMIC_LOAD(&voice->Playing, almemory_order_relaxed))
{
- source->state = AL_STOPPED;
- ATOMIC_STORE(&source->current_buffer, NULL);
- source->position = 0;
- source->position_fraction = 0;
+ /* If the source's voice was playing, it's now effectively
+ * stopped (the source state will be updated the next time it's
+ * checked).
+ */
+ SendSourceStoppedEvent(ctx, source->id);
}
-
- voice++;
+ ATOMIC_STORE(&voice->Playing, false, almemory_order_release);
}
- Context->VoiceCount = 0;
- Context = Context->next;
+ ctx = ATOMIC_LOAD(&ctx->next, almemory_order_relaxed);
}
}
diff --git a/Alc/alcRing.c b/Alc/alcRing.c
deleted file mode 100644
index e9a40a12..00000000
--- a/Alc/alcRing.c
+++ /dev/null
@@ -1,401 +0,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.,
- * 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 "compat.h"
-
-
-struct RingBuffer {
- ALubyte *mem;
-
- ALsizei frame_size;
- ALsizei length;
- ALint read_pos;
- ALint write_pos;
-
- almtx_t mtx;
-};
-
-
-RingBuffer *CreateRingBuffer(ALsizei frame_size, ALsizei length)
-{
- RingBuffer *ring = calloc(1, sizeof(*ring) + ((length+1) * frame_size));
- if(ring)
- {
- ring->mem = (ALubyte*)(ring+1);
-
- ring->frame_size = frame_size;
- ring->length = length+1;
- ring->read_pos = 0;
- ring->write_pos = 0;
-
- almtx_init(&ring->mtx, almtx_plain);
- }
- return ring;
-}
-
-void DestroyRingBuffer(RingBuffer *ring)
-{
- if(ring)
- {
- almtx_destroy(&ring->mtx);
- free(ring);
- }
-}
-
-ALsizei RingBufferSize(RingBuffer *ring)
-{
- ALsizei s;
-
- almtx_lock(&ring->mtx);
- s = (ring->write_pos-ring->read_pos+ring->length) % ring->length;
- almtx_unlock(&ring->mtx);
-
- return s;
-}
-
-void WriteRingBuffer(RingBuffer *ring, const ALubyte *data, ALsizei len)
-{
- int remain;
-
- almtx_lock(&ring->mtx);
-
- remain = (ring->read_pos-ring->write_pos-1+ring->length) % ring->length;
- if(remain < len) len = remain;
-
- if(len > 0)
- {
- remain = ring->length - ring->write_pos;
- if(remain < len)
- {
- memcpy(ring->mem+(ring->write_pos*ring->frame_size), data,
- remain*ring->frame_size);
- memcpy(ring->mem, data+(remain*ring->frame_size),
- (len-remain)*ring->frame_size);
- }
- else
- memcpy(ring->mem+(ring->write_pos*ring->frame_size), data,
- len*ring->frame_size);
-
- ring->write_pos += len;
- ring->write_pos %= ring->length;
- }
-
- almtx_unlock(&ring->mtx);
-}
-
-void ReadRingBuffer(RingBuffer *ring, ALubyte *data, ALsizei len)
-{
- int remain;
-
- almtx_lock(&ring->mtx);
-
- remain = ring->length - ring->read_pos;
- if(remain < len)
- {
- memcpy(data, ring->mem+(ring->read_pos*ring->frame_size), remain*ring->frame_size);
- memcpy(data+(remain*ring->frame_size), ring->mem, (len-remain)*ring->frame_size);
- }
- else
- memcpy(data, ring->mem+(ring->read_pos*ring->frame_size), len*ring->frame_size);
-
- ring->read_pos += len;
- ring->read_pos %= ring->length;
-
- almtx_unlock(&ring->mtx);
-}
-
-
-/* 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;
- }
-}
diff --git a/Alc/alcConfig.c b/Alc/alconfig.c
index 6fc9db33..3d0ed140 100644
--- a/Alc/alcConfig.c
+++ b/Alc/alconfig.c
@@ -36,8 +36,12 @@
#include <windows.h>
#include <shlobj.h>
#endif
+#ifdef __APPLE__
+#include <CoreFoundation/CoreFoundation.h>
+#endif
#include "alMain.h"
+#include "alconfig.h"
#include "compat.h"
#include "bool.h"
@@ -233,7 +237,61 @@ static void LoadConfigFromFile(FILE *f)
curSection[0] = 0;
else
{
- strncpy(curSection, section, sizeof(curSection)-1);
+ size_t len, p = 0;
+ do {
+ char *nextp = strchr(section, '%');
+ if(!nextp)
+ {
+ strncpy(curSection+p, section, sizeof(curSection)-1-p);
+ break;
+ }
+
+ len = nextp - section;
+ if(len > sizeof(curSection)-1-p)
+ len = sizeof(curSection)-1-p;
+ strncpy(curSection+p, section, len);
+ p += len;
+ section = nextp;
+
+ if(((section[1] >= '0' && section[1] <= '9') ||
+ (section[1] >= 'a' && section[1] <= 'f') ||
+ (section[1] >= 'A' && section[1] <= 'F')) &&
+ ((section[2] >= '0' && section[2] <= '9') ||
+ (section[2] >= 'a' && section[2] <= 'f') ||
+ (section[2] >= 'A' && section[2] <= 'F')))
+ {
+ unsigned char b = 0;
+ if(section[1] >= '0' && section[1] <= '9')
+ b = (section[1]-'0') << 4;
+ else if(section[1] >= 'a' && section[1] <= 'f')
+ b = (section[1]-'a'+0xa) << 4;
+ else if(section[1] >= 'A' && section[1] <= 'F')
+ b = (section[1]-'A'+0x0a) << 4;
+ if(section[2] >= '0' && section[2] <= '9')
+ b |= (section[2]-'0');
+ else if(section[2] >= 'a' && section[2] <= 'f')
+ b |= (section[2]-'a'+0xa);
+ else if(section[2] >= 'A' && section[2] <= 'F')
+ b |= (section[2]-'A'+0x0a);
+ if(p < sizeof(curSection)-1)
+ curSection[p++] = b;
+ section += 3;
+ }
+ else if(section[1] == '%')
+ {
+ if(p < sizeof(curSection)-1)
+ curSection[p++] = '%';
+ section += 2;
+ }
+ else
+ {
+ if(p < sizeof(curSection)-1)
+ curSection[p++] = '%';
+ section += 1;
+ }
+ if(p < sizeof(curSection)-1)
+ curSection[p] = 0;
+ } while(p < sizeof(curSection)-1 && *section != 0);
curSection[sizeof(curSection)-1] = 0;
}
@@ -311,45 +369,62 @@ static void LoadConfigFromFile(FILE *f)
#ifdef _WIN32
void ReadALConfig(void)
{
- WCHAR buffer[PATH_MAX];
+ al_string ppath = AL_STRING_INIT_STATIC();
+ WCHAR buffer[MAX_PATH];
const WCHAR *str;
FILE *f;
if(SHGetSpecialFolderPathW(NULL, buffer, CSIDL_APPDATA, FALSE) != FALSE)
{
al_string filepath = AL_STRING_INIT_STATIC();
- al_string_copy_wcstr(&filepath, buffer);
- al_string_append_cstr(&filepath, "\\alsoft.ini");
+ alstr_copy_wcstr(&filepath, buffer);
+ alstr_append_cstr(&filepath, "\\alsoft.ini");
- TRACE("Loading config %s...\n", al_string_get_cstr(filepath));
- f = al_fopen(al_string_get_cstr(filepath), "rt");
+ TRACE("Loading config %s...\n", alstr_get_cstr(filepath));
+ f = al_fopen(alstr_get_cstr(filepath), "rt");
+ if(f)
+ {
+ LoadConfigFromFile(f);
+ fclose(f);
+ }
+ alstr_reset(&filepath);
+ }
+
+ GetProcBinary(&ppath, NULL);
+ if(!alstr_empty(ppath))
+ {
+ alstr_append_cstr(&ppath, "\\alsoft.ini");
+ TRACE("Loading config %s...\n", alstr_get_cstr(ppath));
+ f = al_fopen(alstr_get_cstr(ppath), "r");
if(f)
{
LoadConfigFromFile(f);
fclose(f);
}
- al_string_deinit(&filepath);
}
if((str=_wgetenv(L"ALSOFT_CONF")) != NULL && *str)
{
al_string filepath = AL_STRING_INIT_STATIC();
- al_string_copy_wcstr(&filepath, str);
+ alstr_copy_wcstr(&filepath, str);
- TRACE("Loading config %s...\n", al_string_get_cstr(filepath));
- f = al_fopen(al_string_get_cstr(filepath), "rt");
+ TRACE("Loading config %s...\n", alstr_get_cstr(filepath));
+ f = al_fopen(alstr_get_cstr(filepath), "rt");
if(f)
{
LoadConfigFromFile(f);
fclose(f);
}
- al_string_deinit(&filepath);
+ alstr_reset(&filepath);
}
+
+ alstr_reset(&ppath);
}
#else
void ReadALConfig(void)
{
- char buffer[PATH_MAX];
+ al_string confpaths = AL_STRING_INIT_STATIC();
+ al_string fname = AL_STRING_INIT_STATIC();
const char *str;
FILE *f;
@@ -365,45 +440,75 @@ void ReadALConfig(void)
if(!(str=getenv("XDG_CONFIG_DIRS")) || str[0] == 0)
str = "/etc/xdg";
- strncpy(buffer, str, sizeof(buffer)-1);
- buffer[sizeof(buffer)-1] = 0;
+ alstr_copy_cstr(&confpaths, str);
/* Go through the list in reverse, since "the order of base directories
* denotes their importance; the first directory listed is the most
* important". Ergo, we need to load the settings from the later dirs
* first so that the settings in the earlier dirs override them.
*/
- while(1)
+ while(!alstr_empty(confpaths))
{
- char *next = strrchr(buffer, ':');
- if(next) *(next++) = 0;
- else next = buffer;
+ char *next = strrchr(alstr_get_cstr(confpaths), ':');
+ if(next)
+ {
+ size_t len = next - alstr_get_cstr(confpaths);
+ alstr_copy_cstr(&fname, next+1);
+ VECTOR_RESIZE(confpaths, len, len+1);
+ VECTOR_ELEM(confpaths, len) = 0;
+ }
+ else
+ {
+ alstr_reset(&fname);
+ fname = confpaths;
+ AL_STRING_INIT(confpaths);
+ }
- if(next[0] != '/')
- WARN("Ignoring XDG config dir: %s\n", next);
+ if(alstr_empty(fname) || VECTOR_FRONT(fname) != '/')
+ WARN("Ignoring XDG config dir: %s\n", alstr_get_cstr(fname));
else
{
- size_t len = strlen(next);
- strncpy(next+len, "/alsoft.conf", buffer+sizeof(buffer)-next-len);
- buffer[sizeof(buffer)-1] = 0;
+ if(VECTOR_BACK(fname) != '/') alstr_append_cstr(&fname, "/alsoft.conf");
+ else alstr_append_cstr(&fname, "alsoft.conf");
- TRACE("Loading config %s...\n", next);
- f = al_fopen(next, "r");
+ TRACE("Loading config %s...\n", alstr_get_cstr(fname));
+ f = al_fopen(alstr_get_cstr(fname), "r");
if(f)
{
LoadConfigFromFile(f);
fclose(f);
}
}
- if(next == buffer)
- break;
+ alstr_clear(&fname);
}
+#ifdef __APPLE__
+ CFBundleRef mainBundle = CFBundleGetMainBundle();
+ if(mainBundle)
+ {
+ unsigned char fileName[PATH_MAX];
+ CFURLRef configURL;
+
+ if((configURL=CFBundleCopyResourceURL(mainBundle, CFSTR(".alsoftrc"), CFSTR(""), NULL)) &&
+ CFURLGetFileSystemRepresentation(configURL, true, fileName, sizeof(fileName)))
+ {
+ f = al_fopen((const char*)fileName, "r");
+ if(f)
+ {
+ LoadConfigFromFile(f);
+ fclose(f);
+ }
+ }
+ }
+#endif
+
if((str=getenv("HOME")) != NULL && *str)
{
- snprintf(buffer, sizeof(buffer), "%s/.alsoftrc", str);
+ alstr_copy_cstr(&fname, str);
+ if(VECTOR_BACK(fname) != '/') alstr_append_cstr(&fname, "/.alsoftrc");
+ else alstr_append_cstr(&fname, ".alsoftrc");
- TRACE("Loading config %s...\n", buffer);
- f = al_fopen(buffer, "r");
+ TRACE("Loading config %s...\n", alstr_get_cstr(fname));
+ f = al_fopen(alstr_get_cstr(fname), "r");
if(f)
{
LoadConfigFromFile(f);
@@ -412,17 +517,41 @@ void ReadALConfig(void)
}
if((str=getenv("XDG_CONFIG_HOME")) != NULL && str[0] != 0)
- snprintf(buffer, sizeof(buffer), "%s/%s", str, "alsoft.conf");
+ {
+ alstr_copy_cstr(&fname, str);
+ if(VECTOR_BACK(fname) != '/') alstr_append_cstr(&fname, "/alsoft.conf");
+ else alstr_append_cstr(&fname, "alsoft.conf");
+ }
else
{
- buffer[0] = 0;
+ alstr_clear(&fname);
if((str=getenv("HOME")) != NULL && str[0] != 0)
- snprintf(buffer, sizeof(buffer), "%s/.config/%s", str, "alsoft.conf");
+ {
+ alstr_copy_cstr(&fname, str);
+ if(VECTOR_BACK(fname) != '/') alstr_append_cstr(&fname, "/.config/alsoft.conf");
+ else alstr_append_cstr(&fname, ".config/alsoft.conf");
+ }
}
- if(buffer[0] != 0)
+ if(!alstr_empty(fname))
{
- TRACE("Loading config %s...\n", buffer);
- f = al_fopen(buffer, "r");
+ TRACE("Loading config %s...\n", alstr_get_cstr(fname));
+ f = al_fopen(alstr_get_cstr(fname), "r");
+ if(f)
+ {
+ LoadConfigFromFile(f);
+ fclose(f);
+ }
+ }
+
+ alstr_clear(&fname);
+ GetProcBinary(&fname, NULL);
+ if(!alstr_empty(fname))
+ {
+ if(VECTOR_BACK(fname) != '/') alstr_append_cstr(&fname, "/alsoft.conf");
+ else alstr_append_cstr(&fname, "alsoft.conf");
+
+ TRACE("Loading config %s...\n", alstr_get_cstr(fname));
+ f = al_fopen(alstr_get_cstr(fname), "r");
if(f)
{
LoadConfigFromFile(f);
@@ -440,6 +569,9 @@ void ReadALConfig(void)
fclose(f);
}
}
+
+ alstr_reset(&fname);
+ alstr_reset(&confpaths);
}
#endif
diff --git a/Alc/alconfig.h b/Alc/alconfig.h
new file mode 100644
index 00000000..1e493e2e
--- /dev/null
+++ b/Alc/alconfig.h
@@ -0,0 +1,17 @@
+#ifndef ALCONFIG_H
+#define ALCONFIG_H
+
+void ReadALConfig(void);
+void FreeALConfig(void);
+
+int ConfigValueExists(const char *devName, const char *blockName, const char *keyName);
+const char *GetConfigValue(const char *devName, const char *blockName, const char *keyName, const char *def);
+int GetConfigValueBool(const char *devName, const char *blockName, const char *keyName, int def);
+
+int ConfigValueStr(const char *devName, const char *blockName, const char *keyName, const char **ret);
+int ConfigValueInt(const char *devName, const char *blockName, const char *keyName, int *ret);
+int ConfigValueUInt(const char *devName, const char *blockName, const char *keyName, unsigned int *ret);
+int ConfigValueFloat(const char *devName, const char *blockName, const char *keyName, float *ret);
+int ConfigValueBool(const char *devName, const char *blockName, const char *keyName, int *ret);
+
+#endif /* ALCONFIG_H */
diff --git a/Alc/alstring.h b/Alc/alstring.h
index f53d2c57..923a5ea2 100644
--- a/Alc/alstring.h
+++ b/Alc/alstring.h
@@ -6,43 +6,53 @@
#include "vector.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef char al_string_char_type;
TYPEDEF_VECTOR(al_string_char_type, al_string)
TYPEDEF_VECTOR(al_string, vector_al_string)
-inline void al_string_deinit(al_string *str)
+inline void alstr_reset(al_string *str)
{ VECTOR_DEINIT(*str); }
#define AL_STRING_INIT(_x) do { (_x) = (al_string)NULL; } while(0)
#define AL_STRING_INIT_STATIC() ((al_string)NULL)
-#define AL_STRING_DEINIT(_x) al_string_deinit(&(_x))
+#define AL_STRING_DEINIT(_x) alstr_reset(&(_x))
-inline size_t al_string_length(const_al_string str)
+inline size_t alstr_length(const_al_string str)
{ return VECTOR_SIZE(str); }
-inline ALboolean al_string_empty(const_al_string str)
-{ return al_string_length(str) == 0; }
+inline ALboolean alstr_empty(const_al_string str)
+{ return alstr_length(str) == 0; }
-inline const al_string_char_type *al_string_get_cstr(const_al_string str)
+inline const al_string_char_type *alstr_get_cstr(const_al_string str)
{ return str ? &VECTOR_FRONT(str) : ""; }
-void al_string_clear(al_string *str);
+void alstr_clear(al_string *str);
-int al_string_cmp(const_al_string str1, const_al_string str2);
-int al_string_cmp_cstr(const_al_string str1, const al_string_char_type *str2);
+int alstr_cmp(const_al_string str1, const_al_string str2);
+int alstr_cmp_cstr(const_al_string str1, const al_string_char_type *str2);
-void al_string_copy(al_string *str, const_al_string from);
-void al_string_copy_cstr(al_string *str, const al_string_char_type *from);
+void alstr_copy(al_string *str, const_al_string from);
+void alstr_copy_cstr(al_string *str, const al_string_char_type *from);
+void alstr_copy_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to);
-void al_string_append_char(al_string *str, const al_string_char_type c);
-void al_string_append_cstr(al_string *str, const al_string_char_type *from);
-void al_string_append_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to);
+void alstr_append_char(al_string *str, const al_string_char_type c);
+void alstr_append_cstr(al_string *str, const al_string_char_type *from);
+void alstr_append_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to);
#ifdef _WIN32
#include <wchar.h>
/* Windows-only methods to deal with WideChar strings. */
-void al_string_copy_wcstr(al_string *str, const wchar_t *from);
-void al_string_append_wcstr(al_string *str, const wchar_t *from);
-void al_string_append_wrange(al_string *str, const wchar_t *from, const wchar_t *to);
+void alstr_copy_wcstr(al_string *str, const wchar_t *from);
+void alstr_append_wcstr(al_string *str, const wchar_t *from);
+void alstr_copy_wrange(al_string *str, const wchar_t *from, const wchar_t *to);
+void alstr_append_wrange(al_string *str, const wchar_t *from, const wchar_t *to);
+#endif
+
+#ifdef __cplusplus
+} /* extern "C" */
#endif
#endif /* ALSTRING_H */
diff --git a/Alc/ambdec.c b/Alc/ambdec.c
new file mode 100644
index 00000000..da114335
--- /dev/null
+++ b/Alc/ambdec.c
@@ -0,0 +1,566 @@
+
+#include "config.h"
+
+#include "ambdec.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "compat.h"
+
+
+static char *lstrip(char *line)
+{
+ while(isspace(line[0]))
+ line++;
+ return line;
+}
+
+static char *rstrip(char *line)
+{
+ size_t len = strlen(line);
+ while(len > 0 && isspace(line[len-1]))
+ len--;
+ line[len] = 0;
+ return line;
+}
+
+static int readline(FILE *f, char **output, size_t *maxlen)
+{
+ size_t len = 0;
+ int c;
+
+ while((c=fgetc(f)) != EOF && (c == '\r' || c == '\n'))
+ ;
+ if(c == EOF)
+ return 0;
+
+ do {
+ if(len+1 >= *maxlen)
+ {
+ void *temp = NULL;
+ size_t newmax;
+
+ newmax = (*maxlen ? (*maxlen)<<1 : 32);
+ if(newmax > *maxlen)
+ temp = realloc(*output, newmax);
+ if(!temp)
+ {
+ ERR("Failed to realloc "SZFMT" bytes from "SZFMT"!\n", newmax, *maxlen);
+ return 0;
+ }
+
+ *output = temp;
+ *maxlen = newmax;
+ }
+ (*output)[len++] = c;
+ (*output)[len] = '\0';
+ } while((c=fgetc(f)) != EOF && c != '\r' && c != '\n');
+
+ return 1;
+}
+
+
+/* Custom strtok_r, since we can't rely on it existing. */
+static char *my_strtok_r(char *str, const char *delim, char **saveptr)
+{
+ /* Sanity check and update internal pointer. */
+ if(!saveptr || !delim) return NULL;
+ if(str) *saveptr = str;
+ str = *saveptr;
+
+ /* Nothing more to do with this string. */
+ if(!str) return NULL;
+
+ /* Find the first non-delimiter character. */
+ while(*str != '\0' && strchr(delim, *str) != NULL)
+ str++;
+ if(*str == '\0')
+ {
+ /* End of string. */
+ *saveptr = NULL;
+ return NULL;
+ }
+
+ /* Find the next delimiter character. */
+ *saveptr = strpbrk(str, delim);
+ if(*saveptr) *((*saveptr)++) = '\0';
+
+ return str;
+}
+
+static char *read_int(ALint *num, const char *line, int base)
+{
+ char *end;
+ *num = strtol(line, &end, base);
+ if(end && *end != '\0')
+ end = lstrip(end);
+ return end;
+}
+
+static char *read_uint(ALuint *num, const char *line, int base)
+{
+ char *end;
+ *num = strtoul(line, &end, base);
+ if(end && *end != '\0')
+ end = lstrip(end);
+ return end;
+}
+
+static char *read_float(ALfloat *num, const char *line)
+{
+ char *end;
+#ifdef HAVE_STRTOF
+ *num = strtof(line, &end);
+#else
+ *num = (ALfloat)strtod(line, &end);
+#endif
+ if(end && *end != '\0')
+ end = lstrip(end);
+ return end;
+}
+
+
+char *read_clipped_line(FILE *f, char **buffer, size_t *maxlen)
+{
+ while(readline(f, buffer, maxlen))
+ {
+ char *line, *comment;
+
+ line = lstrip(*buffer);
+ comment = strchr(line, '#');
+ if(comment) *(comment++) = 0;
+
+ line = rstrip(line);
+ if(line[0]) return line;
+ }
+ return NULL;
+}
+
+static int load_ambdec_speakers(AmbDecConf *conf, FILE *f, char **buffer, size_t *maxlen, char **saveptr)
+{
+ ALsizei cur = 0;
+ while(cur < conf->NumSpeakers)
+ {
+ const char *cmd = my_strtok_r(NULL, " \t", saveptr);
+ if(!cmd)
+ {
+ char *line = read_clipped_line(f, buffer, maxlen);
+ if(!line)
+ {
+ ERR("Unexpected end of file\n");
+ return 0;
+ }
+ cmd = my_strtok_r(line, " \t", saveptr);
+ }
+
+ if(strcmp(cmd, "add_spkr") == 0)
+ {
+ const char *name = my_strtok_r(NULL, " \t", saveptr);
+ const char *dist = my_strtok_r(NULL, " \t", saveptr);
+ const char *az = my_strtok_r(NULL, " \t", saveptr);
+ const char *elev = my_strtok_r(NULL, " \t", saveptr);
+ const char *conn = my_strtok_r(NULL, " \t", saveptr);
+
+ if(!name) WARN("Name not specified for speaker %u\n", cur+1);
+ else alstr_copy_cstr(&conf->Speakers[cur].Name, name);
+ if(!dist) WARN("Distance not specified for speaker %u\n", cur+1);
+ else read_float(&conf->Speakers[cur].Distance, dist);
+ if(!az) WARN("Azimuth not specified for speaker %u\n", cur+1);
+ else read_float(&conf->Speakers[cur].Azimuth, az);
+ if(!elev) WARN("Elevation not specified for speaker %u\n", cur+1);
+ else read_float(&conf->Speakers[cur].Elevation, elev);
+ if(!conn) TRACE("Connection not specified for speaker %u\n", cur+1);
+ else alstr_copy_cstr(&conf->Speakers[cur].Connection, conn);
+
+ cur++;
+ }
+ else
+ {
+ ERR("Unexpected speakers command: %s\n", cmd);
+ return 0;
+ }
+
+ cmd = my_strtok_r(NULL, " \t", saveptr);
+ if(cmd)
+ {
+ ERR("Unexpected junk on line: %s\n", cmd);
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+static int load_ambdec_matrix(ALfloat *gains, ALfloat (*matrix)[MAX_AMBI_COEFFS], ALsizei maxrow, FILE *f, char **buffer, size_t *maxlen, char **saveptr)
+{
+ int gotgains = 0;
+ ALsizei cur = 0;
+ while(cur < maxrow)
+ {
+ const char *cmd = my_strtok_r(NULL, " \t", saveptr);
+ if(!cmd)
+ {
+ char *line = read_clipped_line(f, buffer, maxlen);
+ if(!line)
+ {
+ ERR("Unexpected end of file\n");
+ return 0;
+ }
+ cmd = my_strtok_r(line, " \t", saveptr);
+ }
+
+ if(strcmp(cmd, "order_gain") == 0)
+ {
+ ALuint curgain = 0;
+ char *line;
+ while((line=my_strtok_r(NULL, " \t", saveptr)) != NULL)
+ {
+ ALfloat value;
+ line = read_float(&value, line);
+ if(line && *line != '\0')
+ {
+ ERR("Extra junk on gain %u: %s\n", curgain+1, line);
+ return 0;
+ }
+ if(curgain < MAX_AMBI_ORDER+1)
+ gains[curgain] = value;
+ curgain++;
+ }
+ while(curgain < MAX_AMBI_ORDER+1)
+ gains[curgain++] = 0.0f;
+ gotgains = 1;
+ }
+ else if(strcmp(cmd, "add_row") == 0)
+ {
+ ALuint curidx = 0;
+ char *line;
+ while((line=my_strtok_r(NULL, " \t", saveptr)) != NULL)
+ {
+ ALfloat value;
+ line = read_float(&value, line);
+ if(line && *line != '\0')
+ {
+ ERR("Extra junk on matrix element %ux%u: %s\n", cur, curidx, line);
+ return 0;
+ }
+ if(curidx < MAX_AMBI_COEFFS)
+ matrix[cur][curidx] = value;
+ curidx++;
+ }
+ while(curidx < MAX_AMBI_COEFFS)
+ matrix[cur][curidx++] = 0.0f;
+ cur++;
+ }
+ else
+ {
+ ERR("Unexpected speakers command: %s\n", cmd);
+ return 0;
+ }
+
+ cmd = my_strtok_r(NULL, " \t", saveptr);
+ if(cmd)
+ {
+ ERR("Unexpected junk on line: %s\n", cmd);
+ return 0;
+ }
+ }
+
+ if(!gotgains)
+ {
+ ERR("Matrix order_gain not specified\n");
+ return 0;
+ }
+
+ return 1;
+}
+
+void ambdec_init(AmbDecConf *conf)
+{
+ ALsizei i;
+
+ memset(conf, 0, sizeof(*conf));
+ AL_STRING_INIT(conf->Description);
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ {
+ AL_STRING_INIT(conf->Speakers[i].Name);
+ AL_STRING_INIT(conf->Speakers[i].Connection);
+ }
+}
+
+void ambdec_deinit(AmbDecConf *conf)
+{
+ ALsizei i;
+
+ alstr_reset(&conf->Description);
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ {
+ alstr_reset(&conf->Speakers[i].Name);
+ alstr_reset(&conf->Speakers[i].Connection);
+ }
+ memset(conf, 0, sizeof(*conf));
+}
+
+int ambdec_load(AmbDecConf *conf, const char *fname)
+{
+ char *buffer = NULL;
+ size_t maxlen = 0;
+ char *line;
+ FILE *f;
+
+ f = al_fopen(fname, "r");
+ if(!f)
+ {
+ ERR("Failed to open: %s\n", fname);
+ return 0;
+ }
+
+ while((line=read_clipped_line(f, &buffer, &maxlen)) != NULL)
+ {
+ char *saveptr;
+ char *command;
+
+ command = my_strtok_r(line, "/ \t", &saveptr);
+ if(!command)
+ {
+ ERR("Malformed line: %s\n", line);
+ goto fail;
+ }
+
+ if(strcmp(command, "description") == 0)
+ {
+ char *value = my_strtok_r(NULL, "", &saveptr);
+ alstr_copy_cstr(&conf->Description, lstrip(value));
+ }
+ else if(strcmp(command, "version") == 0)
+ {
+ line = my_strtok_r(NULL, "", &saveptr);
+ line = read_uint(&conf->Version, line, 10);
+ if(line && *line != '\0')
+ {
+ ERR("Extra junk after version: %s\n", line);
+ goto fail;
+ }
+ if(conf->Version != 3)
+ {
+ ERR("Unsupported version: %u\n", conf->Version);
+ goto fail;
+ }
+ }
+ else if(strcmp(command, "dec") == 0)
+ {
+ const char *dec = my_strtok_r(NULL, "/ \t", &saveptr);
+ if(strcmp(dec, "chan_mask") == 0)
+ {
+ line = my_strtok_r(NULL, "", &saveptr);
+ line = read_uint(&conf->ChanMask, line, 16);
+ if(line && *line != '\0')
+ {
+ ERR("Extra junk after mask: %s\n", line);
+ goto fail;
+ }
+ }
+ else if(strcmp(dec, "freq_bands") == 0)
+ {
+ line = my_strtok_r(NULL, "", &saveptr);
+ line = read_uint(&conf->FreqBands, line, 10);
+ if(line && *line != '\0')
+ {
+ ERR("Extra junk after freq_bands: %s\n", line);
+ goto fail;
+ }
+ if(conf->FreqBands != 1 && conf->FreqBands != 2)
+ {
+ ERR("Invalid freq_bands value: %u\n", conf->FreqBands);
+ goto fail;
+ }
+ }
+ else if(strcmp(dec, "speakers") == 0)
+ {
+ line = my_strtok_r(NULL, "", &saveptr);
+ line = read_int(&conf->NumSpeakers, line, 10);
+ if(line && *line != '\0')
+ {
+ ERR("Extra junk after speakers: %s\n", line);
+ goto fail;
+ }
+ if(conf->NumSpeakers > MAX_OUTPUT_CHANNELS)
+ {
+ ERR("Unsupported speaker count: %u\n", conf->NumSpeakers);
+ goto fail;
+ }
+ }
+ else if(strcmp(dec, "coeff_scale") == 0)
+ {
+ line = my_strtok_r(NULL, " \t", &saveptr);
+ if(strcmp(line, "n3d") == 0)
+ conf->CoeffScale = ADS_N3D;
+ else if(strcmp(line, "sn3d") == 0)
+ conf->CoeffScale = ADS_SN3D;
+ else if(strcmp(line, "fuma") == 0)
+ conf->CoeffScale = ADS_FuMa;
+ else
+ {
+ ERR("Unsupported coeff scale: %s\n", line);
+ goto fail;
+ }
+ }
+ else
+ {
+ ERR("Unexpected /dec option: %s\n", dec);
+ goto fail;
+ }
+ }
+ else if(strcmp(command, "opt") == 0)
+ {
+ const char *opt = my_strtok_r(NULL, "/ \t", &saveptr);
+ if(strcmp(opt, "xover_freq") == 0)
+ {
+ line = my_strtok_r(NULL, "", &saveptr);
+ line = read_float(&conf->XOverFreq, line);
+ if(line && *line != '\0')
+ {
+ ERR("Extra junk after xover_freq: %s\n", line);
+ goto fail;
+ }
+ }
+ else if(strcmp(opt, "xover_ratio") == 0)
+ {
+ line = my_strtok_r(NULL, "", &saveptr);
+ line = read_float(&conf->XOverRatio, line);
+ if(line && *line != '\0')
+ {
+ ERR("Extra junk after xover_ratio: %s\n", line);
+ goto fail;
+ }
+ }
+ else if(strcmp(opt, "input_scale") == 0 || strcmp(opt, "nfeff_comp") == 0 ||
+ strcmp(opt, "delay_comp") == 0 || strcmp(opt, "level_comp") == 0)
+ {
+ /* Unused */
+ my_strtok_r(NULL, " \t", &saveptr);
+ }
+ else
+ {
+ ERR("Unexpected /opt option: %s\n", opt);
+ goto fail;
+ }
+ }
+ else if(strcmp(command, "speakers") == 0)
+ {
+ const char *value = my_strtok_r(NULL, "/ \t", &saveptr);
+ if(strcmp(value, "{") != 0)
+ {
+ ERR("Expected { after %s command, got %s\n", command, value);
+ goto fail;
+ }
+ if(!load_ambdec_speakers(conf, f, &buffer, &maxlen, &saveptr))
+ goto fail;
+ value = my_strtok_r(NULL, "/ \t", &saveptr);
+ if(!value)
+ {
+ line = read_clipped_line(f, &buffer, &maxlen);
+ if(!line)
+ {
+ ERR("Unexpected end of file\n");
+ goto fail;
+ }
+ value = my_strtok_r(line, "/ \t", &saveptr);
+ }
+ if(strcmp(value, "}") != 0)
+ {
+ ERR("Expected } after speaker definitions, got %s\n", value);
+ goto fail;
+ }
+ }
+ else if(strcmp(command, "lfmatrix") == 0 || strcmp(command, "hfmatrix") == 0 ||
+ strcmp(command, "matrix") == 0)
+ {
+ const char *value = my_strtok_r(NULL, "/ \t", &saveptr);
+ if(strcmp(value, "{") != 0)
+ {
+ ERR("Expected { after %s command, got %s\n", command, value);
+ goto fail;
+ }
+ if(conf->FreqBands == 1)
+ {
+ if(strcmp(command, "matrix") != 0)
+ {
+ ERR("Unexpected \"%s\" type for a single-band decoder\n", command);
+ goto fail;
+ }
+ if(!load_ambdec_matrix(conf->HFOrderGain, conf->HFMatrix, conf->NumSpeakers,
+ f, &buffer, &maxlen, &saveptr))
+ goto fail;
+ }
+ else
+ {
+ if(strcmp(command, "lfmatrix") == 0)
+ {
+ if(!load_ambdec_matrix(conf->LFOrderGain, conf->LFMatrix, conf->NumSpeakers,
+ f, &buffer, &maxlen, &saveptr))
+ goto fail;
+ }
+ else if(strcmp(command, "hfmatrix") == 0)
+ {
+ if(!load_ambdec_matrix(conf->HFOrderGain, conf->HFMatrix, conf->NumSpeakers,
+ f, &buffer, &maxlen, &saveptr))
+ goto fail;
+ }
+ else
+ {
+ ERR("Unexpected \"%s\" type for a dual-band decoder\n", command);
+ goto fail;
+ }
+ }
+ value = my_strtok_r(NULL, "/ \t", &saveptr);
+ if(!value)
+ {
+ line = read_clipped_line(f, &buffer, &maxlen);
+ if(!line)
+ {
+ ERR("Unexpected end of file\n");
+ goto fail;
+ }
+ value = my_strtok_r(line, "/ \t", &saveptr);
+ }
+ if(strcmp(value, "}") != 0)
+ {
+ ERR("Expected } after matrix definitions, got %s\n", value);
+ goto fail;
+ }
+ }
+ else if(strcmp(command, "end") == 0)
+ {
+ line = my_strtok_r(NULL, "/ \t", &saveptr);
+ if(line)
+ {
+ ERR("Unexpected junk on end: %s\n", line);
+ goto fail;
+ }
+
+ fclose(f);
+ free(buffer);
+ return 1;
+ }
+ else
+ {
+ ERR("Unexpected command: %s\n", command);
+ goto fail;
+ }
+
+ line = my_strtok_r(NULL, "/ \t", &saveptr);
+ if(line)
+ {
+ ERR("Unexpected junk on line: %s\n", line);
+ goto fail;
+ }
+ }
+ ERR("Unexpected end of file\n");
+
+fail:
+ fclose(f);
+ free(buffer);
+ return 0;
+}
diff --git a/Alc/ambdec.h b/Alc/ambdec.h
new file mode 100644
index 00000000..0bb84072
--- /dev/null
+++ b/Alc/ambdec.h
@@ -0,0 +1,46 @@
+#ifndef AMBDEC_H
+#define AMBDEC_H
+
+#include "alstring.h"
+#include "alMain.h"
+
+/* Helpers to read .ambdec configuration files. */
+
+enum AmbDecScaleType {
+ ADS_N3D,
+ ADS_SN3D,
+ ADS_FuMa,
+};
+typedef struct AmbDecConf {
+ al_string Description;
+ ALuint Version; /* Must be 3 */
+
+ ALuint ChanMask;
+ ALuint FreqBands; /* Must be 1 or 2 */
+ ALsizei NumSpeakers;
+ enum AmbDecScaleType CoeffScale;
+
+ ALfloat XOverFreq;
+ ALfloat XOverRatio;
+
+ struct {
+ al_string Name;
+ ALfloat Distance;
+ ALfloat Azimuth;
+ ALfloat Elevation;
+ al_string Connection;
+ } Speakers[MAX_OUTPUT_CHANNELS];
+
+ /* Unused when FreqBands == 1 */
+ ALfloat LFOrderGain[MAX_AMBI_ORDER+1];
+ ALfloat LFMatrix[MAX_OUTPUT_CHANNELS][MAX_AMBI_COEFFS];
+
+ ALfloat HFOrderGain[MAX_AMBI_ORDER+1];
+ ALfloat HFMatrix[MAX_OUTPUT_CHANNELS][MAX_AMBI_COEFFS];
+} AmbDecConf;
+
+void ambdec_init(AmbDecConf *conf);
+void ambdec_deinit(AmbDecConf *conf);
+int ambdec_load(AmbDecConf *conf, const char *fname);
+
+#endif /* AMBDEC_H */
diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c
index 9a443c09..a967fff0 100644
--- a/Alc/backends/alsa.c
+++ b/Alc/backends/alsa.c
@@ -26,6 +26,8 @@
#include "alMain.h"
#include "alu.h"
+#include "alconfig.h"
+#include "ringbuffer.h"
#include "threads.h"
#include "compat.h"
@@ -199,15 +201,21 @@ static ALCboolean alsa_load(void)
#ifdef HAVE_DYNLOAD
if(!alsa_handle)
{
+ al_string missing_funcs = AL_STRING_INIT_STATIC();
+
alsa_handle = LoadLib("libasound.so.2");
if(!alsa_handle)
+ {
+ WARN("Failed to load %s\n", "libasound.so.2");
return ALC_FALSE;
+ }
error = ALC_FALSE;
#define LOAD_FUNC(f) do { \
p##f = GetSymbol(alsa_handle, #f); \
if(p##f == NULL) { \
error = ALC_TRUE; \
+ alstr_append_cstr(&missing_funcs, "\n" #f); \
} \
} while(0)
ALSA_FUNCS(LOAD_FUNC);
@@ -215,10 +223,11 @@ static ALCboolean alsa_load(void)
if(error)
{
+ WARN("Missing expected functions:%s\n", alstr_get_cstr(missing_funcs));
CloseLib(alsa_handle);
alsa_handle = NULL;
- return ALC_FALSE;
}
+ alstr_reset(&missing_funcs);
}
#endif
@@ -237,16 +246,13 @@ static vector_DevMap CaptureDevices;
static void clear_devlist(vector_DevMap *devlist)
{
- DevMap *iter, *end;
-
- iter = VECTOR_ITER_BEGIN(*devlist);
- end = VECTOR_ITER_END(*devlist);
- for(;iter != end;iter++)
- {
- AL_STRING_DEINIT(iter->name);
- AL_STRING_DEINIT(iter->device_name);
- }
- VECTOR_RESIZE(*devlist, 0);
+#define FREE_DEV(i) do { \
+ AL_STRING_DEINIT((i)->name); \
+ AL_STRING_DEINIT((i)->device_name); \
+} while(0)
+ VECTOR_FOR_EACH(DevMap, *devlist, FREE_DEV);
+ VECTOR_RESIZE(*devlist, 0, 0);
+#undef FREE_DEV
}
@@ -272,11 +278,45 @@ static void probe_devices(snd_pcm_stream_t stream, vector_DevMap *DeviceList)
AL_STRING_INIT(entry.name);
AL_STRING_INIT(entry.device_name);
- al_string_copy_cstr(&entry.name, alsaDevice);
- al_string_copy_cstr(&entry.device_name, GetConfigValue(NULL, "alsa", (stream==SND_PCM_STREAM_PLAYBACK) ?
- "device" : "capture", "default"));
+ alstr_copy_cstr(&entry.name, alsaDevice);
+ alstr_copy_cstr(&entry.device_name, GetConfigValue(
+ NULL, "alsa", (stream==SND_PCM_STREAM_PLAYBACK) ? "device" : "capture", "default"
+ ));
VECTOR_PUSH_BACK(*DeviceList, entry);
+ if(stream == SND_PCM_STREAM_PLAYBACK)
+ {
+ const char *customdevs, *sep, *next;
+ next = GetConfigValue(NULL, "alsa", "custom-devices", "");
+ while((customdevs=next) != NULL && customdevs[0])
+ {
+ next = strchr(customdevs, ';');
+ sep = strchr(customdevs, '=');
+ if(!sep)
+ {
+ al_string spec = AL_STRING_INIT_STATIC();
+ if(next)
+ alstr_copy_range(&spec, customdevs, next++);
+ else
+ alstr_copy_cstr(&spec, customdevs);
+ ERR("Invalid ALSA device specification \"%s\"\n", alstr_get_cstr(spec));
+ alstr_reset(&spec);
+ continue;
+ }
+
+ AL_STRING_INIT(entry.name);
+ AL_STRING_INIT(entry.device_name);
+ alstr_copy_range(&entry.name, customdevs, sep++);
+ if(next)
+ alstr_copy_range(&entry.device_name, sep, next++);
+ else
+ alstr_copy_cstr(&entry.device_name, sep);
+ TRACE("Got device \"%s\", \"%s\"\n", alstr_get_cstr(entry.name),
+ alstr_get_cstr(entry.device_name));
+ VECTOR_PUSH_BACK(*DeviceList, entry);
+ }
+ }
+
card = -1;
if((err=snd_card_next(&card)) < 0)
ERR("Failed to find a card: %s\n", snd_strerror(err));
@@ -321,7 +361,8 @@ static void probe_devices(snd_pcm_stream_t stream, vector_DevMap *DeviceList)
snd_pcm_info_set_device(pcminfo, dev);
snd_pcm_info_set_subdevice(pcminfo, 0);
snd_pcm_info_set_stream(pcminfo, stream);
- if((err = snd_ctl_pcm_info(handle, pcminfo)) < 0) {
+ if((err = snd_ctl_pcm_info(handle, pcminfo)) < 0)
+ {
if(err != -ENOENT)
ERR("control digital audio info (hw:%d): %s\n", card, snd_strerror(err));
continue;
@@ -333,15 +374,15 @@ static void probe_devices(snd_pcm_stream_t stream, vector_DevMap *DeviceList)
ConfigValueStr(NULL, "alsa", name, &device_prefix);
snprintf(name, sizeof(name), "%s, %s (CARD=%s,DEV=%d)",
- cardname, devname, cardid, dev);
+ cardname, devname, cardid, dev);
snprintf(device, sizeof(device), "%sCARD=%s,DEV=%d",
- device_prefix, cardid, dev);
+ device_prefix, cardid, dev);
TRACE("Got device \"%s\", \"%s\"\n", name, device);
AL_STRING_INIT(entry.name);
AL_STRING_INIT(entry.device_name);
- al_string_copy_cstr(&entry.name, name);
- al_string_copy_cstr(&entry.device_name, device);
+ alstr_copy_cstr(&entry.name, name);
+ alstr_copy_cstr(&entry.device_name, device);
VECTOR_PUSH_BACK(*DeviceList, entry);
}
snd_ctl_close(handle);
@@ -397,7 +438,7 @@ typedef struct ALCplaybackAlsa {
ALvoid *buffer;
ALsizei size;
- volatile int killNow;
+ ATOMIC(ALenum) killNow;
althrd_t thread;
} ALCplaybackAlsa;
@@ -405,15 +446,14 @@ static int ALCplaybackAlsa_mixerProc(void *ptr);
static int ALCplaybackAlsa_mixerNoMMapProc(void *ptr);
static void ALCplaybackAlsa_Construct(ALCplaybackAlsa *self, ALCdevice *device);
-static DECLARE_FORWARD(ALCplaybackAlsa, ALCbackend, void, Destruct)
+static void ALCplaybackAlsa_Destruct(ALCplaybackAlsa *self);
static ALCenum ALCplaybackAlsa_open(ALCplaybackAlsa *self, const ALCchar *name);
-static void ALCplaybackAlsa_close(ALCplaybackAlsa *self);
static ALCboolean ALCplaybackAlsa_reset(ALCplaybackAlsa *self);
static ALCboolean ALCplaybackAlsa_start(ALCplaybackAlsa *self);
static void ALCplaybackAlsa_stop(ALCplaybackAlsa *self);
static DECLARE_FORWARD2(ALCplaybackAlsa, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
static DECLARE_FORWARD(ALCplaybackAlsa, ALCbackend, ALCuint, availableSamples)
-static ALint64 ALCplaybackAlsa_getLatency(ALCplaybackAlsa *self);
+static ClockLatency ALCplaybackAlsa_getClockLatency(ALCplaybackAlsa *self);
static DECLARE_FORWARD(ALCplaybackAlsa, ALCbackend, void, lock)
static DECLARE_FORWARD(ALCplaybackAlsa, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCplaybackAlsa)
@@ -425,6 +465,19 @@ static void ALCplaybackAlsa_Construct(ALCplaybackAlsa *self, ALCdevice *device)
{
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCplaybackAlsa, ALCbackend, self);
+
+ self->pcmHandle = NULL;
+ self->buffer = NULL;
+
+ ATOMIC_INIT(&self->killNow, AL_TRUE);
+}
+
+void ALCplaybackAlsa_Destruct(ALCplaybackAlsa *self)
+{
+ if(self->pcmHandle)
+ snd_pcm_close(self->pcmHandle);
+ self->pcmHandle = NULL;
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}
@@ -444,14 +497,14 @@ static int ALCplaybackAlsa_mixerProc(void *ptr)
update_size = device->UpdateSize;
num_updates = device->NumUpdates;
- while(!self->killNow)
+ while(!ATOMIC_LOAD(&self->killNow, almemory_order_acquire))
{
int state = verify_state(self->pcmHandle);
if(state < 0)
{
ERR("Invalid state detected: %s\n", snd_strerror(state));
ALCplaybackAlsa_lock(self);
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Bad state: %s", snd_strerror(state));
ALCplaybackAlsa_unlock(self);
break;
}
@@ -534,14 +587,14 @@ static int ALCplaybackAlsa_mixerNoMMapProc(void *ptr)
update_size = device->UpdateSize;
num_updates = device->NumUpdates;
- while(!self->killNow)
+ while(!ATOMIC_LOAD(&self->killNow, almemory_order_acquire))
{
int state = verify_state(self->pcmHandle);
if(state < 0)
{
ERR("Invalid state detected: %s\n", snd_strerror(state));
ALCplaybackAlsa_lock(self);
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Bad state: %s", snd_strerror(state));
ALCplaybackAlsa_unlock(self);
break;
}
@@ -588,7 +641,9 @@ static int ALCplaybackAlsa_mixerNoMMapProc(void *ptr)
{
case -EAGAIN:
continue;
+#if ESTRPIPE != EPIPE
case -ESTRPIPE:
+#endif
case -EPIPE:
case -EINTR:
ret = snd_pcm_recover(self->pcmHandle, ret, 1);
@@ -630,12 +685,12 @@ static ALCenum ALCplaybackAlsa_open(ALCplaybackAlsa *self, const ALCchar *name)
if(VECTOR_SIZE(PlaybackDevices) == 0)
probe_devices(SND_PCM_STREAM_PLAYBACK, &PlaybackDevices);
-#define MATCH_NAME(i) (al_string_cmp_cstr((i)->name, name) == 0)
+#define MATCH_NAME(i) (alstr_cmp_cstr((i)->name, name) == 0)
VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_NAME);
#undef MATCH_NAME
- if(iter == VECTOR_ITER_END(PlaybackDevices))
+ if(iter == VECTOR_END(PlaybackDevices))
return ALC_INVALID_VALUE;
- driver = al_string_get_cstr(iter->device_name);
+ driver = alstr_get_cstr(iter->device_name);
}
else
{
@@ -654,16 +709,11 @@ static ALCenum ALCplaybackAlsa_open(ALCplaybackAlsa *self, const ALCchar *name)
/* Free alsa's global config tree. Otherwise valgrind reports a ton of leaks. */
snd_config_update_free_global();
- al_string_copy_cstr(&device->DeviceName, name);
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
}
-static void ALCplaybackAlsa_close(ALCplaybackAlsa *self)
-{
- snd_pcm_close(self->pcmHandle);
-}
-
static ALCboolean ALCplaybackAlsa_reset(ALCplaybackAlsa *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
@@ -677,6 +727,7 @@ static ALCboolean ALCplaybackAlsa_reset(ALCplaybackAlsa *self)
unsigned int rate;
const char *funcerr;
int allowmmap;
+ int dir;
int err;
switch(device->FmtType)
@@ -704,7 +755,7 @@ static ALCboolean ALCplaybackAlsa_reset(ALCplaybackAlsa *self)
break;
}
- allowmmap = GetConfigValueBool(al_string_get_cstr(device->DeviceName), "alsa", "mmap", 1);
+ allowmmap = GetConfigValueBool(alstr_get_cstr(device->DeviceName), "alsa", "mmap", 1);
periods = device->NumUpdates;
periodLen = (ALuint64)device->UpdateSize * 1000000 / device->Frequency;
bufferLen = periodLen * periods;
@@ -748,7 +799,7 @@ static ALCboolean ALCplaybackAlsa_reset(ALCplaybackAlsa *self)
}
CHECK(snd_pcm_hw_params_set_format(self->pcmHandle, hp, format));
/* test and set channels (implicitly sets frame bits) */
- if(snd_pcm_hw_params_test_channels(self->pcmHandle, hp, ChannelsFromDevFmt(device->FmtChans)) < 0)
+ if(snd_pcm_hw_params_test_channels(self->pcmHandle, hp, ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder)) < 0)
{
static const enum DevFmtChannels channellist[] = {
DevFmtStereo,
@@ -761,20 +812,24 @@ static ALCboolean ALCplaybackAlsa_reset(ALCplaybackAlsa *self)
for(k = 0;k < COUNTOF(channellist);k++)
{
- if(snd_pcm_hw_params_test_channels(self->pcmHandle, hp, ChannelsFromDevFmt(channellist[k])) >= 0)
+ if(snd_pcm_hw_params_test_channels(self->pcmHandle, hp, ChannelsFromDevFmt(channellist[k], 0)) >= 0)
{
device->FmtChans = channellist[k];
+ device->AmbiOrder = 0;
break;
}
}
}
- CHECK(snd_pcm_hw_params_set_channels(self->pcmHandle, hp, ChannelsFromDevFmt(device->FmtChans)));
+ CHECK(snd_pcm_hw_params_set_channels(self->pcmHandle, hp, ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder)));
/* set rate (implicitly constrains period/buffer parameters) */
- if(GetConfigValueBool(al_string_get_cstr(device->DeviceName), "alsa", "allow-resampler", 0))
+ if(!GetConfigValueBool(alstr_get_cstr(device->DeviceName), "alsa", "allow-resampler", 0) ||
+ !(device->Flags&DEVICE_FREQUENCY_REQUEST))
{
if(snd_pcm_hw_params_set_rate_resample(self->pcmHandle, hp, 0) < 0)
ERR("Failed to disable ALSA resampler\n");
}
+ else if(snd_pcm_hw_params_set_rate_resample(self->pcmHandle, hp, 1) < 0)
+ ERR("Failed to enable ALSA resampler\n");
CHECK(snd_pcm_hw_params_set_rate_near(self->pcmHandle, hp, &rate, NULL));
/* set buffer time (implicitly constrains period/buffer parameters) */
if((err=snd_pcm_hw_params_set_buffer_time_near(self->pcmHandle, hp, &bufferLen, NULL)) < 0)
@@ -787,7 +842,9 @@ static ALCboolean ALCplaybackAlsa_reset(ALCplaybackAlsa *self)
/* retrieve configuration info */
CHECK(snd_pcm_hw_params_get_access(hp, &access));
CHECK(snd_pcm_hw_params_get_period_size(hp, &periodSizeInFrames, NULL));
- CHECK(snd_pcm_hw_params_get_periods(hp, &periods, NULL));
+ CHECK(snd_pcm_hw_params_get_periods(hp, &periods, &dir));
+ if(dir != 0)
+ WARN("Inexact period count: %u (%d)\n", periods, dir);
snd_pcm_hw_params_free(hp);
hp = NULL;
@@ -837,7 +894,7 @@ static ALCboolean ALCplaybackAlsa_start(ALCplaybackAlsa *self)
self->size = snd_pcm_frames_to_bytes(self->pcmHandle, device->UpdateSize);
if(access == SND_PCM_ACCESS_RW_INTERLEAVED)
{
- self->buffer = malloc(self->size);
+ self->buffer = al_malloc(16, self->size);
if(!self->buffer)
{
ERR("buffer malloc failed\n");
@@ -855,11 +912,11 @@ static ALCboolean ALCplaybackAlsa_start(ALCplaybackAlsa *self)
}
thread_func = ALCplaybackAlsa_mixerProc;
}
- self->killNow = 0;
+ ATOMIC_STORE(&self->killNow, AL_FALSE, almemory_order_release);
if(althrd_create(&self->thread, thread_func, self) != althrd_success)
{
ERR("Could not create playback thread\n");
- free(self->buffer);
+ al_free(self->buffer);
self->buffer = NULL;
return ALC_FALSE;
}
@@ -876,28 +933,33 @@ static void ALCplaybackAlsa_stop(ALCplaybackAlsa *self)
{
int res;
- if(self->killNow)
+ if(ATOMIC_EXCHANGE(&self->killNow, AL_TRUE, almemory_order_acq_rel))
return;
-
- self->killNow = 1;
althrd_join(self->thread, &res);
- free(self->buffer);
+ al_free(self->buffer);
self->buffer = NULL;
}
-static ALint64 ALCplaybackAlsa_getLatency(ALCplaybackAlsa *self)
+static ClockLatency ALCplaybackAlsa_getClockLatency(ALCplaybackAlsa *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
snd_pcm_sframes_t delay = 0;
+ ClockLatency ret;
int err;
+ ALCplaybackAlsa_lock(self);
+ ret.ClockTime = GetDeviceClockTime(device);
if((err=snd_pcm_delay(self->pcmHandle, &delay)) < 0)
{
ERR("Failed to get pcm delay: %s\n", snd_strerror(err));
- return 0;
+ delay = 0;
}
- return maxi64((ALint64)delay*1000000000/device->Frequency, 0);
+ if(delay < 0) delay = 0;
+ ret.Latency = delay * DEVICE_CLOCK_RES / device->Frequency;
+ ALCplaybackAlsa_unlock(self);
+
+ return ret;
}
@@ -910,21 +972,20 @@ typedef struct ALCcaptureAlsa {
ALsizei size;
ALboolean doCapture;
- RingBuffer *ring;
+ ll_ringbuffer_t *ring;
snd_pcm_sframes_t last_avail;
} ALCcaptureAlsa;
static void ALCcaptureAlsa_Construct(ALCcaptureAlsa *self, ALCdevice *device);
-static DECLARE_FORWARD(ALCcaptureAlsa, ALCbackend, void, Destruct)
+static void ALCcaptureAlsa_Destruct(ALCcaptureAlsa *self);
static ALCenum ALCcaptureAlsa_open(ALCcaptureAlsa *self, const ALCchar *name);
-static void ALCcaptureAlsa_close(ALCcaptureAlsa *self);
static DECLARE_FORWARD(ALCcaptureAlsa, ALCbackend, ALCboolean, reset)
static ALCboolean ALCcaptureAlsa_start(ALCcaptureAlsa *self);
static void ALCcaptureAlsa_stop(ALCcaptureAlsa *self);
static ALCenum ALCcaptureAlsa_captureSamples(ALCcaptureAlsa *self, ALCvoid *buffer, ALCuint samples);
static ALCuint ALCcaptureAlsa_availableSamples(ALCcaptureAlsa *self);
-static ALint64 ALCcaptureAlsa_getLatency(ALCcaptureAlsa *self);
+static ClockLatency ALCcaptureAlsa_getClockLatency(ALCcaptureAlsa *self);
static DECLARE_FORWARD(ALCcaptureAlsa, ALCbackend, void, lock)
static DECLARE_FORWARD(ALCcaptureAlsa, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCcaptureAlsa)
@@ -936,6 +997,25 @@ static void ALCcaptureAlsa_Construct(ALCcaptureAlsa *self, ALCdevice *device)
{
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCcaptureAlsa, ALCbackend, self);
+
+ self->pcmHandle = NULL;
+ self->buffer = NULL;
+ self->ring = NULL;
+}
+
+void ALCcaptureAlsa_Destruct(ALCcaptureAlsa *self)
+{
+ if(self->pcmHandle)
+ snd_pcm_close(self->pcmHandle);
+ self->pcmHandle = NULL;
+
+ al_free(self->buffer);
+ self->buffer = NULL;
+
+ ll_ringbuffer_free(self->ring);
+ self->ring = NULL;
+
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}
@@ -958,12 +1038,12 @@ static ALCenum ALCcaptureAlsa_open(ALCcaptureAlsa *self, const ALCchar *name)
if(VECTOR_SIZE(CaptureDevices) == 0)
probe_devices(SND_PCM_STREAM_CAPTURE, &CaptureDevices);
-#define MATCH_NAME(i) (al_string_cmp_cstr((i)->name, name) == 0)
+#define MATCH_NAME(i) (alstr_cmp_cstr((i)->name, name) == 0)
VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_NAME);
#undef MATCH_NAME
- if(iter == VECTOR_ITER_END(CaptureDevices))
+ if(iter == VECTOR_END(CaptureDevices))
return ALC_INVALID_VALUE;
- driver = al_string_get_cstr(iter->device_name);
+ driver = alstr_get_cstr(iter->device_name);
}
else
{
@@ -1020,7 +1100,7 @@ static ALCenum ALCcaptureAlsa_open(ALCcaptureAlsa *self, const ALCchar *name)
/* set format (implicitly sets sample bits) */
CHECK(snd_pcm_hw_params_set_format(self->pcmHandle, hp, format));
/* set channels (implicitly sets frame bits) */
- CHECK(snd_pcm_hw_params_set_channels(self->pcmHandle, hp, ChannelsFromDevFmt(device->FmtChans)));
+ CHECK(snd_pcm_hw_params_set_channels(self->pcmHandle, hp, ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder)));
/* set rate (implicitly constrains period/buffer parameters) */
CHECK(snd_pcm_hw_params_set_rate(self->pcmHandle, hp, device->Frequency, 0));
/* set buffer size in frame units (implicitly sets period size/bytes/time and buffer time/bytes) */
@@ -1042,24 +1122,19 @@ static ALCenum ALCcaptureAlsa_open(ALCcaptureAlsa *self, const ALCchar *name)
if(needring)
{
- self->ring = CreateRingBuffer(FrameSizeFromDevFmt(device->FmtChans, device->FmtType),
- device->UpdateSize*device->NumUpdates);
+ self->ring = ll_ringbuffer_create(
+ device->UpdateSize*device->NumUpdates,
+ FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder),
+ false
+ );
if(!self->ring)
{
ERR("ring buffer create failed\n");
goto error2;
}
-
- self->size = snd_pcm_frames_to_bytes(self->pcmHandle, periodSizeInFrames);
- self->buffer = malloc(self->size);
- if(!self->buffer)
- {
- ERR("buffer malloc failed\n");
- goto error2;
- }
}
- al_string_copy_cstr(&device->DeviceName, name);
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
@@ -1068,31 +1143,29 @@ error:
if(hp) snd_pcm_hw_params_free(hp);
error2:
- free(self->buffer);
- self->buffer = NULL;
- DestroyRingBuffer(self->ring);
+ ll_ringbuffer_free(self->ring);
self->ring = NULL;
snd_pcm_close(self->pcmHandle);
+ self->pcmHandle = NULL;
return ALC_INVALID_VALUE;
}
-static void ALCcaptureAlsa_close(ALCcaptureAlsa *self)
-{
- snd_pcm_close(self->pcmHandle);
- DestroyRingBuffer(self->ring);
-
- free(self->buffer);
- self->buffer = NULL;
-}
-
static ALCboolean ALCcaptureAlsa_start(ALCcaptureAlsa *self)
{
- int err = snd_pcm_start(self->pcmHandle);
+ int err = snd_pcm_prepare(self->pcmHandle);
+ if(err < 0)
+ ERR("prepare failed: %s\n", snd_strerror(err));
+ else
+ {
+ err = snd_pcm_start(self->pcmHandle);
+ if(err < 0)
+ ERR("start failed: %s\n", snd_strerror(err));
+ }
if(err < 0)
{
- ERR("start failed: %s\n", snd_strerror(err));
- aluHandleDisconnect(STATIC_CAST(ALCbackend, self)->mDevice);
+ aluHandleDisconnect(STATIC_CAST(ALCbackend, self)->mDevice, "Capture state failure: %s",
+ snd_strerror(err));
return ALC_FALSE;
}
@@ -1117,11 +1190,11 @@ static void ALCcaptureAlsa_stop(ALCcaptureAlsa *self)
void *ptr;
size = snd_pcm_frames_to_bytes(self->pcmHandle, avail);
- ptr = malloc(size);
+ ptr = al_malloc(16, size);
if(ptr)
{
ALCcaptureAlsa_captureSamples(self, ptr, avail);
- free(self->buffer);
+ al_free(self->buffer);
self->buffer = ptr;
self->size = size;
}
@@ -1138,12 +1211,12 @@ static ALCenum ALCcaptureAlsa_captureSamples(ALCcaptureAlsa *self, ALCvoid *buff
if(self->ring)
{
- ReadRingBuffer(self->ring, buffer, samples);
+ ll_ringbuffer_read(self->ring, buffer, samples);
return ALC_NO_ERROR;
}
self->last_avail -= samples;
- while(device->Connected && samples > 0)
+ while(ATOMIC_LOAD(&device->Connected, almemory_order_acquire) && samples > 0)
{
snd_pcm_sframes_t amt = 0;
@@ -1163,7 +1236,7 @@ static ALCenum ALCcaptureAlsa_captureSamples(ALCcaptureAlsa *self, ALCvoid *buff
}
else
{
- free(self->buffer);
+ al_free(self->buffer);
self->buffer = NULL;
self->size = 0;
}
@@ -1186,7 +1259,7 @@ static ALCenum ALCcaptureAlsa_captureSamples(ALCcaptureAlsa *self, ALCvoid *buff
if(amt < 0)
{
ERR("restore error: %s\n", snd_strerror(amt));
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Capture recovery failure: %s", snd_strerror(amt));
break;
}
/* If the amount available is less than what's asked, we lost it
@@ -1211,7 +1284,7 @@ static ALCuint ALCcaptureAlsa_availableSamples(ALCcaptureAlsa *self)
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
snd_pcm_sframes_t avail = 0;
- if(device->Connected && self->doCapture)
+ if(ATOMIC_LOAD(&device->Connected, almemory_order_acquire) && self->doCapture)
avail = snd_pcm_avail_update(self->pcmHandle);
if(avail < 0)
{
@@ -1227,7 +1300,7 @@ static ALCuint ALCcaptureAlsa_availableSamples(ALCcaptureAlsa *self)
if(avail < 0)
{
ERR("restore error: %s\n", snd_strerror(avail));
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Capture recovery failure: %s", snd_strerror(avail));
}
}
@@ -1241,12 +1314,15 @@ static ALCuint ALCcaptureAlsa_availableSamples(ALCcaptureAlsa *self)
while(avail > 0)
{
+ ll_ringbuffer_data_t vec[2];
snd_pcm_sframes_t amt;
- amt = snd_pcm_bytes_to_frames(self->pcmHandle, self->size);
- if(avail < amt) amt = avail;
+ ll_ringbuffer_get_write_vector(self->ring, vec);
+ if(vec[0].len == 0) break;
- amt = snd_pcm_readi(self->pcmHandle, self->buffer, amt);
+ amt = (vec[0].len < (snd_pcm_uframes_t)avail) ?
+ vec[0].len : (snd_pcm_uframes_t)avail;
+ amt = snd_pcm_readi(self->pcmHandle, vec[0].buf, amt);
if(amt < 0)
{
ERR("read error: %s\n", snd_strerror(amt));
@@ -1263,39 +1339,41 @@ static ALCuint ALCcaptureAlsa_availableSamples(ALCcaptureAlsa *self)
if(amt < 0)
{
ERR("restore error: %s\n", snd_strerror(amt));
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Capture recovery failure: %s", snd_strerror(amt));
break;
}
avail = amt;
continue;
}
- WriteRingBuffer(self->ring, self->buffer, amt);
+ ll_ringbuffer_write_advance(self->ring, amt);
avail -= amt;
}
- return RingBufferSize(self->ring);
+ return ll_ringbuffer_read_space(self->ring);
}
-static ALint64 ALCcaptureAlsa_getLatency(ALCcaptureAlsa *self)
+static ClockLatency ALCcaptureAlsa_getClockLatency(ALCcaptureAlsa *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
snd_pcm_sframes_t delay = 0;
+ ClockLatency ret;
int err;
+ ALCcaptureAlsa_lock(self);
+ ret.ClockTime = GetDeviceClockTime(device);
if((err=snd_pcm_delay(self->pcmHandle, &delay)) < 0)
{
ERR("Failed to get pcm delay: %s\n", snd_strerror(err));
- return 0;
+ delay = 0;
}
- return maxi64((ALint64)delay*1000000000/device->Frequency, 0);
-}
+ if(delay < 0) delay = 0;
+ ret.Latency = delay * DEVICE_CLOCK_RES / device->Frequency;
+ ALCcaptureAlsa_unlock(self);
+ return ret;
+}
-static inline void AppendAllDevicesList2(const DevMap *entry)
-{ AppendAllDevicesList(al_string_get_cstr(entry->name)); }
-static inline void AppendCaptureDeviceList2(const DevMap *entry)
-{ AppendCaptureDeviceList(al_string_get_cstr(entry->name)); }
typedef struct ALCalsaBackendFactory {
DERIVE_FROM_TYPE(ALCbackendFactory);
@@ -1334,19 +1412,25 @@ static ALCboolean ALCalsaBackendFactory_querySupport(ALCalsaBackendFactory* UNUS
return ALC_FALSE;
}
-static void ALCalsaBackendFactory_probe(ALCalsaBackendFactory* UNUSED(self), enum DevProbe type)
+static void ALCalsaBackendFactory_probe(ALCalsaBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
switch(type)
{
+#define APPEND_OUTNAME(i) do { \
+ if(!alstr_empty((i)->name)) \
+ alstr_append_range(outnames, VECTOR_BEGIN((i)->name), \
+ VECTOR_END((i)->name)+1); \
+} while(0)
case ALL_DEVICE_PROBE:
probe_devices(SND_PCM_STREAM_PLAYBACK, &PlaybackDevices);
- VECTOR_FOR_EACH(const DevMap, PlaybackDevices, AppendAllDevicesList2);
+ VECTOR_FOR_EACH(const DevMap, PlaybackDevices, APPEND_OUTNAME);
break;
case CAPTURE_DEVICE_PROBE:
probe_devices(SND_PCM_STREAM_CAPTURE, &CaptureDevices);
- VECTOR_FOR_EACH(const DevMap, CaptureDevices, AppendCaptureDeviceList2);
+ VECTOR_FOR_EACH(const DevMap, CaptureDevices, APPEND_OUTNAME);
break;
+#undef APPEND_OUTNAME
}
}
diff --git a/Alc/backends/base.c b/Alc/backends/base.c
index ebeb31bf..9d8614b1 100644
--- a/Alc/backends/base.c
+++ b/Alc/backends/base.c
@@ -4,17 +4,22 @@
#include <stdlib.h>
#include "alMain.h"
+#include "alu.h"
#include "backends/base.h"
+extern inline ALuint64 GetDeviceClockTime(ALCdevice *device);
+extern inline void ALCdevice_Lock(ALCdevice *device);
+extern inline void ALCdevice_Unlock(ALCdevice *device);
+extern inline ClockLatency GetClockLatency(ALCdevice *device);
+
/* Base ALCbackend method implementations. */
void ALCbackend_Construct(ALCbackend *self, ALCdevice *device)
{
- int ret;
- self->mDevice = device;
- ret = almtx_init(&self->mMutex, almtx_recursive);
+ int ret = almtx_init(&self->mMutex, almtx_recursive);
assert(ret == althrd_success);
+ self->mDevice = device;
}
void ALCbackend_Destruct(ALCbackend *self)
@@ -37,9 +42,27 @@ ALCuint ALCbackend_availableSamples(ALCbackend* UNUSED(self))
return 0;
}
-ALint64 ALCbackend_getLatency(ALCbackend* UNUSED(self))
+ClockLatency ALCbackend_getClockLatency(ALCbackend *self)
{
- return 0;
+ ALCdevice *device = self->mDevice;
+ ALuint refcount;
+ ClockLatency ret;
+
+ do {
+ while(((refcount=ATOMIC_LOAD(&device->MixCount, almemory_order_acquire))&1))
+ althrd_yield();
+ ret.ClockTime = GetDeviceClockTime(device);
+ ATOMIC_THREAD_FENCE(almemory_order_acquire);
+ } while(refcount != ATOMIC_LOAD(&device->MixCount, almemory_order_relaxed));
+
+ /* NOTE: The device will generally have about all but one periods filled at
+ * any given time during playback. Without a more accurate measurement from
+ * the output, this is an okay approximation.
+ */
+ ret.Latency = device->UpdateSize * DEVICE_CLOCK_RES / device->Frequency *
+ maxu(device->NumUpdates-1, 1);
+
+ return ret;
}
void ALCbackend_lock(ALCbackend *self)
@@ -59,157 +82,3 @@ void ALCbackend_unlock(ALCbackend *self)
void ALCbackendFactory_deinit(ALCbackendFactory* UNUSED(self))
{
}
-
-
-/* Wrappers to use an old-style backend with the new interface. */
-typedef struct PlaybackWrapper {
- DERIVE_FROM_TYPE(ALCbackend);
-
- const BackendFuncs *Funcs;
-} PlaybackWrapper;
-
-static void PlaybackWrapper_Construct(PlaybackWrapper *self, ALCdevice *device, const BackendFuncs *funcs);
-static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, void, Destruct)
-static ALCenum PlaybackWrapper_open(PlaybackWrapper *self, const ALCchar *name);
-static void PlaybackWrapper_close(PlaybackWrapper *self);
-static ALCboolean PlaybackWrapper_reset(PlaybackWrapper *self);
-static ALCboolean PlaybackWrapper_start(PlaybackWrapper *self);
-static void PlaybackWrapper_stop(PlaybackWrapper *self);
-static DECLARE_FORWARD2(PlaybackWrapper, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
-static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, ALCuint, availableSamples)
-static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, ALint64, getLatency)
-static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, void, lock)
-static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, void, unlock)
-DECLARE_DEFAULT_ALLOCATORS(PlaybackWrapper)
-DEFINE_ALCBACKEND_VTABLE(PlaybackWrapper);
-
-static void PlaybackWrapper_Construct(PlaybackWrapper *self, ALCdevice *device, const BackendFuncs *funcs)
-{
- ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
- SET_VTABLE2(PlaybackWrapper, ALCbackend, self);
-
- self->Funcs = funcs;
-}
-
-static ALCenum PlaybackWrapper_open(PlaybackWrapper *self, const ALCchar *name)
-{
- ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- return self->Funcs->OpenPlayback(device, name);
-}
-
-static void PlaybackWrapper_close(PlaybackWrapper *self)
-{
- ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- self->Funcs->ClosePlayback(device);
-}
-
-static ALCboolean PlaybackWrapper_reset(PlaybackWrapper *self)
-{
- ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- return self->Funcs->ResetPlayback(device);
-}
-
-static ALCboolean PlaybackWrapper_start(PlaybackWrapper *self)
-{
- ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- return self->Funcs->StartPlayback(device);
-}
-
-static void PlaybackWrapper_stop(PlaybackWrapper *self)
-{
- ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- self->Funcs->StopPlayback(device);
-}
-
-
-typedef struct CaptureWrapper {
- DERIVE_FROM_TYPE(ALCbackend);
-
- const BackendFuncs *Funcs;
-} CaptureWrapper;
-
-static void CaptureWrapper_Construct(CaptureWrapper *self, ALCdevice *device, const BackendFuncs *funcs);
-static DECLARE_FORWARD(CaptureWrapper, ALCbackend, void, Destruct)
-static ALCenum CaptureWrapper_open(CaptureWrapper *self, const ALCchar *name);
-static void CaptureWrapper_close(CaptureWrapper *self);
-static DECLARE_FORWARD(CaptureWrapper, ALCbackend, ALCboolean, reset)
-static ALCboolean CaptureWrapper_start(CaptureWrapper *self);
-static void CaptureWrapper_stop(CaptureWrapper *self);
-static ALCenum CaptureWrapper_captureSamples(CaptureWrapper *self, void *buffer, ALCuint samples);
-static ALCuint CaptureWrapper_availableSamples(CaptureWrapper *self);
-static DECLARE_FORWARD(CaptureWrapper, ALCbackend, ALint64, getLatency)
-static DECLARE_FORWARD(CaptureWrapper, ALCbackend, void, lock)
-static DECLARE_FORWARD(CaptureWrapper, ALCbackend, void, unlock)
-DECLARE_DEFAULT_ALLOCATORS(CaptureWrapper)
-DEFINE_ALCBACKEND_VTABLE(CaptureWrapper);
-
-static void CaptureWrapper_Construct(CaptureWrapper *self, ALCdevice *device, const BackendFuncs *funcs)
-{
- ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
- SET_VTABLE2(CaptureWrapper, ALCbackend, self);
-
- self->Funcs = funcs;
-}
-
-static ALCenum CaptureWrapper_open(CaptureWrapper *self, const ALCchar *name)
-{
- ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- return self->Funcs->OpenCapture(device, name);
-}
-
-static void CaptureWrapper_close(CaptureWrapper *self)
-{
- ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- self->Funcs->CloseCapture(device);
-}
-
-static ALCboolean CaptureWrapper_start(CaptureWrapper *self)
-{
- ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- self->Funcs->StartCapture(device);
- return ALC_TRUE;
-}
-
-static void CaptureWrapper_stop(CaptureWrapper *self)
-{
- ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- self->Funcs->StopCapture(device);
-}
-
-static ALCenum CaptureWrapper_captureSamples(CaptureWrapper *self, void *buffer, ALCuint samples)
-{
- ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- return self->Funcs->CaptureSamples(device, buffer, samples);
-}
-
-static ALCuint CaptureWrapper_availableSamples(CaptureWrapper *self)
-{
- ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- return self->Funcs->AvailableSamples(device);
-}
-
-
-ALCbackend *create_backend_wrapper(ALCdevice *device, const BackendFuncs *funcs, ALCbackend_Type type)
-{
- if(type == ALCbackend_Playback)
- {
- PlaybackWrapper *backend;
-
- NEW_OBJ(backend, PlaybackWrapper)(device, funcs);
- if(!backend) return NULL;
-
- return STATIC_CAST(ALCbackend, backend);
- }
-
- if(type == ALCbackend_Capture)
- {
- CaptureWrapper *backend;
-
- NEW_OBJ(backend, CaptureWrapper)(device, funcs);
- if(!backend) return NULL;
-
- return STATIC_CAST(ALCbackend, backend);
- }
-
- return NULL;
-}
diff --git a/Alc/backends/base.h b/Alc/backends/base.h
index f6b4b80a..03db56e9 100644
--- a/Alc/backends/base.h
+++ b/Alc/backends/base.h
@@ -3,6 +3,26 @@
#include "alMain.h"
#include "threads.h"
+#include "alstring.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct ClockLatency {
+ ALint64 ClockTime;
+ ALint64 Latency;
+} ClockLatency;
+
+/* Helper to get the current clock time from the device's ClockBase, and
+ * SamplesDone converted from the sample rate.
+ */
+inline ALuint64 GetDeviceClockTime(ALCdevice *device)
+{
+ return device->ClockBase + (device->SamplesDone * DEVICE_CLOCK_RES /
+ device->Frequency);
+}
struct ALCbackendVtable;
@@ -20,7 +40,7 @@ void ALCbackend_Destruct(ALCbackend *self);
ALCboolean ALCbackend_reset(ALCbackend *self);
ALCenum ALCbackend_captureSamples(ALCbackend *self, void *buffer, ALCuint samples);
ALCuint ALCbackend_availableSamples(ALCbackend *self);
-ALint64 ALCbackend_getLatency(ALCbackend *self);
+ClockLatency ALCbackend_getClockLatency(ALCbackend *self);
void ALCbackend_lock(ALCbackend *self);
void ALCbackend_unlock(ALCbackend *self);
@@ -28,7 +48,6 @@ struct ALCbackendVtable {
void (*const Destruct)(ALCbackend*);
ALCenum (*const open)(ALCbackend*, const ALCchar*);
- void (*const close)(ALCbackend*);
ALCboolean (*const reset)(ALCbackend*);
ALCboolean (*const start)(ALCbackend*);
@@ -37,7 +56,7 @@ struct ALCbackendVtable {
ALCenum (*const captureSamples)(ALCbackend*, void*, ALCuint);
ALCuint (*const availableSamples)(ALCbackend*);
- ALint64 (*const getLatency)(ALCbackend*);
+ ClockLatency (*const getClockLatency)(ALCbackend*);
void (*const lock)(ALCbackend*);
void (*const unlock)(ALCbackend*);
@@ -48,13 +67,12 @@ struct ALCbackendVtable {
#define DEFINE_ALCBACKEND_VTABLE(T) \
DECLARE_THUNK(T, ALCbackend, void, Destruct) \
DECLARE_THUNK1(T, ALCbackend, ALCenum, open, const ALCchar*) \
-DECLARE_THUNK(T, ALCbackend, void, close) \
DECLARE_THUNK(T, ALCbackend, ALCboolean, reset) \
DECLARE_THUNK(T, ALCbackend, ALCboolean, start) \
DECLARE_THUNK(T, ALCbackend, void, stop) \
DECLARE_THUNK2(T, ALCbackend, ALCenum, captureSamples, void*, ALCuint) \
DECLARE_THUNK(T, ALCbackend, ALCuint, availableSamples) \
-DECLARE_THUNK(T, ALCbackend, ALint64, getLatency) \
+DECLARE_THUNK(T, ALCbackend, ClockLatency, getClockLatency) \
DECLARE_THUNK(T, ALCbackend, void, lock) \
DECLARE_THUNK(T, ALCbackend, void, unlock) \
static void T##_ALCbackend_Delete(void *ptr) \
@@ -64,13 +82,12 @@ static const struct ALCbackendVtable T##_ALCbackend_vtable = { \
T##_ALCbackend_Destruct, \
\
T##_ALCbackend_open, \
- T##_ALCbackend_close, \
T##_ALCbackend_reset, \
T##_ALCbackend_start, \
T##_ALCbackend_stop, \
T##_ALCbackend_captureSamples, \
T##_ALCbackend_availableSamples, \
- T##_ALCbackend_getLatency, \
+ T##_ALCbackend_getClockLatency, \
T##_ALCbackend_lock, \
T##_ALCbackend_unlock, \
\
@@ -99,7 +116,7 @@ struct ALCbackendFactoryVtable {
ALCboolean (*const querySupport)(ALCbackendFactory *self, ALCbackend_Type type);
- void (*const probe)(ALCbackendFactory *self, enum DevProbe type);
+ void (*const probe)(ALCbackendFactory *self, enum DevProbe type, al_string *outnames);
ALCbackend* (*const createBackend)(ALCbackendFactory *self, ALCdevice *device, ALCbackend_Type type);
};
@@ -108,7 +125,7 @@ struct ALCbackendFactoryVtable {
DECLARE_THUNK(T, ALCbackendFactory, ALCboolean, init) \
DECLARE_THUNK(T, ALCbackendFactory, void, deinit) \
DECLARE_THUNK1(T, ALCbackendFactory, ALCboolean, querySupport, ALCbackend_Type) \
-DECLARE_THUNK1(T, ALCbackendFactory, void, probe, enum DevProbe) \
+DECLARE_THUNK2(T, ALCbackendFactory, void, probe, enum DevProbe, al_string*) \
DECLARE_THUNK2(T, ALCbackendFactory, ALCbackend*, createBackend, ALCdevice*, ALCbackend_Type) \
\
static const struct ALCbackendFactoryVtable T##_ALCbackendFactory_vtable = { \
@@ -122,17 +139,40 @@ static const struct ALCbackendFactoryVtable T##_ALCbackendFactory_vtable = { \
ALCbackendFactory *ALCpulseBackendFactory_getFactory(void);
ALCbackendFactory *ALCalsaBackendFactory_getFactory(void);
+ALCbackendFactory *ALCcoreAudioBackendFactory_getFactory(void);
ALCbackendFactory *ALCossBackendFactory_getFactory(void);
ALCbackendFactory *ALCjackBackendFactory_getFactory(void);
ALCbackendFactory *ALCsolarisBackendFactory_getFactory(void);
-ALCbackendFactory *ALCmmdevBackendFactory_getFactory(void);
+ALCbackendFactory *SndioBackendFactory_getFactory(void);
+ALCbackendFactory *ALCqsaBackendFactory_getFactory(void);
+ALCbackendFactory *ALCwasapiBackendFactory_getFactory(void);
ALCbackendFactory *ALCdsoundBackendFactory_getFactory(void);
ALCbackendFactory *ALCwinmmBackendFactory_getFactory(void);
ALCbackendFactory *ALCportBackendFactory_getFactory(void);
+ALCbackendFactory *ALCopenslBackendFactory_getFactory(void);
ALCbackendFactory *ALCnullBackendFactory_getFactory(void);
ALCbackendFactory *ALCwaveBackendFactory_getFactory(void);
+ALCbackendFactory *ALCsdl2BackendFactory_getFactory(void);
ALCbackendFactory *ALCloopbackFactory_getFactory(void);
-ALCbackend *create_backend_wrapper(ALCdevice *device, const BackendFuncs *funcs, ALCbackend_Type type);
+
+inline void ALCdevice_Lock(ALCdevice *device)
+{ V0(device->Backend,lock)(); }
+
+inline void ALCdevice_Unlock(ALCdevice *device)
+{ V0(device->Backend,unlock)(); }
+
+
+inline ClockLatency GetClockLatency(ALCdevice *device)
+{
+ ClockLatency ret = V0(device->Backend,getClockLatency)();
+ ret.Latency += device->FixedLatency;
+ return ret;
+}
+
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
#endif /* AL_BACKENDS_BASE_H */
diff --git a/Alc/backends/coreaudio.c b/Alc/backends/coreaudio.c
index 43e881da..adb01fa6 100644
--- a/Alc/backends/coreaudio.c
+++ b/Alc/backends/coreaudio.c
@@ -23,195 +23,145 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <alloca.h>
#include "alMain.h"
#include "alu.h"
+#include "ringbuffer.h"
-#include <CoreServices/CoreServices.h>
#include <unistd.h>
#include <AudioUnit/AudioUnit.h>
#include <AudioToolbox/AudioToolbox.h>
+#include "backends/base.h"
-typedef struct {
- AudioUnit audioUnit;
-
- ALuint frameSize;
- ALdouble sampleRateRatio; // Ratio of hardware sample rate / requested sample rate
- AudioStreamBasicDescription format; // This is the OpenAL format as a CoreAudio ASBD
- AudioConverterRef audioConverter; // Sample rate converter if needed
- AudioBufferList *bufferList; // Buffer for data coming from the input device
- ALCvoid *resampleBuffer; // Buffer for returned RingBuffer data when resampling
+static const ALCchar ca_device[] = "CoreAudio Default";
- RingBuffer *ring;
-} ca_data;
-static const ALCchar ca_device[] = "CoreAudio Default";
+typedef struct ALCcoreAudioPlayback {
+ DERIVE_FROM_TYPE(ALCbackend);
+ AudioUnit audioUnit;
-static void destroy_buffer_list(AudioBufferList* list)
-{
- if(list)
- {
- UInt32 i;
- for(i = 0;i < list->mNumberBuffers;i++)
- free(list->mBuffers[i].mData);
- free(list);
- }
-}
+ ALuint frameSize;
+ AudioStreamBasicDescription format; // This is the OpenAL format as a CoreAudio ASBD
+} ALCcoreAudioPlayback;
-static AudioBufferList* allocate_buffer_list(UInt32 channelCount, UInt32 byteSize)
-{
- AudioBufferList *list;
+static void ALCcoreAudioPlayback_Construct(ALCcoreAudioPlayback *self, ALCdevice *device);
+static void ALCcoreAudioPlayback_Destruct(ALCcoreAudioPlayback *self);
+static ALCenum ALCcoreAudioPlayback_open(ALCcoreAudioPlayback *self, const ALCchar *name);
+static ALCboolean ALCcoreAudioPlayback_reset(ALCcoreAudioPlayback *self);
+static ALCboolean ALCcoreAudioPlayback_start(ALCcoreAudioPlayback *self);
+static void ALCcoreAudioPlayback_stop(ALCcoreAudioPlayback *self);
+static DECLARE_FORWARD2(ALCcoreAudioPlayback, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
+static DECLARE_FORWARD(ALCcoreAudioPlayback, ALCbackend, ALCuint, availableSamples)
+static DECLARE_FORWARD(ALCcoreAudioPlayback, ALCbackend, ClockLatency, getClockLatency)
+static DECLARE_FORWARD(ALCcoreAudioPlayback, ALCbackend, void, lock)
+static DECLARE_FORWARD(ALCcoreAudioPlayback, ALCbackend, void, unlock)
+DECLARE_DEFAULT_ALLOCATORS(ALCcoreAudioPlayback)
- list = calloc(1, sizeof(AudioBufferList) + sizeof(AudioBuffer));
- if(list)
- {
- list->mNumberBuffers = 1;
+DEFINE_ALCBACKEND_VTABLE(ALCcoreAudioPlayback);
- list->mBuffers[0].mNumberChannels = channelCount;
- list->mBuffers[0].mDataByteSize = byteSize;
- list->mBuffers[0].mData = malloc(byteSize);
- if(list->mBuffers[0].mData == NULL)
- {
- free(list);
- list = NULL;
- }
- }
- return list;
-}
-static OSStatus ca_callback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp,
- UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
+static void ALCcoreAudioPlayback_Construct(ALCcoreAudioPlayback *self, ALCdevice *device)
{
- ALCdevice *device = (ALCdevice*)inRefCon;
- ca_data *data = (ca_data*)device->ExtraData;
-
- aluMixData(device, ioData->mBuffers[0].mData,
- ioData->mBuffers[0].mDataByteSize / data->frameSize);
+ ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
+ SET_VTABLE2(ALCcoreAudioPlayback, ALCbackend, self);
- return noErr;
+ self->frameSize = 0;
+ memset(&self->format, 0, sizeof(self->format));
}
-static OSStatus ca_capture_conversion_callback(AudioConverterRef inAudioConverter, UInt32 *ioNumberDataPackets,
- AudioBufferList *ioData, AudioStreamPacketDescription **outDataPacketDescription, void* inUserData)
+static void ALCcoreAudioPlayback_Destruct(ALCcoreAudioPlayback *self)
{
- ALCdevice *device = (ALCdevice*)inUserData;
- ca_data *data = (ca_data*)device->ExtraData;
+ AudioUnitUninitialize(self->audioUnit);
+ AudioComponentInstanceDispose(self->audioUnit);
- // Read from the ring buffer and store temporarily in a large buffer
- ReadRingBuffer(data->ring, data->resampleBuffer, (ALsizei)(*ioNumberDataPackets));
-
- // Set the input data
- ioData->mNumberBuffers = 1;
- ioData->mBuffers[0].mNumberChannels = data->format.mChannelsPerFrame;
- ioData->mBuffers[0].mData = data->resampleBuffer;
- ioData->mBuffers[0].mDataByteSize = (*ioNumberDataPackets) * data->format.mBytesPerFrame;
-
- return noErr;
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}
-static OSStatus ca_capture_callback(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags,
- const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber,
- UInt32 inNumberFrames, AudioBufferList *ioData)
-{
- ALCdevice *device = (ALCdevice*)inRefCon;
- ca_data *data = (ca_data*)device->ExtraData;
- AudioUnitRenderActionFlags flags = 0;
- OSStatus err;
- // fill the bufferList with data from the input device
- err = AudioUnitRender(data->audioUnit, &flags, inTimeStamp, 1, inNumberFrames, data->bufferList);
- if(err != noErr)
- {
- ERR("AudioUnitRender error: %d\n", err);
- return err;
- }
+static OSStatus ALCcoreAudioPlayback_MixerProc(void *inRefCon,
+ AudioUnitRenderActionFlags* UNUSED(ioActionFlags), const AudioTimeStamp* UNUSED(inTimeStamp),
+ UInt32 UNUSED(inBusNumber), UInt32 UNUSED(inNumberFrames), AudioBufferList *ioData)
+{
+ ALCcoreAudioPlayback *self = inRefCon;
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
- WriteRingBuffer(data->ring, data->bufferList->mBuffers[0].mData, inNumberFrames);
+ ALCcoreAudioPlayback_lock(self);
+ aluMixData(device, ioData->mBuffers[0].mData,
+ ioData->mBuffers[0].mDataByteSize / self->frameSize);
+ ALCcoreAudioPlayback_unlock(self);
return noErr;
}
-static ALCenum ca_open_playback(ALCdevice *device, const ALCchar *deviceName)
+
+static ALCenum ALCcoreAudioPlayback_open(ALCcoreAudioPlayback *self, const ALCchar *name)
{
- ComponentDescription desc;
- Component comp;
- ca_data *data;
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
+ AudioComponentDescription desc;
+ AudioComponent comp;
OSStatus err;
- if(!deviceName)
- deviceName = ca_device;
- else if(strcmp(deviceName, ca_device) != 0)
+ if(!name)
+ name = ca_device;
+ else if(strcmp(name, ca_device) != 0)
return ALC_INVALID_VALUE;
/* open the default output unit */
desc.componentType = kAudioUnitType_Output;
+#if TARGET_OS_IOS
+ desc.componentSubType = kAudioUnitSubType_RemoteIO;
+#else
desc.componentSubType = kAudioUnitSubType_DefaultOutput;
+#endif
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
- comp = FindNextComponent(NULL, &desc);
+ comp = AudioComponentFindNext(NULL, &desc);
if(comp == NULL)
{
- ERR("FindNextComponent failed\n");
+ ERR("AudioComponentFindNext failed\n");
return ALC_INVALID_VALUE;
}
- data = calloc(1, sizeof(*data));
-
- err = OpenAComponent(comp, &data->audioUnit);
+ err = AudioComponentInstanceNew(comp, &self->audioUnit);
if(err != noErr)
{
- ERR("OpenAComponent failed\n");
- free(data);
+ ERR("AudioComponentInstanceNew failed\n");
return ALC_INVALID_VALUE;
}
/* init and start the default audio unit... */
- err = AudioUnitInitialize(data->audioUnit);
+ err = AudioUnitInitialize(self->audioUnit);
if(err != noErr)
{
ERR("AudioUnitInitialize failed\n");
- CloseComponent(data->audioUnit);
- free(data);
+ AudioComponentInstanceDispose(self->audioUnit);
return ALC_INVALID_VALUE;
}
- al_string_copy_cstr(&device->DeviceName, deviceName);
- device->ExtraData = data;
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
}
-static void ca_close_playback(ALCdevice *device)
+static ALCboolean ALCcoreAudioPlayback_reset(ALCcoreAudioPlayback *self)
{
- ca_data *data = (ca_data*)device->ExtraData;
-
- AudioUnitUninitialize(data->audioUnit);
- CloseComponent(data->audioUnit);
-
- free(data);
- device->ExtraData = NULL;
-}
-
-static ALCboolean ca_reset_playback(ALCdevice *device)
-{
- ca_data *data = (ca_data*)device->ExtraData;
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
AudioStreamBasicDescription streamFormat;
AURenderCallbackStruct input;
OSStatus err;
UInt32 size;
- err = AudioUnitUninitialize(data->audioUnit);
+ err = AudioUnitUninitialize(self->audioUnit);
if(err != noErr)
ERR("-- AudioUnitUninitialize failed.\n");
/* retrieve default output unit's properties (output side) */
size = sizeof(AudioStreamBasicDescription);
- err = AudioUnitGetProperty(data->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &streamFormat, &size);
+ err = AudioUnitGetProperty(self->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &streamFormat, &size);
if(err != noErr || size != sizeof(AudioStreamBasicDescription))
{
ERR("AudioUnitGetProperty failed\n");
@@ -229,7 +179,7 @@ static ALCboolean ca_reset_playback(ALCdevice *device)
#endif
/* set default output unit's input side to match output side */
- err = AudioUnitSetProperty(data->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &streamFormat, size);
+ err = AudioUnitSetProperty(self->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &streamFormat, size);
if(err != noErr)
{
ERR("AudioUnitSetProperty failed\n");
@@ -238,7 +188,7 @@ static ALCboolean ca_reset_playback(ALCdevice *device)
if(device->Frequency != streamFormat.mSampleRate)
{
- device->UpdateSize = (ALuint)((ALuint64)device->UpdateSize *
+ device->NumUpdates = (ALuint)((ALuint64)device->NumUpdates *
streamFormat.mSampleRate /
device->Frequency);
device->Frequency = streamFormat.mSampleRate;
@@ -313,7 +263,7 @@ static ALCboolean ca_reset_playback(ALCdevice *device)
streamFormat.mFormatFlags |= kAudioFormatFlagsNativeEndian |
kLinearPCMFormatFlagIsPacked;
- err = AudioUnitSetProperty(data->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &streamFormat, sizeof(AudioStreamBasicDescription));
+ err = AudioUnitSetProperty(self->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &streamFormat, sizeof(AudioStreamBasicDescription));
if(err != noErr)
{
ERR("AudioUnitSetProperty failed\n");
@@ -321,11 +271,11 @@ static ALCboolean ca_reset_playback(ALCdevice *device)
}
/* setup callback */
- data->frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
- input.inputProc = ca_callback;
- input.inputProcRefCon = device;
+ self->frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
+ input.inputProc = ALCcoreAudioPlayback_MixerProc;
+ input.inputProcRefCon = self;
- err = AudioUnitSetProperty(data->audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &input, sizeof(AURenderCallbackStruct));
+ err = AudioUnitSetProperty(self->audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &input, sizeof(AURenderCallbackStruct));
if(err != noErr)
{
ERR("AudioUnitSetProperty failed\n");
@@ -333,7 +283,7 @@ static ALCboolean ca_reset_playback(ALCdevice *device)
}
/* init the default audio unit... */
- err = AudioUnitInitialize(data->audioUnit);
+ err = AudioUnitInitialize(self->audioUnit);
if(err != noErr)
{
ERR("AudioUnitInitialize failed\n");
@@ -343,12 +293,9 @@ static ALCboolean ca_reset_playback(ALCdevice *device)
return ALC_TRUE;
}
-static ALCboolean ca_start_playback(ALCdevice *device)
+static ALCboolean ALCcoreAudioPlayback_start(ALCcoreAudioPlayback *self)
{
- ca_data *data = (ca_data*)device->ExtraData;
- OSStatus err;
-
- err = AudioOutputUnitStart(data->audioUnit);
+ OSStatus err = AudioOutputUnitStart(self->audioUnit);
if(err != noErr)
{
ERR("AudioOutputUnitStart failed\n");
@@ -358,64 +305,196 @@ static ALCboolean ca_start_playback(ALCdevice *device)
return ALC_TRUE;
}
-static void ca_stop_playback(ALCdevice *device)
+static void ALCcoreAudioPlayback_stop(ALCcoreAudioPlayback *self)
+{
+ OSStatus err = AudioOutputUnitStop(self->audioUnit);
+ if(err != noErr)
+ ERR("AudioOutputUnitStop failed\n");
+}
+
+
+
+
+typedef struct ALCcoreAudioCapture {
+ DERIVE_FROM_TYPE(ALCbackend);
+
+ AudioUnit audioUnit;
+
+ ALuint frameSize;
+ ALdouble sampleRateRatio; // Ratio of hardware sample rate / requested sample rate
+ AudioStreamBasicDescription format; // This is the OpenAL format as a CoreAudio ASBD
+
+ AudioConverterRef audioConverter; // Sample rate converter if needed
+ AudioBufferList *bufferList; // Buffer for data coming from the input device
+ ALCvoid *resampleBuffer; // Buffer for returned RingBuffer data when resampling
+
+ ll_ringbuffer_t *ring;
+} ALCcoreAudioCapture;
+
+static void ALCcoreAudioCapture_Construct(ALCcoreAudioCapture *self, ALCdevice *device);
+static void ALCcoreAudioCapture_Destruct(ALCcoreAudioCapture *self);
+static ALCenum ALCcoreAudioCapture_open(ALCcoreAudioCapture *self, const ALCchar *name);
+static DECLARE_FORWARD(ALCcoreAudioCapture, ALCbackend, ALCboolean, reset)
+static ALCboolean ALCcoreAudioCapture_start(ALCcoreAudioCapture *self);
+static void ALCcoreAudioCapture_stop(ALCcoreAudioCapture *self);
+static ALCenum ALCcoreAudioCapture_captureSamples(ALCcoreAudioCapture *self, ALCvoid *buffer, ALCuint samples);
+static ALCuint ALCcoreAudioCapture_availableSamples(ALCcoreAudioCapture *self);
+static DECLARE_FORWARD(ALCcoreAudioCapture, ALCbackend, ClockLatency, getClockLatency)
+static DECLARE_FORWARD(ALCcoreAudioCapture, ALCbackend, void, lock)
+static DECLARE_FORWARD(ALCcoreAudioCapture, ALCbackend, void, unlock)
+DECLARE_DEFAULT_ALLOCATORS(ALCcoreAudioCapture)
+
+DEFINE_ALCBACKEND_VTABLE(ALCcoreAudioCapture);
+
+
+static AudioBufferList *allocate_buffer_list(UInt32 channelCount, UInt32 byteSize)
+{
+ AudioBufferList *list;
+
+ list = calloc(1, FAM_SIZE(AudioBufferList, mBuffers, 1) + byteSize);
+ if(list)
+ {
+ list->mNumberBuffers = 1;
+
+ list->mBuffers[0].mNumberChannels = channelCount;
+ list->mBuffers[0].mDataByteSize = byteSize;
+ list->mBuffers[0].mData = &list->mBuffers[1];
+ }
+ return list;
+}
+
+static void destroy_buffer_list(AudioBufferList *list)
+{
+ free(list);
+}
+
+
+static void ALCcoreAudioCapture_Construct(ALCcoreAudioCapture *self, ALCdevice *device)
+{
+ ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
+ SET_VTABLE2(ALCcoreAudioCapture, ALCbackend, self);
+
+ self->audioUnit = 0;
+ self->audioConverter = NULL;
+ self->bufferList = NULL;
+ self->resampleBuffer = NULL;
+ self->ring = NULL;
+}
+
+static void ALCcoreAudioCapture_Destruct(ALCcoreAudioCapture *self)
+{
+ ll_ringbuffer_free(self->ring);
+ self->ring = NULL;
+
+ free(self->resampleBuffer);
+ self->resampleBuffer = NULL;
+
+ destroy_buffer_list(self->bufferList);
+ self->bufferList = NULL;
+
+ if(self->audioConverter)
+ AudioConverterDispose(self->audioConverter);
+ self->audioConverter = NULL;
+
+ if(self->audioUnit)
+ AudioComponentInstanceDispose(self->audioUnit);
+ self->audioUnit = 0;
+
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
+}
+
+
+static OSStatus ALCcoreAudioCapture_RecordProc(void *inRefCon,
+ AudioUnitRenderActionFlags* UNUSED(ioActionFlags),
+ const AudioTimeStamp *inTimeStamp, UInt32 UNUSED(inBusNumber),
+ UInt32 inNumberFrames, AudioBufferList* UNUSED(ioData))
{
- ca_data *data = (ca_data*)device->ExtraData;
+ ALCcoreAudioCapture *self = inRefCon;
+ AudioUnitRenderActionFlags flags = 0;
OSStatus err;
- err = AudioOutputUnitStop(data->audioUnit);
+ // fill the bufferList with data from the input device
+ err = AudioUnitRender(self->audioUnit, &flags, inTimeStamp, 1, inNumberFrames, self->bufferList);
if(err != noErr)
- ERR("AudioOutputUnitStop failed\n");
+ {
+ ERR("AudioUnitRender error: %d\n", err);
+ return err;
+ }
+
+ ll_ringbuffer_write(self->ring, self->bufferList->mBuffers[0].mData, inNumberFrames);
+
+ return noErr;
+}
+
+static OSStatus ALCcoreAudioCapture_ConvertCallback(AudioConverterRef UNUSED(inAudioConverter),
+ UInt32 *ioNumberDataPackets, AudioBufferList *ioData,
+ AudioStreamPacketDescription** UNUSED(outDataPacketDescription),
+ void *inUserData)
+{
+ ALCcoreAudioCapture *self = inUserData;
+
+ // Read from the ring buffer and store temporarily in a large buffer
+ ll_ringbuffer_read(self->ring, self->resampleBuffer, *ioNumberDataPackets);
+
+ // Set the input data
+ ioData->mNumberBuffers = 1;
+ ioData->mBuffers[0].mNumberChannels = self->format.mChannelsPerFrame;
+ ioData->mBuffers[0].mData = self->resampleBuffer;
+ ioData->mBuffers[0].mDataByteSize = (*ioNumberDataPackets) * self->format.mBytesPerFrame;
+
+ return noErr;
}
-static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
+
+static ALCenum ALCcoreAudioCapture_open(ALCcoreAudioCapture *self, const ALCchar *name)
{
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
AudioStreamBasicDescription requestedFormat; // The application requested format
AudioStreamBasicDescription hardwareFormat; // The hardware format
AudioStreamBasicDescription outputFormat; // The AudioUnit output format
AURenderCallbackStruct input;
- ComponentDescription desc;
- AudioDeviceID inputDevice;
+ AudioComponentDescription desc;
UInt32 outputFrameCount;
UInt32 propertySize;
+ AudioObjectPropertyAddress propertyAddress;
UInt32 enableIO;
- Component comp;
- ca_data *data;
+ AudioComponent comp;
OSStatus err;
- if(!deviceName)
- deviceName = ca_device;
- else if(strcmp(deviceName, ca_device) != 0)
+ if(!name)
+ name = ca_device;
+ else if(strcmp(name, ca_device) != 0)
return ALC_INVALID_VALUE;
desc.componentType = kAudioUnitType_Output;
+#if TARGET_OS_IOS
+ desc.componentSubType = kAudioUnitSubType_RemoteIO;
+#else
desc.componentSubType = kAudioUnitSubType_HALOutput;
+#endif
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
// Search for component with given description
- comp = FindNextComponent(NULL, &desc);
+ comp = AudioComponentFindNext(NULL, &desc);
if(comp == NULL)
{
- ERR("FindNextComponent failed\n");
+ ERR("AudioComponentFindNext failed\n");
return ALC_INVALID_VALUE;
}
- data = calloc(1, sizeof(*data));
- device->ExtraData = data;
-
// Open the component
- err = OpenAComponent(comp, &data->audioUnit);
+ err = AudioComponentInstanceNew(comp, &self->audioUnit);
if(err != noErr)
{
- ERR("OpenAComponent failed\n");
+ ERR("AudioComponentInstanceNew failed\n");
goto error;
}
// Turn off AudioUnit output
enableIO = 0;
- err = AudioUnitSetProperty(data->audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, &enableIO, sizeof(ALuint));
+ err = AudioUnitSetProperty(self->audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, &enableIO, sizeof(ALuint));
if(err != noErr)
{
ERR("AudioUnitSetProperty failed\n");
@@ -424,22 +503,28 @@ static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
// Turn on AudioUnit input
enableIO = 1;
- err = AudioUnitSetProperty(data->audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &enableIO, sizeof(ALuint));
+ err = AudioUnitSetProperty(self->audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &enableIO, sizeof(ALuint));
if(err != noErr)
{
ERR("AudioUnitSetProperty failed\n");
goto error;
}
+#if !TARGET_OS_IOS
// Get the default input device
+ AudioDeviceID inputDevice = kAudioDeviceUnknown;
+
propertySize = sizeof(AudioDeviceID);
- err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice, &propertySize, &inputDevice);
+ propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
+ propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
+ propertyAddress.mElement = kAudioObjectPropertyElementMaster;
+
+ err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &propertySize, &inputDevice);
if(err != noErr)
{
- ERR("AudioHardwareGetProperty failed\n");
+ ERR("AudioObjectGetPropertyData failed\n");
goto error;
}
-
if(inputDevice == kAudioDeviceUnknown)
{
ERR("No input device found\n");
@@ -447,18 +532,19 @@ static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
}
// Track the input device
- err = AudioUnitSetProperty(data->audioUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &inputDevice, sizeof(AudioDeviceID));
+ err = AudioUnitSetProperty(self->audioUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &inputDevice, sizeof(AudioDeviceID));
if(err != noErr)
{
ERR("AudioUnitSetProperty failed\n");
goto error;
}
+#endif
// set capture callback
- input.inputProc = ca_capture_callback;
- input.inputProcRefCon = device;
+ input.inputProc = ALCcoreAudioCapture_RecordProc;
+ input.inputProcRefCon = self;
- err = AudioUnitSetProperty(data->audioUnit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &input, sizeof(AURenderCallbackStruct));
+ err = AudioUnitSetProperty(self->audioUnit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &input, sizeof(AURenderCallbackStruct));
if(err != noErr)
{
ERR("AudioUnitSetProperty failed\n");
@@ -466,7 +552,7 @@ static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
}
// Initialize the device
- err = AudioUnitInitialize(data->audioUnit);
+ err = AudioUnitInitialize(self->audioUnit);
if(err != noErr)
{
ERR("AudioUnitInitialize failed\n");
@@ -475,7 +561,7 @@ static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
// Get the hardware format
propertySize = sizeof(AudioStreamBasicDescription);
- err = AudioUnitGetProperty(data->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 1, &hardwareFormat, &propertySize);
+ err = AudioUnitGetProperty(self->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 1, &hardwareFormat, &propertySize);
if(err != noErr || propertySize != sizeof(AudioStreamBasicDescription))
{
ERR("AudioUnitGetProperty failed\n");
@@ -522,7 +608,7 @@ static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
case DevFmtX51Rear:
case DevFmtX61:
case DevFmtX71:
- case DevFmtBFormat3D:
+ case DevFmtAmbi3D:
ERR("%s not supported\n", DevFmtChannelsString(device->FmtChans));
goto error;
}
@@ -535,8 +621,8 @@ static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
requestedFormat.mFramesPerPacket = 1;
// save requested format description for later use
- data->format = requestedFormat;
- data->frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ self->format = requestedFormat;
+ self->frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
// Use intermediate format for sample rate conversion (outputFormat)
// Set sample rate to the same as hardware for resampling later
@@ -544,11 +630,11 @@ static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
outputFormat.mSampleRate = hardwareFormat.mSampleRate;
// Determine sample rate ratio for resampling
- data->sampleRateRatio = outputFormat.mSampleRate / device->Frequency;
+ self->sampleRateRatio = outputFormat.mSampleRate / device->Frequency;
// The output format should be the requested format, but using the hardware sample rate
// This is because the AudioUnit will automatically scale other properties, except for sample rate
- err = AudioUnitSetProperty(data->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, (void *)&outputFormat, sizeof(outputFormat));
+ err = AudioUnitSetProperty(self->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, (void *)&outputFormat, sizeof(outputFormat));
if(err != noErr)
{
ERR("AudioUnitSetProperty failed\n");
@@ -556,8 +642,8 @@ static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
}
// Set the AudioUnit output format frame count
- outputFrameCount = device->UpdateSize * data->sampleRateRatio;
- err = AudioUnitSetProperty(data->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Output, 0, &outputFrameCount, sizeof(outputFrameCount));
+ outputFrameCount = device->UpdateSize * self->sampleRateRatio;
+ err = AudioUnitSetProperty(self->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Output, 0, &outputFrameCount, sizeof(outputFrameCount));
if(err != noErr)
{
ERR("AudioUnitSetProperty failed: %d\n", err);
@@ -565,7 +651,7 @@ static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
}
// Set up sample converter
- err = AudioConverterNew(&outputFormat, &requestedFormat, &data->audioConverter);
+ err = AudioConverterNew(&outputFormat, &requestedFormat, &self->audioConverter);
if(err != noErr)
{
ERR("AudioConverterNew failed: %d\n", err);
@@ -573,92 +659,83 @@ static ALCenum ca_open_capture(ALCdevice *device, const ALCchar *deviceName)
}
// Create a buffer for use in the resample callback
- data->resampleBuffer = malloc(device->UpdateSize * data->frameSize * data->sampleRateRatio);
+ self->resampleBuffer = malloc(device->UpdateSize * self->frameSize * self->sampleRateRatio);
// Allocate buffer for the AudioUnit output
- data->bufferList = allocate_buffer_list(outputFormat.mChannelsPerFrame, device->UpdateSize * data->frameSize * data->sampleRateRatio);
- if(data->bufferList == NULL)
+ self->bufferList = allocate_buffer_list(outputFormat.mChannelsPerFrame, device->UpdateSize * self->frameSize * self->sampleRateRatio);
+ if(self->bufferList == NULL)
goto error;
- data->ring = CreateRingBuffer(data->frameSize, (device->UpdateSize * data->sampleRateRatio) * device->NumUpdates);
- if(data->ring == NULL)
- goto error;
+ self->ring = ll_ringbuffer_create(
+ (size_t)ceil(device->UpdateSize*self->sampleRateRatio*device->NumUpdates),
+ self->frameSize, false
+ );
+ if(!self->ring) goto error;
- al_string_copy_cstr(&device->DeviceName, deviceName);
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
error:
- DestroyRingBuffer(data->ring);
- free(data->resampleBuffer);
- destroy_buffer_list(data->bufferList);
-
- if(data->audioConverter)
- AudioConverterDispose(data->audioConverter);
- if(data->audioUnit)
- CloseComponent(data->audioUnit);
-
- free(data);
- device->ExtraData = NULL;
+ ll_ringbuffer_free(self->ring);
+ self->ring = NULL;
+ free(self->resampleBuffer);
+ self->resampleBuffer = NULL;
+ destroy_buffer_list(self->bufferList);
+ self->bufferList = NULL;
+
+ if(self->audioConverter)
+ AudioConverterDispose(self->audioConverter);
+ self->audioConverter = NULL;
+ if(self->audioUnit)
+ AudioComponentInstanceDispose(self->audioUnit);
+ self->audioUnit = 0;
return ALC_INVALID_VALUE;
}
-static void ca_close_capture(ALCdevice *device)
-{
- ca_data *data = (ca_data*)device->ExtraData;
-
- DestroyRingBuffer(data->ring);
- free(data->resampleBuffer);
- destroy_buffer_list(data->bufferList);
- AudioConverterDispose(data->audioConverter);
- CloseComponent(data->audioUnit);
-
- free(data);
- device->ExtraData = NULL;
-}
-
-static void ca_start_capture(ALCdevice *device)
+static ALCboolean ALCcoreAudioCapture_start(ALCcoreAudioCapture *self)
{
- ca_data *data = (ca_data*)device->ExtraData;
- OSStatus err = AudioOutputUnitStart(data->audioUnit);
+ OSStatus err = AudioOutputUnitStart(self->audioUnit);
if(err != noErr)
+ {
ERR("AudioOutputUnitStart failed\n");
+ return ALC_FALSE;
+ }
+ return ALC_TRUE;
}
-static void ca_stop_capture(ALCdevice *device)
+static void ALCcoreAudioCapture_stop(ALCcoreAudioCapture *self)
{
- ca_data *data = (ca_data*)device->ExtraData;
- OSStatus err = AudioOutputUnitStop(data->audioUnit);
+ OSStatus err = AudioOutputUnitStop(self->audioUnit);
if(err != noErr)
ERR("AudioOutputUnitStop failed\n");
}
-static ALCenum ca_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples)
+static ALCenum ALCcoreAudioCapture_captureSamples(ALCcoreAudioCapture *self, ALCvoid *buffer, ALCuint samples)
{
- ca_data *data = (ca_data*)device->ExtraData;
- AudioBufferList *list;
+ union {
+ ALbyte _[sizeof(AudioBufferList) + sizeof(AudioBuffer)];
+ AudioBufferList list;
+ } audiobuf = { { 0 } };
UInt32 frameCount;
OSStatus err;
// If no samples are requested, just return
- if(samples == 0)
- return ALC_NO_ERROR;
-
- // Allocate a temporary AudioBufferList to use as the return resamples data
- list = alloca(sizeof(AudioBufferList) + sizeof(AudioBuffer));
+ if(samples == 0) return ALC_NO_ERROR;
// Point the resampling buffer to the capture buffer
- list->mNumberBuffers = 1;
- list->mBuffers[0].mNumberChannels = data->format.mChannelsPerFrame;
- list->mBuffers[0].mDataByteSize = samples * data->frameSize;
- list->mBuffers[0].mData = buffer;
+ audiobuf.list.mNumberBuffers = 1;
+ audiobuf.list.mBuffers[0].mNumberChannels = self->format.mChannelsPerFrame;
+ audiobuf.list.mBuffers[0].mDataByteSize = samples * self->frameSize;
+ audiobuf.list.mBuffers[0].mData = buffer;
// Resample into another AudioBufferList
frameCount = samples;
- err = AudioConverterFillComplexBuffer(data->audioConverter, ca_capture_conversion_callback,
- device, &frameCount, list, NULL);
+ err = AudioConverterFillComplexBuffer(self->audioConverter,
+ ALCcoreAudioCapture_ConvertCallback, self, &frameCount, &audiobuf.list, NULL
+ );
if(err != noErr)
{
ERR("AudioConverterFillComplexBuffer error: %d\n", err);
@@ -667,46 +744,73 @@ static ALCenum ca_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint sa
return ALC_NO_ERROR;
}
-static ALCuint ca_available_samples(ALCdevice *device)
+static ALCuint ALCcoreAudioCapture_availableSamples(ALCcoreAudioCapture *self)
{
- ca_data *data = device->ExtraData;
- return RingBufferSize(data->ring) / data->sampleRateRatio;
+ return ll_ringbuffer_read_space(self->ring) / self->sampleRateRatio;
}
-static const BackendFuncs ca_funcs = {
- ca_open_playback,
- ca_close_playback,
- ca_reset_playback,
- ca_start_playback,
- ca_stop_playback,
- ca_open_capture,
- ca_close_capture,
- ca_start_capture,
- ca_stop_capture,
- ca_capture_samples,
- ca_available_samples
-};
-
-ALCboolean alc_ca_init(BackendFuncs *func_list)
+typedef struct ALCcoreAudioBackendFactory {
+ DERIVE_FROM_TYPE(ALCbackendFactory);
+} ALCcoreAudioBackendFactory;
+#define ALCCOREAUDIOBACKENDFACTORY_INITIALIZER { { GET_VTABLE2(ALCcoreAudioBackendFactory, ALCbackendFactory) } }
+
+ALCbackendFactory *ALCcoreAudioBackendFactory_getFactory(void);
+
+static ALCboolean ALCcoreAudioBackendFactory_init(ALCcoreAudioBackendFactory *self);
+static DECLARE_FORWARD(ALCcoreAudioBackendFactory, ALCbackendFactory, void, deinit)
+static ALCboolean ALCcoreAudioBackendFactory_querySupport(ALCcoreAudioBackendFactory *self, ALCbackend_Type type);
+static void ALCcoreAudioBackendFactory_probe(ALCcoreAudioBackendFactory *self, enum DevProbe type, al_string *outnames);
+static ALCbackend* ALCcoreAudioBackendFactory_createBackend(ALCcoreAudioBackendFactory *self, ALCdevice *device, ALCbackend_Type type);
+DEFINE_ALCBACKENDFACTORY_VTABLE(ALCcoreAudioBackendFactory);
+
+
+ALCbackendFactory *ALCcoreAudioBackendFactory_getFactory(void)
+{
+ static ALCcoreAudioBackendFactory factory = ALCCOREAUDIOBACKENDFACTORY_INITIALIZER;
+ return STATIC_CAST(ALCbackendFactory, &factory);
+}
+
+
+static ALCboolean ALCcoreAudioBackendFactory_init(ALCcoreAudioBackendFactory* UNUSED(self))
{
- *func_list = ca_funcs;
return ALC_TRUE;
}
-void alc_ca_deinit(void)
+static ALCboolean ALCcoreAudioBackendFactory_querySupport(ALCcoreAudioBackendFactory* UNUSED(self), ALCbackend_Type type)
{
+ if(type == ALCbackend_Playback || ALCbackend_Capture)
+ return ALC_TRUE;
+ return ALC_FALSE;
}
-void alc_ca_probe(enum DevProbe type)
+static void ALCcoreAudioBackendFactory_probe(ALCcoreAudioBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
switch(type)
{
case ALL_DEVICE_PROBE:
- AppendAllDevicesList(ca_device);
- break;
case CAPTURE_DEVICE_PROBE:
- AppendCaptureDeviceList(ca_device);
+ alstr_append_range(outnames, ca_device, ca_device+sizeof(ca_device));
break;
}
}
+
+static ALCbackend* ALCcoreAudioBackendFactory_createBackend(ALCcoreAudioBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type)
+{
+ if(type == ALCbackend_Playback)
+ {
+ ALCcoreAudioPlayback *backend;
+ NEW_OBJ(backend, ALCcoreAudioPlayback)(device);
+ if(!backend) return NULL;
+ return STATIC_CAST(ALCbackend, backend);
+ }
+ if(type == ALCbackend_Capture)
+ {
+ ALCcoreAudioCapture *backend;
+ NEW_OBJ(backend, ALCcoreAudioCapture)(device);
+ if(!backend) return NULL;
+ return STATIC_CAST(ALCbackend, backend);
+ }
+
+ return NULL;
+}
diff --git a/Alc/backends/dsound.c b/Alc/backends/dsound.c
index 4db4b557..c368cffb 100644
--- a/Alc/backends/dsound.c
+++ b/Alc/backends/dsound.c
@@ -34,6 +34,7 @@
#include "alMain.h"
#include "alu.h"
+#include "ringbuffer.h"
#include "threads.h"
#include "compat.h"
#include "alstring.h"
@@ -60,7 +61,7 @@
DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM, 0x00000001, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
DEFINE_GUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, 0x00000003, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71);
-#define DEVNAME_TAIL " on OpenAL Soft"
+#define DEVNAME_HEAD "OpenAL Soft on "
#ifdef HAVE_DYNLOAD
@@ -123,7 +124,7 @@ static void clear_devlist(vector_DevMap *list)
{
#define DEINIT_STR(i) AL_STRING_DEINIT((i)->name)
VECTOR_FOR_EACH(DevMap, *list, DEINIT_STR);
- VECTOR_RESIZE(*list, 0);
+ VECTOR_RESIZE(*list, 0, 0);
#undef DEINIT_STR
}
@@ -145,19 +146,18 @@ static BOOL CALLBACK DSoundEnumDevices(GUID *guid, const WCHAR *desc, const WCHA
{
const DevMap *iter;
- al_string_copy_wcstr(&entry.name, desc);
- if(count == 0)
- al_string_append_cstr(&entry.name, DEVNAME_TAIL);
- else
+ alstr_copy_cstr(&entry.name, DEVNAME_HEAD);
+ alstr_append_wcstr(&entry.name, desc);
+ if(count != 0)
{
char str[64];
- snprintf(str, sizeof(str), " #%d"DEVNAME_TAIL, count+1);
- al_string_append_cstr(&entry.name, str);
+ snprintf(str, sizeof(str), " #%d", count+1);
+ alstr_append_cstr(&entry.name, str);
}
-#define MATCH_ENTRY(i) (al_string_cmp(entry.name, (i)->name) == 0)
+#define MATCH_ENTRY(i) (alstr_cmp(entry.name, (i)->name) == 0)
VECTOR_FIND_IF(iter, const DevMap, *devices, MATCH_ENTRY);
- if(iter == VECTOR_ITER_END(*devices)) break;
+ if(iter == VECTOR_END(*devices)) break;
#undef MATCH_ENTRY
count++;
}
@@ -166,7 +166,7 @@ static BOOL CALLBACK DSoundEnumDevices(GUID *guid, const WCHAR *desc, const WCHA
hr = StringFromCLSID(guid, &guidstr);
if(SUCCEEDED(hr))
{
- TRACE("Got device \"%s\", GUID \"%ls\"\n", al_string_get_cstr(entry.name), guidstr);
+ TRACE("Got device \"%s\", GUID \"%ls\"\n", alstr_get_cstr(entry.name), guidstr);
CoTaskMemFree(guidstr);
}
@@ -185,22 +185,21 @@ typedef struct ALCdsoundPlayback {
IDirectSoundNotify *Notifies;
HANDLE NotifyEvent;
- volatile int killNow;
+ ATOMIC(ALenum) killNow;
althrd_t thread;
} ALCdsoundPlayback;
static int ALCdsoundPlayback_mixerProc(void *ptr);
static void ALCdsoundPlayback_Construct(ALCdsoundPlayback *self, ALCdevice *device);
-static DECLARE_FORWARD(ALCdsoundPlayback, ALCbackend, void, Destruct)
+static void ALCdsoundPlayback_Destruct(ALCdsoundPlayback *self);
static ALCenum ALCdsoundPlayback_open(ALCdsoundPlayback *self, const ALCchar *name);
-static void ALCdsoundPlayback_close(ALCdsoundPlayback *self);
static ALCboolean ALCdsoundPlayback_reset(ALCdsoundPlayback *self);
static ALCboolean ALCdsoundPlayback_start(ALCdsoundPlayback *self);
static void ALCdsoundPlayback_stop(ALCdsoundPlayback *self);
static DECLARE_FORWARD2(ALCdsoundPlayback, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
static DECLARE_FORWARD(ALCdsoundPlayback, ALCbackend, ALCuint, availableSamples)
-static DECLARE_FORWARD(ALCdsoundPlayback, ALCbackend, ALint64, getLatency)
+static DECLARE_FORWARD(ALCdsoundPlayback, ALCbackend, ClockLatency, getClockLatency)
static DECLARE_FORWARD(ALCdsoundPlayback, ALCbackend, void, lock)
static DECLARE_FORWARD(ALCdsoundPlayback, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCdsoundPlayback)
@@ -212,6 +211,35 @@ static void ALCdsoundPlayback_Construct(ALCdsoundPlayback *self, ALCdevice *devi
{
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCdsoundPlayback, ALCbackend, self);
+
+ self->DS = NULL;
+ self->PrimaryBuffer = NULL;
+ self->Buffer = NULL;
+ self->Notifies = NULL;
+ self->NotifyEvent = NULL;
+ ATOMIC_INIT(&self->killNow, AL_TRUE);
+}
+
+static void ALCdsoundPlayback_Destruct(ALCdsoundPlayback *self)
+{
+ if(self->Notifies)
+ IDirectSoundNotify_Release(self->Notifies);
+ self->Notifies = NULL;
+ if(self->Buffer)
+ IDirectSoundBuffer_Release(self->Buffer);
+ self->Buffer = NULL;
+ if(self->PrimaryBuffer != NULL)
+ IDirectSoundBuffer_Release(self->PrimaryBuffer);
+ self->PrimaryBuffer = NULL;
+
+ if(self->DS)
+ IDirectSound_Release(self->DS);
+ self->DS = NULL;
+ if(self->NotifyEvent)
+ CloseHandle(self->NotifyEvent);
+ self->NotifyEvent = NULL;
+
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}
@@ -240,16 +268,17 @@ FORCE_ALIGN static int ALCdsoundPlayback_mixerProc(void *ptr)
{
ERR("Failed to get buffer caps: 0x%lx\n", err);
ALCdevice_Lock(device);
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failure retrieving playback buffer info: 0x%lx", err);
ALCdevice_Unlock(device);
return 1;
}
- FrameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ FrameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
FragSize = device->UpdateSize * FrameSize;
IDirectSoundBuffer_GetCurrentPosition(self->Buffer, &LastCursor, NULL);
- while(!self->killNow)
+ while(!ATOMIC_LOAD(&self->killNow, almemory_order_acquire) &&
+ ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
{
// Get current play cursor
IDirectSoundBuffer_GetCurrentPosition(self->Buffer, &PlayCursor, NULL);
@@ -264,7 +293,7 @@ FORCE_ALIGN static int ALCdsoundPlayback_mixerProc(void *ptr)
{
ERR("Failed to play buffer: 0x%lx\n", err);
ALCdevice_Lock(device);
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failure starting playback: 0x%lx", err);
ALCdevice_Unlock(device);
return 1;
}
@@ -300,8 +329,10 @@ FORCE_ALIGN static int ALCdsoundPlayback_mixerProc(void *ptr)
if(SUCCEEDED(err))
{
// If we have an active context, mix data directly into output buffer otherwise fill with silence
+ ALCdevice_Lock(device);
aluMixData(device, WritePtr1, WriteCnt1/FrameSize);
aluMixData(device, WritePtr2, WriteCnt2/FrameSize);
+ ALCdevice_Unlock(device);
// Unlock output buffer only when successfully locked
IDirectSoundBuffer_Unlock(self->Buffer, WritePtr1, WriteCnt1, WritePtr2, WriteCnt2);
@@ -310,7 +341,7 @@ FORCE_ALIGN static int ALCdsoundPlayback_mixerProc(void *ptr)
{
ERR("Buffer lock error: %#lx\n", err);
ALCdevice_Lock(device);
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failed to lock output buffer: 0x%lx", err);
ALCdevice_Unlock(device);
return 1;
}
@@ -342,23 +373,23 @@ static ALCenum ALCdsoundPlayback_open(ALCdsoundPlayback *self, const ALCchar *de
if(!deviceName && VECTOR_SIZE(PlaybackDevices) > 0)
{
- deviceName = al_string_get_cstr(VECTOR_FRONT(PlaybackDevices).name);
+ deviceName = alstr_get_cstr(VECTOR_FRONT(PlaybackDevices).name);
guid = &VECTOR_FRONT(PlaybackDevices).guid;
}
else
{
const DevMap *iter;
-#define MATCH_NAME(i) (al_string_cmp_cstr((i)->name, deviceName) == 0)
+#define MATCH_NAME(i) (alstr_cmp_cstr((i)->name, deviceName) == 0)
VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_NAME);
#undef MATCH_NAME
- if(iter == VECTOR_ITER_END(PlaybackDevices))
+ if(iter == VECTOR_END(PlaybackDevices))
return ALC_INVALID_VALUE;
guid = &iter->guid;
}
hr = DS_OK;
- self->NotifyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ self->NotifyEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
if(self->NotifyEvent == NULL)
hr = E_FAIL;
@@ -380,29 +411,11 @@ static ALCenum ALCdsoundPlayback_open(ALCdsoundPlayback *self, const ALCchar *de
return ALC_INVALID_VALUE;
}
- al_string_copy_cstr(&device->DeviceName, deviceName);
+ alstr_copy_cstr(&device->DeviceName, deviceName);
return ALC_NO_ERROR;
}
-static void ALCdsoundPlayback_close(ALCdsoundPlayback *self)
-{
- if(self->Notifies)
- IDirectSoundNotify_Release(self->Notifies);
- self->Notifies = NULL;
- if(self->Buffer)
- IDirectSoundBuffer_Release(self->Buffer);
- self->Buffer = NULL;
- if(self->PrimaryBuffer != NULL)
- IDirectSoundBuffer_Release(self->PrimaryBuffer);
- self->PrimaryBuffer = NULL;
-
- IDirectSound_Release(self->DS);
- self->DS = NULL;
- CloseHandle(self->NotifyEvent);
- self->NotifyEvent = NULL;
-}
-
static ALCboolean ALCdsoundPlayback_reset(ALCdsoundPlayback *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
@@ -473,7 +486,7 @@ static ALCboolean ALCdsoundPlayback_reset(ALCdsoundPlayback *self)
case DevFmtMono:
OutputType.dwChannelMask = SPEAKER_FRONT_CENTER;
break;
- case DevFmtBFormat3D:
+ case DevFmtAmbi3D:
device->FmtChans = DevFmtStereo;
/*fall-through*/
case DevFmtStereo:
@@ -526,7 +539,7 @@ static ALCboolean ALCdsoundPlayback_reset(ALCdsoundPlayback *self)
retry_open:
hr = S_OK;
OutputType.Format.wFormatTag = WAVE_FORMAT_PCM;
- OutputType.Format.nChannels = ChannelsFromDevFmt(device->FmtChans);
+ OutputType.Format.nChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
OutputType.Format.wBitsPerSample = BytesFromDevFmt(device->FmtType) * 8;
OutputType.Format.nBlockAlign = OutputType.Format.nChannels*OutputType.Format.wBitsPerSample/8;
OutputType.Format.nSamplesPerSec = device->Frequency;
@@ -625,7 +638,7 @@ retry_open:
static ALCboolean ALCdsoundPlayback_start(ALCdsoundPlayback *self)
{
- self->killNow = 0;
+ ATOMIC_STORE(&self->killNow, AL_FALSE, almemory_order_release);
if(althrd_create(&self->thread, ALCdsoundPlayback_mixerProc, self) != althrd_success)
return ALC_FALSE;
@@ -636,10 +649,8 @@ static void ALCdsoundPlayback_stop(ALCdsoundPlayback *self)
{
int res;
- if(self->killNow)
+ if(ATOMIC_EXCHANGE(&self->killNow, AL_TRUE, almemory_order_acq_rel))
return;
-
- self->killNow = 1;
althrd_join(self->thread, &res);
IDirectSoundBuffer_Stop(self->Buffer);
@@ -654,19 +665,19 @@ typedef struct ALCdsoundCapture {
IDirectSoundCaptureBuffer *DSCbuffer;
DWORD BufferBytes;
DWORD Cursor;
- RingBuffer *Ring;
+
+ ll_ringbuffer_t *Ring;
} ALCdsoundCapture;
static void ALCdsoundCapture_Construct(ALCdsoundCapture *self, ALCdevice *device);
-static DECLARE_FORWARD(ALCdsoundCapture, ALCbackend, void, Destruct)
+static void ALCdsoundCapture_Destruct(ALCdsoundCapture *self);
static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *name);
-static void ALCdsoundCapture_close(ALCdsoundCapture *self);
static DECLARE_FORWARD(ALCdsoundCapture, ALCbackend, ALCboolean, reset)
static ALCboolean ALCdsoundCapture_start(ALCdsoundCapture *self);
static void ALCdsoundCapture_stop(ALCdsoundCapture *self);
static ALCenum ALCdsoundCapture_captureSamples(ALCdsoundCapture *self, ALCvoid *buffer, ALCuint samples);
static ALCuint ALCdsoundCapture_availableSamples(ALCdsoundCapture *self);
-static DECLARE_FORWARD(ALCdsoundCapture, ALCbackend, ALint64, getLatency)
+static DECLARE_FORWARD(ALCdsoundCapture, ALCbackend, ClockLatency, getClockLatency)
static DECLARE_FORWARD(ALCdsoundCapture, ALCbackend, void, lock)
static DECLARE_FORWARD(ALCdsoundCapture, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCdsoundCapture)
@@ -677,6 +688,29 @@ static void ALCdsoundCapture_Construct(ALCdsoundCapture *self, ALCdevice *device
{
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCdsoundCapture, ALCbackend, self);
+
+ self->DSC = NULL;
+ self->DSCbuffer = NULL;
+ self->Ring = NULL;
+}
+
+static void ALCdsoundCapture_Destruct(ALCdsoundCapture *self)
+{
+ ll_ringbuffer_free(self->Ring);
+ self->Ring = NULL;
+
+ if(self->DSCbuffer != NULL)
+ {
+ IDirectSoundCaptureBuffer_Stop(self->DSCbuffer);
+ IDirectSoundCaptureBuffer_Release(self->DSCbuffer);
+ self->DSCbuffer = NULL;
+ }
+
+ if(self->DSC)
+ IDirectSoundCapture_Release(self->DSC);
+ self->DSC = NULL;
+
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}
@@ -702,17 +736,17 @@ static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *devi
if(!deviceName && VECTOR_SIZE(CaptureDevices) > 0)
{
- deviceName = al_string_get_cstr(VECTOR_FRONT(CaptureDevices).name);
+ deviceName = alstr_get_cstr(VECTOR_FRONT(CaptureDevices).name);
guid = &VECTOR_FRONT(CaptureDevices).guid;
}
else
{
const DevMap *iter;
-#define MATCH_NAME(i) (al_string_cmp_cstr((i)->name, deviceName) == 0)
+#define MATCH_NAME(i) (alstr_cmp_cstr((i)->name, deviceName) == 0)
VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_NAME);
#undef MATCH_NAME
- if(iter == VECTOR_ITER_END(CaptureDevices))
+ if(iter == VECTOR_END(CaptureDevices))
return ALC_INVALID_VALUE;
guid = &iter->guid;
}
@@ -732,99 +766,98 @@ static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *devi
break;
}
- //DirectSoundCapture Init code
- hr = DirectSoundCaptureCreate(guid, &self->DSC, NULL);
- if(SUCCEEDED(hr))
+ memset(&InputType, 0, sizeof(InputType));
+ switch(device->FmtChans)
{
- memset(&InputType, 0, sizeof(InputType));
-
- switch(device->FmtChans)
- {
- case DevFmtMono:
- InputType.dwChannelMask = SPEAKER_FRONT_CENTER;
- break;
- case DevFmtStereo:
- InputType.dwChannelMask = SPEAKER_FRONT_LEFT |
- SPEAKER_FRONT_RIGHT;
- break;
- case DevFmtQuad:
- InputType.dwChannelMask = SPEAKER_FRONT_LEFT |
- SPEAKER_FRONT_RIGHT |
- SPEAKER_BACK_LEFT |
- SPEAKER_BACK_RIGHT;
- break;
- case DevFmtX51:
- InputType.dwChannelMask = SPEAKER_FRONT_LEFT |
- SPEAKER_FRONT_RIGHT |
- SPEAKER_FRONT_CENTER |
- SPEAKER_LOW_FREQUENCY |
- SPEAKER_SIDE_LEFT |
- SPEAKER_SIDE_RIGHT;
- break;
- case DevFmtX51Rear:
- InputType.dwChannelMask = SPEAKER_FRONT_LEFT |
- SPEAKER_FRONT_RIGHT |
- SPEAKER_FRONT_CENTER |
- SPEAKER_LOW_FREQUENCY |
- SPEAKER_BACK_LEFT |
- SPEAKER_BACK_RIGHT;
- break;
- case DevFmtX61:
- InputType.dwChannelMask = SPEAKER_FRONT_LEFT |
- SPEAKER_FRONT_RIGHT |
- SPEAKER_FRONT_CENTER |
- SPEAKER_LOW_FREQUENCY |
- SPEAKER_BACK_CENTER |
- SPEAKER_SIDE_LEFT |
- SPEAKER_SIDE_RIGHT;
- break;
- case DevFmtX71:
- InputType.dwChannelMask = SPEAKER_FRONT_LEFT |
- SPEAKER_FRONT_RIGHT |
- SPEAKER_FRONT_CENTER |
- SPEAKER_LOW_FREQUENCY |
- SPEAKER_BACK_LEFT |
- SPEAKER_BACK_RIGHT |
- SPEAKER_SIDE_LEFT |
- SPEAKER_SIDE_RIGHT;
- break;
- case DevFmtBFormat3D:
- break;
- }
+ case DevFmtMono:
+ InputType.dwChannelMask = SPEAKER_FRONT_CENTER;
+ break;
+ case DevFmtStereo:
+ InputType.dwChannelMask = SPEAKER_FRONT_LEFT |
+ SPEAKER_FRONT_RIGHT;
+ break;
+ case DevFmtQuad:
+ InputType.dwChannelMask = SPEAKER_FRONT_LEFT |
+ SPEAKER_FRONT_RIGHT |
+ SPEAKER_BACK_LEFT |
+ SPEAKER_BACK_RIGHT;
+ break;
+ case DevFmtX51:
+ InputType.dwChannelMask = SPEAKER_FRONT_LEFT |
+ SPEAKER_FRONT_RIGHT |
+ SPEAKER_FRONT_CENTER |
+ SPEAKER_LOW_FREQUENCY |
+ SPEAKER_SIDE_LEFT |
+ SPEAKER_SIDE_RIGHT;
+ break;
+ case DevFmtX51Rear:
+ InputType.dwChannelMask = SPEAKER_FRONT_LEFT |
+ SPEAKER_FRONT_RIGHT |
+ SPEAKER_FRONT_CENTER |
+ SPEAKER_LOW_FREQUENCY |
+ SPEAKER_BACK_LEFT |
+ SPEAKER_BACK_RIGHT;
+ break;
+ case DevFmtX61:
+ InputType.dwChannelMask = SPEAKER_FRONT_LEFT |
+ SPEAKER_FRONT_RIGHT |
+ SPEAKER_FRONT_CENTER |
+ SPEAKER_LOW_FREQUENCY |
+ SPEAKER_BACK_CENTER |
+ SPEAKER_SIDE_LEFT |
+ SPEAKER_SIDE_RIGHT;
+ break;
+ case DevFmtX71:
+ InputType.dwChannelMask = SPEAKER_FRONT_LEFT |
+ SPEAKER_FRONT_RIGHT |
+ SPEAKER_FRONT_CENTER |
+ SPEAKER_LOW_FREQUENCY |
+ SPEAKER_BACK_LEFT |
+ SPEAKER_BACK_RIGHT |
+ SPEAKER_SIDE_LEFT |
+ SPEAKER_SIDE_RIGHT;
+ break;
+ case DevFmtAmbi3D:
+ WARN("%s capture not supported\n", DevFmtChannelsString(device->FmtChans));
+ return ALC_INVALID_ENUM;
+ }
- InputType.Format.wFormatTag = WAVE_FORMAT_PCM;
- InputType.Format.nChannels = ChannelsFromDevFmt(device->FmtChans);
- InputType.Format.wBitsPerSample = BytesFromDevFmt(device->FmtType) * 8;
- InputType.Format.nBlockAlign = InputType.Format.nChannels*InputType.Format.wBitsPerSample/8;
- InputType.Format.nSamplesPerSec = device->Frequency;
- InputType.Format.nAvgBytesPerSec = InputType.Format.nSamplesPerSec*InputType.Format.nBlockAlign;
- InputType.Format.cbSize = 0;
+ InputType.Format.wFormatTag = WAVE_FORMAT_PCM;
+ InputType.Format.nChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
+ InputType.Format.wBitsPerSample = BytesFromDevFmt(device->FmtType) * 8;
+ InputType.Format.nBlockAlign = InputType.Format.nChannels*InputType.Format.wBitsPerSample/8;
+ InputType.Format.nSamplesPerSec = device->Frequency;
+ InputType.Format.nAvgBytesPerSec = InputType.Format.nSamplesPerSec*InputType.Format.nBlockAlign;
+ InputType.Format.cbSize = 0;
+ InputType.Samples.wValidBitsPerSample = InputType.Format.wBitsPerSample;
+ if(device->FmtType == DevFmtFloat)
+ InputType.SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
+ else
+ InputType.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
- if(InputType.Format.nChannels > 2 || device->FmtType == DevFmtFloat)
- {
- InputType.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
- InputType.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
- InputType.Samples.wValidBitsPerSample = InputType.Format.wBitsPerSample;
- if(device->FmtType == DevFmtFloat)
- InputType.SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
- else
- InputType.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
- }
+ if(InputType.Format.nChannels > 2 || device->FmtType == DevFmtFloat)
+ {
+ InputType.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
+ InputType.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
+ }
- samples = device->UpdateSize * device->NumUpdates;
- samples = maxu(samples, 100 * device->Frequency / 1000);
+ samples = device->UpdateSize * device->NumUpdates;
+ samples = maxu(samples, 100 * device->Frequency / 1000);
- memset(&DSCBDescription, 0, sizeof(DSCBUFFERDESC));
- DSCBDescription.dwSize = sizeof(DSCBUFFERDESC);
- DSCBDescription.dwFlags = 0;
- DSCBDescription.dwBufferBytes = samples * InputType.Format.nBlockAlign;
- DSCBDescription.lpwfxFormat = &InputType.Format;
+ memset(&DSCBDescription, 0, sizeof(DSCBUFFERDESC));
+ DSCBDescription.dwSize = sizeof(DSCBUFFERDESC);
+ DSCBDescription.dwFlags = 0;
+ DSCBDescription.dwBufferBytes = samples * InputType.Format.nBlockAlign;
+ DSCBDescription.lpwfxFormat = &InputType.Format;
+ //DirectSoundCapture Init code
+ hr = DirectSoundCaptureCreate(guid, &self->DSC, NULL);
+ if(SUCCEEDED(hr))
hr = IDirectSoundCapture_CreateCaptureBuffer(self->DSC, &DSCBDescription, &self->DSCbuffer, NULL);
- }
if(SUCCEEDED(hr))
{
- self->Ring = CreateRingBuffer(InputType.Format.nBlockAlign, device->UpdateSize * device->NumUpdates);
+ self->Ring = ll_ringbuffer_create(device->UpdateSize*device->NumUpdates,
+ InputType.Format.nBlockAlign, false);
if(self->Ring == NULL)
hr = DSERR_OUTOFMEMORY;
}
@@ -833,7 +866,7 @@ static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *devi
{
ERR("Device init failed: 0x%08lx\n", hr);
- DestroyRingBuffer(self->Ring);
+ ll_ringbuffer_free(self->Ring);
self->Ring = NULL;
if(self->DSCbuffer != NULL)
IDirectSoundCaptureBuffer_Release(self->DSCbuffer);
@@ -848,27 +881,11 @@ static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *devi
self->BufferBytes = DSCBDescription.dwBufferBytes;
SetDefaultWFXChannelOrder(device);
- al_string_copy_cstr(&device->DeviceName, deviceName);
+ alstr_copy_cstr(&device->DeviceName, deviceName);
return ALC_NO_ERROR;
}
-static void ALCdsoundCapture_close(ALCdsoundCapture *self)
-{
- DestroyRingBuffer(self->Ring);
- self->Ring = NULL;
-
- if(self->DSCbuffer != NULL)
- {
- IDirectSoundCaptureBuffer_Stop(self->DSCbuffer);
- IDirectSoundCaptureBuffer_Release(self->DSCbuffer);
- self->DSCbuffer = NULL;
- }
-
- IDirectSoundCapture_Release(self->DSC);
- self->DSC = NULL;
-}
-
static ALCboolean ALCdsoundCapture_start(ALCdsoundCapture *self)
{
HRESULT hr;
@@ -877,7 +894,8 @@ static ALCboolean ALCdsoundCapture_start(ALCdsoundCapture *self)
if(FAILED(hr))
{
ERR("start failed: 0x%08lx\n", hr);
- aluHandleDisconnect(STATIC_CAST(ALCbackend, self)->mDevice);
+ aluHandleDisconnect(STATIC_CAST(ALCbackend, self)->mDevice,
+ "Failure starting capture: 0x%lx", hr);
return ALC_FALSE;
}
@@ -892,13 +910,14 @@ static void ALCdsoundCapture_stop(ALCdsoundCapture *self)
if(FAILED(hr))
{
ERR("stop failed: 0x%08lx\n", hr);
- aluHandleDisconnect(STATIC_CAST(ALCbackend, self)->mDevice);
+ aluHandleDisconnect(STATIC_CAST(ALCbackend, self)->mDevice,
+ "Failure stopping capture: 0x%lx", hr);
}
}
static ALCenum ALCdsoundCapture_captureSamples(ALCdsoundCapture *self, ALCvoid *buffer, ALCuint samples)
{
- ReadRingBuffer(self->Ring, buffer, samples);
+ ll_ringbuffer_read(self->Ring, buffer, samples);
return ALC_NO_ERROR;
}
@@ -911,10 +930,10 @@ static ALCuint ALCdsoundCapture_availableSamples(ALCdsoundCapture *self)
DWORD FrameSize;
HRESULT hr;
- if(!device->Connected)
+ if(!ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
goto done;
- FrameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ FrameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
BufferBytes = self->BufferBytes;
LastCursor = self->Cursor;
@@ -930,9 +949,9 @@ static ALCuint ALCdsoundCapture_availableSamples(ALCdsoundCapture *self)
}
if(SUCCEEDED(hr))
{
- WriteRingBuffer(self->Ring, ReadPtr1, ReadCnt1/FrameSize);
+ ll_ringbuffer_write(self->Ring, ReadPtr1, ReadCnt1/FrameSize);
if(ReadPtr2 != NULL)
- WriteRingBuffer(self->Ring, ReadPtr2, ReadCnt2/FrameSize);
+ ll_ringbuffer_write(self->Ring, ReadPtr2, ReadCnt2/FrameSize);
hr = IDirectSoundCaptureBuffer_Unlock(self->DSCbuffer,
ReadPtr1, ReadCnt1,
ReadPtr2, ReadCnt2);
@@ -942,19 +961,14 @@ static ALCuint ALCdsoundCapture_availableSamples(ALCdsoundCapture *self)
if(FAILED(hr))
{
ERR("update failed: 0x%08lx\n", hr);
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failure retrieving capture data: 0x%lx", hr);
}
done:
- return RingBufferSize(self->Ring);
+ return (ALCuint)ll_ringbuffer_read_space(self->Ring);
}
-static inline void AppendAllDevicesList2(const DevMap *entry)
-{ AppendAllDevicesList(al_string_get_cstr(entry->name)); }
-static inline void AppendCaptureDeviceList2(const DevMap *entry)
-{ AppendCaptureDeviceList(al_string_get_cstr(entry->name)); }
-
typedef struct ALCdsoundBackendFactory {
DERIVE_FROM_TYPE(ALCbackendFactory);
} ALCdsoundBackendFactory;
@@ -965,7 +979,7 @@ ALCbackendFactory *ALCdsoundBackendFactory_getFactory(void);
static ALCboolean ALCdsoundBackendFactory_init(ALCdsoundBackendFactory *self);
static void ALCdsoundBackendFactory_deinit(ALCdsoundBackendFactory *self);
static ALCboolean ALCdsoundBackendFactory_querySupport(ALCdsoundBackendFactory *self, ALCbackend_Type type);
-static void ALCdsoundBackendFactory_probe(ALCdsoundBackendFactory *self, enum DevProbe type);
+static void ALCdsoundBackendFactory_probe(ALCdsoundBackendFactory *self, enum DevProbe type, al_string *outnames);
static ALCbackend* ALCdsoundBackendFactory_createBackend(ALCdsoundBackendFactory *self, ALCdevice *device, ALCbackend_Type type);
DEFINE_ALCBACKENDFACTORY_VTABLE(ALCdsoundBackendFactory);
@@ -1009,7 +1023,7 @@ static ALCboolean ALCdsoundBackendFactory_querySupport(ALCdsoundBackendFactory*
return ALC_FALSE;
}
-static void ALCdsoundBackendFactory_probe(ALCdsoundBackendFactory* UNUSED(self), enum DevProbe type)
+static void ALCdsoundBackendFactory_probe(ALCdsoundBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
HRESULT hr, hrcom;
@@ -1017,12 +1031,17 @@ static void ALCdsoundBackendFactory_probe(ALCdsoundBackendFactory* UNUSED(self),
hrcom = CoInitialize(NULL);
switch(type)
{
+#define APPEND_OUTNAME(e) do { \
+ if(!alstr_empty((e)->name)) \
+ alstr_append_range(outnames, VECTOR_BEGIN((e)->name), \
+ VECTOR_END((e)->name)+1); \
+} while(0)
case ALL_DEVICE_PROBE:
clear_devlist(&PlaybackDevices);
hr = DirectSoundEnumerateW(DSoundEnumDevices, &PlaybackDevices);
if(FAILED(hr))
ERR("Error enumerating DirectSound playback devices (0x%lx)!\n", hr);
- VECTOR_FOR_EACH(const DevMap, PlaybackDevices, AppendAllDevicesList2);
+ VECTOR_FOR_EACH(const DevMap, PlaybackDevices, APPEND_OUTNAME);
break;
case CAPTURE_DEVICE_PROBE:
@@ -1030,8 +1049,9 @@ static void ALCdsoundBackendFactory_probe(ALCdsoundBackendFactory* UNUSED(self),
hr = DirectSoundCaptureEnumerateW(DSoundEnumDevices, &CaptureDevices);
if(FAILED(hr))
ERR("Error enumerating DirectSound capture devices (0x%lx)!\n", hr);
- VECTOR_FOR_EACH(const DevMap, CaptureDevices, AppendCaptureDeviceList2);
+ VECTOR_FOR_EACH(const DevMap, CaptureDevices, APPEND_OUTNAME);
break;
+#undef APPEND_OUTNAME
}
if(SUCCEEDED(hrcom))
CoUninitialize();
diff --git a/Alc/backends/jack.c b/Alc/backends/jack.c
index 69d1277a..fdbe93f2 100644
--- a/Alc/backends/jack.c
+++ b/Alc/backends/jack.c
@@ -26,6 +26,8 @@
#include "alMain.h"
#include "alu.h"
+#include "alconfig.h"
+#include "ringbuffer.h"
#include "threads.h"
#include "compat.h"
@@ -54,6 +56,7 @@ static const ALCchar jackDevice[] = "JACK Default";
MAGIC(jack_get_ports); \
MAGIC(jack_free); \
MAGIC(jack_get_sample_rate); \
+ MAGIC(jack_set_error_function); \
MAGIC(jack_set_process_callback); \
MAGIC(jack_set_buffer_size_callback); \
MAGIC(jack_set_buffer_size); \
@@ -62,6 +65,7 @@ static const ALCchar jackDevice[] = "JACK Default";
static void *jack_handle;
#define MAKE_FUNC(f) static __typeof(f) * p##f
JACK_FUNCS(MAKE_FUNC);
+static __typeof(jack_error_callback) * pjack_error_callback;
#undef MAKE_FUNC
#define jack_client_open pjack_client_open
@@ -78,10 +82,12 @@ JACK_FUNCS(MAKE_FUNC);
#define jack_get_ports pjack_get_ports
#define jack_free pjack_free
#define jack_get_sample_rate pjack_get_sample_rate
+#define jack_set_error_function pjack_set_error_function
#define jack_set_process_callback pjack_set_process_callback
#define jack_set_buffer_size_callback pjack_set_buffer_size_callback
#define jack_set_buffer_size pjack_set_buffer_size
#define jack_get_buffer_size pjack_get_buffer_size
+#define jack_error_callback (*pjack_error_callback)
#endif
@@ -94,26 +100,42 @@ static ALCboolean jack_load(void)
#ifdef HAVE_DYNLOAD
if(!jack_handle)
{
- jack_handle = LoadLib("libjack.so.0");
+ al_string missing_funcs = AL_STRING_INIT_STATIC();
+
+#ifdef _WIN32
+#define JACKLIB "libjack.dll"
+#else
+#define JACKLIB "libjack.so.0"
+#endif
+ jack_handle = LoadLib(JACKLIB);
if(!jack_handle)
+ {
+ WARN("Failed to load %s\n", JACKLIB);
return ALC_FALSE;
+ }
error = ALC_FALSE;
#define LOAD_FUNC(f) do { \
p##f = GetSymbol(jack_handle, #f); \
if(p##f == NULL) { \
error = ALC_TRUE; \
+ alstr_append_cstr(&missing_funcs, "\n" #f); \
} \
} while(0)
JACK_FUNCS(LOAD_FUNC);
#undef LOAD_FUNC
+ /* Optional symbols. These don't exist in all versions of JACK. */
+#define LOAD_SYM(f) p##f = GetSymbol(jack_handle, #f)
+ LOAD_SYM(jack_error_callback);
+#undef LOAD_SYM
if(error)
{
+ WARN("Missing expected functions:%s\n", alstr_get_cstr(missing_funcs));
CloseLib(jack_handle);
jack_handle = NULL;
- return ALC_FALSE;
}
+ alstr_reset(&missing_funcs);
}
#endif
@@ -128,9 +150,9 @@ typedef struct ALCjackPlayback {
jack_port_t *Port[MAX_OUTPUT_CHANNELS];
ll_ringbuffer_t *Ring;
- alcnd_t Cond;
+ alsem_t Sem;
- volatile int killNow;
+ ATOMIC(ALenum) killNow;
althrd_t thread;
} ALCjackPlayback;
@@ -142,15 +164,14 @@ static int ALCjackPlayback_mixerProc(void *arg);
static void ALCjackPlayback_Construct(ALCjackPlayback *self, ALCdevice *device);
static void ALCjackPlayback_Destruct(ALCjackPlayback *self);
static ALCenum ALCjackPlayback_open(ALCjackPlayback *self, const ALCchar *name);
-static void ALCjackPlayback_close(ALCjackPlayback *self);
static ALCboolean ALCjackPlayback_reset(ALCjackPlayback *self);
static ALCboolean ALCjackPlayback_start(ALCjackPlayback *self);
static void ALCjackPlayback_stop(ALCjackPlayback *self);
static DECLARE_FORWARD2(ALCjackPlayback, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
static DECLARE_FORWARD(ALCjackPlayback, ALCbackend, ALCuint, availableSamples)
-static ALint64 ALCjackPlayback_getLatency(ALCjackPlayback *self);
-static void ALCjackPlayback_lock(ALCjackPlayback *self);
-static void ALCjackPlayback_unlock(ALCjackPlayback *self);
+static ClockLatency ALCjackPlayback_getClockLatency(ALCjackPlayback *self);
+static DECLARE_FORWARD(ALCjackPlayback, ALCbackend, void, lock)
+static DECLARE_FORWARD(ALCjackPlayback, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCjackPlayback)
DEFINE_ALCBACKEND_VTABLE(ALCjackPlayback);
@@ -163,14 +184,14 @@ static void ALCjackPlayback_Construct(ALCjackPlayback *self, ALCdevice *device)
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCjackPlayback, ALCbackend, self);
- alcnd_init(&self->Cond);
+ alsem_init(&self->Sem, 0);
self->Client = NULL;
for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
self->Port[i] = NULL;
self->Ring = NULL;
- self->killNow = 1;
+ ATOMIC_INIT(&self->killNow, AL_TRUE);
}
static void ALCjackPlayback_Destruct(ALCjackPlayback *self)
@@ -189,7 +210,7 @@ static void ALCjackPlayback_Destruct(ALCjackPlayback *self)
self->Client = NULL;
}
- alcnd_destroy(&self->Cond);
+ alsem_destroy(&self->Sem);
ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}
@@ -204,19 +225,23 @@ static int ALCjackPlayback_bufferSizeNotify(jack_nframes_t numframes, void *arg)
ALCjackPlayback_lock(self);
device->UpdateSize = numframes;
device->NumUpdates = 2;
- TRACE("%u update size x%u\n", device->UpdateSize, device->NumUpdates);
bufsize = device->UpdateSize;
- if(ConfigValueUInt(al_string_get_cstr(device->DeviceName), "jack", "buffer-size", &bufsize))
+ if(ConfigValueUInt(alstr_get_cstr(device->DeviceName), "jack", "buffer-size", &bufsize))
bufsize = maxu(NextPowerOf2(bufsize), device->UpdateSize);
- bufsize += device->UpdateSize;
+ device->NumUpdates = (bufsize+device->UpdateSize) / device->UpdateSize;
+
+ TRACE("%u update size x%u\n", device->UpdateSize, device->NumUpdates);
ll_ringbuffer_free(self->Ring);
- self->Ring = ll_ringbuffer_create(bufsize, FrameSizeFromDevFmt(device->FmtChans, device->FmtType));
+ self->Ring = ll_ringbuffer_create(bufsize,
+ FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder),
+ true
+ );
if(!self->Ring)
{
ERR("Failed to reallocate ringbuffer\n");
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failed to reallocate %u-sample buffer", bufsize);
}
ALCjackPlayback_unlock(self);
return 0;
@@ -230,7 +255,7 @@ static int ALCjackPlayback_process(jack_nframes_t numframes, void *arg)
ll_ringbuffer_data_t data[2];
jack_nframes_t total = 0;
jack_nframes_t todo;
- ALuint i, c, numchans;
+ ALsizei i, c, numchans;
ll_ringbuffer_get_read_vector(self->Ring, data);
@@ -241,8 +266,9 @@ static int ALCjackPlayback_process(jack_nframes_t numframes, void *arg)
todo = minu(numframes, data[0].len);
for(c = 0;c < numchans;c++)
{
- for(i = 0;i < todo;i++)
- out[c][i] = ((ALfloat*)data[0].buf)[i*numchans + c];
+ const ALfloat *restrict in = ((ALfloat*)data[0].buf) + c;
+ for(i = 0;(jack_nframes_t)i < todo;i++)
+ out[c][i] = in[i*numchans];
out[c] += todo;
}
total += todo;
@@ -252,22 +278,23 @@ static int ALCjackPlayback_process(jack_nframes_t numframes, void *arg)
{
for(c = 0;c < numchans;c++)
{
- for(i = 0;i < todo;i++)
- out[c][i] = ((ALfloat*)data[1].buf)[i*numchans + c];
+ const ALfloat *restrict in = ((ALfloat*)data[1].buf) + c;
+ for(i = 0;(jack_nframes_t)i < todo;i++)
+ out[c][i] = in[i*numchans];
out[c] += todo;
}
total += todo;
}
ll_ringbuffer_read_advance(self->Ring, total);
- alcnd_signal(&self->Cond);
+ alsem_post(&self->Sem);
if(numframes > total)
{
todo = numframes-total;
for(c = 0;c < numchans;c++)
{
- for(i = 0;i < todo;i++)
+ for(i = 0;(jack_nframes_t)i < todo;i++)
out[c][i] = 0.0f;
}
}
@@ -285,27 +312,16 @@ static int ALCjackPlayback_mixerProc(void *arg)
althrd_setname(althrd_current(), MIXER_THREAD_NAME);
ALCjackPlayback_lock(self);
- while(!self->killNow && device->Connected)
+ while(!ATOMIC_LOAD(&self->killNow, almemory_order_acquire) &&
+ ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
{
ALuint todo, len1, len2;
- /* NOTE: Unfortunately, there is an unavoidable race condition here.
- * It's possible for the process() method to run, updating the read
- * pointer and signaling the condition variable, in between the mixer
- * loop checking the write size and waiting for the condition variable.
- * This will cause the mixer loop to wait until the *next* process()
- * invocation, most likely writing silence for it.
- *
- * However, this should only happen if the mixer is running behind
- * anyway (as ideally we'll be asleep in alcnd_wait by the time the
- * process() method is invoked), so this behavior is not unwarranted.
- * It's unfortunate since it'll be wasting time sleeping that could be
- * used to catch up, but there's no way around it without blocking in
- * the process() method.
- */
if(ll_ringbuffer_write_space(self->Ring) < device->UpdateSize)
{
- alcnd_wait(&self->Cond, &STATIC_CAST(ALCbackend,self)->mMutex);
+ ALCjackPlayback_unlock(self);
+ alsem_wait(&self->Sem);
+ ALCjackPlayback_lock(self);
continue;
}
@@ -355,29 +371,15 @@ static ALCenum ALCjackPlayback_open(ALCjackPlayback *self, const ALCchar *name)
jack_set_process_callback(self->Client, ALCjackPlayback_process, self);
jack_set_buffer_size_callback(self->Client, ALCjackPlayback_bufferSizeNotify, self);
- al_string_copy_cstr(&device->DeviceName, name);
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
}
-static void ALCjackPlayback_close(ALCjackPlayback *self)
-{
- ALuint i;
-
- for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
- {
- if(self->Port[i])
- jack_port_unregister(self->Client, self->Port[i]);
- self->Port[i] = NULL;
- }
- jack_client_close(self->Client);
- self->Client = NULL;
-}
-
static ALCboolean ALCjackPlayback_reset(ALCjackPlayback *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- ALuint numchans, i;
+ ALsizei numchans, i;
ALuint bufsize;
for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
@@ -388,23 +390,21 @@ static ALCboolean ALCjackPlayback_reset(ALCjackPlayback *self)
}
/* Ignore the requested buffer metrics and just keep one JACK-sized buffer
- * ready for when requested. Note that one period's worth of audio in the
- * ring buffer will always be left unfilled because one element of the ring
- * buffer will not be writeable, and we only write in period-sized chunks.
+ * ready for when requested.
*/
device->Frequency = jack_get_sample_rate(self->Client);
device->UpdateSize = jack_get_buffer_size(self->Client);
device->NumUpdates = 2;
bufsize = device->UpdateSize;
- if(ConfigValueUInt(al_string_get_cstr(device->DeviceName), "jack", "buffer-size", &bufsize))
+ if(ConfigValueUInt(alstr_get_cstr(device->DeviceName), "jack", "buffer-size", &bufsize))
bufsize = maxu(NextPowerOf2(bufsize), device->UpdateSize);
- bufsize += device->UpdateSize;
+ device->NumUpdates = (bufsize+device->UpdateSize) / device->UpdateSize;
/* Force 32-bit float output. */
device->FmtType = DevFmtFloat;
- numchans = ChannelsFromDevFmt(device->FmtChans);
+ numchans = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
for(i = 0;i < numchans;i++)
{
char name[64];
@@ -433,7 +433,10 @@ static ALCboolean ALCjackPlayback_reset(ALCjackPlayback *self)
}
ll_ringbuffer_free(self->Ring);
- self->Ring = ll_ringbuffer_create(bufsize, FrameSizeFromDevFmt(device->FmtChans, device->FmtType));
+ self->Ring = ll_ringbuffer_create(bufsize,
+ FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder),
+ true
+ );
if(!self->Ring)
{
ERR("Failed to allocate ringbuffer\n");
@@ -448,7 +451,7 @@ static ALCboolean ALCjackPlayback_reset(ALCjackPlayback *self)
static ALCboolean ALCjackPlayback_start(ALCjackPlayback *self)
{
const char **ports;
- ALuint i;
+ ALsizei i;
if(jack_activate(self->Client))
{
@@ -475,7 +478,7 @@ static ALCboolean ALCjackPlayback_start(ALCjackPlayback *self)
}
jack_free(ports);
- self->killNow = 0;
+ ATOMIC_STORE(&self->killNow, AL_FALSE, almemory_order_release);
if(althrd_create(&self->thread, ALCjackPlayback_mixerProc, self) != althrd_success)
{
jack_deactivate(self->Client);
@@ -489,47 +492,36 @@ static void ALCjackPlayback_stop(ALCjackPlayback *self)
{
int res;
- if(self->killNow)
+ if(ATOMIC_EXCHANGE(&self->killNow, AL_TRUE, almemory_order_acq_rel))
return;
- self->killNow = 1;
- /* Lock the backend to ensure we don't flag the mixer to die and signal the
- * mixer to wake up in between it checking the flag and going to sleep and
- * wait for a wakeup (potentially leading to it never waking back up to see
- * the flag). */
- ALCjackPlayback_lock(self);
- ALCjackPlayback_unlock(self);
- alcnd_signal(&self->Cond);
+ alsem_post(&self->Sem);
althrd_join(self->thread, &res);
jack_deactivate(self->Client);
}
-static ALint64 ALCjackPlayback_getLatency(ALCjackPlayback *self)
+static ClockLatency ALCjackPlayback_getClockLatency(ALCjackPlayback *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- ALint64 latency;
+ ClockLatency ret;
ALCjackPlayback_lock(self);
- latency = ll_ringbuffer_read_space(self->Ring);
+ ret.ClockTime = GetDeviceClockTime(device);
+ ret.Latency = ll_ringbuffer_read_space(self->Ring) * DEVICE_CLOCK_RES /
+ device->Frequency;
ALCjackPlayback_unlock(self);
- return latency * 1000000000 / device->Frequency;
+ return ret;
}
-static void ALCjackPlayback_lock(ALCjackPlayback *self)
+static void jack_msg_handler(const char *message)
{
- almtx_lock(&STATIC_CAST(ALCbackend,self)->mMutex);
+ WARN("%s\n", message);
}
-static void ALCjackPlayback_unlock(ALCjackPlayback *self)
-{
- almtx_unlock(&STATIC_CAST(ALCbackend,self)->mMutex);
-}
-
-
typedef struct ALCjackBackendFactory {
DERIVE_FROM_TYPE(ALCbackendFactory);
} ALCjackBackendFactory;
@@ -537,6 +529,7 @@ typedef struct ALCjackBackendFactory {
static ALCboolean ALCjackBackendFactory_init(ALCjackBackendFactory* UNUSED(self))
{
+ void (*old_error_cb)(const char*);
jack_client_t *client;
jack_status_t status;
@@ -545,7 +538,11 @@ static ALCboolean ALCjackBackendFactory_init(ALCjackBackendFactory* UNUSED(self)
if(!GetConfigValueBool(NULL, "jack", "spawn-server", 0))
ClientOptions |= JackNoStartServer;
+
+ old_error_cb = (&jack_error_callback ? jack_error_callback : NULL);
+ jack_set_error_function(jack_msg_handler);
client = jack_client_open("alsoft", ClientOptions, &status, NULL);
+ jack_set_error_function(old_error_cb);
if(client == NULL)
{
WARN("jack_client_open() failed, 0x%02x\n", status);
@@ -574,12 +571,12 @@ static ALCboolean ALCjackBackendFactory_querySupport(ALCjackBackendFactory* UNUS
return ALC_FALSE;
}
-static void ALCjackBackendFactory_probe(ALCjackBackendFactory* UNUSED(self), enum DevProbe type)
+static void ALCjackBackendFactory_probe(ALCjackBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
switch(type)
{
case ALL_DEVICE_PROBE:
- AppendAllDevicesList(jackDevice);
+ alstr_append_range(outnames, jackDevice, jackDevice+sizeof(jackDevice));
break;
case CAPTURE_DEVICE_PROBE:
diff --git a/Alc/backends/loopback.c b/Alc/backends/loopback.c
index 3e577f78..e9940086 100644
--- a/Alc/backends/loopback.c
+++ b/Alc/backends/loopback.c
@@ -35,13 +35,12 @@ typedef struct ALCloopback {
static void ALCloopback_Construct(ALCloopback *self, ALCdevice *device);
static DECLARE_FORWARD(ALCloopback, ALCbackend, void, Destruct)
static ALCenum ALCloopback_open(ALCloopback *self, const ALCchar *name);
-static void ALCloopback_close(ALCloopback *self);
static ALCboolean ALCloopback_reset(ALCloopback *self);
static ALCboolean ALCloopback_start(ALCloopback *self);
static void ALCloopback_stop(ALCloopback *self);
static DECLARE_FORWARD2(ALCloopback, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
static DECLARE_FORWARD(ALCloopback, ALCbackend, ALCuint, availableSamples)
-static DECLARE_FORWARD(ALCloopback, ALCbackend, ALint64, getLatency)
+static DECLARE_FORWARD(ALCloopback, ALCbackend, ClockLatency, getClockLatency)
static DECLARE_FORWARD(ALCloopback, ALCbackend, void, lock)
static DECLARE_FORWARD(ALCloopback, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCloopback)
@@ -59,14 +58,10 @@ static ALCenum ALCloopback_open(ALCloopback *self, const ALCchar *name)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- al_string_copy_cstr(&device->DeviceName, name);
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
}
-static void ALCloopback_close(ALCloopback* UNUSED(self))
-{
-}
-
static ALCboolean ALCloopback_reset(ALCloopback *self)
{
SetDefaultWFXChannelOrder(STATIC_CAST(ALCbackend, self)->mDevice);
@@ -92,7 +87,7 @@ ALCbackendFactory *ALCloopbackFactory_getFactory(void);
static ALCboolean ALCloopbackFactory_init(ALCloopbackFactory *self);
static DECLARE_FORWARD(ALCloopbackFactory, ALCbackendFactory, void, deinit)
static ALCboolean ALCloopbackFactory_querySupport(ALCloopbackFactory *self, ALCbackend_Type type);
-static void ALCloopbackFactory_probe(ALCloopbackFactory *self, enum DevProbe type);
+static void ALCloopbackFactory_probe(ALCloopbackFactory *self, enum DevProbe type, al_string *outnames);
static ALCbackend* ALCloopbackFactory_createBackend(ALCloopbackFactory *self, ALCdevice *device, ALCbackend_Type type);
DEFINE_ALCBACKENDFACTORY_VTABLE(ALCloopbackFactory);
@@ -115,7 +110,7 @@ static ALCboolean ALCloopbackFactory_querySupport(ALCloopbackFactory* UNUSED(sel
return ALC_FALSE;
}
-static void ALCloopbackFactory_probe(ALCloopbackFactory* UNUSED(self), enum DevProbe UNUSED(type))
+static void ALCloopbackFactory_probe(ALCloopbackFactory* UNUSED(self), enum DevProbe UNUSED(type), al_string* UNUSED(outnames))
{
}
diff --git a/Alc/backends/null.c b/Alc/backends/null.c
index 99729c0a..d1c110e8 100644
--- a/Alc/backends/null.c
+++ b/Alc/backends/null.c
@@ -36,7 +36,7 @@
typedef struct ALCnullBackend {
DERIVE_FROM_TYPE(ALCbackend);
- volatile int killNow;
+ ATOMIC(int) killNow;
althrd_t thread;
} ALCnullBackend;
@@ -45,13 +45,12 @@ static int ALCnullBackend_mixerProc(void *ptr);
static void ALCnullBackend_Construct(ALCnullBackend *self, ALCdevice *device);
static DECLARE_FORWARD(ALCnullBackend, ALCbackend, void, Destruct)
static ALCenum ALCnullBackend_open(ALCnullBackend *self, const ALCchar *name);
-static void ALCnullBackend_close(ALCnullBackend *self);
static ALCboolean ALCnullBackend_reset(ALCnullBackend *self);
static ALCboolean ALCnullBackend_start(ALCnullBackend *self);
static void ALCnullBackend_stop(ALCnullBackend *self);
static DECLARE_FORWARD2(ALCnullBackend, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
static DECLARE_FORWARD(ALCnullBackend, ALCbackend, ALCuint, availableSamples)
-static DECLARE_FORWARD(ALCnullBackend, ALCbackend, ALint64, getLatency)
+static DECLARE_FORWARD(ALCnullBackend, ALCbackend, ClockLatency, getClockLatency)
static DECLARE_FORWARD(ALCnullBackend, ALCbackend, void, lock)
static DECLARE_FORWARD(ALCnullBackend, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCnullBackend)
@@ -66,6 +65,8 @@ static void ALCnullBackend_Construct(ALCnullBackend *self, ALCdevice *device)
{
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCnullBackend, ALCbackend, self);
+
+ ATOMIC_INIT(&self->killNow, AL_TRUE);
}
@@ -87,7 +88,8 @@ static int ALCnullBackend_mixerProc(void *ptr)
ERR("Failed to get starting time\n");
return 1;
}
- while(!self->killNow && device->Connected)
+ while(!ATOMIC_LOAD(&self->killNow, almemory_order_acquire) &&
+ ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
{
if(altimespec_get(&now, AL_TIME_UTC) != AL_TIME_UTC)
{
@@ -109,7 +111,9 @@ static int ALCnullBackend_mixerProc(void *ptr)
al_nssleep(restTime);
else while(avail-done >= device->UpdateSize)
{
+ ALCnullBackend_lock(self);
aluMixData(device, NULL, device->UpdateSize);
+ ALCnullBackend_unlock(self);
done += device->UpdateSize;
}
}
@@ -128,15 +132,11 @@ static ALCenum ALCnullBackend_open(ALCnullBackend *self, const ALCchar *name)
return ALC_INVALID_VALUE;
device = STATIC_CAST(ALCbackend, self)->mDevice;
- al_string_copy_cstr(&device->DeviceName, name);
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
}
-static void ALCnullBackend_close(ALCnullBackend* UNUSED(self))
-{
-}
-
static ALCboolean ALCnullBackend_reset(ALCnullBackend *self)
{
SetDefaultWFXChannelOrder(STATIC_CAST(ALCbackend, self)->mDevice);
@@ -145,7 +145,7 @@ static ALCboolean ALCnullBackend_reset(ALCnullBackend *self)
static ALCboolean ALCnullBackend_start(ALCnullBackend *self)
{
- self->killNow = 0;
+ ATOMIC_STORE(&self->killNow, AL_FALSE, almemory_order_release);
if(althrd_create(&self->thread, ALCnullBackend_mixerProc, self) != althrd_success)
return ALC_FALSE;
return ALC_TRUE;
@@ -155,10 +155,8 @@ static void ALCnullBackend_stop(ALCnullBackend *self)
{
int res;
- if(self->killNow)
+ if(ATOMIC_EXCHANGE(&self->killNow, AL_TRUE, almemory_order_acq_rel))
return;
-
- self->killNow = 1;
althrd_join(self->thread, &res);
}
@@ -173,7 +171,7 @@ ALCbackendFactory *ALCnullBackendFactory_getFactory(void);
static ALCboolean ALCnullBackendFactory_init(ALCnullBackendFactory *self);
static DECLARE_FORWARD(ALCnullBackendFactory, ALCbackendFactory, void, deinit)
static ALCboolean ALCnullBackendFactory_querySupport(ALCnullBackendFactory *self, ALCbackend_Type type);
-static void ALCnullBackendFactory_probe(ALCnullBackendFactory *self, enum DevProbe type);
+static void ALCnullBackendFactory_probe(ALCnullBackendFactory *self, enum DevProbe type, al_string *outnames);
static ALCbackend* ALCnullBackendFactory_createBackend(ALCnullBackendFactory *self, ALCdevice *device, ALCbackend_Type type);
DEFINE_ALCBACKENDFACTORY_VTABLE(ALCnullBackendFactory);
@@ -197,14 +195,13 @@ static ALCboolean ALCnullBackendFactory_querySupport(ALCnullBackendFactory* UNUS
return ALC_FALSE;
}
-static void ALCnullBackendFactory_probe(ALCnullBackendFactory* UNUSED(self), enum DevProbe type)
+static void ALCnullBackendFactory_probe(ALCnullBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
switch(type)
{
case ALL_DEVICE_PROBE:
- AppendAllDevicesList(nullDevice);
- break;
case CAPTURE_DEVICE_PROBE:
+ alstr_append_range(outnames, nullDevice, nullDevice+sizeof(nullDevice));
break;
}
}
diff --git a/Alc/backends/opensl.c b/Alc/backends/opensl.c
index 7b8fdb25..d8ae001b 100644
--- a/Alc/backends/opensl.c
+++ b/Alc/backends/opensl.c
@@ -22,38 +22,25 @@
#include "config.h"
#include <stdlib.h>
+#include <jni.h>
#include "alMain.h"
#include "alu.h"
+#include "ringbuffer.h"
#include "threads.h"
+#include "compat.h"
+
+#include "backends/base.h"
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>
+#include <SLES/OpenSLES_AndroidConfiguration.h>
/* Helper macros */
#define VCALL(obj, func) ((*(obj))->func((obj), EXTRACT_VCALL_ARGS
#define VCALL0(obj, func) ((*(obj))->func((obj) EXTRACT_VCALL_ARGS
-typedef struct {
- /* engine interfaces */
- SLObjectItf engineObject;
- SLEngineItf engine;
-
- /* output mix interfaces */
- SLObjectItf outputMix;
-
- /* buffer queue player interfaces */
- SLObjectItf bufferQueueObject;
-
- void *buffer;
- ALuint bufferSize;
- ALuint curBuffer;
-
- ALuint frameSize;
-} osl_data;
-
-
static const ALCchar opensl_device[] = "OpenSL";
@@ -79,10 +66,31 @@ static SLuint32 GetChannelMask(enum DevFmtChannels chans)
SL_SPEAKER_FRONT_CENTER|SL_SPEAKER_LOW_FREQUENCY|
SL_SPEAKER_BACK_LEFT|SL_SPEAKER_BACK_RIGHT|
SL_SPEAKER_SIDE_LEFT|SL_SPEAKER_SIDE_RIGHT;
- case DevFmtBFormat3D: break;
+ case DevFmtAmbi3D:
+ break;
+ }
+ return 0;
+}
+
+#ifdef SL_DATAFORMAT_PCM_EX
+static SLuint32 GetTypeRepresentation(enum DevFmtType type)
+{
+ switch(type)
+ {
+ case DevFmtUByte:
+ case DevFmtUShort:
+ case DevFmtUInt:
+ return SL_PCM_REPRESENTATION_UNSIGNED_INT;
+ case DevFmtByte:
+ case DevFmtShort:
+ case DevFmtInt:
+ return SL_PCM_REPRESENTATION_SIGNED_INT;
+ case DevFmtFloat:
+ return SL_PCM_REPRESENTATION_FLOAT;
}
return 0;
}
+#endif
static const char *res_str(SLresult result)
{
@@ -123,311 +131,940 @@ static const char *res_str(SLresult result)
ERR("%s: %s\n", (s), res_str((x))); \
} while(0)
+
+typedef struct ALCopenslPlayback {
+ DERIVE_FROM_TYPE(ALCbackend);
+
+ /* engine interfaces */
+ SLObjectItf mEngineObj;
+ SLEngineItf mEngine;
+
+ /* output mix interfaces */
+ SLObjectItf mOutputMix;
+
+ /* buffer queue player interfaces */
+ SLObjectItf mBufferQueueObj;
+
+ ll_ringbuffer_t *mRing;
+ alsem_t mSem;
+
+ ALsizei mFrameSize;
+
+ ATOMIC(ALenum) mKillNow;
+ althrd_t mThread;
+} ALCopenslPlayback;
+
+static void ALCopenslPlayback_process(SLAndroidSimpleBufferQueueItf bq, void *context);
+static int ALCopenslPlayback_mixerProc(void *arg);
+
+static void ALCopenslPlayback_Construct(ALCopenslPlayback *self, ALCdevice *device);
+static void ALCopenslPlayback_Destruct(ALCopenslPlayback *self);
+static ALCenum ALCopenslPlayback_open(ALCopenslPlayback *self, const ALCchar *name);
+static ALCboolean ALCopenslPlayback_reset(ALCopenslPlayback *self);
+static ALCboolean ALCopenslPlayback_start(ALCopenslPlayback *self);
+static void ALCopenslPlayback_stop(ALCopenslPlayback *self);
+static DECLARE_FORWARD2(ALCopenslPlayback, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
+static DECLARE_FORWARD(ALCopenslPlayback, ALCbackend, ALCuint, availableSamples)
+static ClockLatency ALCopenslPlayback_getClockLatency(ALCopenslPlayback *self);
+static DECLARE_FORWARD(ALCopenslPlayback, ALCbackend, void, lock)
+static DECLARE_FORWARD(ALCopenslPlayback, ALCbackend, void, unlock)
+DECLARE_DEFAULT_ALLOCATORS(ALCopenslPlayback)
+
+DEFINE_ALCBACKEND_VTABLE(ALCopenslPlayback);
+
+
+static void ALCopenslPlayback_Construct(ALCopenslPlayback *self, ALCdevice *device)
+{
+ ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
+ SET_VTABLE2(ALCopenslPlayback, ALCbackend, self);
+
+ self->mEngineObj = NULL;
+ self->mEngine = NULL;
+ self->mOutputMix = NULL;
+ self->mBufferQueueObj = NULL;
+
+ self->mRing = NULL;
+ alsem_init(&self->mSem, 0);
+
+ self->mFrameSize = 0;
+
+ ATOMIC_INIT(&self->mKillNow, AL_FALSE);
+}
+
+static void ALCopenslPlayback_Destruct(ALCopenslPlayback* self)
+{
+ if(self->mBufferQueueObj != NULL)
+ VCALL0(self->mBufferQueueObj,Destroy)();
+ self->mBufferQueueObj = NULL;
+
+ if(self->mOutputMix)
+ VCALL0(self->mOutputMix,Destroy)();
+ self->mOutputMix = NULL;
+
+ if(self->mEngineObj)
+ VCALL0(self->mEngineObj,Destroy)();
+ self->mEngineObj = NULL;
+ self->mEngine = NULL;
+
+ ll_ringbuffer_free(self->mRing);
+ self->mRing = NULL;
+
+ alsem_destroy(&self->mSem);
+
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
+}
+
+
/* this callback handler is called every time a buffer finishes playing */
-static void opensl_callback(SLAndroidSimpleBufferQueueItf bq, void *context)
+static void ALCopenslPlayback_process(SLAndroidSimpleBufferQueueItf UNUSED(bq), void *context)
+{
+ ALCopenslPlayback *self = context;
+
+ /* A note on the ringbuffer usage: The buffer queue seems to hold on to the
+ * pointer passed to the Enqueue method, rather than copying the audio.
+ * Consequently, the ringbuffer contains the audio that is currently queued
+ * and waiting to play. This process() callback is called when a buffer is
+ * finished, so we simply move the read pointer up to indicate the space is
+ * available for writing again, and wake up the mixer thread to mix and
+ * queue more audio.
+ */
+ ll_ringbuffer_read_advance(self->mRing, 1);
+
+ alsem_post(&self->mSem);
+}
+
+
+static int ALCopenslPlayback_mixerProc(void *arg)
{
- ALCdevice *Device = context;
- osl_data *data = Device->ExtraData;
- ALvoid *buf;
+ ALCopenslPlayback *self = arg;
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
+ SLAndroidSimpleBufferQueueItf bufferQueue;
+ ll_ringbuffer_data_t data[2];
+ SLPlayItf player;
SLresult result;
- buf = (ALbyte*)data->buffer + data->curBuffer*data->bufferSize;
- aluMixData(Device, buf, data->bufferSize/data->frameSize);
+ SetRTPriority();
+ althrd_setname(althrd_current(), MIXER_THREAD_NAME);
- result = VCALL(bq,Enqueue)(buf, data->bufferSize);
- PRINTERR(result, "bq->Enqueue");
+ result = VCALL(self->mBufferQueueObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
+ &bufferQueue);
+ PRINTERR(result, "bufferQueue->GetInterface SL_IID_ANDROIDSIMPLEBUFFERQUEUE");
+ if(SL_RESULT_SUCCESS == result)
+ {
+ result = VCALL(self->mBufferQueueObj,GetInterface)(SL_IID_PLAY, &player);
+ PRINTERR(result, "bufferQueue->GetInterface SL_IID_PLAY");
+ }
- data->curBuffer = (data->curBuffer+1) % Device->NumUpdates;
+ ALCopenslPlayback_lock(self);
+ if(SL_RESULT_SUCCESS != result)
+ aluHandleDisconnect(device, "Failed to get playback buffer: 0x%08x", result);
+
+ while(SL_RESULT_SUCCESS == result &&
+ !ATOMIC_LOAD(&self->mKillNow, almemory_order_acquire) &&
+ ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
+ {
+ size_t todo;
+
+ if(ll_ringbuffer_write_space(self->mRing) == 0)
+ {
+ SLuint32 state = 0;
+
+ result = VCALL(player,GetPlayState)(&state);
+ PRINTERR(result, "player->GetPlayState");
+ if(SL_RESULT_SUCCESS == result && state != SL_PLAYSTATE_PLAYING)
+ {
+ result = VCALL(player,SetPlayState)(SL_PLAYSTATE_PLAYING);
+ PRINTERR(result, "player->SetPlayState");
+ }
+ if(SL_RESULT_SUCCESS != result)
+ {
+ aluHandleDisconnect(device, "Failed to start platback: 0x%08x", result);
+ break;
+ }
+
+ if(ll_ringbuffer_write_space(self->mRing) == 0)
+ {
+ ALCopenslPlayback_unlock(self);
+ alsem_wait(&self->mSem);
+ ALCopenslPlayback_lock(self);
+ continue;
+ }
+ }
+
+ ll_ringbuffer_get_write_vector(self->mRing, data);
+
+ aluMixData(device, data[0].buf, data[0].len*device->UpdateSize);
+ if(data[1].len > 0)
+ aluMixData(device, data[1].buf, data[1].len*device->UpdateSize);
+
+ todo = data[0].len+data[1].len;
+ ll_ringbuffer_write_advance(self->mRing, todo);
+
+ for(size_t i = 0;i < todo;i++)
+ {
+ if(!data[0].len)
+ {
+ data[0] = data[1];
+ data[1].buf = NULL;
+ data[1].len = 0;
+ }
+
+ result = VCALL(bufferQueue,Enqueue)(data[0].buf, device->UpdateSize*self->mFrameSize);
+ PRINTERR(result, "bufferQueue->Enqueue");
+ if(SL_RESULT_SUCCESS != result)
+ {
+ aluHandleDisconnect(device, "Failed to queue audio: 0x%08x", result);
+ break;
+ }
+
+ data[0].len--;
+ data[0].buf += device->UpdateSize*self->mFrameSize;
+ }
+ }
+ ALCopenslPlayback_unlock(self);
+
+ return 0;
}
-static ALCenum opensl_open_playback(ALCdevice *Device, const ALCchar *deviceName)
+static ALCenum ALCopenslPlayback_open(ALCopenslPlayback *self, const ALCchar *name)
{
- osl_data *data = NULL;
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
SLresult result;
- if(!deviceName)
- deviceName = opensl_device;
- else if(strcmp(deviceName, opensl_device) != 0)
+ if(!name)
+ name = opensl_device;
+ else if(strcmp(name, opensl_device) != 0)
return ALC_INVALID_VALUE;
- data = calloc(1, sizeof(*data));
- if(!data)
- return ALC_OUT_OF_MEMORY;
-
// create engine
- result = slCreateEngine(&data->engineObject, 0, NULL, 0, NULL, NULL);
+ result = slCreateEngine(&self->mEngineObj, 0, NULL, 0, NULL, NULL);
PRINTERR(result, "slCreateEngine");
if(SL_RESULT_SUCCESS == result)
{
- result = VCALL(data->engineObject,Realize)(SL_BOOLEAN_FALSE);
+ result = VCALL(self->mEngineObj,Realize)(SL_BOOLEAN_FALSE);
PRINTERR(result, "engine->Realize");
}
if(SL_RESULT_SUCCESS == result)
{
- result = VCALL(data->engineObject,GetInterface)(SL_IID_ENGINE, &data->engine);
+ result = VCALL(self->mEngineObj,GetInterface)(SL_IID_ENGINE, &self->mEngine);
PRINTERR(result, "engine->GetInterface");
}
if(SL_RESULT_SUCCESS == result)
{
- result = VCALL(data->engine,CreateOutputMix)(&data->outputMix, 0, NULL, NULL);
+ result = VCALL(self->mEngine,CreateOutputMix)(&self->mOutputMix, 0, NULL, NULL);
PRINTERR(result, "engine->CreateOutputMix");
}
if(SL_RESULT_SUCCESS == result)
{
- result = VCALL(data->outputMix,Realize)(SL_BOOLEAN_FALSE);
+ result = VCALL(self->mOutputMix,Realize)(SL_BOOLEAN_FALSE);
PRINTERR(result, "outputMix->Realize");
}
if(SL_RESULT_SUCCESS != result)
{
- if(data->outputMix != NULL)
- VCALL0(data->outputMix,Destroy)();
- data->outputMix = NULL;
+ if(self->mOutputMix != NULL)
+ VCALL0(self->mOutputMix,Destroy)();
+ self->mOutputMix = NULL;
- if(data->engineObject != NULL)
- VCALL0(data->engineObject,Destroy)();
- data->engineObject = NULL;
- data->engine = NULL;
+ if(self->mEngineObj != NULL)
+ VCALL0(self->mEngineObj,Destroy)();
+ self->mEngineObj = NULL;
+ self->mEngine = NULL;
- free(data);
return ALC_INVALID_VALUE;
}
- al_string_copy_cstr(&Device->DeviceName, deviceName);
- Device->ExtraData = data;
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
}
-
-static void opensl_close_playback(ALCdevice *Device)
-{
- osl_data *data = Device->ExtraData;
-
- if(data->bufferQueueObject != NULL)
- VCALL0(data->bufferQueueObject,Destroy)();
- data->bufferQueueObject = NULL;
-
- VCALL0(data->outputMix,Destroy)();
- data->outputMix = NULL;
-
- VCALL0(data->engineObject,Destroy)();
- data->engineObject = NULL;
- data->engine = NULL;
-
- free(data);
- Device->ExtraData = NULL;
-}
-
-static ALCboolean opensl_reset_playback(ALCdevice *Device)
+static ALCboolean ALCopenslPlayback_reset(ALCopenslPlayback *self)
{
- osl_data *data = Device->ExtraData;
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
SLDataLocator_AndroidSimpleBufferQueue loc_bufq;
SLDataLocator_OutputMix loc_outmix;
- SLDataFormat_PCM format_pcm;
SLDataSource audioSrc;
SLDataSink audioSnk;
- SLInterfaceID id;
- SLboolean req;
+ ALuint sampleRate;
+ SLInterfaceID ids[2];
+ SLboolean reqs[2];
SLresult result;
+ if(self->mBufferQueueObj != NULL)
+ VCALL0(self->mBufferQueueObj,Destroy)();
+ self->mBufferQueueObj = NULL;
+
+ ll_ringbuffer_free(self->mRing);
+ self->mRing = NULL;
- Device->UpdateSize = (ALuint64)Device->UpdateSize * 44100 / Device->Frequency;
- Device->UpdateSize = Device->UpdateSize * Device->NumUpdates / 2;
- Device->NumUpdates = 2;
+ sampleRate = device->Frequency;
+#if 0
+ if(!(device->Flags&DEVICE_FREQUENCY_REQUEST))
+ {
+ /* FIXME: Disabled until I figure out how to get the Context needed for
+ * the getSystemService call.
+ */
+ JNIEnv *env = Android_GetJNIEnv();
+ jobject jctx = Android_GetContext();
+
+ /* Get necessary stuff for using java.lang.Integer,
+ * android.content.Context, and android.media.AudioManager.
+ */
+ jclass int_cls = JCALL(env,FindClass)("java/lang/Integer");
+ jmethodID int_parseint = JCALL(env,GetStaticMethodID)(int_cls,
+ "parseInt", "(Ljava/lang/String;)I"
+ );
+ TRACE("Integer: %p, parseInt: %p\n", int_cls, int_parseint);
+
+ jclass ctx_cls = JCALL(env,FindClass)("android/content/Context");
+ jfieldID ctx_audsvc = JCALL(env,GetStaticFieldID)(ctx_cls,
+ "AUDIO_SERVICE", "Ljava/lang/String;"
+ );
+ jmethodID ctx_getSysSvc = JCALL(env,GetMethodID)(ctx_cls,
+ "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;"
+ );
+ TRACE("Context: %p, AUDIO_SERVICE: %p, getSystemService: %p\n",
+ ctx_cls, ctx_audsvc, ctx_getSysSvc);
+
+ jclass audmgr_cls = JCALL(env,FindClass)("android/media/AudioManager");
+ jfieldID audmgr_prop_out_srate = JCALL(env,GetStaticFieldID)(audmgr_cls,
+ "PROPERTY_OUTPUT_SAMPLE_RATE", "Ljava/lang/String;"
+ );
+ jmethodID audmgr_getproperty = JCALL(env,GetMethodID)(audmgr_cls,
+ "getProperty", "(Ljava/lang/String;)Ljava/lang/String;"
+ );
+ TRACE("AudioManager: %p, PROPERTY_OUTPUT_SAMPLE_RATE: %p, getProperty: %p\n",
+ audmgr_cls, audmgr_prop_out_srate, audmgr_getproperty);
+
+ const char *strchars;
+ jstring strobj;
+
+ /* Now make the calls. */
+ //AudioManager audMgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
+ strobj = JCALL(env,GetStaticObjectField)(ctx_cls, ctx_audsvc);
+ jobject audMgr = JCALL(env,CallObjectMethod)(jctx, ctx_getSysSvc, strobj);
+ strchars = JCALL(env,GetStringUTFChars)(strobj, NULL);
+ TRACE("Context.getSystemService(%s) = %p\n", strchars, audMgr);
+ JCALL(env,ReleaseStringUTFChars)(strobj, strchars);
+
+ //String srateStr = audMgr.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
+ strobj = JCALL(env,GetStaticObjectField)(audmgr_cls, audmgr_prop_out_srate);
+ jstring srateStr = JCALL(env,CallObjectMethod)(audMgr, audmgr_getproperty, strobj);
+ strchars = JCALL(env,GetStringUTFChars)(strobj, NULL);
+ TRACE("audMgr.getProperty(%s) = %p\n", strchars, srateStr);
+ JCALL(env,ReleaseStringUTFChars)(strobj, strchars);
+
+ //int sampleRate = Integer.parseInt(srateStr);
+ sampleRate = JCALL(env,CallStaticIntMethod)(int_cls, int_parseint, srateStr);
+
+ strchars = JCALL(env,GetStringUTFChars)(srateStr, NULL);
+ TRACE("Got system sample rate %uhz (%s)\n", sampleRate, strchars);
+ JCALL(env,ReleaseStringUTFChars)(srateStr, strchars);
+
+ if(!sampleRate) sampleRate = device->Frequency;
+ else sampleRate = maxu(sampleRate, MIN_OUTPUT_RATE);
+ }
+#endif
- Device->Frequency = 44100;
- Device->FmtChans = DevFmtStereo;
- Device->FmtType = DevFmtShort;
+ if(sampleRate != device->Frequency)
+ {
+ device->NumUpdates = (device->NumUpdates*sampleRate + (device->Frequency>>1)) /
+ device->Frequency;
+ device->NumUpdates = maxu(device->NumUpdates, 2);
+ device->Frequency = sampleRate;
+ }
- SetDefaultWFXChannelOrder(Device);
+ device->FmtChans = DevFmtStereo;
+ device->FmtType = DevFmtShort;
+ SetDefaultWFXChannelOrder(device);
+ self->mFrameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
- id = SL_IID_ANDROIDSIMPLEBUFFERQUEUE;
- req = SL_BOOLEAN_TRUE;
loc_bufq.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE;
- loc_bufq.numBuffers = Device->NumUpdates;
-
+ loc_bufq.numBuffers = device->NumUpdates;
+
+#ifdef SL_DATAFORMAT_PCM_EX
+ SLDataFormat_PCM_EX format_pcm;
+ format_pcm.formatType = SL_DATAFORMAT_PCM_EX;
+ format_pcm.numChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
+ format_pcm.sampleRate = device->Frequency * 1000;
+ format_pcm.bitsPerSample = BytesFromDevFmt(device->FmtType) * 8;
+ format_pcm.containerSize = format_pcm.bitsPerSample;
+ format_pcm.channelMask = GetChannelMask(device->FmtChans);
+ format_pcm.endianness = IS_LITTLE_ENDIAN ? SL_BYTEORDER_LITTLEENDIAN :
+ SL_BYTEORDER_BIGENDIAN;
+ format_pcm.representation = GetTypeRepresentation(device->FmtType);
+#else
+ SLDataFormat_PCM format_pcm;
format_pcm.formatType = SL_DATAFORMAT_PCM;
- format_pcm.numChannels = ChannelsFromDevFmt(Device->FmtChans);
- format_pcm.samplesPerSec = Device->Frequency * 1000;
- format_pcm.bitsPerSample = BytesFromDevFmt(Device->FmtType) * 8;
+ format_pcm.numChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
+ format_pcm.samplesPerSec = device->Frequency * 1000;
+ format_pcm.bitsPerSample = BytesFromDevFmt(device->FmtType) * 8;
format_pcm.containerSize = format_pcm.bitsPerSample;
- format_pcm.channelMask = GetChannelMask(Device->FmtChans);
+ format_pcm.channelMask = GetChannelMask(device->FmtChans);
format_pcm.endianness = IS_LITTLE_ENDIAN ? SL_BYTEORDER_LITTLEENDIAN :
SL_BYTEORDER_BIGENDIAN;
+#endif
audioSrc.pLocator = &loc_bufq;
audioSrc.pFormat = &format_pcm;
loc_outmix.locatorType = SL_DATALOCATOR_OUTPUTMIX;
- loc_outmix.outputMix = data->outputMix;
+ loc_outmix.outputMix = self->mOutputMix;
audioSnk.pLocator = &loc_outmix;
audioSnk.pFormat = NULL;
- if(data->bufferQueueObject != NULL)
- VCALL0(data->bufferQueueObject,Destroy)();
- data->bufferQueueObject = NULL;
+ ids[0] = SL_IID_ANDROIDSIMPLEBUFFERQUEUE;
+ reqs[0] = SL_BOOLEAN_TRUE;
+ ids[1] = SL_IID_ANDROIDCONFIGURATION;
+ reqs[1] = SL_BOOLEAN_FALSE;
- result = VCALL(data->engine,CreateAudioPlayer)(&data->bufferQueueObject, &audioSrc, &audioSnk, 1, &id, &req);
+ result = VCALL(self->mEngine,CreateAudioPlayer)(&self->mBufferQueueObj,
+ &audioSrc, &audioSnk, COUNTOF(ids), ids, reqs
+ );
PRINTERR(result, "engine->CreateAudioPlayer");
if(SL_RESULT_SUCCESS == result)
{
- result = VCALL(data->bufferQueueObject,Realize)(SL_BOOLEAN_FALSE);
+ /* Set the stream type to "media" (games, music, etc), if possible. */
+ SLAndroidConfigurationItf config;
+ result = VCALL(self->mBufferQueueObj,GetInterface)(SL_IID_ANDROIDCONFIGURATION, &config);
+ PRINTERR(result, "bufferQueue->GetInterface SL_IID_ANDROIDCONFIGURATION");
+ if(SL_RESULT_SUCCESS == result)
+ {
+ SLint32 streamType = SL_ANDROID_STREAM_MEDIA;
+ result = VCALL(config,SetConfiguration)(SL_ANDROID_KEY_STREAM_TYPE,
+ &streamType, sizeof(streamType)
+ );
+ PRINTERR(result, "config->SetConfiguration");
+ }
+
+ /* Clear any error since this was optional. */
+ result = SL_RESULT_SUCCESS;
+ }
+ if(SL_RESULT_SUCCESS == result)
+ {
+ result = VCALL(self->mBufferQueueObj,Realize)(SL_BOOLEAN_FALSE);
PRINTERR(result, "bufferQueue->Realize");
}
+ if(SL_RESULT_SUCCESS == result)
+ {
+ self->mRing = ll_ringbuffer_create(device->NumUpdates,
+ self->mFrameSize*device->UpdateSize, true
+ );
+ if(!self->mRing)
+ {
+ ERR("Out of memory allocating ring buffer %ux%u %u\n", device->UpdateSize,
+ device->NumUpdates, self->mFrameSize);
+ result = SL_RESULT_MEMORY_FAILURE;
+ }
+ }
if(SL_RESULT_SUCCESS != result)
{
- if(data->bufferQueueObject != NULL)
- VCALL0(data->bufferQueueObject,Destroy)();
- data->bufferQueueObject = NULL;
+ if(self->mBufferQueueObj != NULL)
+ VCALL0(self->mBufferQueueObj,Destroy)();
+ self->mBufferQueueObj = NULL;
+
+ return ALC_FALSE;
+ }
+
+ return ALC_TRUE;
+}
+
+static ALCboolean ALCopenslPlayback_start(ALCopenslPlayback *self)
+{
+ SLAndroidSimpleBufferQueueItf bufferQueue;
+ SLresult result;
+
+ ll_ringbuffer_reset(self->mRing);
+
+ result = VCALL(self->mBufferQueueObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
+ &bufferQueue);
+ PRINTERR(result, "bufferQueue->GetInterface");
+ if(SL_RESULT_SUCCESS != result)
+ return ALC_FALSE;
+
+ result = VCALL(bufferQueue,RegisterCallback)(ALCopenslPlayback_process, self);
+ PRINTERR(result, "bufferQueue->RegisterCallback");
+ if(SL_RESULT_SUCCESS != result)
+ return ALC_FALSE;
+ ATOMIC_STORE_SEQ(&self->mKillNow, AL_FALSE);
+ if(althrd_create(&self->mThread, ALCopenslPlayback_mixerProc, self) != althrd_success)
+ {
+ ERR("Failed to start mixer thread\n");
return ALC_FALSE;
}
return ALC_TRUE;
}
-static ALCboolean opensl_start_playback(ALCdevice *Device)
+
+static void ALCopenslPlayback_stop(ALCopenslPlayback *self)
{
- osl_data *data = Device->ExtraData;
SLAndroidSimpleBufferQueueItf bufferQueue;
SLPlayItf player;
SLresult result;
- ALuint i;
+ int res;
+
+ if(ATOMIC_EXCHANGE_SEQ(&self->mKillNow, AL_TRUE))
+ return;
+
+ alsem_post(&self->mSem);
+ althrd_join(self->mThread, &res);
- result = VCALL(data->bufferQueueObject,GetInterface)(SL_IID_BUFFERQUEUE, &bufferQueue);
+ result = VCALL(self->mBufferQueueObj,GetInterface)(SL_IID_PLAY, &player);
PRINTERR(result, "bufferQueue->GetInterface");
if(SL_RESULT_SUCCESS == result)
{
- result = VCALL(bufferQueue,RegisterCallback)(opensl_callback, Device);
+ result = VCALL(player,SetPlayState)(SL_PLAYSTATE_STOPPED);
+ PRINTERR(result, "player->SetPlayState");
+ }
+
+ result = VCALL(self->mBufferQueueObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
+ &bufferQueue);
+ PRINTERR(result, "bufferQueue->GetInterface");
+ if(SL_RESULT_SUCCESS == result)
+ {
+ result = VCALL0(bufferQueue,Clear)();
+ PRINTERR(result, "bufferQueue->Clear");
+ }
+ if(SL_RESULT_SUCCESS == result)
+ {
+ result = VCALL(bufferQueue,RegisterCallback)(NULL, NULL);
PRINTERR(result, "bufferQueue->RegisterCallback");
}
if(SL_RESULT_SUCCESS == result)
{
- data->frameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType);
- data->bufferSize = Device->UpdateSize * data->frameSize;
- data->buffer = calloc(Device->NumUpdates, data->bufferSize);
- if(!data->buffer)
- {
- result = SL_RESULT_MEMORY_FAILURE;
- PRINTERR(result, "calloc");
- }
+ SLAndroidSimpleBufferQueueState state;
+ do {
+ althrd_yield();
+ result = VCALL(bufferQueue,GetState)(&state);
+ } while(SL_RESULT_SUCCESS == result && state.count > 0);
+ PRINTERR(result, "bufferQueue->GetState");
+ }
+}
+
+static ClockLatency ALCopenslPlayback_getClockLatency(ALCopenslPlayback *self)
+{
+ ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
+ ClockLatency ret;
+
+ ALCopenslPlayback_lock(self);
+ ret.ClockTime = GetDeviceClockTime(device);
+ ret.Latency = ll_ringbuffer_read_space(self->mRing)*device->UpdateSize *
+ DEVICE_CLOCK_RES / device->Frequency;
+ ALCopenslPlayback_unlock(self);
+
+ return ret;
+}
+
+
+typedef struct ALCopenslCapture {
+ DERIVE_FROM_TYPE(ALCbackend);
+
+ /* engine interfaces */
+ SLObjectItf mEngineObj;
+ SLEngineItf mEngine;
+
+ /* recording interfaces */
+ SLObjectItf mRecordObj;
+
+ ll_ringbuffer_t *mRing;
+ ALCuint mSplOffset;
+
+ ALsizei mFrameSize;
+} ALCopenslCapture;
+
+static void ALCopenslCapture_process(SLAndroidSimpleBufferQueueItf bq, void *context);
+
+static void ALCopenslCapture_Construct(ALCopenslCapture *self, ALCdevice *device);
+static void ALCopenslCapture_Destruct(ALCopenslCapture *self);
+static ALCenum ALCopenslCapture_open(ALCopenslCapture *self, const ALCchar *name);
+static DECLARE_FORWARD(ALCopenslCapture, ALCbackend, ALCboolean, reset)
+static ALCboolean ALCopenslCapture_start(ALCopenslCapture *self);
+static void ALCopenslCapture_stop(ALCopenslCapture *self);
+static ALCenum ALCopenslCapture_captureSamples(ALCopenslCapture *self, ALCvoid *buffer, ALCuint samples);
+static ALCuint ALCopenslCapture_availableSamples(ALCopenslCapture *self);
+static DECLARE_FORWARD(ALCopenslCapture, ALCbackend, ClockLatency, getClockLatency)
+static DECLARE_FORWARD(ALCopenslCapture, ALCbackend, void, lock)
+static DECLARE_FORWARD(ALCopenslCapture, ALCbackend, void, unlock)
+DECLARE_DEFAULT_ALLOCATORS(ALCopenslCapture)
+DEFINE_ALCBACKEND_VTABLE(ALCopenslCapture);
+
+
+static void ALCopenslCapture_process(SLAndroidSimpleBufferQueueItf UNUSED(bq), void *context)
+{
+ ALCopenslCapture *self = context;
+ /* A new chunk has been written into the ring buffer, advance it. */
+ ll_ringbuffer_write_advance(self->mRing, 1);
+}
+
+
+static void ALCopenslCapture_Construct(ALCopenslCapture *self, ALCdevice *device)
+{
+ ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
+ SET_VTABLE2(ALCopenslCapture, ALCbackend, self);
+
+ self->mEngineObj = NULL;
+ self->mEngine = NULL;
+
+ self->mRecordObj = NULL;
+
+ self->mRing = NULL;
+ self->mSplOffset = 0;
+
+ self->mFrameSize = 0;
+}
+
+static void ALCopenslCapture_Destruct(ALCopenslCapture *self)
+{
+ if(self->mRecordObj != NULL)
+ VCALL0(self->mRecordObj,Destroy)();
+ self->mRecordObj = NULL;
+
+ if(self->mEngineObj != NULL)
+ VCALL0(self->mEngineObj,Destroy)();
+ self->mEngineObj = NULL;
+ self->mEngine = NULL;
+
+ ll_ringbuffer_free(self->mRing);
+ self->mRing = NULL;
+
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
+}
+
+static ALCenum ALCopenslCapture_open(ALCopenslCapture *self, const ALCchar *name)
+{
+ ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
+ SLDataLocator_AndroidSimpleBufferQueue loc_bq;
+ SLAndroidSimpleBufferQueueItf bufferQueue;
+ SLDataLocator_IODevice loc_dev;
+ SLDataSource audioSrc;
+ SLDataSink audioSnk;
+ SLresult result;
+
+ if(!name)
+ name = opensl_device;
+ else if(strcmp(name, opensl_device) != 0)
+ return ALC_INVALID_VALUE;
+
+ result = slCreateEngine(&self->mEngineObj, 0, NULL, 0, NULL, NULL);
+ PRINTERR(result, "slCreateEngine");
+ if(SL_RESULT_SUCCESS == result)
+ {
+ result = VCALL(self->mEngineObj,Realize)(SL_BOOLEAN_FALSE);
+ PRINTERR(result, "engine->Realize");
}
- /* enqueue the first buffer to kick off the callbacks */
- for(i = 0;i < Device->NumUpdates;i++)
+ if(SL_RESULT_SUCCESS == result)
+ {
+ result = VCALL(self->mEngineObj,GetInterface)(SL_IID_ENGINE, &self->mEngine);
+ PRINTERR(result, "engine->GetInterface");
+ }
+ if(SL_RESULT_SUCCESS == result)
{
+ /* Ensure the total length is at least 100ms */
+ ALsizei length = maxi(device->NumUpdates * device->UpdateSize,
+ device->Frequency / 10);
+ /* Ensure the per-chunk length is at least 10ms, and no more than 50ms. */
+ ALsizei update_len = clampi(device->NumUpdates*device->UpdateSize / 3,
+ device->Frequency / 100,
+ device->Frequency / 100 * 5);
+
+ device->UpdateSize = update_len;
+ device->NumUpdates = (length+update_len-1) / update_len;
+
+ self->mFrameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
+ }
+ loc_dev.locatorType = SL_DATALOCATOR_IODEVICE;
+ loc_dev.deviceType = SL_IODEVICE_AUDIOINPUT;
+ loc_dev.deviceID = SL_DEFAULTDEVICEID_AUDIOINPUT;
+ loc_dev.device = NULL;
+
+ audioSrc.pLocator = &loc_dev;
+ audioSrc.pFormat = NULL;
+
+ loc_bq.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE;
+ loc_bq.numBuffers = device->NumUpdates;
+
+#ifdef SL_DATAFORMAT_PCM_EX
+ SLDataFormat_PCM_EX format_pcm;
+ format_pcm.formatType = SL_DATAFORMAT_PCM_EX;
+ format_pcm.numChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
+ format_pcm.sampleRate = device->Frequency * 1000;
+ format_pcm.bitsPerSample = BytesFromDevFmt(device->FmtType) * 8;
+ format_pcm.containerSize = format_pcm.bitsPerSample;
+ format_pcm.channelMask = GetChannelMask(device->FmtChans);
+ format_pcm.endianness = IS_LITTLE_ENDIAN ? SL_BYTEORDER_LITTLEENDIAN :
+ SL_BYTEORDER_BIGENDIAN;
+ format_pcm.representation = GetTypeRepresentation(device->FmtType);
+#else
+ SLDataFormat_PCM format_pcm;
+ format_pcm.formatType = SL_DATAFORMAT_PCM;
+ format_pcm.numChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
+ format_pcm.samplesPerSec = device->Frequency * 1000;
+ format_pcm.bitsPerSample = BytesFromDevFmt(device->FmtType) * 8;
+ format_pcm.containerSize = format_pcm.bitsPerSample;
+ format_pcm.channelMask = GetChannelMask(device->FmtChans);
+ format_pcm.endianness = IS_LITTLE_ENDIAN ? SL_BYTEORDER_LITTLEENDIAN :
+ SL_BYTEORDER_BIGENDIAN;
+#endif
+
+ audioSnk.pLocator = &loc_bq;
+ audioSnk.pFormat = &format_pcm;
+
+ if(SL_RESULT_SUCCESS == result)
+ {
+ const SLInterfaceID ids[2] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SL_IID_ANDROIDCONFIGURATION };
+ const SLboolean reqs[2] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_FALSE };
+
+ result = VCALL(self->mEngine,CreateAudioRecorder)(&self->mRecordObj,
+ &audioSrc, &audioSnk, COUNTOF(ids), ids, reqs
+ );
+ PRINTERR(result, "engine->CreateAudioRecorder");
+ }
+ if(SL_RESULT_SUCCESS == result)
+ {
+ /* Set the record preset to "generic", if possible. */
+ SLAndroidConfigurationItf config;
+ result = VCALL(self->mRecordObj,GetInterface)(SL_IID_ANDROIDCONFIGURATION, &config);
+ PRINTERR(result, "recordObj->GetInterface SL_IID_ANDROIDCONFIGURATION");
if(SL_RESULT_SUCCESS == result)
{
- ALvoid *buf = (ALbyte*)data->buffer + i*data->bufferSize;
- result = VCALL(bufferQueue,Enqueue)(buf, data->bufferSize);
- PRINTERR(result, "bufferQueue->Enqueue");
+ SLuint32 preset = SL_ANDROID_RECORDING_PRESET_GENERIC;
+ result = VCALL(config,SetConfiguration)(SL_ANDROID_KEY_RECORDING_PRESET,
+ &preset, sizeof(preset)
+ );
+ PRINTERR(result, "config->SetConfiguration");
}
+
+ /* Clear any error since this was optional. */
+ result = SL_RESULT_SUCCESS;
}
- data->curBuffer = 0;
if(SL_RESULT_SUCCESS == result)
{
- result = VCALL(data->bufferQueueObject,GetInterface)(SL_IID_PLAY, &player);
- PRINTERR(result, "bufferQueue->GetInterface");
+ result = VCALL(self->mRecordObj,Realize)(SL_BOOLEAN_FALSE);
+ PRINTERR(result, "recordObj->Realize");
}
+
if(SL_RESULT_SUCCESS == result)
{
- result = VCALL(player,SetPlayState)(SL_PLAYSTATE_PLAYING);
- PRINTERR(result, "player->SetPlayState");
+ self->mRing = ll_ringbuffer_create(device->NumUpdates,
+ device->UpdateSize*self->mFrameSize, false
+ );
+
+ result = VCALL(self->mRecordObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
+ &bufferQueue);
+ PRINTERR(result, "recordObj->GetInterface");
+ }
+ if(SL_RESULT_SUCCESS == result)
+ {
+ result = VCALL(bufferQueue,RegisterCallback)(ALCopenslCapture_process, self);
+ PRINTERR(result, "bufferQueue->RegisterCallback");
+ }
+ if(SL_RESULT_SUCCESS == result)
+ {
+ ALsizei chunk_size = device->UpdateSize * self->mFrameSize;
+ ll_ringbuffer_data_t data[2];
+ size_t i;
+
+ ll_ringbuffer_get_write_vector(self->mRing, data);
+ for(i = 0;i < data[0].len && SL_RESULT_SUCCESS == result;i++)
+ {
+ result = VCALL(bufferQueue,Enqueue)(data[0].buf + chunk_size*i, chunk_size);
+ PRINTERR(result, "bufferQueue->Enqueue");
+ }
+ for(i = 0;i < data[1].len && SL_RESULT_SUCCESS == result;i++)
+ {
+ result = VCALL(bufferQueue,Enqueue)(data[1].buf + chunk_size*i, chunk_size);
+ PRINTERR(result, "bufferQueue->Enqueue");
+ }
}
if(SL_RESULT_SUCCESS != result)
{
- if(data->bufferQueueObject != NULL)
- VCALL0(data->bufferQueueObject,Destroy)();
- data->bufferQueueObject = NULL;
+ if(self->mRecordObj != NULL)
+ VCALL0(self->mRecordObj,Destroy)();
+ self->mRecordObj = NULL;
+
+ if(self->mEngineObj != NULL)
+ VCALL0(self->mEngineObj,Destroy)();
+ self->mEngineObj = NULL;
+ self->mEngine = NULL;
+
+ return ALC_INVALID_VALUE;
+ }
+
+ alstr_copy_cstr(&device->DeviceName, name);
+
+ return ALC_NO_ERROR;
+}
- free(data->buffer);
- data->buffer = NULL;
- data->bufferSize = 0;
+static ALCboolean ALCopenslCapture_start(ALCopenslCapture *self)
+{
+ SLRecordItf record;
+ SLresult result;
+ result = VCALL(self->mRecordObj,GetInterface)(SL_IID_RECORD, &record);
+ PRINTERR(result, "recordObj->GetInterface");
+
+ if(SL_RESULT_SUCCESS == result)
+ {
+ result = VCALL(record,SetRecordState)(SL_RECORDSTATE_RECORDING);
+ PRINTERR(result, "record->SetRecordState");
+ }
+
+ if(SL_RESULT_SUCCESS != result)
+ {
+ ALCopenslCapture_lock(self);
+ aluHandleDisconnect(STATIC_CAST(ALCbackend, self)->mDevice,
+ "Failed to start capture: 0x%08x", result);
+ ALCopenslCapture_unlock(self);
return ALC_FALSE;
}
return ALC_TRUE;
}
-
-static void opensl_stop_playback(ALCdevice *Device)
+static void ALCopenslCapture_stop(ALCopenslCapture *self)
{
- osl_data *data = Device->ExtraData;
- SLPlayItf player;
- SLAndroidSimpleBufferQueueItf bufferQueue;
+ SLRecordItf record;
SLresult result;
- result = VCALL(data->bufferQueueObject,GetInterface)(SL_IID_PLAY, &player);
- PRINTERR(result, "bufferQueue->GetInterface");
+ result = VCALL(self->mRecordObj,GetInterface)(SL_IID_RECORD, &record);
+ PRINTERR(result, "recordObj->GetInterface");
+
if(SL_RESULT_SUCCESS == result)
{
- result = VCALL(player,SetPlayState)(SL_PLAYSTATE_STOPPED);
- PRINTERR(result, "player->SetPlayState");
+ result = VCALL(record,SetRecordState)(SL_RECORDSTATE_PAUSED);
+ PRINTERR(result, "record->SetRecordState");
}
+}
- result = VCALL(data->bufferQueueObject,GetInterface)(SL_IID_BUFFERQUEUE, &bufferQueue);
- PRINTERR(result, "bufferQueue->GetInterface");
- if(SL_RESULT_SUCCESS == result)
+static ALCenum ALCopenslCapture_captureSamples(ALCopenslCapture *self, ALCvoid *buffer, ALCuint samples)
+{
+ ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
+ ALsizei chunk_size = device->UpdateSize * self->mFrameSize;
+ SLAndroidSimpleBufferQueueItf bufferQueue;
+ ll_ringbuffer_data_t data[2];
+ SLresult result;
+ ALCuint i;
+
+ result = VCALL(self->mRecordObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
+ &bufferQueue);
+ PRINTERR(result, "recordObj->GetInterface");
+
+ /* Read the desired samples from the ring buffer then advance its read
+ * pointer.
+ */
+ ll_ringbuffer_get_read_vector(self->mRing, data);
+ for(i = 0;i < samples;)
{
- result = VCALL0(bufferQueue,Clear)();
- PRINTERR(result, "bufferQueue->Clear");
+ ALCuint rem = minu(samples - i, device->UpdateSize - self->mSplOffset);
+ memcpy((ALCbyte*)buffer + i*self->mFrameSize,
+ data[0].buf + self->mSplOffset*self->mFrameSize,
+ rem * self->mFrameSize);
+
+ self->mSplOffset += rem;
+ if(self->mSplOffset == device->UpdateSize)
+ {
+ /* Finished a chunk, reset the offset and advance the read pointer. */
+ self->mSplOffset = 0;
+
+ ll_ringbuffer_read_advance(self->mRing, 1);
+ result = VCALL(bufferQueue,Enqueue)(data[0].buf, chunk_size);
+ PRINTERR(result, "bufferQueue->Enqueue");
+ if(SL_RESULT_SUCCESS != result) break;
+
+ data[0].len--;
+ if(!data[0].len)
+ data[0] = data[1];
+ else
+ data[0].buf += chunk_size;
+ }
+
+ i += rem;
}
- if(SL_RESULT_SUCCESS == result)
+
+ if(SL_RESULT_SUCCESS != result)
{
- SLAndroidSimpleBufferQueueState state;
- do {
- althrd_yield();
- result = VCALL(bufferQueue,GetState)(&state);
- } while(SL_RESULT_SUCCESS == result && state.count > 0);
- PRINTERR(result, "bufferQueue->GetState");
+ ALCopenslCapture_lock(self);
+ aluHandleDisconnect(device, "Failed to update capture buffer: 0x%08x", result);
+ ALCopenslCapture_unlock(self);
+ return ALC_INVALID_DEVICE;
}
- free(data->buffer);
- data->buffer = NULL;
- data->bufferSize = 0;
+ return ALC_NO_ERROR;
}
+static ALCuint ALCopenslCapture_availableSamples(ALCopenslCapture *self)
+{
+ ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
+ return ll_ringbuffer_read_space(self->mRing) * device->UpdateSize;
+}
-static const BackendFuncs opensl_funcs = {
- opensl_open_playback,
- opensl_close_playback,
- opensl_reset_playback,
- opensl_start_playback,
- opensl_stop_playback,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
-};
+typedef struct ALCopenslBackendFactory {
+ DERIVE_FROM_TYPE(ALCbackendFactory);
+} ALCopenslBackendFactory;
+#define ALCOPENSLBACKENDFACTORY_INITIALIZER { { GET_VTABLE2(ALCopenslBackendFactory, ALCbackendFactory) } }
-ALCboolean alc_opensl_init(BackendFuncs *func_list)
+static ALCboolean ALCopenslBackendFactory_init(ALCopenslBackendFactory* UNUSED(self))
{
- *func_list = opensl_funcs;
return ALC_TRUE;
}
-void alc_opensl_deinit(void)
+static void ALCopenslBackendFactory_deinit(ALCopenslBackendFactory* UNUSED(self))
+{
+}
+
+static ALCboolean ALCopenslBackendFactory_querySupport(ALCopenslBackendFactory* UNUSED(self), ALCbackend_Type type)
{
+ if(type == ALCbackend_Playback || type == ALCbackend_Capture)
+ return ALC_TRUE;
+ return ALC_FALSE;
}
-void alc_opensl_probe(enum DevProbe type)
+static void ALCopenslBackendFactory_probe(ALCopenslBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
switch(type)
{
case ALL_DEVICE_PROBE:
- AppendAllDevicesList(opensl_device);
- break;
case CAPTURE_DEVICE_PROBE:
+ alstr_append_range(outnames, opensl_device, opensl_device+sizeof(opensl_device));
break;
}
}
+
+static ALCbackend* ALCopenslBackendFactory_createBackend(ALCopenslBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type)
+{
+ if(type == ALCbackend_Playback)
+ {
+ ALCopenslPlayback *backend;
+ NEW_OBJ(backend, ALCopenslPlayback)(device);
+ if(!backend) return NULL;
+ return STATIC_CAST(ALCbackend, backend);
+ }
+ if(type == ALCbackend_Capture)
+ {
+ ALCopenslCapture *backend;
+ NEW_OBJ(backend, ALCopenslCapture)(device);
+ if(!backend) return NULL;
+ return STATIC_CAST(ALCbackend, backend);
+ }
+
+ return NULL;
+}
+
+DEFINE_ALCBACKENDFACTORY_VTABLE(ALCopenslBackendFactory);
+
+
+ALCbackendFactory *ALCopenslBackendFactory_getFactory(void)
+{
+ static ALCopenslBackendFactory factory = ALCOPENSLBACKENDFACTORY_INITIALIZER;
+ return STATIC_CAST(ALCbackendFactory, &factory);
+}
diff --git a/Alc/backends/oss.c b/Alc/backends/oss.c
index dce42e21..71faad25 100644
--- a/Alc/backends/oss.c
+++ b/Alc/backends/oss.c
@@ -22,10 +22,12 @@
#include <sys/ioctl.h>
#include <sys/types.h>
+#include <sys/time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <memory.h>
#include <unistd.h>
#include <errno.h>
@@ -33,6 +35,8 @@
#include "alMain.h"
#include "alu.h"
+#include "alconfig.h"
+#include "ringbuffer.h"
#include "threads.h"
#include "compat.h"
@@ -51,11 +55,176 @@
#define SOUND_MIXER_WRITE MIXER_WRITE
#endif
+#if defined(SOUND_VERSION) && (SOUND_VERSION < 0x040000)
+#define ALC_OSS_COMPAT
+#endif
+#ifndef SNDCTL_AUDIOINFO
+#define ALC_OSS_COMPAT
+#endif
+
+/*
+ * FreeBSD strongly discourages the use of specific devices,
+ * such as those returned in oss_audioinfo.devnode
+ */
+#ifdef __FreeBSD__
+#define ALC_OSS_DEVNODE_TRUC
+#endif
+
+struct oss_device {
+ const ALCchar *handle;
+ const char *path;
+ struct oss_device *next;
+};
+
+static struct oss_device oss_playback = {
+ "OSS Default",
+ "/dev/dsp",
+ NULL
+};
+
+static struct oss_device oss_capture = {
+ "OSS Default",
+ "/dev/dsp",
+ NULL
+};
+
+#ifdef ALC_OSS_COMPAT
+
+#define DSP_CAP_OUTPUT 0x00020000
+#define DSP_CAP_INPUT 0x00010000
+static void ALCossListPopulate(struct oss_device *UNUSED(devlist), int UNUSED(type_flag))
+{
+}
+
+#else
+
+#ifndef HAVE_STRNLEN
+static size_t strnlen(const char *str, size_t maxlen)
+{
+ const char *end = memchr(str, 0, maxlen);
+ if(!end) return maxlen;
+ return end - str;
+}
+#endif
+
+static void ALCossListAppend(struct oss_device *list, const char *handle, size_t hlen, const char *path, size_t plen)
+{
+ struct oss_device *next;
+ struct oss_device *last;
+ size_t i;
+
+ /* skip the first item "OSS Default" */
+ last = list;
+ next = list->next;
+#ifdef ALC_OSS_DEVNODE_TRUC
+ for(i = 0;i < plen;i++)
+ {
+ if(path[i] == '.')
+ {
+ if(strncmp(path + i, handle + hlen + i - plen, plen - i) == 0)
+ hlen = hlen + i - plen;
+ plen = i;
+ }
+ }
+#else
+ (void)i;
+#endif
+ if(handle[0] == '\0')
+ {
+ handle = path;
+ hlen = plen;
+ }
+
+ while(next != NULL)
+ {
+ if(strncmp(next->path, path, plen) == 0)
+ return;
+ last = next;
+ next = next->next;
+ }
+
+ next = (struct oss_device*)malloc(sizeof(struct oss_device) + hlen + plen + 2);
+ next->handle = (char*)(next + 1);
+ next->path = next->handle + hlen + 1;
+ next->next = NULL;
+ last->next = next;
+
+ strncpy((char*)next->handle, handle, hlen);
+ ((char*)next->handle)[hlen] = '\0';
+ strncpy((char*)next->path, path, plen);
+ ((char*)next->path)[plen] = '\0';
-static const ALCchar oss_device[] = "OSS Default";
+ TRACE("Got device \"%s\", \"%s\"\n", next->handle, next->path);
+}
+
+static void ALCossListPopulate(struct oss_device *devlist, int type_flag)
+{
+ struct oss_sysinfo si;
+ struct oss_audioinfo ai;
+ int fd, i;
+
+ if((fd=open("/dev/mixer", O_RDONLY)) < 0)
+ {
+ TRACE("Could not open /dev/mixer: %s\n", strerror(errno));
+ return;
+ }
+ if(ioctl(fd, SNDCTL_SYSINFO, &si) == -1)
+ {
+ TRACE("SNDCTL_SYSINFO failed: %s\n", strerror(errno));
+ goto done;
+ }
+ for(i = 0;i < si.numaudios;i++)
+ {
+ const char *handle;
+ size_t len;
-static const char *oss_driver = "/dev/dsp";
-static const char *oss_capture = "/dev/dsp";
+ ai.dev = i;
+ if(ioctl(fd, SNDCTL_AUDIOINFO, &ai) == -1)
+ {
+ ERR("SNDCTL_AUDIOINFO (%d) failed: %s\n", i, strerror(errno));
+ continue;
+ }
+ if(ai.devnode[0] == '\0')
+ continue;
+
+ if(ai.handle[0] != '\0')
+ {
+ len = strnlen(ai.handle, sizeof(ai.handle));
+ handle = ai.handle;
+ }
+ else
+ {
+ len = strnlen(ai.name, sizeof(ai.name));
+ handle = ai.name;
+ }
+ if((ai.caps&type_flag))
+ ALCossListAppend(devlist, handle, len, ai.devnode,
+ strnlen(ai.devnode, sizeof(ai.devnode)));
+ }
+
+done:
+ close(fd);
+}
+
+#endif
+
+static void ALCossListFree(struct oss_device *list)
+{
+ struct oss_device *cur;
+ if(list == NULL)
+ return;
+
+ /* skip the first item "OSS Default" */
+ cur = list->next;
+ list->next = NULL;
+
+ while(cur != NULL)
+ {
+ struct oss_device *next = cur->next;
+ free(cur);
+ cur = next;
+ }
+}
static int log2i(ALCuint x)
{
@@ -68,7 +237,6 @@ static int log2i(ALCuint x)
return y;
}
-
typedef struct ALCplaybackOSS {
DERIVE_FROM_TYPE(ALCbackend);
@@ -77,22 +245,21 @@ typedef struct ALCplaybackOSS {
ALubyte *mix_data;
int data_size;
- volatile int killNow;
+ ATOMIC(ALenum) killNow;
althrd_t thread;
} ALCplaybackOSS;
static int ALCplaybackOSS_mixerProc(void *ptr);
static void ALCplaybackOSS_Construct(ALCplaybackOSS *self, ALCdevice *device);
-static DECLARE_FORWARD(ALCplaybackOSS, ALCbackend, void, Destruct)
+static void ALCplaybackOSS_Destruct(ALCplaybackOSS *self);
static ALCenum ALCplaybackOSS_open(ALCplaybackOSS *self, const ALCchar *name);
-static void ALCplaybackOSS_close(ALCplaybackOSS *self);
static ALCboolean ALCplaybackOSS_reset(ALCplaybackOSS *self);
static ALCboolean ALCplaybackOSS_start(ALCplaybackOSS *self);
static void ALCplaybackOSS_stop(ALCplaybackOSS *self);
static DECLARE_FORWARD2(ALCplaybackOSS, ALCbackend, ALCenum, captureSamples, ALCvoid*, ALCuint)
static DECLARE_FORWARD(ALCplaybackOSS, ALCbackend, ALCuint, availableSamples)
-static DECLARE_FORWARD(ALCplaybackOSS, ALCbackend, ALint64, getLatency)
+static DECLARE_FORWARD(ALCplaybackOSS, ALCbackend, ClockLatency, getClockLatency)
static DECLARE_FORWARD(ALCplaybackOSS, ALCbackend, void, lock)
static DECLARE_FORWARD(ALCplaybackOSS, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCplaybackOSS)
@@ -103,42 +270,66 @@ static int ALCplaybackOSS_mixerProc(void *ptr)
{
ALCplaybackOSS *self = (ALCplaybackOSS*)ptr;
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- ALint frameSize;
+ struct timeval timeout;
+ ALubyte *write_ptr;
+ ALint frame_size;
+ ALint to_write;
ssize_t wrote;
+ fd_set wfds;
+ int sret;
SetRTPriority();
althrd_setname(althrd_current(), MIXER_THREAD_NAME);
- frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ frame_size = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
- while(!self->killNow && device->Connected)
+ ALCplaybackOSS_lock(self);
+ while(!ATOMIC_LOAD(&self->killNow, almemory_order_acquire) &&
+ ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
{
- ALint len = self->data_size;
- ALubyte *WritePtr = self->mix_data;
+ FD_ZERO(&wfds);
+ FD_SET(self->fd, &wfds);
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+
+ ALCplaybackOSS_unlock(self);
+ sret = select(self->fd+1, NULL, &wfds, NULL, &timeout);
+ ALCplaybackOSS_lock(self);
+ if(sret < 0)
+ {
+ if(errno == EINTR)
+ continue;
+ ERR("select failed: %s\n", strerror(errno));
+ aluHandleDisconnect(device, "Failed waiting for playback buffer: %s", strerror(errno));
+ break;
+ }
+ else if(sret == 0)
+ {
+ WARN("select timeout\n");
+ continue;
+ }
- aluMixData(device, WritePtr, len/frameSize);
- while(len > 0 && !self->killNow)
+ write_ptr = self->mix_data;
+ to_write = self->data_size;
+ aluMixData(device, write_ptr, to_write/frame_size);
+ while(to_write > 0 && !ATOMIC_LOAD_SEQ(&self->killNow))
{
- wrote = write(self->fd, WritePtr, len);
+ wrote = write(self->fd, write_ptr, to_write);
if(wrote < 0)
{
- if(errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
- {
- ERR("write failed: %s\n", strerror(errno));
- ALCplaybackOSS_lock(self);
- aluHandleDisconnect(device);
- ALCplaybackOSS_unlock(self);
- break;
- }
-
- al_nssleep(1000000);
- continue;
+ if(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
+ continue;
+ ERR("write failed: %s\n", strerror(errno));
+ aluHandleDisconnect(device, "Failed writing playback samples: %s",
+ strerror(errno));
+ break;
}
- len -= wrote;
- WritePtr += wrote;
+ to_write -= wrote;
+ write_ptr += wrote;
}
}
+ ALCplaybackOSS_unlock(self);
return 0;
}
@@ -148,37 +339,59 @@ static void ALCplaybackOSS_Construct(ALCplaybackOSS *self, ALCdevice *device)
{
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCplaybackOSS, ALCbackend, self);
+
+ self->fd = -1;
+ ATOMIC_INIT(&self->killNow, AL_FALSE);
+}
+
+static void ALCplaybackOSS_Destruct(ALCplaybackOSS *self)
+{
+ if(self->fd != -1)
+ close(self->fd);
+ self->fd = -1;
+
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}
static ALCenum ALCplaybackOSS_open(ALCplaybackOSS *self, const ALCchar *name)
{
+ struct oss_device *dev = &oss_playback;
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- if(!name)
- name = oss_device;
- else if(strcmp(name, oss_device) != 0)
- return ALC_INVALID_VALUE;
-
- self->killNow = 0;
+ if(!name || strcmp(name, dev->handle) == 0)
+ name = dev->handle;
+ else
+ {
+ if(!dev->next)
+ {
+ ALCossListPopulate(&oss_playback, DSP_CAP_OUTPUT);
+ dev = &oss_playback;
+ }
+ while(dev != NULL)
+ {
+ if (strcmp(dev->handle, name) == 0)
+ break;
+ dev = dev->next;
+ }
+ if(dev == NULL)
+ {
+ WARN("Could not find \"%s\" in device list\n", name);
+ return ALC_INVALID_VALUE;
+ }
+ }
- self->fd = open(oss_driver, O_WRONLY);
+ self->fd = open(dev->path, O_WRONLY);
if(self->fd == -1)
{
- ERR("Could not open %s: %s\n", oss_driver, strerror(errno));
+ ERR("Could not open %s: %s\n", dev->path, strerror(errno));
return ALC_INVALID_VALUE;
}
- al_string_copy_cstr(&device->DeviceName, name);
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
}
-static void ALCplaybackOSS_close(ALCplaybackOSS *self)
-{
- close(self->fd);
- self->fd = -1;
-}
-
static ALCboolean ALCplaybackOSS_reset(ALCplaybackOSS *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
@@ -212,18 +425,11 @@ static ALCboolean ALCplaybackOSS_reset(ALCplaybackOSS *self)
}
periods = device->NumUpdates;
- numChannels = ChannelsFromDevFmt(device->FmtChans);
- frameSize = numChannels * BytesFromDevFmt(device->FmtType);
-
+ numChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
ossSpeed = device->Frequency;
- log2FragmentSize = log2i(device->UpdateSize * frameSize);
-
- /* according to the OSS spec, 16 bytes are the minimum */
- if (log2FragmentSize < 4)
- log2FragmentSize = 4;
- /* Subtract one period since the temp mixing buffer counts as one. Still
- * need at least two on the card, though. */
- if(periods > 2) periods--;
+ frameSize = numChannels * BytesFromDevFmt(device->FmtType);
+ /* According to the OSS spec, 16 bytes (log2(16)) is the minimum. */
+ log2FragmentSize = maxi(log2i(device->UpdateSize*frameSize), 4);
numFragmentsLogSize = (periods << 16) | log2FragmentSize;
#define CHECKERR(func) if((func) < 0) { \
@@ -245,7 +451,7 @@ static ALCboolean ALCplaybackOSS_reset(ALCplaybackOSS *self)
}
#undef CHECKERR
- if((int)ChannelsFromDevFmt(device->FmtChans) != numChannels)
+ if((int)ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder) != numChannels)
{
ERR("Failed to set %s, got %d channels instead\n", DevFmtChannelsString(device->FmtChans), numChannels);
return ALC_FALSE;
@@ -261,7 +467,7 @@ static ALCboolean ALCplaybackOSS_reset(ALCplaybackOSS *self)
device->Frequency = ossSpeed;
device->UpdateSize = info.fragsize / frameSize;
- device->NumUpdates = info.fragments + 1;
+ device->NumUpdates = info.fragments;
SetDefaultChannelOrder(device);
@@ -272,10 +478,12 @@ static ALCboolean ALCplaybackOSS_start(ALCplaybackOSS *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- self->data_size = device->UpdateSize * FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ self->data_size = device->UpdateSize * FrameSizeFromDevFmt(
+ device->FmtChans, device->FmtType, device->AmbiOrder
+ );
self->mix_data = calloc(1, self->data_size);
- self->killNow = 0;
+ ATOMIC_STORE_SEQ(&self->killNow, AL_FALSE);
if(althrd_create(&self->thread, ALCplaybackOSS_mixerProc, self) != althrd_success)
{
free(self->mix_data);
@@ -290,10 +498,8 @@ static void ALCplaybackOSS_stop(ALCplaybackOSS *self)
{
int res;
- if(self->killNow)
+ if(ATOMIC_EXCHANGE_SEQ(&self->killNow, AL_TRUE))
return;
-
- self->killNow = 1;
althrd_join(self->thread, &res);
if(ioctl(self->fd, SNDCTL_DSP_RESET) != 0)
@@ -309,28 +515,23 @@ typedef struct ALCcaptureOSS {
int fd;
- ALubyte *read_data;
- int data_size;
-
- RingBuffer *ring;
- int doCapture;
+ ll_ringbuffer_t *ring;
- volatile int killNow;
+ ATOMIC(ALenum) killNow;
althrd_t thread;
} ALCcaptureOSS;
static int ALCcaptureOSS_recordProc(void *ptr);
static void ALCcaptureOSS_Construct(ALCcaptureOSS *self, ALCdevice *device);
-static DECLARE_FORWARD(ALCcaptureOSS, ALCbackend, void, Destruct)
+static void ALCcaptureOSS_Destruct(ALCcaptureOSS *self);
static ALCenum ALCcaptureOSS_open(ALCcaptureOSS *self, const ALCchar *name);
-static void ALCcaptureOSS_close(ALCcaptureOSS *self);
static DECLARE_FORWARD(ALCcaptureOSS, ALCbackend, ALCboolean, reset)
static ALCboolean ALCcaptureOSS_start(ALCcaptureOSS *self);
static void ALCcaptureOSS_stop(ALCcaptureOSS *self);
static ALCenum ALCcaptureOSS_captureSamples(ALCcaptureOSS *self, ALCvoid *buffer, ALCuint samples);
static ALCuint ALCcaptureOSS_availableSamples(ALCcaptureOSS *self);
-static DECLARE_FORWARD(ALCcaptureOSS, ALCbackend, ALint64, getLatency)
+static DECLARE_FORWARD(ALCcaptureOSS, ALCbackend, ClockLatency, getClockLatency)
static DECLARE_FORWARD(ALCcaptureOSS, ALCbackend, void, lock)
static DECLARE_FORWARD(ALCcaptureOSS, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCcaptureOSS)
@@ -341,32 +542,55 @@ static int ALCcaptureOSS_recordProc(void *ptr)
{
ALCcaptureOSS *self = (ALCcaptureOSS*)ptr;
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- int frameSize;
- int amt;
+ struct timeval timeout;
+ int frame_size;
+ fd_set rfds;
+ ssize_t amt;
+ int sret;
SetRTPriority();
althrd_setname(althrd_current(), RECORD_THREAD_NAME);
- frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ frame_size = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
- while(!self->killNow)
+ while(!ATOMIC_LOAD_SEQ(&self->killNow))
{
- amt = read(self->fd, self->read_data, self->data_size);
- if(amt < 0)
+ ll_ringbuffer_data_t vec[2];
+
+ FD_ZERO(&rfds);
+ FD_SET(self->fd, &rfds);
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+
+ sret = select(self->fd+1, &rfds, NULL, NULL, &timeout);
+ if(sret < 0)
{
- ERR("read failed: %s\n", strerror(errno));
- ALCcaptureOSS_lock(self);
- aluHandleDisconnect(device);
- ALCcaptureOSS_unlock(self);
+ if(errno == EINTR)
+ continue;
+ ERR("select failed: %s\n", strerror(errno));
+ aluHandleDisconnect(device, "Failed to check capture samples: %s", strerror(errno));
break;
}
- if(amt == 0)
+ else if(sret == 0)
{
- al_nssleep(1000000);
+ WARN("select timeout\n");
continue;
}
- if(self->doCapture)
- WriteRingBuffer(self->ring, self->read_data, amt/frameSize);
+
+ ll_ringbuffer_get_write_vector(self->ring, vec);
+ if(vec[0].len > 0)
+ {
+ amt = read(self->fd, vec[0].buf, vec[0].len*frame_size);
+ if(amt < 0)
+ {
+ ERR("read failed: %s\n", strerror(errno));
+ ALCcaptureOSS_lock(self);
+ aluHandleDisconnect(device, "Failed reading capture samples: %s", strerror(errno));
+ ALCcaptureOSS_unlock(self);
+ break;
+ }
+ ll_ringbuffer_write_advance(self->ring, amt/frame_size);
+ }
}
return 0;
@@ -377,11 +601,27 @@ static void ALCcaptureOSS_Construct(ALCcaptureOSS *self, ALCdevice *device)
{
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCcaptureOSS, ALCbackend, self);
+
+ self->fd = -1;
+ self->ring = NULL;
+ ATOMIC_INIT(&self->killNow, AL_FALSE);
+}
+
+static void ALCcaptureOSS_Destruct(ALCcaptureOSS *self)
+{
+ if(self->fd != -1)
+ close(self->fd);
+ self->fd = -1;
+
+ ll_ringbuffer_free(self->ring);
+ self->ring = NULL;
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}
static ALCenum ALCcaptureOSS_open(ALCcaptureOSS *self, const ALCchar *name)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
+ struct oss_device *dev = &oss_capture;
int numFragmentsLogSize;
int log2FragmentSize;
unsigned int periods;
@@ -392,15 +632,32 @@ static ALCenum ALCcaptureOSS_open(ALCcaptureOSS *self, const ALCchar *name)
int ossSpeed;
char *err;
- if(!name)
- name = oss_device;
- else if(strcmp(name, oss_device) != 0)
- return ALC_INVALID_VALUE;
+ if(!name || strcmp(name, dev->handle) == 0)
+ name = dev->handle;
+ else
+ {
+ if(!dev->next)
+ {
+ ALCossListPopulate(&oss_capture, DSP_CAP_INPUT);
+ dev = &oss_capture;
+ }
+ while(dev != NULL)
+ {
+ if (strcmp(dev->handle, name) == 0)
+ break;
+ dev = dev->next;
+ }
+ if(dev == NULL)
+ {
+ WARN("Could not find \"%s\" in device list\n", name);
+ return ALC_INVALID_VALUE;
+ }
+ }
- self->fd = open(oss_capture, O_RDONLY);
+ self->fd = open(dev->path, O_RDONLY);
if(self->fd == -1)
{
- ERR("Could not open %s: %s\n", oss_capture, strerror(errno));
+ ERR("Could not open %s: %s\n", dev->path, strerror(errno));
return ALC_INVALID_VALUE;
}
@@ -424,7 +681,7 @@ static ALCenum ALCcaptureOSS_open(ALCcaptureOSS *self, const ALCchar *name)
}
periods = 4;
- numChannels = ChannelsFromDevFmt(device->FmtChans);
+ numChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
frameSize = numChannels * BytesFromDevFmt(device->FmtType);
ossSpeed = device->Frequency;
log2FragmentSize = log2i(device->UpdateSize * device->NumUpdates *
@@ -454,7 +711,7 @@ static ALCenum ALCcaptureOSS_open(ALCcaptureOSS *self, const ALCchar *name)
}
#undef CHECKERR
- if((int)ChannelsFromDevFmt(device->FmtChans) != numChannels)
+ if((int)ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder) != numChannels)
{
ERR("Failed to set %s, got %d channels instead\n", DevFmtChannelsString(device->FmtChans), numChannels);
close(self->fd);
@@ -472,7 +729,7 @@ static ALCenum ALCcaptureOSS_open(ALCcaptureOSS *self, const ALCchar *name)
return ALC_INVALID_VALUE;
}
- self->ring = CreateRingBuffer(frameSize, device->UpdateSize * device->NumUpdates);
+ self->ring = ll_ringbuffer_create(device->UpdateSize*device->NumUpdates, frameSize, false);
if(!self->ring)
{
ERR("Ring buffer create failed\n");
@@ -481,60 +738,41 @@ static ALCenum ALCcaptureOSS_open(ALCcaptureOSS *self, const ALCchar *name)
return ALC_OUT_OF_MEMORY;
}
- self->data_size = info.fragsize;
- self->read_data = calloc(1, self->data_size);
-
- self->killNow = 0;
- if(althrd_create(&self->thread, ALCcaptureOSS_recordProc, self) != althrd_success)
- {
- device->ExtraData = NULL;
- close(self->fd);
- self->fd = -1;
- return ALC_OUT_OF_MEMORY;
- }
-
- al_string_copy_cstr(&device->DeviceName, name);
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
}
-static void ALCcaptureOSS_close(ALCcaptureOSS *self)
-{
- int res;
-
- self->killNow = 1;
- althrd_join(self->thread, &res);
-
- close(self->fd);
- self->fd = -1;
-
- DestroyRingBuffer(self->ring);
- self->ring = NULL;
-
- free(self->read_data);
- self->read_data = NULL;
-}
-
static ALCboolean ALCcaptureOSS_start(ALCcaptureOSS *self)
{
- self->doCapture = 1;
+ ATOMIC_STORE_SEQ(&self->killNow, AL_FALSE);
+ if(althrd_create(&self->thread, ALCcaptureOSS_recordProc, self) != althrd_success)
+ return ALC_FALSE;
return ALC_TRUE;
}
static void ALCcaptureOSS_stop(ALCcaptureOSS *self)
{
- self->doCapture = 0;
+ int res;
+
+ if(ATOMIC_EXCHANGE_SEQ(&self->killNow, AL_TRUE))
+ return;
+
+ althrd_join(self->thread, &res);
+
+ if(ioctl(self->fd, SNDCTL_DSP_RESET) != 0)
+ ERR("Error resetting device: %s\n", strerror(errno));
}
static ALCenum ALCcaptureOSS_captureSamples(ALCcaptureOSS *self, ALCvoid *buffer, ALCuint samples)
{
- ReadRingBuffer(self->ring, buffer, samples);
+ ll_ringbuffer_read(self->ring, buffer, samples);
return ALC_NO_ERROR;
}
static ALCuint ALCcaptureOSS_availableSamples(ALCcaptureOSS *self)
{
- return RingBufferSize(self->ring);
+ return ll_ringbuffer_read_space(self->ring);
}
@@ -546,9 +784,9 @@ typedef struct ALCossBackendFactory {
ALCbackendFactory *ALCossBackendFactory_getFactory(void);
static ALCboolean ALCossBackendFactory_init(ALCossBackendFactory *self);
-static DECLARE_FORWARD(ALCossBackendFactory, ALCbackendFactory, void, deinit)
+static void ALCossBackendFactory_deinit(ALCossBackendFactory *self);
static ALCboolean ALCossBackendFactory_querySupport(ALCossBackendFactory *self, ALCbackend_Type type);
-static void ALCossBackendFactory_probe(ALCossBackendFactory *self, enum DevProbe type);
+static void ALCossBackendFactory_probe(ALCossBackendFactory *self, enum DevProbe type, al_string *outnames);
static ALCbackend* ALCossBackendFactory_createBackend(ALCossBackendFactory *self, ALCdevice *device, ALCbackend_Type type);
DEFINE_ALCBACKENDFACTORY_VTABLE(ALCossBackendFactory);
@@ -562,12 +800,19 @@ ALCbackendFactory *ALCossBackendFactory_getFactory(void)
ALCboolean ALCossBackendFactory_init(ALCossBackendFactory* UNUSED(self))
{
- ConfigValueStr(NULL, "oss", "device", &oss_driver);
- ConfigValueStr(NULL, "oss", "capture", &oss_capture);
+ ConfigValueStr(NULL, "oss", "device", &oss_playback.path);
+ ConfigValueStr(NULL, "oss", "capture", &oss_capture.path);
return ALC_TRUE;
}
+void ALCossBackendFactory_deinit(ALCossBackendFactory* UNUSED(self))
+{
+ ALCossListFree(&oss_playback);
+ ALCossListFree(&oss_capture);
+}
+
+
ALCboolean ALCossBackendFactory_querySupport(ALCossBackendFactory* UNUSED(self), ALCbackend_Type type)
{
if(type == ALCbackend_Playback || type == ALCbackend_Capture)
@@ -575,29 +820,31 @@ ALCboolean ALCossBackendFactory_querySupport(ALCossBackendFactory* UNUSED(self),
return ALC_FALSE;
}
-void ALCossBackendFactory_probe(ALCossBackendFactory* UNUSED(self), enum DevProbe type)
+void ALCossBackendFactory_probe(ALCossBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
+ struct oss_device *cur = NULL;
switch(type)
{
case ALL_DEVICE_PROBE:
- {
-#ifdef HAVE_STAT
- struct stat buf;
- if(stat(oss_driver, &buf) == 0)
-#endif
- AppendAllDevicesList(oss_device);
- }
- break;
+ ALCossListFree(&oss_playback);
+ ALCossListPopulate(&oss_playback, DSP_CAP_OUTPUT);
+ cur = &oss_playback;
+ break;
case CAPTURE_DEVICE_PROBE:
- {
+ ALCossListFree(&oss_capture);
+ ALCossListPopulate(&oss_capture, DSP_CAP_INPUT);
+ cur = &oss_capture;
+ break;
+ }
+ while(cur != NULL)
+ {
#ifdef HAVE_STAT
- struct stat buf;
- if(stat(oss_capture, &buf) == 0)
+ struct stat buf;
+ if(stat(cur->path, &buf) == 0)
#endif
- AppendCaptureDeviceList(oss_device);
- }
- break;
+ alstr_append_range(outnames, cur->handle, cur->handle+strlen(cur->handle)+1);
+ cur = cur->next;
}
}
diff --git a/Alc/backends/portaudio.c b/Alc/backends/portaudio.c
index f45833c6..6a6cfa31 100644
--- a/Alc/backends/portaudio.c
+++ b/Alc/backends/portaudio.c
@@ -26,6 +26,8 @@
#include "alMain.h"
#include "alu.h"
+#include "alconfig.h"
+#include "ringbuffer.h"
#include "compat.h"
#include "backends/base.h"
@@ -139,13 +141,12 @@ static int ALCportPlayback_WriteCallback(const void *inputBuffer, void *outputBu
static void ALCportPlayback_Construct(ALCportPlayback *self, ALCdevice *device);
static void ALCportPlayback_Destruct(ALCportPlayback *self);
static ALCenum ALCportPlayback_open(ALCportPlayback *self, const ALCchar *name);
-static void ALCportPlayback_close(ALCportPlayback *self);
static ALCboolean ALCportPlayback_reset(ALCportPlayback *self);
static ALCboolean ALCportPlayback_start(ALCportPlayback *self);
static void ALCportPlayback_stop(ALCportPlayback *self);
static DECLARE_FORWARD2(ALCportPlayback, ALCbackend, ALCenum, captureSamples, ALCvoid*, ALCuint)
static DECLARE_FORWARD(ALCportPlayback, ALCbackend, ALCuint, availableSamples)
-static DECLARE_FORWARD(ALCportPlayback, ALCbackend, ALint64, getLatency)
+static DECLARE_FORWARD(ALCportPlayback, ALCbackend, ClockLatency, getClockLatency)
static DECLARE_FORWARD(ALCportPlayback, ALCbackend, void, lock)
static DECLARE_FORWARD(ALCportPlayback, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCportPlayback)
@@ -163,8 +164,9 @@ static void ALCportPlayback_Construct(ALCportPlayback *self, ALCdevice *device)
static void ALCportPlayback_Destruct(ALCportPlayback *self)
{
- if(self->stream)
- Pa_CloseStream(self->stream);
+ PaError err = self->stream ? Pa_CloseStream(self->stream) : paNoError;
+ if(err != paNoError)
+ ERR("Error closing stream: %s\n", Pa_GetErrorText(err));
self->stream = NULL;
ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
@@ -177,7 +179,9 @@ static int ALCportPlayback_WriteCallback(const void *UNUSED(inputBuffer), void *
{
ALCportPlayback *self = userData;
+ ALCportPlayback_lock(self);
aluMixData(STATIC_CAST(ALCbackend, self)->mDevice, outputBuffer, framesPerBuffer);
+ ALCportPlayback_unlock(self);
return 0;
}
@@ -243,20 +247,12 @@ retry_open:
return ALC_INVALID_VALUE;
}
- al_string_copy_cstr(&device->DeviceName, name);
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
}
-static void ALCportPlayback_close(ALCportPlayback *self)
-{
- PaError err = Pa_CloseStream(self->stream);
- if(err != paNoError)
- ERR("Error closing stream: %s\n", Pa_GetErrorText(err));
- self->stream = NULL;
-}
-
static ALCboolean ALCportPlayback_reset(ALCportPlayback *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
@@ -334,13 +330,12 @@ static int ALCportCapture_ReadCallback(const void *inputBuffer, void *outputBuff
static void ALCportCapture_Construct(ALCportCapture *self, ALCdevice *device);
static void ALCportCapture_Destruct(ALCportCapture *self);
static ALCenum ALCportCapture_open(ALCportCapture *self, const ALCchar *name);
-static void ALCportCapture_close(ALCportCapture *self);
static DECLARE_FORWARD(ALCportCapture, ALCbackend, ALCboolean, reset)
static ALCboolean ALCportCapture_start(ALCportCapture *self);
static void ALCportCapture_stop(ALCportCapture *self);
static ALCenum ALCportCapture_captureSamples(ALCportCapture *self, ALCvoid *buffer, ALCuint samples);
static ALCuint ALCportCapture_availableSamples(ALCportCapture *self);
-static DECLARE_FORWARD(ALCportCapture, ALCbackend, ALint64, getLatency)
+static DECLARE_FORWARD(ALCportCapture, ALCbackend, ClockLatency, getClockLatency)
static DECLARE_FORWARD(ALCportCapture, ALCbackend, void, lock)
static DECLARE_FORWARD(ALCportCapture, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCportCapture)
@@ -354,16 +349,17 @@ static void ALCportCapture_Construct(ALCportCapture *self, ALCdevice *device)
SET_VTABLE2(ALCportCapture, ALCbackend, self);
self->stream = NULL;
+ self->ring = NULL;
}
static void ALCportCapture_Destruct(ALCportCapture *self)
{
- if(self->stream)
- Pa_CloseStream(self->stream);
+ PaError err = self->stream ? Pa_CloseStream(self->stream) : paNoError;
+ if(err != paNoError)
+ ERR("Error closing stream: %s\n", Pa_GetErrorText(err));
self->stream = NULL;
- if(self->ring)
- ll_ringbuffer_free(self->ring);
+ ll_ringbuffer_free(self->ring);
self->ring = NULL;
ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
@@ -397,9 +393,9 @@ static ALCenum ALCportCapture_open(ALCportCapture *self, const ALCchar *name)
samples = device->UpdateSize * device->NumUpdates;
samples = maxu(samples, 100 * device->Frequency / 1000);
- frame_size = FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ frame_size = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
- self->ring = ll_ringbuffer_create(samples, frame_size);
+ self->ring = ll_ringbuffer_create(samples, frame_size, false);
if(self->ring == NULL) return ALC_INVALID_VALUE;
self->params.device = -1;
@@ -431,7 +427,7 @@ static ALCenum ALCportCapture_open(ALCportCapture *self, const ALCchar *name)
ERR("%s samples not supported\n", DevFmtTypeString(device->FmtType));
return ALC_INVALID_VALUE;
}
- self->params.channelCount = ChannelsFromDevFmt(device->FmtChans);
+ self->params.channelCount = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
err = Pa_OpenStream(&self->stream, &self->params, NULL,
device->Frequency, paFramesPerBufferUnspecified, paNoFlag,
@@ -443,22 +439,11 @@ static ALCenum ALCportCapture_open(ALCportCapture *self, const ALCchar *name)
return ALC_INVALID_VALUE;
}
- al_string_copy_cstr(&device->DeviceName, name);
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
}
-static void ALCportCapture_close(ALCportCapture *self)
-{
- PaError err = Pa_CloseStream(self->stream);
- if(err != paNoError)
- ERR("Error closing stream: %s\n", Pa_GetErrorText(err));
- self->stream = NULL;
-
- ll_ringbuffer_free(self->ring);
- self->ring = NULL;
-}
-
static ALCboolean ALCportCapture_start(ALCportCapture *self)
{
@@ -499,9 +484,8 @@ typedef struct ALCportBackendFactory {
static ALCboolean ALCportBackendFactory_init(ALCportBackendFactory *self);
static void ALCportBackendFactory_deinit(ALCportBackendFactory *self);
static ALCboolean ALCportBackendFactory_querySupport(ALCportBackendFactory *self, ALCbackend_Type type);
-static void ALCportBackendFactory_probe(ALCportBackendFactory *self, enum DevProbe type);
+static void ALCportBackendFactory_probe(ALCportBackendFactory *self, enum DevProbe type, al_string *outnames);
static ALCbackend* ALCportBackendFactory_createBackend(ALCportBackendFactory *self, ALCdevice *device, ALCbackend_Type type);
-
DEFINE_ALCBACKENDFACTORY_VTABLE(ALCportBackendFactory);
@@ -533,15 +517,13 @@ static ALCboolean ALCportBackendFactory_querySupport(ALCportBackendFactory* UNUS
return ALC_FALSE;
}
-static void ALCportBackendFactory_probe(ALCportBackendFactory* UNUSED(self), enum DevProbe type)
+static void ALCportBackendFactory_probe(ALCportBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
switch(type)
{
case ALL_DEVICE_PROBE:
- AppendAllDevicesList(pa_device);
- break;
case CAPTURE_DEVICE_PROBE:
- AppendCaptureDeviceList(pa_device);
+ alstr_append_range(outnames, pa_device, pa_device+sizeof(pa_device));
break;
}
}
diff --git a/Alc/backends/pulseaudio.c b/Alc/backends/pulseaudio.c
index 9ad04a71..b34d7abc 100644
--- a/Alc/backends/pulseaudio.c
+++ b/Alc/backends/pulseaudio.c
@@ -25,6 +25,7 @@
#include "alMain.h"
#include "alu.h"
+#include "alconfig.h"
#include "threads.h"
#include "compat.h"
@@ -182,6 +183,8 @@ static ALCboolean pulse_load(void)
#ifdef HAVE_DYNLOAD
if(!pa_handle)
{
+ al_string missing_funcs = AL_STRING_INIT_STATIC();
+
#ifdef _WIN32
#define PALIB "libpulse-0.dll"
#elif defined(__APPLE__) && defined(__MACH__)
@@ -191,12 +194,16 @@ static ALCboolean pulse_load(void)
#endif
pa_handle = LoadLib(PALIB);
if(!pa_handle)
+ {
+ WARN("Failed to load %s\n", PALIB);
return ALC_FALSE;
+ }
#define LOAD_FUNC(x) do { \
p##x = GetSymbol(pa_handle, #x); \
if(!(p##x)) { \
ret = ALC_FALSE; \
+ alstr_append_cstr(&missing_funcs, "\n" #x); \
} \
} while(0)
LOAD_FUNC(pa_context_unref);
@@ -270,9 +277,11 @@ static ALCboolean pulse_load(void)
if(ret == ALC_FALSE)
{
+ WARN("Missing expected functions:%s\n", alstr_get_cstr(missing_funcs));
CloseLib(pa_handle);
pa_handle = NULL;
}
+ alstr_reset(&missing_funcs);
}
#endif /* HAVE_DYNLOAD */
return ret;
@@ -325,18 +334,20 @@ static void wait_for_operation(pa_operation *op, pa_threaded_mainloop *loop)
static pa_context *connect_context(pa_threaded_mainloop *loop, ALboolean silent)
{
const char *name = "OpenAL Soft";
- char path_name[PATH_MAX];
+ al_string binname = AL_STRING_INIT_STATIC();
pa_context_state_t state;
pa_context *context;
int err;
- if(pa_get_binary_name(path_name, sizeof(path_name)))
- name = pa_path_get_filename(path_name);
+ GetProcBinary(NULL, &binname);
+ if(!alstr_empty(binname))
+ name = alstr_get_cstr(binname);
context = pa_context_new(pa_threaded_mainloop_get_api(loop), name);
if(!context)
{
ERR("pa_context_new() failed\n");
+ alstr_reset(&binname);
return NULL;
}
@@ -363,9 +374,10 @@ static pa_context *connect_context(pa_threaded_mainloop *loop, ALboolean silent)
if(!silent)
ERR("Context did not connect: %s\n", pa_strerror(err));
pa_context_unref(context);
- return NULL;
+ context = NULL;
}
+ alstr_reset(&binname);
return context;
}
@@ -443,7 +455,7 @@ static void clear_devlist(vector_DevMap *list)
#define DEINIT_STRS(i) (AL_STRING_DEINIT((i)->name),AL_STRING_DEINIT((i)->device_name))
VECTOR_FOR_EACH(DevMap, *list, DEINIT_STRS);
#undef DEINIT_STRS
- VECTOR_RESIZE(*list, 0);
+ VECTOR_RESIZE(*list, 0, 0);
}
@@ -460,7 +472,7 @@ typedef struct ALCpulsePlayback {
pa_stream *stream;
pa_context *context;
- volatile ALboolean killNow;
+ ATOMIC(ALenum) killNow;
althrd_t thread;
} ALCpulsePlayback;
@@ -483,13 +495,12 @@ static int ALCpulsePlayback_mixerProc(void *ptr);
static void ALCpulsePlayback_Construct(ALCpulsePlayback *self, ALCdevice *device);
static void ALCpulsePlayback_Destruct(ALCpulsePlayback *self);
static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name);
-static void ALCpulsePlayback_close(ALCpulsePlayback *self);
static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self);
static ALCboolean ALCpulsePlayback_start(ALCpulsePlayback *self);
static void ALCpulsePlayback_stop(ALCpulsePlayback *self);
static DECLARE_FORWARD2(ALCpulsePlayback, ALCbackend, ALCenum, captureSamples, ALCvoid*, ALCuint)
static DECLARE_FORWARD(ALCpulsePlayback, ALCbackend, ALCuint, availableSamples)
-static ALint64 ALCpulsePlayback_getLatency(ALCpulsePlayback *self);
+static ClockLatency ALCpulsePlayback_getClockLatency(ALCpulsePlayback *self);
static void ALCpulsePlayback_lock(ALCpulsePlayback *self);
static void ALCpulsePlayback_unlock(ALCpulsePlayback *self);
DECLARE_DEFAULT_ALLOCATORS(ALCpulsePlayback)
@@ -502,11 +513,20 @@ static void ALCpulsePlayback_Construct(ALCpulsePlayback *self, ALCdevice *device
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCpulsePlayback, ALCbackend, self);
+ self->loop = NULL;
AL_STRING_INIT(self->device_name);
+ ATOMIC_INIT(&self->killNow, AL_TRUE);
}
static void ALCpulsePlayback_Destruct(ALCpulsePlayback *self)
{
+ if(self->loop)
+ {
+ pulse_close(self->loop, self->context, self->stream);
+ self->loop = NULL;
+ self->context = NULL;
+ self->stream = NULL;
+ }
AL_STRING_DEINIT(self->device_name);
ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}
@@ -525,35 +545,35 @@ static void ALCpulsePlayback_deviceCallback(pa_context *UNUSED(context), const p
return;
}
-#define MATCH_INFO_NAME(iter) (al_string_cmp_cstr((iter)->device_name, info->name) == 0)
+#define MATCH_INFO_NAME(iter) (alstr_cmp_cstr((iter)->device_name, info->name) == 0)
VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_INFO_NAME);
- if(iter != VECTOR_ITER_END(PlaybackDevices)) return;
+ if(iter != VECTOR_END(PlaybackDevices)) return;
#undef MATCH_INFO_NAME
AL_STRING_INIT(entry.name);
AL_STRING_INIT(entry.device_name);
- al_string_copy_cstr(&entry.device_name, info->name);
+ alstr_copy_cstr(&entry.device_name, info->name);
count = 0;
while(1)
{
- al_string_copy_cstr(&entry.name, info->description);
+ alstr_copy_cstr(&entry.name, info->description);
if(count != 0)
{
char str[64];
snprintf(str, sizeof(str), " #%d", count+1);
- al_string_append_cstr(&entry.name, str);
+ alstr_append_cstr(&entry.name, str);
}
-#define MATCH_ENTRY(i) (al_string_cmp(entry.name, (i)->name) == 0)
+#define MATCH_ENTRY(i) (alstr_cmp(entry.name, (i)->name) == 0)
VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_ENTRY);
- if(iter == VECTOR_ITER_END(PlaybackDevices)) break;
+ if(iter == VECTOR_END(PlaybackDevices)) break;
#undef MATCH_ENTRY
count++;
}
- TRACE("Got device \"%s\", \"%s\"\n", al_string_get_cstr(entry.name), al_string_get_cstr(entry.device_name));
+ TRACE("Got device \"%s\", \"%s\"\n", alstr_get_cstr(entry.name), alstr_get_cstr(entry.device_name));
VECTOR_PUSH_BACK(PlaybackDevices, entry);
}
@@ -618,6 +638,11 @@ static void ALCpulsePlayback_bufferAttrCallback(pa_stream *stream, void *pdata)
self->attr = *pa_stream_get_buffer_attr(stream);
TRACE("minreq=%d, tlength=%d, prebuf=%d\n", self->attr.minreq, self->attr.tlength, self->attr.prebuf);
+ /* FIXME: Update the device's UpdateSize (and/or NumUpdates) using the new
+ * buffer attributes? Changing UpdateSize will change the ALC_REFRESH
+ * property, which probably shouldn't change between device resets. But
+ * leaving it alone means ALC_REFRESH will be off.
+ */
}
static void ALCpulsePlayback_contextStateCallback(pa_context *context, void *pdata)
@@ -626,7 +651,7 @@ static void ALCpulsePlayback_contextStateCallback(pa_context *context, void *pda
if(pa_context_get_state(context) == PA_CONTEXT_FAILED)
{
ERR("Received context failure!\n");
- aluHandleDisconnect(STATIC_CAST(ALCbackend,self)->mDevice);
+ aluHandleDisconnect(STATIC_CAST(ALCbackend,self)->mDevice, "Playback state failure");
}
pa_threaded_mainloop_signal(self->loop, 0);
}
@@ -637,7 +662,7 @@ static void ALCpulsePlayback_streamStateCallback(pa_stream *stream, void *pdata)
if(pa_stream_get_state(stream) == PA_STREAM_FAILED)
{
ERR("Received stream failure!\n");
- aluHandleDisconnect(STATIC_CAST(ALCbackend,self)->mDevice);
+ aluHandleDisconnect(STATIC_CAST(ALCbackend,self)->mDevice, "Playback stream failure");
}
pa_threaded_mainloop_signal(self->loop, 0);
}
@@ -729,7 +754,7 @@ static void ALCpulsePlayback_sinkNameCallback(pa_context *UNUSED(context), const
return;
}
- al_string_copy_cstr(&device->DeviceName, info->description);
+ alstr_copy_cstr(&device->DeviceName, info->description);
}
@@ -737,9 +762,9 @@ static void ALCpulsePlayback_streamMovedCallback(pa_stream *stream, void *pdata)
{
ALCpulsePlayback *self = pdata;
- al_string_copy_cstr(&self->device_name, pa_stream_get_device_name(stream));
+ alstr_copy_cstr(&self->device_name, pa_stream_get_device_name(stream));
- TRACE("Stream moved to %s\n", al_string_get_cstr(self->device_name));
+ TRACE("Stream moved to %s\n", alstr_get_cstr(self->device_name));
}
@@ -751,6 +776,13 @@ static pa_stream *ALCpulsePlayback_connectStream(const char *device_name,
pa_stream_state_t state;
pa_stream *stream;
+ if(!device_name)
+ {
+ device_name = getenv("ALSOFT_PULSE_DEFAULT");
+ if(device_name && !device_name[0])
+ device_name = NULL;
+ }
+
stream = pa_stream_new_with_proplist(context, "Playback Stream", spec, chanmap, prop_filter);
if(!stream)
{
@@ -789,7 +821,6 @@ static int ALCpulsePlayback_mixerProc(void *ptr)
ALCpulsePlayback *self = ptr;
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
ALuint buffer_size;
- ALint update_size;
size_t frame_size;
ssize_t len;
@@ -798,18 +829,35 @@ static int ALCpulsePlayback_mixerProc(void *ptr)
pa_threaded_mainloop_lock(self->loop);
frame_size = pa_frame_size(&self->spec);
- update_size = device->UpdateSize * frame_size;
-
- /* Sanitize buffer metrics, in case we actually have less than what we
- * asked for. */
- buffer_size = minu(update_size*device->NumUpdates, self->attr.tlength);
- update_size = minu(update_size, buffer_size/2);
- do {
- len = pa_stream_writable_size(self->stream) - self->attr.tlength +
- buffer_size;
- if(len < update_size)
+
+ while(!ATOMIC_LOAD(&self->killNow, almemory_order_acquire) &&
+ ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
+ {
+ void *buf;
+ int ret;
+
+ len = pa_stream_writable_size(self->stream);
+ if(len < 0)
+ {
+ ERR("Failed to get writable size: %ld", (long)len);
+ aluHandleDisconnect(device, "Failed to get writable size: %ld", (long)len);
+ break;
+ }
+
+ /* Make sure we're going to write at least 2 'periods' (minreqs), in
+ * case the server increased it since starting playback. Also round up
+ * the number of writable periods if it's not an integer count.
+ */
+ buffer_size = maxu((self->attr.tlength + self->attr.minreq/2) / self->attr.minreq, 2) *
+ self->attr.minreq;
+
+ /* NOTE: This assumes pa_stream_writable_size returns between 0 and
+ * tlength, else there will be more latency than intended.
+ */
+ len = mini(len - (ssize_t)self->attr.tlength, 0) + buffer_size;
+ if(len < (int32_t)self->attr.minreq)
{
- if(pa_stream_is_corked(self->stream) == 1)
+ if(pa_stream_is_corked(self->stream))
{
pa_operation *o;
o = pa_stream_cork(self->stream, 0, NULL, NULL);
@@ -818,26 +866,17 @@ static int ALCpulsePlayback_mixerProc(void *ptr)
pa_threaded_mainloop_wait(self->loop);
continue;
}
- len -= len%update_size;
- while(len > 0)
- {
- size_t newlen = len;
- void *buf;
- pa_free_cb_t free_func = NULL;
+ len -= len%self->attr.minreq;
+ len -= len%frame_size;
- if(pa_stream_begin_write(self->stream, &buf, &newlen) < 0)
- {
- buf = pa_xmalloc(newlen);
- free_func = pa_xfree;
- }
+ buf = pa_xmalloc(len);
- aluMixData(device, buf, newlen/frame_size);
+ aluMixData(device, buf, len/frame_size);
- pa_stream_write(self->stream, buf, newlen, free_func, 0, PA_SEEK_RELATIVE);
- len -= newlen;
- }
- } while(!self->killNow && device->Connected);
+ ret = pa_stream_write(self->stream, buf, len, pa_xfree, 0, PA_SEEK_RELATIVE);
+ if(ret != PA_OK) ERR("Failed to write to stream: %d, %s\n", ret, pa_strerror(ret));
+ }
pa_threaded_mainloop_unlock(self->loop);
return 0;
@@ -858,12 +897,12 @@ static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name
if(VECTOR_SIZE(PlaybackDevices) == 0)
ALCpulsePlayback_probeDevices();
-#define MATCH_NAME(iter) (al_string_cmp_cstr((iter)->name, name) == 0)
+#define MATCH_NAME(iter) (alstr_cmp_cstr((iter)->name, name) == 0)
VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_NAME);
#undef MATCH_NAME
- if(iter == VECTOR_ITER_END(PlaybackDevices))
+ if(iter == VECTOR_END(PlaybackDevices))
return ALC_INVALID_VALUE;
- pulse_name = al_string_get_cstr(iter->device_name);
+ pulse_name = alstr_get_cstr(iter->device_name);
dev_name = iter->name;
}
@@ -894,11 +933,11 @@ static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name
}
pa_stream_set_moved_callback(self->stream, ALCpulsePlayback_streamMovedCallback, self);
- al_string_copy_cstr(&self->device_name, pa_stream_get_device_name(self->stream));
- if(al_string_empty(dev_name))
+ alstr_copy_cstr(&self->device_name, pa_stream_get_device_name(self->stream));
+ if(alstr_empty(dev_name))
{
pa_operation *o = pa_context_get_sink_info_by_name(
- self->context, al_string_get_cstr(self->device_name),
+ self->context, alstr_get_cstr(self->device_name),
ALCpulsePlayback_sinkNameCallback, self
);
wait_for_operation(o, self->loop);
@@ -906,7 +945,7 @@ static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name
else
{
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
- al_string_copy(&device->DeviceName, dev_name);
+ alstr_copy(&device->DeviceName, dev_name);
}
pa_threaded_mainloop_unlock(self->loop);
@@ -914,16 +953,6 @@ static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name
return ALC_NO_ERROR;
}
-static void ALCpulsePlayback_close(ALCpulsePlayback *self)
-{
- pulse_close(self->loop, self->context, self->stream);
- self->loop = NULL;
- self->context = NULL;
- self->stream = NULL;
-
- al_string_clear(&self->device_name);
-}
-
static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
@@ -931,7 +960,6 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
const char *mapname = NULL;
pa_channel_map chanmap;
pa_operation *o;
- ALuint len;
pa_threaded_mainloop_lock(self->loop);
@@ -946,11 +974,11 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
self->stream = NULL;
}
- o = pa_context_get_sink_info_by_name(self->context, al_string_get_cstr(self->device_name),
+ o = pa_context_get_sink_info_by_name(self->context, alstr_get_cstr(self->device_name),
ALCpulsePlayback_sinkInfoCallback, self);
wait_for_operation(o, self->loop);
- if(GetConfigValueBool(al_string_get_cstr(device->DeviceName), "pulse", "fix-rate", 0) ||
+ if(GetConfigValueBool(alstr_get_cstr(device->DeviceName), "pulse", "fix-rate", 0) ||
!(device->Flags&DEVICE_FREQUENCY_REQUEST))
flags |= PA_STREAM_FIX_RATE;
flags |= PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE;
@@ -984,7 +1012,7 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
break;
}
self->spec.rate = device->Frequency;
- self->spec.channels = ChannelsFromDevFmt(device->FmtChans);
+ self->spec.channels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
if(pa_sample_spec_valid(&self->spec) == 0)
{
@@ -998,7 +1026,7 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
case DevFmtMono:
mapname = "mono";
break;
- case DevFmtBFormat3D:
+ case DevFmtAmbi3D:
device->FmtChans = DevFmtStereo;
/*fall-through*/
case DevFmtStereo:
@@ -1034,9 +1062,9 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
self->attr.tlength = self->attr.minreq * maxu(device->NumUpdates, 2);
self->attr.maxlength = -1;
- self->stream = ALCpulsePlayback_connectStream(al_string_get_cstr(self->device_name),
- self->loop, self->context, flags,
- &self->attr, &self->spec, &chanmap);
+ self->stream = ALCpulsePlayback_connectStream(alstr_get_cstr(self->device_name),
+ self->loop, self->context, flags, &self->attr, &self->spec, &chanmap
+ );
if(!self->stream)
{
pa_threaded_mainloop_unlock(self->loop);
@@ -1051,10 +1079,12 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
{
/* Server updated our playback rate, so modify the buffer attribs
* accordingly. */
- device->NumUpdates = (ALuint)((ALdouble)device->NumUpdates / device->Frequency *
- self->spec.rate + 0.5);
+ device->NumUpdates = (ALuint)clampd(
+ (ALdouble)device->NumUpdates/device->Frequency*self->spec.rate + 0.5, 2.0, 16.0
+ );
+
self->attr.minreq = device->UpdateSize * pa_frame_size(&self->spec);
- self->attr.tlength = self->attr.minreq * clampu(device->NumUpdates, 2, 16);
+ self->attr.tlength = self->attr.minreq * device->NumUpdates;
self->attr.maxlength = -1;
self->attr.prebuf = 0;
@@ -1068,10 +1098,30 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
pa_stream_set_buffer_attr_callback(self->stream, ALCpulsePlayback_bufferAttrCallback, self);
ALCpulsePlayback_bufferAttrCallback(self->stream, self);
- len = self->attr.minreq / pa_frame_size(&self->spec);
- device->NumUpdates = (ALuint)((ALdouble)device->NumUpdates/len*device->UpdateSize + 0.5);
- device->NumUpdates = clampu(device->NumUpdates, 2, 16);
- device->UpdateSize = len;
+ device->NumUpdates = (ALuint)clampu64(
+ (self->attr.tlength + self->attr.minreq/2) / self->attr.minreq, 2, 16
+ );
+ device->UpdateSize = self->attr.minreq / pa_frame_size(&self->spec);
+
+ /* HACK: prebuf should be 0 as that's what we set it to. However on some
+ * systems it comes back as non-0, so we have to make sure the device will
+ * write enough audio to start playback. The lack of manual start control
+ * may have unintended consequences, but it's better than not starting at
+ * all.
+ */
+ if(self->attr.prebuf != 0)
+ {
+ ALuint len = self->attr.prebuf / pa_frame_size(&self->spec);
+ if(len <= device->UpdateSize*device->NumUpdates)
+ ERR("Non-0 prebuf, %u samples (%u bytes), device has %u samples\n",
+ len, self->attr.prebuf, device->UpdateSize*device->NumUpdates);
+ else
+ {
+ ERR("Large prebuf, %u samples (%u bytes), increasing device from %u samples",
+ len, self->attr.prebuf, device->UpdateSize*device->NumUpdates);
+ device->NumUpdates = (len+device->UpdateSize-1) / device->UpdateSize;
+ }
+ }
pa_threaded_mainloop_unlock(self->loop);
return ALC_TRUE;
@@ -1079,7 +1129,7 @@ static ALCboolean ALCpulsePlayback_reset(ALCpulsePlayback *self)
static ALCboolean ALCpulsePlayback_start(ALCpulsePlayback *self)
{
- self->killNow = AL_FALSE;
+ ATOMIC_STORE(&self->killNow, AL_FALSE, almemory_order_release);
if(althrd_create(&self->thread, ALCpulsePlayback_mixerProc, self) != althrd_success)
return ALC_FALSE;
return ALC_TRUE;
@@ -1090,10 +1140,9 @@ static void ALCpulsePlayback_stop(ALCpulsePlayback *self)
pa_operation *o;
int res;
- if(!self->stream || self->killNow)
+ if(!self->stream || ATOMIC_EXCHANGE(&self->killNow, AL_TRUE, almemory_order_acq_rel))
return;
- self->killNow = AL_TRUE;
/* Signal the main loop in case PulseAudio isn't sending us audio requests
* (e.g. if the device is suspended). We need to lock the mainloop in case
* the mixer is between checking the killNow flag but before waiting for
@@ -1113,12 +1162,18 @@ static void ALCpulsePlayback_stop(ALCpulsePlayback *self)
}
-static ALint64 ALCpulsePlayback_getLatency(ALCpulsePlayback *self)
+static ClockLatency ALCpulsePlayback_getClockLatency(ALCpulsePlayback *self)
{
- pa_usec_t latency = 0;
+ ClockLatency ret;
+ pa_usec_t latency;
int neg, err;
- if((err=pa_stream_get_latency(self->stream, &latency, &neg)) != 0)
+ pa_threaded_mainloop_lock(self->loop);
+ ret.ClockTime = GetDeviceClockTime(STATIC_CAST(ALCbackend,self)->mDevice);
+ err = pa_stream_get_latency(self->stream, &latency, &neg);
+ pa_threaded_mainloop_unlock(self->loop);
+
+ if(UNLIKELY(err != 0))
{
/* FIXME: if err = -PA_ERR_NODATA, it means we were called too soon
* after starting the stream and no timing info has been received from
@@ -1126,11 +1181,14 @@ static ALint64 ALCpulsePlayback_getLatency(ALCpulsePlayback *self)
* dummy value? Either way, it shouldn't be 0. */
if(err != -PA_ERR_NODATA)
ERR("Failed to get stream latency: 0x%x\n", err);
- return 0;
+ latency = 0;
+ neg = 0;
}
+ else if(UNLIKELY(neg))
+ latency = 0;
+ ret.Latency = (ALint64)minu64(latency, U64(0x7fffffffffffffff)/1000) * 1000;
- if(neg) latency = 0;
- return (ALint64)minu64(latency, U64(0x7fffffffffffffff)/1000) * 1000;
+ return ret;
}
@@ -1180,13 +1238,12 @@ static pa_stream *ALCpulseCapture_connectStream(const char *device_name,
static void ALCpulseCapture_Construct(ALCpulseCapture *self, ALCdevice *device);
static void ALCpulseCapture_Destruct(ALCpulseCapture *self);
static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name);
-static void ALCpulseCapture_close(ALCpulseCapture *self);
static DECLARE_FORWARD(ALCpulseCapture, ALCbackend, ALCboolean, reset)
static ALCboolean ALCpulseCapture_start(ALCpulseCapture *self);
static void ALCpulseCapture_stop(ALCpulseCapture *self);
static ALCenum ALCpulseCapture_captureSamples(ALCpulseCapture *self, ALCvoid *buffer, ALCuint samples);
static ALCuint ALCpulseCapture_availableSamples(ALCpulseCapture *self);
-static ALint64 ALCpulseCapture_getLatency(ALCpulseCapture *self);
+static ClockLatency ALCpulseCapture_getClockLatency(ALCpulseCapture *self);
static void ALCpulseCapture_lock(ALCpulseCapture *self);
static void ALCpulseCapture_unlock(ALCpulseCapture *self);
DECLARE_DEFAULT_ALLOCATORS(ALCpulseCapture)
@@ -1199,11 +1256,19 @@ static void ALCpulseCapture_Construct(ALCpulseCapture *self, ALCdevice *device)
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
SET_VTABLE2(ALCpulseCapture, ALCbackend, self);
+ self->loop = NULL;
AL_STRING_INIT(self->device_name);
}
static void ALCpulseCapture_Destruct(ALCpulseCapture *self)
{
+ if(self->loop)
+ {
+ pulse_close(self->loop, self->context, self->stream);
+ self->loop = NULL;
+ self->context = NULL;
+ self->stream = NULL;
+ }
AL_STRING_DEINIT(self->device_name);
ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}
@@ -1222,35 +1287,35 @@ static void ALCpulseCapture_deviceCallback(pa_context *UNUSED(context), const pa
return;
}
-#define MATCH_INFO_NAME(iter) (al_string_cmp_cstr((iter)->device_name, info->name) == 0)
+#define MATCH_INFO_NAME(iter) (alstr_cmp_cstr((iter)->device_name, info->name) == 0)
VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_INFO_NAME);
- if(iter != VECTOR_ITER_END(CaptureDevices)) return;
+ if(iter != VECTOR_END(CaptureDevices)) return;
#undef MATCH_INFO_NAME
AL_STRING_INIT(entry.name);
AL_STRING_INIT(entry.device_name);
- al_string_copy_cstr(&entry.device_name, info->name);
+ alstr_copy_cstr(&entry.device_name, info->name);
count = 0;
while(1)
{
- al_string_copy_cstr(&entry.name, info->description);
+ alstr_copy_cstr(&entry.name, info->description);
if(count != 0)
{
char str[64];
snprintf(str, sizeof(str), " #%d", count+1);
- al_string_append_cstr(&entry.name, str);
+ alstr_append_cstr(&entry.name, str);
}
-#define MATCH_ENTRY(i) (al_string_cmp(entry.name, (i)->name) == 0)
+#define MATCH_ENTRY(i) (alstr_cmp(entry.name, (i)->name) == 0)
VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_ENTRY);
- if(iter == VECTOR_ITER_END(CaptureDevices)) break;
+ if(iter == VECTOR_END(CaptureDevices)) break;
#undef MATCH_ENTRY
count++;
}
- TRACE("Got device \"%s\", \"%s\"\n", al_string_get_cstr(entry.name), al_string_get_cstr(entry.device_name));
+ TRACE("Got device \"%s\", \"%s\"\n", alstr_get_cstr(entry.name), alstr_get_cstr(entry.device_name));
VECTOR_PUSH_BACK(CaptureDevices, entry);
}
@@ -1315,7 +1380,7 @@ static void ALCpulseCapture_contextStateCallback(pa_context *context, void *pdat
if(pa_context_get_state(context) == PA_CONTEXT_FAILED)
{
ERR("Received context failure!\n");
- aluHandleDisconnect(STATIC_CAST(ALCbackend,self)->mDevice);
+ aluHandleDisconnect(STATIC_CAST(ALCbackend,self)->mDevice, "Capture state failure");
}
pa_threaded_mainloop_signal(self->loop, 0);
}
@@ -1326,7 +1391,7 @@ static void ALCpulseCapture_streamStateCallback(pa_stream *stream, void *pdata)
if(pa_stream_get_state(stream) == PA_STREAM_FAILED)
{
ERR("Received stream failure!\n");
- aluHandleDisconnect(STATIC_CAST(ALCbackend,self)->mDevice);
+ aluHandleDisconnect(STATIC_CAST(ALCbackend,self)->mDevice, "Capture stream failure");
}
pa_threaded_mainloop_signal(self->loop, 0);
}
@@ -1343,7 +1408,7 @@ static void ALCpulseCapture_sourceNameCallback(pa_context *UNUSED(context), cons
return;
}
- al_string_copy_cstr(&device->DeviceName, info->description);
+ alstr_copy_cstr(&device->DeviceName, info->description);
}
@@ -1351,9 +1416,9 @@ static void ALCpulseCapture_streamMovedCallback(pa_stream *stream, void *pdata)
{
ALCpulseCapture *self = pdata;
- al_string_copy_cstr(&self->device_name, pa_stream_get_device_name(stream));
+ alstr_copy_cstr(&self->device_name, pa_stream_get_device_name(stream));
- TRACE("Stream moved to %s\n", al_string_get_cstr(self->device_name));
+ TRACE("Stream moved to %s\n", alstr_get_cstr(self->device_name));
}
@@ -1403,6 +1468,7 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
const char *pulse_name = NULL;
pa_stream_flags_t flags = 0;
+ const char *mapname = NULL;
pa_channel_map chanmap;
ALuint samples;
@@ -1413,13 +1479,13 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
if(VECTOR_SIZE(CaptureDevices) == 0)
ALCpulseCapture_probeDevices();
-#define MATCH_NAME(iter) (al_string_cmp_cstr((iter)->name, name) == 0)
+#define MATCH_NAME(iter) (alstr_cmp_cstr((iter)->name, name) == 0)
VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_NAME);
#undef MATCH_NAME
- if(iter == VECTOR_ITER_END(CaptureDevices))
+ if(iter == VECTOR_END(CaptureDevices))
return ALC_INVALID_VALUE;
- pulse_name = al_string_get_cstr(iter->device_name);
- al_string_copy(&device->DeviceName, iter->name);
+ pulse_name = alstr_get_cstr(iter->device_name);
+ alstr_copy(&device->DeviceName, iter->name);
}
if(!pulse_open(&self->loop, &self->context, ALCpulseCapture_contextStateCallback, self))
@@ -1427,9 +1493,6 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
pa_threaded_mainloop_lock(self->loop);
- self->spec.rate = device->Frequency;
- self->spec.channels = ChannelsFromDevFmt(device->FmtChans);
-
switch(device->FmtType)
{
case DevFmtUByte:
@@ -1452,6 +1515,44 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
goto fail;
}
+ switch(device->FmtChans)
+ {
+ case DevFmtMono:
+ mapname = "mono";
+ break;
+ case DevFmtStereo:
+ mapname = "front-left,front-right";
+ break;
+ case DevFmtQuad:
+ mapname = "front-left,front-right,rear-left,rear-right";
+ break;
+ case DevFmtX51:
+ mapname = "front-left,front-right,front-center,lfe,side-left,side-right";
+ break;
+ case DevFmtX51Rear:
+ mapname = "front-left,front-right,front-center,lfe,rear-left,rear-right";
+ break;
+ case DevFmtX61:
+ mapname = "front-left,front-right,front-center,lfe,rear-center,side-left,side-right";
+ break;
+ case DevFmtX71:
+ mapname = "front-left,front-right,front-center,lfe,rear-left,rear-right,side-left,side-right";
+ break;
+ case DevFmtAmbi3D:
+ ERR("%s capture samples not supported\n", DevFmtChannelsString(device->FmtChans));
+ pa_threaded_mainloop_unlock(self->loop);
+ goto fail;
+ }
+ if(!pa_channel_map_parse(&chanmap, mapname))
+ {
+ ERR("Failed to build channel map for %s\n", DevFmtChannelsString(device->FmtChans));
+ pa_threaded_mainloop_unlock(self->loop);
+ return ALC_FALSE;
+ }
+
+ self->spec.rate = device->Frequency;
+ self->spec.channels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
+
if(pa_sample_spec_valid(&self->spec) == 0)
{
ERR("Invalid sample format\n");
@@ -1481,9 +1582,9 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
flags |= PA_STREAM_DONT_MOVE;
TRACE("Connecting to \"%s\"\n", pulse_name ? pulse_name : "(default)");
- self->stream = ALCpulseCapture_connectStream(pulse_name, self->loop, self->context,
- flags, &self->attr, &self->spec,
- &chanmap);
+ self->stream = ALCpulseCapture_connectStream(pulse_name,
+ self->loop, self->context, flags, &self->attr, &self->spec, &chanmap
+ );
if(!self->stream)
{
pa_threaded_mainloop_unlock(self->loop);
@@ -1492,11 +1593,11 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
pa_stream_set_moved_callback(self->stream, ALCpulseCapture_streamMovedCallback, self);
pa_stream_set_state_callback(self->stream, ALCpulseCapture_streamStateCallback, self);
- al_string_copy_cstr(&self->device_name, pa_stream_get_device_name(self->stream));
- if(al_string_empty(device->DeviceName))
+ alstr_copy_cstr(&self->device_name, pa_stream_get_device_name(self->stream));
+ if(alstr_empty(device->DeviceName))
{
pa_operation *o = pa_context_get_source_info_by_name(
- self->context, al_string_get_cstr(self->device_name),
+ self->context, alstr_get_cstr(self->device_name),
ALCpulseCapture_sourceNameCallback, self
);
wait_for_operation(o, self->loop);
@@ -1514,30 +1615,23 @@ fail:
return ALC_INVALID_VALUE;
}
-static void ALCpulseCapture_close(ALCpulseCapture *self)
-{
- pulse_close(self->loop, self->context, self->stream);
- self->loop = NULL;
- self->context = NULL;
- self->stream = NULL;
-
- al_string_clear(&self->device_name);
-}
-
static ALCboolean ALCpulseCapture_start(ALCpulseCapture *self)
{
pa_operation *o;
+ pa_threaded_mainloop_lock(self->loop);
o = pa_stream_cork(self->stream, 0, stream_success_callback, self->loop);
wait_for_operation(o, self->loop);
-
+ pa_threaded_mainloop_unlock(self->loop);
return ALC_TRUE;
}
static void ALCpulseCapture_stop(ALCpulseCapture *self)
{
pa_operation *o;
+ pa_threaded_mainloop_lock(self->loop);
o = pa_stream_cork(self->stream, 1, stream_success_callback, self->loop);
wait_for_operation(o, self->loop);
+ pa_threaded_mainloop_unlock(self->loop);
}
static ALCenum ALCpulseCapture_captureSamples(ALCpulseCapture *self, ALCvoid *buffer, ALCuint samples)
@@ -1548,6 +1642,7 @@ static ALCenum ALCpulseCapture_captureSamples(ALCpulseCapture *self, ALCvoid *bu
/* Capture is done in fragment-sized chunks, so we loop until we get all
* that's available */
self->last_readable -= todo;
+ pa_threaded_mainloop_lock(self->loop);
while(todo > 0)
{
size_t rem = todo;
@@ -1559,14 +1654,15 @@ static ALCenum ALCpulseCapture_captureSamples(ALCpulseCapture *self, ALCvoid *bu
state = pa_stream_get_state(self->stream);
if(!PA_STREAM_IS_GOOD(state))
{
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Bad capture state: %u", state);
break;
}
if(pa_stream_peek(self->stream, &self->cap_store, &self->cap_len) < 0)
{
ERR("pa_stream_peek() failed: %s\n",
pa_strerror(pa_context_errno(self->context)));
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failed retrieving capture samples: %s",
+ pa_strerror(pa_context_errno(self->context)));
break;
}
self->cap_remain = self->cap_len;
@@ -1587,6 +1683,7 @@ static ALCenum ALCpulseCapture_captureSamples(ALCpulseCapture *self, ALCvoid *bu
self->cap_len = 0;
}
}
+ pa_threaded_mainloop_unlock(self->loop);
if(todo > 0)
memset(buffer, ((device->FmtType==DevFmtUByte) ? 0x80 : 0), todo);
@@ -1598,16 +1695,19 @@ static ALCuint ALCpulseCapture_availableSamples(ALCpulseCapture *self)
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
size_t readable = self->cap_remain;
- if(device->Connected)
+ if(ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
{
- ssize_t got = pa_stream_readable_size(self->stream);
+ ssize_t got;
+ pa_threaded_mainloop_lock(self->loop);
+ got = pa_stream_readable_size(self->stream);
if(got < 0)
{
ERR("pa_stream_readable_size() failed: %s\n", pa_strerror(got));
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failed getting readable size: %s", pa_strerror(got));
}
else if((size_t)got > self->cap_len)
readable += got - self->cap_len;
+ pa_threaded_mainloop_unlock(self->loop);
}
if(self->last_readable < readable)
@@ -1616,19 +1716,28 @@ static ALCuint ALCpulseCapture_availableSamples(ALCpulseCapture *self)
}
-static ALint64 ALCpulseCapture_getLatency(ALCpulseCapture *self)
+static ClockLatency ALCpulseCapture_getClockLatency(ALCpulseCapture *self)
{
- pa_usec_t latency = 0;
- int neg;
+ ClockLatency ret;
+ pa_usec_t latency;
+ int neg, err;
+
+ pa_threaded_mainloop_lock(self->loop);
+ ret.ClockTime = GetDeviceClockTime(STATIC_CAST(ALCbackend,self)->mDevice);
+ err = pa_stream_get_latency(self->stream, &latency, &neg);
+ pa_threaded_mainloop_unlock(self->loop);
- if(pa_stream_get_latency(self->stream, &latency, &neg) != 0)
+ if(UNLIKELY(err != 0))
{
- ERR("Failed to get stream latency!\n");
- return 0;
+ ERR("Failed to get stream latency: 0x%x\n", err);
+ latency = 0;
+ neg = 0;
}
+ else if(UNLIKELY(neg))
+ latency = 0;
+ ret.Latency = (ALint64)minu64(latency, U64(0x7fffffffffffffff)/1000) * 1000;
- if(neg) latency = 0;
- return (ALint64)minu64(latency, U64(0x7fffffffffffffff)/1000) * 1000;
+ return ret;
}
@@ -1651,9 +1760,8 @@ typedef struct ALCpulseBackendFactory {
static ALCboolean ALCpulseBackendFactory_init(ALCpulseBackendFactory *self);
static void ALCpulseBackendFactory_deinit(ALCpulseBackendFactory *self);
static ALCboolean ALCpulseBackendFactory_querySupport(ALCpulseBackendFactory *self, ALCbackend_Type type);
-static void ALCpulseBackendFactory_probe(ALCpulseBackendFactory *self, enum DevProbe type);
+static void ALCpulseBackendFactory_probe(ALCpulseBackendFactory *self, enum DevProbe type, al_string *outnames);
static ALCbackend* ALCpulseBackendFactory_createBackend(ALCpulseBackendFactory *self, ALCdevice *device, ALCbackend_Type type);
-
DEFINE_ALCBACKENDFACTORY_VTABLE(ALCpulseBackendFactory);
@@ -1726,23 +1834,25 @@ static ALCboolean ALCpulseBackendFactory_querySupport(ALCpulseBackendFactory* UN
return ALC_FALSE;
}
-static void ALCpulseBackendFactory_probe(ALCpulseBackendFactory* UNUSED(self), enum DevProbe type)
+static void ALCpulseBackendFactory_probe(ALCpulseBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
switch(type)
{
+#define APPEND_OUTNAME(e) do { \
+ if(!alstr_empty((e)->name)) \
+ alstr_append_range(outnames, VECTOR_BEGIN((e)->name), \
+ VECTOR_END((e)->name)+1); \
+} while(0)
case ALL_DEVICE_PROBE:
ALCpulsePlayback_probeDevices();
-#define APPEND_ALL_DEVICES_LIST(e) AppendAllDevicesList(al_string_get_cstr((e)->name))
- VECTOR_FOR_EACH(const DevMap, PlaybackDevices, APPEND_ALL_DEVICES_LIST);
-#undef APPEND_ALL_DEVICES_LIST
+ VECTOR_FOR_EACH(const DevMap, PlaybackDevices, APPEND_OUTNAME);
break;
case CAPTURE_DEVICE_PROBE:
ALCpulseCapture_probeDevices();
-#define APPEND_CAPTURE_DEVICE_LIST(e) AppendCaptureDeviceList(al_string_get_cstr((e)->name))
- VECTOR_FOR_EACH(const DevMap, CaptureDevices, APPEND_CAPTURE_DEVICE_LIST);
-#undef APPEND_CAPTURE_DEVICE_LIST
+ VECTOR_FOR_EACH(const DevMap, CaptureDevices, APPEND_OUTNAME);
break;
+#undef APPEND_OUTNAME
}
}
@@ -1790,7 +1900,7 @@ static ALCboolean ALCpulseBackendFactory_querySupport(ALCpulseBackendFactory* UN
return ALC_FALSE;
}
-static void ALCpulseBackendFactory_probe(ALCpulseBackendFactory* UNUSED(self), enum DevProbe UNUSED(type))
+static void ALCpulseBackendFactory_probe(ALCpulseBackendFactory* UNUSED(self), enum DevProbe UNUSED(type), al_string* UNUSED(outnames))
{
}
diff --git a/Alc/backends/qsa.c b/Alc/backends/qsa.c
index 291e49fc..81645096 100644
--- a/Alc/backends/qsa.c
+++ b/Alc/backends/qsa.c
@@ -33,6 +33,8 @@
#include "alu.h"
#include "threads.h"
+#include "backends/base.h"
+
typedef struct {
snd_pcm_t* pcmHandle;
@@ -44,7 +46,7 @@ typedef struct {
ALvoid* buffer;
ALsizei size;
- volatile int killNow;
+ ATOMIC(ALenum) killNow;
althrd_t thread;
} qsa_data;
@@ -117,8 +119,10 @@ static void deviceList(int type, vector_DevMap *devmap)
if(max_cards < 0)
return;
- VECTOR_RESERVE(*devmap, max_cards+1);
- VECTOR_RESIZE(*devmap, 0);
+#define FREE_NAME(iter) free((iter)->name)
+ VECTOR_FOR_EACH(DevMap, *devmap, FREE_NAME);
+#undef FREE_NAME
+ VECTOR_RESIZE(*devmap, 0, max_cards+1);
entry.name = strdup(qsaDevice);
entry.card = 0;
@@ -158,17 +162,39 @@ static void deviceList(int type, vector_DevMap *devmap)
}
-FORCE_ALIGN static int qsa_proc_playback(void* ptr)
+/* Wrappers to use an old-style backend with the new interface. */
+typedef struct PlaybackWrapper {
+ DERIVE_FROM_TYPE(ALCbackend);
+ qsa_data *ExtraData;
+} PlaybackWrapper;
+
+static void PlaybackWrapper_Construct(PlaybackWrapper *self, ALCdevice *device);
+static void PlaybackWrapper_Destruct(PlaybackWrapper *self);
+static ALCenum PlaybackWrapper_open(PlaybackWrapper *self, const ALCchar *name);
+static ALCboolean PlaybackWrapper_reset(PlaybackWrapper *self);
+static ALCboolean PlaybackWrapper_start(PlaybackWrapper *self);
+static void PlaybackWrapper_stop(PlaybackWrapper *self);
+static DECLARE_FORWARD2(PlaybackWrapper, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
+static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, ALCuint, availableSamples)
+static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, ClockLatency, getClockLatency)
+static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, void, lock)
+static DECLARE_FORWARD(PlaybackWrapper, ALCbackend, void, unlock)
+DECLARE_DEFAULT_ALLOCATORS(PlaybackWrapper)
+DEFINE_ALCBACKEND_VTABLE(PlaybackWrapper);
+
+
+FORCE_ALIGN static int qsa_proc_playback(void *ptr)
{
- ALCdevice* device=(ALCdevice*)ptr;
- qsa_data* data=(qsa_data*)device->ExtraData;
- char* write_ptr;
- int avail;
+ PlaybackWrapper *self = ptr;
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
+ qsa_data *data = self->ExtraData;
snd_pcm_channel_status_t status;
struct sched_param param;
- fd_set wfds;
- int selectret;
struct timeval timeout;
+ char* write_ptr;
+ fd_set wfds;
+ ALint len;
+ int sret;
SetRTPriority();
althrd_setname(althrd_current(), MIXER_THREAD_NAME);
@@ -178,72 +204,69 @@ FORCE_ALIGN static int qsa_proc_playback(void* ptr)
param.sched_priority=param.sched_curpriority+1;
SchedSet(0, 0, SCHED_NOCHANGE, &param);
- ALint frame_size=FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ const ALint frame_size = FrameSizeFromDevFmt(
+ device->FmtChans, device->FmtType, device->AmbiOrder
+ );
- while (!data->killNow)
+ V0(device->Backend,lock)();
+ while(!ATOMIC_LOAD(&data->killNow, almemory_order_acquire))
{
- ALint len=data->size;
- write_ptr=data->buffer;
-
- avail=len/frame_size;
- aluMixData(device, write_ptr, avail);
+ FD_ZERO(&wfds);
+ FD_SET(data->audio_fd, &wfds);
+ timeout.tv_sec=2;
+ timeout.tv_usec=0;
- while (len>0 && !data->killNow)
+ /* Select also works like time slice to OS */
+ V0(device->Backend,unlock)();
+ sret = select(data->audio_fd+1, NULL, &wfds, NULL, &timeout);
+ V0(device->Backend,lock)();
+ if(sret == -1)
{
- FD_ZERO(&wfds);
- FD_SET(data->audio_fd, &wfds);
- timeout.tv_sec=2;
- timeout.tv_usec=0;
-
- /* Select also works like time slice to OS */
- selectret=select(data->audio_fd+1, NULL, &wfds, NULL, &timeout);
- switch (selectret)
- {
- case -1:
- aluHandleDisconnect(device);
- return 1;
- case 0:
- break;
- default:
- if (FD_ISSET(data->audio_fd, &wfds))
- {
- break;
- }
- break;
- }
-
- int wrote=snd_pcm_plugin_write(data->pcmHandle, write_ptr, len);
+ ERR("select error: %s\n", strerror(errno));
+ aluHandleDisconnect(device, "Failed waiting for playback buffer: %s", strerror(errno));
+ break;
+ }
+ if(sret == 0)
+ {
+ ERR("select timeout\n");
+ continue;
+ }
- if (wrote<=0)
+ len = data->size;
+ write_ptr = data->buffer;
+ aluMixData(device, write_ptr, len/frame_size);
+ while(len>0 && !ATOMIC_LOAD(&data->killNow, almemory_order_acquire))
+ {
+ int wrote = snd_pcm_plugin_write(data->pcmHandle, write_ptr, len);
+ if(wrote <= 0)
{
- if ((errno==EAGAIN) || (errno==EWOULDBLOCK))
- {
+ if(errno==EAGAIN || errno==EWOULDBLOCK)
continue;
- }
- memset(&status, 0, sizeof (status));
- status.channel=SND_PCM_CHANNEL_PLAYBACK;
+ memset(&status, 0, sizeof(status));
+ status.channel = SND_PCM_CHANNEL_PLAYBACK;
snd_pcm_plugin_status(data->pcmHandle, &status);
/* we need to reinitialize the sound channel if we've underrun the buffer */
- if ((status.status==SND_PCM_STATUS_UNDERRUN) ||
- (status.status==SND_PCM_STATUS_READY))
+ if(status.status == SND_PCM_STATUS_UNDERRUN ||
+ status.status == SND_PCM_STATUS_READY)
{
- if ((snd_pcm_plugin_prepare(data->pcmHandle, SND_PCM_CHANNEL_PLAYBACK))<0)
+ if(snd_pcm_plugin_prepare(data->pcmHandle, SND_PCM_CHANNEL_PLAYBACK) < 0)
{
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Playback recovery failed");
break;
}
}
}
else
{
- write_ptr+=wrote;
- len-=wrote;
+ write_ptr += wrote;
+ len -= wrote;
}
}
}
+ V0(device->Backend,unlock)();
return 0;
}
@@ -252,8 +275,9 @@ FORCE_ALIGN static int qsa_proc_playback(void* ptr)
/* Playback */
/************/
-static ALCenum qsa_open_playback(ALCdevice* device, const ALCchar* deviceName)
+static ALCenum qsa_open_playback(PlaybackWrapper *self, const ALCchar* deviceName)
{
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
qsa_data *data;
int card, dev;
int status;
@@ -261,6 +285,7 @@ static ALCenum qsa_open_playback(ALCdevice* device, const ALCchar* deviceName)
data = (qsa_data*)calloc(1, sizeof(qsa_data));
if(data == NULL)
return ALC_OUT_OF_MEMORY;
+ ATOMIC_INIT(&data->killNow, AL_TRUE);
if(!deviceName)
deviceName = qsaDevice;
@@ -277,7 +302,7 @@ static ALCenum qsa_open_playback(ALCdevice* device, const ALCchar* deviceName)
#define MATCH_DEVNAME(iter) ((iter)->name && strcmp(deviceName, (iter)->name)==0)
VECTOR_FIND_IF(iter, const DevMap, DeviceNameMap, MATCH_DEVNAME);
#undef MATCH_DEVNAME
- if(iter == VECTOR_ITER_END(DeviceNameMap))
+ if(iter == VECTOR_END(DeviceNameMap))
{
free(data);
return ALC_INVALID_DEVICE;
@@ -300,15 +325,15 @@ static ALCenum qsa_open_playback(ALCdevice* device, const ALCchar* deviceName)
return ALC_INVALID_DEVICE;
}
- al_string_copy_cstr(&device->DeviceName, deviceName);
- device->ExtraData = data;
+ alstr_copy_cstr(&device->DeviceName, deviceName);
+ self->ExtraData = data;
return ALC_NO_ERROR;
}
-static void qsa_close_playback(ALCdevice* device)
+static void qsa_close_playback(PlaybackWrapper *self)
{
- qsa_data* data=(qsa_data*)device->ExtraData;
+ qsa_data *data = self->ExtraData;
if (data->buffer!=NULL)
{
@@ -319,12 +344,13 @@ static void qsa_close_playback(ALCdevice* device)
snd_pcm_close(data->pcmHandle);
free(data);
- device->ExtraData=NULL;
+ self->ExtraData = NULL;
}
-static ALCboolean qsa_reset_playback(ALCdevice* device)
+static ALCboolean qsa_reset_playback(PlaybackWrapper *self)
{
- qsa_data* data=(qsa_data*)device->ExtraData;
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
+ qsa_data *data = self->ExtraData;
int32_t format=-1;
switch(device->FmtType)
@@ -365,14 +391,14 @@ static ALCboolean qsa_reset_playback(ALCdevice* device)
data->cparams.start_mode=SND_PCM_START_FULL;
data->cparams.stop_mode=SND_PCM_STOP_STOP;
- data->cparams.buf.block.frag_size=device->UpdateSize*
- ChannelsFromDevFmt(device->FmtChans)*BytesFromDevFmt(device->FmtType);
+ data->cparams.buf.block.frag_size=device->UpdateSize *
+ FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
data->cparams.buf.block.frags_max=device->NumUpdates;
data->cparams.buf.block.frags_min=device->NumUpdates;
data->cparams.format.interleave=1;
data->cparams.format.rate=device->Frequency;
- data->cparams.format.voices=ChannelsFromDevFmt(device->FmtChans);
+ data->cparams.format.voices=ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
data->cparams.format.format=format;
if ((snd_pcm_plugin_params(data->pcmHandle, &data->cparams))<0)
@@ -556,7 +582,7 @@ static ALCboolean qsa_reset_playback(ALCdevice* device)
SetDefaultChannelOrder(device);
device->UpdateSize=data->csetup.buf.block.frag_size/
- (ChannelsFromDevFmt(device->FmtChans)*BytesFromDevFmt(device->FmtType));
+ FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
device->NumUpdates=data->csetup.buf.block.frags;
data->size=data->csetup.buf.block.frag_size;
@@ -569,35 +595,93 @@ static ALCboolean qsa_reset_playback(ALCdevice* device)
return ALC_TRUE;
}
-static ALCboolean qsa_start_playback(ALCdevice* device)
+static ALCboolean qsa_start_playback(PlaybackWrapper *self)
{
- qsa_data *data = (qsa_data*)device->ExtraData;
+ qsa_data *data = self->ExtraData;
- data->killNow = 0;
- if(althrd_create(&data->thread, qsa_proc_playback, device) != althrd_success)
+ ATOMIC_STORE(&data->killNow, AL_FALSE, almemory_order_release);
+ if(althrd_create(&data->thread, qsa_proc_playback, self) != althrd_success)
return ALC_FALSE;
return ALC_TRUE;
}
-static void qsa_stop_playback(ALCdevice* device)
+static void qsa_stop_playback(PlaybackWrapper *self)
{
- qsa_data *data = (qsa_data*)device->ExtraData;
+ qsa_data *data = self->ExtraData;
int res;
- if(data->killNow)
+ if(ATOMIC_EXCHANGE(&data->killNow, AL_TRUE, almemory_order_acq_rel))
return;
-
- data->killNow = 1;
althrd_join(data->thread, &res);
}
+
+static void PlaybackWrapper_Construct(PlaybackWrapper *self, ALCdevice *device)
+{
+ ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
+ SET_VTABLE2(PlaybackWrapper, ALCbackend, self);
+
+ self->ExtraData = NULL;
+}
+
+static void PlaybackWrapper_Destruct(PlaybackWrapper *self)
+{
+ if(self->ExtraData)
+ qsa_close_playback(self);
+
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
+}
+
+static ALCenum PlaybackWrapper_open(PlaybackWrapper *self, const ALCchar *name)
+{
+ return qsa_open_playback(self, name);
+}
+
+static ALCboolean PlaybackWrapper_reset(PlaybackWrapper *self)
+{
+ return qsa_reset_playback(self);
+}
+
+static ALCboolean PlaybackWrapper_start(PlaybackWrapper *self)
+{
+ return qsa_start_playback(self);
+}
+
+static void PlaybackWrapper_stop(PlaybackWrapper *self)
+{
+ qsa_stop_playback(self);
+}
+
+
+
/***********/
/* Capture */
/***********/
-static ALCenum qsa_open_capture(ALCdevice* device, const ALCchar* deviceName)
+typedef struct CaptureWrapper {
+ DERIVE_FROM_TYPE(ALCbackend);
+ qsa_data *ExtraData;
+} CaptureWrapper;
+
+static void CaptureWrapper_Construct(CaptureWrapper *self, ALCdevice *device);
+static void CaptureWrapper_Destruct(CaptureWrapper *self);
+static ALCenum CaptureWrapper_open(CaptureWrapper *self, const ALCchar *name);
+static DECLARE_FORWARD(CaptureWrapper, ALCbackend, ALCboolean, reset)
+static ALCboolean CaptureWrapper_start(CaptureWrapper *self);
+static void CaptureWrapper_stop(CaptureWrapper *self);
+static ALCenum CaptureWrapper_captureSamples(CaptureWrapper *self, void *buffer, ALCuint samples);
+static ALCuint CaptureWrapper_availableSamples(CaptureWrapper *self);
+static DECLARE_FORWARD(CaptureWrapper, ALCbackend, ClockLatency, getClockLatency)
+static DECLARE_FORWARD(CaptureWrapper, ALCbackend, void, lock)
+static DECLARE_FORWARD(CaptureWrapper, ALCbackend, void, unlock)
+DECLARE_DEFAULT_ALLOCATORS(CaptureWrapper)
+DEFINE_ALCBACKEND_VTABLE(CaptureWrapper);
+
+
+static ALCenum qsa_open_capture(CaptureWrapper *self, const ALCchar *deviceName)
{
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
qsa_data *data;
int card, dev;
int format=-1;
@@ -624,7 +708,7 @@ static ALCenum qsa_open_capture(ALCdevice* device, const ALCchar* deviceName)
#define MATCH_DEVNAME(iter) ((iter)->name && strcmp(deviceName, (iter)->name)==0)
VECTOR_FIND_IF(iter, const DevMap, CaptureNameMap, MATCH_DEVNAME);
#undef MATCH_DEVNAME
- if(iter == VECTOR_ITER_END(CaptureNameMap))
+ if(iter == VECTOR_END(CaptureNameMap))
{
free(data);
return ALC_INVALID_DEVICE;
@@ -647,8 +731,8 @@ static ALCenum qsa_open_capture(ALCdevice* device, const ALCchar* deviceName)
return ALC_INVALID_DEVICE;
}
- al_string_copy_cstr(&device->DeviceName, deviceName);
- device->ExtraData = data;
+ alstr_copy_cstr(&device->DeviceName, deviceName);
+ self->ExtraData = data;
switch (device->FmtType)
{
@@ -688,20 +772,19 @@ static ALCenum qsa_open_capture(ALCdevice* device, const ALCchar* deviceName)
data->cparams.stop_mode=SND_PCM_STOP_STOP;
data->cparams.buf.block.frag_size=device->UpdateSize*
- ChannelsFromDevFmt(device->FmtChans)*BytesFromDevFmt(device->FmtType);
+ FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
data->cparams.buf.block.frags_max=device->NumUpdates;
data->cparams.buf.block.frags_min=device->NumUpdates;
data->cparams.format.interleave=1;
data->cparams.format.rate=device->Frequency;
- data->cparams.format.voices=ChannelsFromDevFmt(device->FmtChans);
+ data->cparams.format.voices=ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
data->cparams.format.format=format;
if(snd_pcm_plugin_params(data->pcmHandle, &data->cparams) < 0)
{
snd_pcm_close(data->pcmHandle);
free(data);
- device->ExtraData=NULL;
return ALC_INVALID_VALUE;
}
@@ -709,20 +792,20 @@ static ALCenum qsa_open_capture(ALCdevice* device, const ALCchar* deviceName)
return ALC_NO_ERROR;
}
-static void qsa_close_capture(ALCdevice* device)
+static void qsa_close_capture(CaptureWrapper *self)
{
- qsa_data* data=(qsa_data*)device->ExtraData;
+ qsa_data *data = self->ExtraData;
if (data->pcmHandle!=NULL)
snd_pcm_close(data->pcmHandle);
free(data);
- device->ExtraData=NULL;
+ self->ExtraData = NULL;
}
-static void qsa_start_capture(ALCdevice* device)
+static void qsa_start_capture(CaptureWrapper *self)
{
- qsa_data* data=(qsa_data*)device->ExtraData;
+ qsa_data *data = self->ExtraData;
int rstatus;
if ((rstatus=snd_pcm_plugin_prepare(data->pcmHandle, SND_PCM_CHANNEL_CAPTURE))<0)
@@ -742,18 +825,18 @@ static void qsa_start_capture(ALCdevice* device)
snd_pcm_capture_go(data->pcmHandle);
}
-static void qsa_stop_capture(ALCdevice* device)
+static void qsa_stop_capture(CaptureWrapper *self)
{
- qsa_data* data=(qsa_data*)device->ExtraData;
-
+ qsa_data *data = self->ExtraData;
snd_pcm_capture_flush(data->pcmHandle);
}
-static ALCuint qsa_available_samples(ALCdevice* device)
+static ALCuint qsa_available_samples(CaptureWrapper *self)
{
- qsa_data* data=(qsa_data*)device->ExtraData;
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
+ qsa_data *data = self->ExtraData;
snd_pcm_channel_status_t status;
- ALint frame_size=FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ ALint frame_size = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
ALint free_size;
int rstatus;
@@ -766,7 +849,7 @@ static ALCuint qsa_available_samples(ALCdevice* device)
if ((rstatus=snd_pcm_plugin_prepare(data->pcmHandle, SND_PCM_CHANNEL_CAPTURE))<0)
{
ERR("capture prepare failed: %s\n", snd_strerror(rstatus));
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failed capture recovery: %s", snd_strerror(rstatus));
return 0;
}
@@ -780,16 +863,17 @@ static ALCuint qsa_available_samples(ALCdevice* device)
return free_size/frame_size;
}
-static ALCenum qsa_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint samples)
+static ALCenum qsa_capture_samples(CaptureWrapper *self, ALCvoid *buffer, ALCuint samples)
{
- qsa_data* data=(qsa_data*)device->ExtraData;
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
+ qsa_data *data = self->ExtraData;
char* read_ptr;
snd_pcm_channel_status_t status;
fd_set rfds;
int selectret;
struct timeval timeout;
int bytes_read;
- ALint frame_size=FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ ALint frame_size=FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
ALint len=samples*frame_size;
int rstatus;
@@ -808,7 +892,7 @@ static ALCenum qsa_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint s
switch (selectret)
{
case -1:
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failed to check capture samples");
return ALC_INVALID_DEVICE;
case 0:
break;
@@ -839,7 +923,8 @@ static ALCenum qsa_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint s
if ((rstatus=snd_pcm_plugin_prepare(data->pcmHandle, SND_PCM_CHANNEL_CAPTURE))<0)
{
ERR("capture prepare failed: %s\n", snd_strerror(rstatus));
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failed capture recovery: %s",
+ snd_strerror(rstatus));
return ALC_INVALID_DEVICE;
}
snd_pcm_capture_go(data->pcmHandle);
@@ -855,27 +940,68 @@ static ALCenum qsa_capture_samples(ALCdevice *device, ALCvoid *buffer, ALCuint s
return ALC_NO_ERROR;
}
-static const BackendFuncs qsa_funcs= {
- qsa_open_playback,
- qsa_close_playback,
- qsa_reset_playback,
- qsa_start_playback,
- qsa_stop_playback,
- qsa_open_capture,
- qsa_close_capture,
- qsa_start_capture,
- qsa_stop_capture,
- qsa_capture_samples,
- qsa_available_samples
-};
-ALCboolean alc_qsa_init(BackendFuncs* func_list)
+static void CaptureWrapper_Construct(CaptureWrapper *self, ALCdevice *device)
+{
+ ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
+ SET_VTABLE2(CaptureWrapper, ALCbackend, self);
+
+ self->ExtraData = NULL;
+}
+
+static void CaptureWrapper_Destruct(CaptureWrapper *self)
+{
+ if(self->ExtraData)
+ qsa_close_capture(self);
+
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
+}
+
+static ALCenum CaptureWrapper_open(CaptureWrapper *self, const ALCchar *name)
+{
+ return qsa_open_capture(self, name);
+}
+
+static ALCboolean CaptureWrapper_start(CaptureWrapper *self)
{
- *func_list = qsa_funcs;
+ qsa_start_capture(self);
return ALC_TRUE;
}
-void alc_qsa_deinit(void)
+static void CaptureWrapper_stop(CaptureWrapper *self)
+{
+ qsa_stop_capture(self);
+}
+
+static ALCenum CaptureWrapper_captureSamples(CaptureWrapper *self, void *buffer, ALCuint samples)
+{
+ return qsa_capture_samples(self, buffer, samples);
+}
+
+static ALCuint CaptureWrapper_availableSamples(CaptureWrapper *self)
+{
+ return qsa_available_samples(self);
+}
+
+
+typedef struct ALCqsaBackendFactory {
+ DERIVE_FROM_TYPE(ALCbackendFactory);
+} ALCqsaBackendFactory;
+#define ALCQSABACKENDFACTORY_INITIALIZER { { GET_VTABLE2(ALCqsaBackendFactory, ALCbackendFactory) } }
+
+static ALCboolean ALCqsaBackendFactory_init(ALCqsaBackendFactory* UNUSED(self));
+static void ALCqsaBackendFactory_deinit(ALCqsaBackendFactory* UNUSED(self));
+static ALCboolean ALCqsaBackendFactory_querySupport(ALCqsaBackendFactory* UNUSED(self), ALCbackend_Type type);
+static void ALCqsaBackendFactory_probe(ALCqsaBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames);
+static ALCbackend* ALCqsaBackendFactory_createBackend(ALCqsaBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type);
+DEFINE_ALCBACKENDFACTORY_VTABLE(ALCqsaBackendFactory);
+
+static ALCboolean ALCqsaBackendFactory_init(ALCqsaBackendFactory* UNUSED(self))
+{
+ return ALC_TRUE;
+}
+
+static void ALCqsaBackendFactory_deinit(ALCqsaBackendFactory* UNUSED(self))
{
#define FREE_NAME(iter) free((iter)->name)
VECTOR_FOR_EACH(DevMap, DeviceNameMap, FREE_NAME);
@@ -886,32 +1012,57 @@ void alc_qsa_deinit(void)
#undef FREE_NAME
}
-void alc_qsa_probe(enum DevProbe type)
+static ALCboolean ALCqsaBackendFactory_querySupport(ALCqsaBackendFactory* UNUSED(self), ALCbackend_Type type)
+{
+ if(type == ALCbackend_Playback || type == ALCbackend_Capture)
+ return ALC_TRUE;
+ return ALC_FALSE;
+}
+
+static void ALCqsaBackendFactory_probe(ALCqsaBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
switch (type)
{
+#define APPEND_OUTNAME(e) do { \
+ const char *n_ = (e)->name; \
+ if(n_ && n_[0]) \
+ alstr_append_range(outnames, n_, n_+strlen(n_)+1); \
+} while(0)
case ALL_DEVICE_PROBE:
-#define FREE_NAME(iter) free((iter)->name)
- VECTOR_FOR_EACH(DevMap, DeviceNameMap, FREE_NAME);
-#undef FREE_NAME
- VECTOR_RESIZE(DeviceNameMap, 0);
-
deviceList(SND_PCM_CHANNEL_PLAYBACK, &DeviceNameMap);
-#define APPEND_DEVICE(iter) AppendAllDevicesList((iter)->name)
- VECTOR_FOR_EACH(const DevMap, DeviceNameMap, APPEND_DEVICE);
-#undef APPEND_DEVICE
+ VECTOR_FOR_EACH(const DevMap, DeviceNameMap, APPEND_OUTNAME);
break;
case CAPTURE_DEVICE_PROBE:
-#define FREE_NAME(iter) free((iter)->name)
- VECTOR_FOR_EACH(DevMap, CaptureNameMap, FREE_NAME);
-#undef FREE_NAME
- VECTOR_RESIZE(CaptureNameMap, 0);
-
deviceList(SND_PCM_CHANNEL_CAPTURE, &CaptureNameMap);
-#define APPEND_DEVICE(iter) AppendCaptureDeviceList((iter)->name)
- VECTOR_FOR_EACH(const DevMap, CaptureNameMap, APPEND_DEVICE);
-#undef APPEND_DEVICE
+ VECTOR_FOR_EACH(const DevMap, CaptureNameMap, APPEND_OUTNAME);
break;
+#undef APPEND_OUTNAME
+ }
+}
+
+static ALCbackend* ALCqsaBackendFactory_createBackend(ALCqsaBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type)
+{
+ if(type == ALCbackend_Playback)
+ {
+ PlaybackWrapper *backend;
+ NEW_OBJ(backend, PlaybackWrapper)(device);
+ if(!backend) return NULL;
+ return STATIC_CAST(ALCbackend, backend);
}
+ if(type == ALCbackend_Capture)
+ {
+ CaptureWrapper *backend;
+ NEW_OBJ(backend, CaptureWrapper)(device);
+ if(!backend) return NULL;
+ return STATIC_CAST(ALCbackend, backend);
+ }
+
+ return NULL;
+}
+
+ALCbackendFactory *ALCqsaBackendFactory_getFactory(void)
+{
+ static ALCqsaBackendFactory factory = ALCQSABACKENDFACTORY_INITIALIZER;
+ return STATIC_CAST(ALCbackendFactory, &factory);
}
diff --git a/Alc/backends/sdl2.c b/Alc/backends/sdl2.c
new file mode 100644
index 00000000..3495e6bf
--- /dev/null
+++ b/Alc/backends/sdl2.c
@@ -0,0 +1,288 @@
+/**
+ * OpenAL cross platform audio library
+ * Copyright (C) 2018 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 <stdlib.h>
+#include <SDL2/SDL.h>
+
+#include "alMain.h"
+#include "alu.h"
+#include "threads.h"
+#include "compat.h"
+
+#include "backends/base.h"
+
+
+#ifdef _WIN32
+#define DEVNAME_PREFIX "OpenAL Soft on "
+#else
+#define DEVNAME_PREFIX ""
+#endif
+
+typedef struct ALCsdl2Backend {
+ DERIVE_FROM_TYPE(ALCbackend);
+
+ SDL_AudioDeviceID deviceID;
+ ALsizei frameSize;
+
+ ALuint Frequency;
+ enum DevFmtChannels FmtChans;
+ enum DevFmtType FmtType;
+ ALuint UpdateSize;
+} ALCsdl2Backend;
+
+static void ALCsdl2Backend_Construct(ALCsdl2Backend *self, ALCdevice *device);
+static void ALCsdl2Backend_Destruct(ALCsdl2Backend *self);
+static ALCenum ALCsdl2Backend_open(ALCsdl2Backend *self, const ALCchar *name);
+static ALCboolean ALCsdl2Backend_reset(ALCsdl2Backend *self);
+static ALCboolean ALCsdl2Backend_start(ALCsdl2Backend *self);
+static void ALCsdl2Backend_stop(ALCsdl2Backend *self);
+static DECLARE_FORWARD2(ALCsdl2Backend, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
+static DECLARE_FORWARD(ALCsdl2Backend, ALCbackend, ALCuint, availableSamples)
+static DECLARE_FORWARD(ALCsdl2Backend, ALCbackend, ClockLatency, getClockLatency)
+static void ALCsdl2Backend_lock(ALCsdl2Backend *self);
+static void ALCsdl2Backend_unlock(ALCsdl2Backend *self);
+DECLARE_DEFAULT_ALLOCATORS(ALCsdl2Backend)
+
+DEFINE_ALCBACKEND_VTABLE(ALCsdl2Backend);
+
+static const ALCchar defaultDeviceName[] = DEVNAME_PREFIX "Default Device";
+
+static void ALCsdl2Backend_Construct(ALCsdl2Backend *self, ALCdevice *device)
+{
+ ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
+ SET_VTABLE2(ALCsdl2Backend, ALCbackend, self);
+
+ self->deviceID = 0;
+ self->frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
+ self->Frequency = device->Frequency;
+ self->FmtChans = device->FmtChans;
+ self->FmtType = device->FmtType;
+ self->UpdateSize = device->UpdateSize;
+}
+
+static void ALCsdl2Backend_Destruct(ALCsdl2Backend *self)
+{
+ if(self->deviceID)
+ SDL_CloseAudioDevice(self->deviceID);
+ self->deviceID = 0;
+
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
+}
+
+
+static void ALCsdl2Backend_audioCallback(void *ptr, Uint8 *stream, int len)
+{
+ ALCsdl2Backend *self = (ALCsdl2Backend*)ptr;
+ ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
+
+ assert((len % self->frameSize) == 0);
+ aluMixData(device, stream, len / self->frameSize);
+}
+
+static ALCenum ALCsdl2Backend_open(ALCsdl2Backend *self, const ALCchar *name)
+{
+ ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
+ SDL_AudioSpec want, have;
+
+ SDL_zero(want);
+ SDL_zero(have);
+
+ want.freq = device->Frequency;
+ switch(device->FmtType)
+ {
+ case DevFmtUByte: want.format = AUDIO_U8; break;
+ case DevFmtByte: want.format = AUDIO_S8; break;
+ case DevFmtUShort: want.format = AUDIO_U16SYS; break;
+ case DevFmtShort: want.format = AUDIO_S16SYS; break;
+ case DevFmtUInt: /* fall-through */
+ case DevFmtInt: want.format = AUDIO_S32SYS; break;
+ case DevFmtFloat: want.format = AUDIO_F32; break;
+ }
+ want.channels = (device->FmtChans == DevFmtMono) ? 1 : 2;
+ want.samples = device->UpdateSize;
+ want.callback = ALCsdl2Backend_audioCallback;
+ want.userdata = self;
+
+ /* Passing NULL to SDL_OpenAudioDevice opens a default, which isn't
+ * necessarily the first in the list.
+ */
+ if(!name || strcmp(name, defaultDeviceName) == 0)
+ self->deviceID = SDL_OpenAudioDevice(NULL, SDL_FALSE, &want, &have,
+ SDL_AUDIO_ALLOW_ANY_CHANGE);
+ else
+ {
+ const size_t prefix_len = strlen(DEVNAME_PREFIX);
+ if(strncmp(name, DEVNAME_PREFIX, prefix_len) == 0)
+ self->deviceID = SDL_OpenAudioDevice(name+prefix_len, SDL_FALSE, &want, &have,
+ SDL_AUDIO_ALLOW_ANY_CHANGE);
+ else
+ self->deviceID = SDL_OpenAudioDevice(name, SDL_FALSE, &want, &have,
+ SDL_AUDIO_ALLOW_ANY_CHANGE);
+ }
+ if(self->deviceID == 0)
+ return ALC_INVALID_VALUE;
+
+ device->Frequency = have.freq;
+ if(have.channels == 1)
+ device->FmtChans = DevFmtMono;
+ else if(have.channels == 2)
+ device->FmtChans = DevFmtStereo;
+ else
+ {
+ ERR("Got unhandled SDL channel count: %d\n", (int)have.channels);
+ return ALC_INVALID_VALUE;
+ }
+ switch(have.format)
+ {
+ case AUDIO_U8: device->FmtType = DevFmtUByte; break;
+ case AUDIO_S8: device->FmtType = DevFmtByte; break;
+ case AUDIO_U16SYS: device->FmtType = DevFmtUShort; break;
+ case AUDIO_S16SYS: device->FmtType = DevFmtShort; break;
+ case AUDIO_S32SYS: device->FmtType = DevFmtInt; break;
+ case AUDIO_F32SYS: device->FmtType = DevFmtFloat; break;
+ default:
+ ERR("Got unsupported SDL format: 0x%04x\n", have.format);
+ return ALC_INVALID_VALUE;
+ }
+ device->UpdateSize = have.samples;
+ device->NumUpdates = 2; /* SDL always (tries to) use two periods. */
+
+ self->frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
+ self->Frequency = device->Frequency;
+ self->FmtChans = device->FmtChans;
+ self->FmtType = device->FmtType;
+ self->UpdateSize = device->UpdateSize;
+
+ alstr_copy_cstr(&device->DeviceName, name ? name : defaultDeviceName);
+
+ return ALC_NO_ERROR;
+}
+
+static ALCboolean ALCsdl2Backend_reset(ALCsdl2Backend *self)
+{
+ ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
+ device->Frequency = self->Frequency;
+ device->FmtChans = self->FmtChans;
+ device->FmtType = self->FmtType;
+ device->UpdateSize = self->UpdateSize;
+ device->NumUpdates = 2;
+ SetDefaultWFXChannelOrder(device);
+ return ALC_TRUE;
+}
+
+static ALCboolean ALCsdl2Backend_start(ALCsdl2Backend *self)
+{
+ SDL_PauseAudioDevice(self->deviceID, 0);
+ return ALC_TRUE;
+}
+
+static void ALCsdl2Backend_stop(ALCsdl2Backend *self)
+{
+ SDL_PauseAudioDevice(self->deviceID, 1);
+}
+
+static void ALCsdl2Backend_lock(ALCsdl2Backend *self)
+{
+ SDL_LockAudioDevice(self->deviceID);
+}
+
+static void ALCsdl2Backend_unlock(ALCsdl2Backend *self)
+{
+ SDL_UnlockAudioDevice(self->deviceID);
+}
+
+
+typedef struct ALCsdl2BackendFactory {
+ DERIVE_FROM_TYPE(ALCbackendFactory);
+} ALCsdl2BackendFactory;
+#define ALCsdl2BACKENDFACTORY_INITIALIZER { { GET_VTABLE2(ALCsdl2BackendFactory, ALCbackendFactory) } }
+
+ALCbackendFactory *ALCsdl2BackendFactory_getFactory(void);
+
+static ALCboolean ALCsdl2BackendFactory_init(ALCsdl2BackendFactory *self);
+static void ALCsdl2BackendFactory_deinit(ALCsdl2BackendFactory *self);
+static ALCboolean ALCsdl2BackendFactory_querySupport(ALCsdl2BackendFactory *self, ALCbackend_Type type);
+static void ALCsdl2BackendFactory_probe(ALCsdl2BackendFactory *self, enum DevProbe type, al_string *outnames);
+static ALCbackend* ALCsdl2BackendFactory_createBackend(ALCsdl2BackendFactory *self, ALCdevice *device, ALCbackend_Type type);
+DEFINE_ALCBACKENDFACTORY_VTABLE(ALCsdl2BackendFactory);
+
+
+ALCbackendFactory *ALCsdl2BackendFactory_getFactory(void)
+{
+ static ALCsdl2BackendFactory factory = ALCsdl2BACKENDFACTORY_INITIALIZER;
+ return STATIC_CAST(ALCbackendFactory, &factory);
+}
+
+
+static ALCboolean ALCsdl2BackendFactory_init(ALCsdl2BackendFactory* UNUSED(self))
+{
+ if(SDL_InitSubSystem(SDL_INIT_AUDIO) == 0)
+ return AL_TRUE;
+ return ALC_FALSE;
+}
+
+static void ALCsdl2BackendFactory_deinit(ALCsdl2BackendFactory* UNUSED(self))
+{
+ SDL_QuitSubSystem(SDL_INIT_AUDIO);
+}
+
+static ALCboolean ALCsdl2BackendFactory_querySupport(ALCsdl2BackendFactory* UNUSED(self), ALCbackend_Type type)
+{
+ if(type == ALCbackend_Playback)
+ return ALC_TRUE;
+ return ALC_FALSE;
+}
+
+static void ALCsdl2BackendFactory_probe(ALCsdl2BackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
+{
+ int num_devices, i;
+ al_string name;
+
+ if(type != ALL_DEVICE_PROBE)
+ return;
+
+ AL_STRING_INIT(name);
+ num_devices = SDL_GetNumAudioDevices(SDL_FALSE);
+
+ alstr_append_range(outnames, defaultDeviceName, defaultDeviceName+sizeof(defaultDeviceName));
+ for(i = 0;i < num_devices;++i)
+ {
+ alstr_copy_cstr(&name, DEVNAME_PREFIX);
+ alstr_append_cstr(&name, SDL_GetAudioDeviceName(i, SDL_FALSE));
+ if(!alstr_empty(name))
+ alstr_append_range(outnames, VECTOR_BEGIN(name), VECTOR_END(name)+1);
+ }
+ alstr_reset(&name);
+}
+
+static ALCbackend* ALCsdl2BackendFactory_createBackend(ALCsdl2BackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type)
+{
+ if(type == ALCbackend_Playback)
+ {
+ ALCsdl2Backend *backend;
+ NEW_OBJ(backend, ALCsdl2Backend)(device);
+ if(!backend) return NULL;
+ return STATIC_CAST(ALCbackend, backend);
+ }
+
+ return NULL;
+}
diff --git a/Alc/backends/sndio.c b/Alc/backends/sndio.c
index 52bff13a..dd174cba 100644
--- a/Alc/backends/sndio.c
+++ b/Alc/backends/sndio.c
@@ -27,6 +27,9 @@
#include "alMain.h"
#include "alu.h"
#include "threads.h"
+#include "ringbuffer.h"
+
+#include "backends/base.h"
#include <sndio.h>
@@ -34,49 +37,88 @@
static const ALCchar sndio_device[] = "SndIO Default";
-static ALCboolean sndio_load(void)
-{
- return ALC_TRUE;
-}
-
+typedef struct SndioPlayback {
+ DERIVE_FROM_TYPE(ALCbackend);
-typedef struct {
struct sio_hdl *sndHandle;
ALvoid *mix_data;
ALsizei data_size;
- volatile int killNow;
+ ATOMIC(int) killNow;
althrd_t thread;
-} sndio_data;
+} SndioPlayback;
+
+static int SndioPlayback_mixerProc(void *ptr);
+static void SndioPlayback_Construct(SndioPlayback *self, ALCdevice *device);
+static void SndioPlayback_Destruct(SndioPlayback *self);
+static ALCenum SndioPlayback_open(SndioPlayback *self, const ALCchar *name);
+static ALCboolean SndioPlayback_reset(SndioPlayback *self);
+static ALCboolean SndioPlayback_start(SndioPlayback *self);
+static void SndioPlayback_stop(SndioPlayback *self);
+static DECLARE_FORWARD2(SndioPlayback, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
+static DECLARE_FORWARD(SndioPlayback, ALCbackend, ALCuint, availableSamples)
+static DECLARE_FORWARD(SndioPlayback, ALCbackend, ClockLatency, getClockLatency)
+static DECLARE_FORWARD(SndioPlayback, ALCbackend, void, lock)
+static DECLARE_FORWARD(SndioPlayback, ALCbackend, void, unlock)
+DECLARE_DEFAULT_ALLOCATORS(SndioPlayback)
+
+DEFINE_ALCBACKEND_VTABLE(SndioPlayback);
+
+
+static void SndioPlayback_Construct(SndioPlayback *self, ALCdevice *device)
+{
+ ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
+ SET_VTABLE2(SndioPlayback, ALCbackend, self);
+
+ self->sndHandle = NULL;
+ self->mix_data = NULL;
+ ATOMIC_INIT(&self->killNow, AL_TRUE);
+}
-static int sndio_proc(void *ptr)
+static void SndioPlayback_Destruct(SndioPlayback *self)
{
- ALCdevice *device = ptr;
- sndio_data *data = device->ExtraData;
+ if(self->sndHandle)
+ sio_close(self->sndHandle);
+ self->sndHandle = NULL;
+
+ al_free(self->mix_data);
+ self->mix_data = NULL;
+
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
+}
+
+
+static int SndioPlayback_mixerProc(void *ptr)
+{
+ SndioPlayback *self = (SndioPlayback*)ptr;
+ ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
ALsizei frameSize;
size_t wrote;
SetRTPriority();
althrd_setname(althrd_current(), MIXER_THREAD_NAME);
- frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
- while(!data->killNow && device->Connected)
+ while(!ATOMIC_LOAD(&self->killNow, almemory_order_acquire) &&
+ ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
{
- ALsizei len = data->data_size;
- ALubyte *WritePtr = data->mix_data;
+ ALsizei len = self->data_size;
+ ALubyte *WritePtr = self->mix_data;
+ SndioPlayback_lock(self);
aluMixData(device, WritePtr, len/frameSize);
- while(len > 0 && !data->killNow)
+ SndioPlayback_unlock(self);
+ while(len > 0 && !ATOMIC_LOAD(&self->killNow, almemory_order_acquire))
{
- wrote = sio_write(data->sndHandle, WritePtr, len);
+ wrote = sio_write(self->sndHandle, WritePtr, len);
if(wrote == 0)
{
ERR("sio_write failed\n");
ALCdevice_Lock(device);
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failed to write playback samples");
ALCdevice_Unlock(device);
break;
}
@@ -90,45 +132,30 @@ static int sndio_proc(void *ptr)
}
-
-static ALCenum sndio_open_playback(ALCdevice *device, const ALCchar *deviceName)
+static ALCenum SndioPlayback_open(SndioPlayback *self, const ALCchar *name)
{
- sndio_data *data;
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
- if(!deviceName)
- deviceName = sndio_device;
- else if(strcmp(deviceName, sndio_device) != 0)
+ if(!name)
+ name = sndio_device;
+ else if(strcmp(name, sndio_device) != 0)
return ALC_INVALID_VALUE;
- data = calloc(1, sizeof(*data));
- data->killNow = 0;
-
- data->sndHandle = sio_open(NULL, SIO_PLAY, 0);
- if(data->sndHandle == NULL)
+ self->sndHandle = sio_open(NULL, SIO_PLAY, 0);
+ if(self->sndHandle == NULL)
{
- free(data);
ERR("Could not open device\n");
return ALC_INVALID_VALUE;
}
- al_string_copy_cstr(&device->DeviceName, deviceName);
- device->ExtraData = data;
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
}
-static void sndio_close_playback(ALCdevice *device)
+static ALCboolean SndioPlayback_reset(SndioPlayback *self)
{
- sndio_data *data = device->ExtraData;
-
- sio_close(data->sndHandle);
- free(data);
- device->ExtraData = NULL;
-}
-
-static ALCboolean sndio_reset_playback(ALCdevice *device)
-{
- sndio_data *data = device->ExtraData;
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
struct sio_par par;
sio_initpar(&par);
@@ -170,7 +197,7 @@ static ALCboolean sndio_reset_playback(ALCdevice *device)
par.appbufsz = device->UpdateSize * (device->NumUpdates-1);
if(!par.appbufsz) par.appbufsz = device->UpdateSize;
- if(!sio_setpar(data->sndHandle, &par) || !sio_getpar(data->sndHandle, &par))
+ if(!sio_setpar(self->sndHandle, &par) || !sio_getpar(self->sndHandle, &par))
{
ERR("Failed to set device parameters\n");
return ALC_FALSE;
@@ -211,84 +238,363 @@ static ALCboolean sndio_reset_playback(ALCdevice *device)
return ALC_TRUE;
}
-static ALCboolean sndio_start_playback(ALCdevice *device)
+static ALCboolean SndioPlayback_start(SndioPlayback *self)
{
- sndio_data *data = device->ExtraData;
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
+
+ self->data_size = device->UpdateSize * FrameSizeFromDevFmt(
+ device->FmtChans, device->FmtType, device->AmbiOrder
+ );
+ al_free(self->mix_data);
+ self->mix_data = al_calloc(16, self->data_size);
- if(!sio_start(data->sndHandle))
+ if(!sio_start(self->sndHandle))
{
ERR("Error starting playback\n");
return ALC_FALSE;
}
- data->data_size = device->UpdateSize * FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
- data->mix_data = calloc(1, data->data_size);
-
- data->killNow = 0;
- if(althrd_create(&data->thread, sndio_proc, device) != althrd_success)
+ ATOMIC_STORE(&self->killNow, AL_FALSE, almemory_order_release);
+ if(althrd_create(&self->thread, SndioPlayback_mixerProc, self) != althrd_success)
{
- sio_stop(data->sndHandle);
- free(data->mix_data);
- data->mix_data = NULL;
+ sio_stop(self->sndHandle);
return ALC_FALSE;
}
return ALC_TRUE;
}
-static void sndio_stop_playback(ALCdevice *device)
+static void SndioPlayback_stop(SndioPlayback *self)
{
- sndio_data *data = device->ExtraData;
int res;
- if(data->killNow)
+ if(ATOMIC_EXCHANGE(&self->killNow, AL_TRUE, almemory_order_acq_rel))
return;
+ althrd_join(self->thread, &res);
- data->killNow = 1;
- althrd_join(data->thread, &res);
-
- if(!sio_stop(data->sndHandle))
+ if(!sio_stop(self->sndHandle))
ERR("Error stopping device\n");
- free(data->mix_data);
- data->mix_data = NULL;
+ al_free(self->mix_data);
+ self->mix_data = NULL;
+}
+
+
+typedef struct SndioCapture {
+ DERIVE_FROM_TYPE(ALCbackend);
+
+ struct sio_hdl *sndHandle;
+
+ ll_ringbuffer_t *ring;
+
+ ATOMIC(int) killNow;
+ althrd_t thread;
+} SndioCapture;
+
+static int SndioCapture_recordProc(void *ptr);
+
+static void SndioCapture_Construct(SndioCapture *self, ALCdevice *device);
+static void SndioCapture_Destruct(SndioCapture *self);
+static ALCenum SndioCapture_open(SndioCapture *self, const ALCchar *name);
+static DECLARE_FORWARD(SndioCapture, ALCbackend, ALCboolean, reset)
+static ALCboolean SndioCapture_start(SndioCapture *self);
+static void SndioCapture_stop(SndioCapture *self);
+static ALCenum SndioCapture_captureSamples(SndioCapture *self, void *buffer, ALCuint samples);
+static ALCuint SndioCapture_availableSamples(SndioCapture *self);
+static DECLARE_FORWARD(SndioCapture, ALCbackend, ClockLatency, getClockLatency)
+static DECLARE_FORWARD(SndioCapture, ALCbackend, void, lock)
+static DECLARE_FORWARD(SndioCapture, ALCbackend, void, unlock)
+DECLARE_DEFAULT_ALLOCATORS(SndioCapture)
+
+DEFINE_ALCBACKEND_VTABLE(SndioCapture);
+
+
+static void SndioCapture_Construct(SndioCapture *self, ALCdevice *device)
+{
+ ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
+ SET_VTABLE2(SndioCapture, ALCbackend, self);
+
+ self->sndHandle = NULL;
+ self->ring = NULL;
+ ATOMIC_INIT(&self->killNow, AL_TRUE);
+}
+
+static void SndioCapture_Destruct(SndioCapture *self)
+{
+ if(self->sndHandle)
+ sio_close(self->sndHandle);
+ self->sndHandle = NULL;
+
+ ll_ringbuffer_free(self->ring);
+ self->ring = NULL;
+
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}
-static const BackendFuncs sndio_funcs = {
- sndio_open_playback,
- sndio_close_playback,
- sndio_reset_playback,
- sndio_start_playback,
- sndio_stop_playback,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL
-};
-
-ALCboolean alc_sndio_init(BackendFuncs *func_list)
+static int SndioCapture_recordProc(void* ptr)
{
- if(!sndio_load())
+ SndioCapture *self = (SndioCapture*)ptr;
+ ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
+ ALsizei frameSize;
+
+ SetRTPriority();
+ althrd_setname(althrd_current(), RECORD_THREAD_NAME);
+
+ frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
+
+ while(!ATOMIC_LOAD(&self->killNow, almemory_order_acquire) &&
+ ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
+ {
+ ll_ringbuffer_data_t data[2];
+ size_t total, todo;
+
+ ll_ringbuffer_get_write_vector(self->ring, data);
+ todo = data[0].len + data[1].len;
+ if(todo == 0)
+ {
+ static char junk[4096];
+ sio_read(self->sndHandle, junk, minz(sizeof(junk)/frameSize, device->UpdateSize)*frameSize);
+ continue;
+ }
+
+ total = 0;
+ data[0].len *= frameSize;
+ data[1].len *= frameSize;
+ todo = minz(todo, device->UpdateSize) * frameSize;
+ while(total < todo)
+ {
+ size_t got;
+
+ if(!data[0].len)
+ data[0] = data[1];
+
+ got = sio_read(self->sndHandle, data[0].buf, minz(todo-total, data[0].len));
+ if(!got)
+ {
+ SndioCapture_lock(self);
+ aluHandleDisconnect(device, "Failed to read capture samples");
+ SndioCapture_unlock(self);
+ break;
+ }
+
+ data[0].buf += got;
+ data[0].len -= got;
+ total += got;
+ }
+ ll_ringbuffer_write_advance(self->ring, total / frameSize);
+ }
+
+ return 0;
+}
+
+
+static ALCenum SndioCapture_open(SndioCapture *self, const ALCchar *name)
+{
+ ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
+ struct sio_par par;
+
+ if(!name)
+ name = sndio_device;
+ else if(strcmp(name, sndio_device) != 0)
+ return ALC_INVALID_VALUE;
+
+ self->sndHandle = sio_open(NULL, SIO_REC, 0);
+ if(self->sndHandle == NULL)
+ {
+ ERR("Could not open device\n");
+ return ALC_INVALID_VALUE;
+ }
+
+ sio_initpar(&par);
+
+ switch(device->FmtType)
+ {
+ case DevFmtByte:
+ par.bps = 1;
+ par.sig = 1;
+ break;
+ case DevFmtUByte:
+ par.bps = 1;
+ par.sig = 0;
+ break;
+ case DevFmtShort:
+ par.bps = 2;
+ par.sig = 1;
+ break;
+ case DevFmtUShort:
+ par.bps = 2;
+ par.sig = 0;
+ break;
+ case DevFmtInt:
+ par.bps = 4;
+ par.sig = 1;
+ break;
+ case DevFmtUInt:
+ par.bps = 4;
+ par.sig = 0;
+ break;
+ case DevFmtFloat:
+ ERR("%s capture samples not supported\n", DevFmtTypeString(device->FmtType));
+ return ALC_INVALID_VALUE;
+ }
+ par.bits = par.bps * 8;
+ par.le = SIO_LE_NATIVE;
+ par.msb = SIO_LE_NATIVE ? 0 : 1;
+ par.rchan = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
+ par.rate = device->Frequency;
+
+ par.appbufsz = maxu(device->UpdateSize*device->NumUpdates, (device->Frequency+9)/10);
+ par.round = clampu(par.appbufsz/device->NumUpdates, (device->Frequency+99)/100,
+ (device->Frequency+19)/20);
+
+ device->UpdateSize = par.round;
+ device->NumUpdates = maxu(par.appbufsz/par.round, 1);
+
+ if(!sio_setpar(self->sndHandle, &par) || !sio_getpar(self->sndHandle, &par))
+ {
+ ERR("Failed to set device parameters\n");
+ return ALC_INVALID_VALUE;
+ }
+
+ if(par.bits != par.bps*8)
+ {
+ ERR("Padded samples not supported (%u of %u bits)\n", par.bits, par.bps*8);
+ return ALC_INVALID_VALUE;
+ }
+
+ if(!((device->FmtType == DevFmtByte && par.bits == 8 && par.sig != 0) ||
+ (device->FmtType == DevFmtUByte && par.bits == 8 && par.sig == 0) ||
+ (device->FmtType == DevFmtShort && par.bits == 16 && par.sig != 0) ||
+ (device->FmtType == DevFmtUShort && par.bits == 16 && par.sig == 0) ||
+ (device->FmtType == DevFmtInt && par.bits == 32 && par.sig != 0) ||
+ (device->FmtType == DevFmtUInt && par.bits == 32 && par.sig == 0)) ||
+ ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder) != (ALsizei)par.rchan ||
+ device->Frequency != par.rate)
+ {
+ ERR("Failed to set format %s %s %uhz, got %c%u %u-channel %uhz instead\n",
+ DevFmtTypeString(device->FmtType), DevFmtChannelsString(device->FmtChans),
+ device->Frequency, par.sig?'s':'u', par.bits, par.rchan, par.rate);
+ return ALC_INVALID_VALUE;
+ }
+
+ self->ring = ll_ringbuffer_create(device->UpdateSize*device->NumUpdates, par.bps*par.rchan, 0);
+ if(!self->ring)
+ {
+ ERR("Failed to allocate %u-byte ringbuffer\n",
+ device->UpdateSize*device->NumUpdates*par.bps*par.rchan);
+ return ALC_OUT_OF_MEMORY;
+ }
+
+ SetDefaultChannelOrder(device);
+
+ alstr_copy_cstr(&device->DeviceName, name);
+
+ return ALC_NO_ERROR;
+}
+
+static ALCboolean SndioCapture_start(SndioCapture *self)
+{
+ if(!sio_start(self->sndHandle))
+ {
+ ERR("Error starting playback\n");
return ALC_FALSE;
- *func_list = sndio_funcs;
+ }
+
+ ATOMIC_STORE(&self->killNow, AL_FALSE, almemory_order_release);
+ if(althrd_create(&self->thread, SndioCapture_recordProc, self) != althrd_success)
+ {
+ sio_stop(self->sndHandle);
+ return ALC_FALSE;
+ }
+
+ return ALC_TRUE;
+}
+
+static void SndioCapture_stop(SndioCapture *self)
+{
+ int res;
+
+ if(ATOMIC_EXCHANGE(&self->killNow, AL_TRUE, almemory_order_acq_rel))
+ return;
+ althrd_join(self->thread, &res);
+
+ if(!sio_stop(self->sndHandle))
+ ERR("Error stopping device\n");
+}
+
+static ALCenum SndioCapture_captureSamples(SndioCapture *self, void *buffer, ALCuint samples)
+{
+ ll_ringbuffer_read(self->ring, buffer, samples);
+ return ALC_NO_ERROR;
+}
+
+static ALCuint SndioCapture_availableSamples(SndioCapture *self)
+{
+ return ll_ringbuffer_read_space(self->ring);
+}
+
+
+typedef struct SndioBackendFactory {
+ DERIVE_FROM_TYPE(ALCbackendFactory);
+} SndioBackendFactory;
+#define SNDIOBACKENDFACTORY_INITIALIZER { { GET_VTABLE2(SndioBackendFactory, ALCbackendFactory) } }
+
+ALCbackendFactory *SndioBackendFactory_getFactory(void);
+
+static ALCboolean SndioBackendFactory_init(SndioBackendFactory *self);
+static DECLARE_FORWARD(SndioBackendFactory, ALCbackendFactory, void, deinit)
+static ALCboolean SndioBackendFactory_querySupport(SndioBackendFactory *self, ALCbackend_Type type);
+static void SndioBackendFactory_probe(SndioBackendFactory *self, enum DevProbe type, al_string *outnames);
+static ALCbackend* SndioBackendFactory_createBackend(SndioBackendFactory *self, ALCdevice *device, ALCbackend_Type type);
+DEFINE_ALCBACKENDFACTORY_VTABLE(SndioBackendFactory);
+
+ALCbackendFactory *SndioBackendFactory_getFactory(void)
+{
+ static SndioBackendFactory factory = SNDIOBACKENDFACTORY_INITIALIZER;
+ return STATIC_CAST(ALCbackendFactory, &factory);
+}
+
+static ALCboolean SndioBackendFactory_init(SndioBackendFactory* UNUSED(self))
+{
+ /* No dynamic loading */
return ALC_TRUE;
}
-void alc_sndio_deinit(void)
+static ALCboolean SndioBackendFactory_querySupport(SndioBackendFactory* UNUSED(self), ALCbackend_Type type)
{
+ if(type == ALCbackend_Playback || type == ALCbackend_Capture)
+ return ALC_TRUE;
+ return ALC_FALSE;
}
-void alc_sndio_probe(enum DevProbe type)
+static void SndioBackendFactory_probe(SndioBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
switch(type)
{
case ALL_DEVICE_PROBE:
- AppendAllDevicesList(sndio_device);
- break;
case CAPTURE_DEVICE_PROBE:
+ alstr_append_range(outnames, sndio_device, sndio_device+sizeof(sndio_device));
break;
}
}
+
+static ALCbackend* SndioBackendFactory_createBackend(SndioBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type)
+{
+ if(type == ALCbackend_Playback)
+ {
+ SndioPlayback *backend;
+ NEW_OBJ(backend, SndioPlayback)(device);
+ if(!backend) return NULL;
+ return STATIC_CAST(ALCbackend, backend);
+ }
+ if(type == ALCbackend_Capture)
+ {
+ SndioCapture *backend;
+ NEW_OBJ(backend, SndioCapture)(device);
+ if(!backend) return NULL;
+ return STATIC_CAST(ALCbackend, backend);
+ }
+
+ return NULL;
+}
diff --git a/Alc/backends/solaris.c b/Alc/backends/solaris.c
index 52ca9090..71282204 100644
--- a/Alc/backends/solaris.c
+++ b/Alc/backends/solaris.c
@@ -22,6 +22,7 @@
#include <sys/ioctl.h>
#include <sys/types.h>
+#include <sys/time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -33,6 +34,7 @@
#include "alMain.h"
#include "alu.h"
+#include "alconfig.h"
#include "threads.h"
#include "compat.h"
@@ -49,7 +51,7 @@ typedef struct ALCsolarisBackend {
ALubyte *mix_data;
int data_size;
- volatile int killNow;
+ ATOMIC(ALenum) killNow;
althrd_t thread;
} ALCsolarisBackend;
@@ -58,13 +60,12 @@ static int ALCsolarisBackend_mixerProc(void *ptr);
static void ALCsolarisBackend_Construct(ALCsolarisBackend *self, ALCdevice *device);
static void ALCsolarisBackend_Destruct(ALCsolarisBackend *self);
static ALCenum ALCsolarisBackend_open(ALCsolarisBackend *self, const ALCchar *name);
-static void ALCsolarisBackend_close(ALCsolarisBackend *self);
static ALCboolean ALCsolarisBackend_reset(ALCsolarisBackend *self);
static ALCboolean ALCsolarisBackend_start(ALCsolarisBackend *self);
static void ALCsolarisBackend_stop(ALCsolarisBackend *self);
static DECLARE_FORWARD2(ALCsolarisBackend, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
static DECLARE_FORWARD(ALCsolarisBackend, ALCbackend, ALCuint, availableSamples)
-static DECLARE_FORWARD(ALCsolarisBackend, ALCbackend, ALint64, getLatency)
+static DECLARE_FORWARD(ALCsolarisBackend, ALCbackend, ClockLatency, getClockLatency)
static DECLARE_FORWARD(ALCsolarisBackend, ALCbackend, void, lock)
static DECLARE_FORWARD(ALCsolarisBackend, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCsolarisBackend)
@@ -83,6 +84,8 @@ static void ALCsolarisBackend_Construct(ALCsolarisBackend *self, ALCdevice *devi
SET_VTABLE2(ALCsolarisBackend, ALCbackend, self);
self->fd = -1;
+ self->mix_data = NULL;
+ ATOMIC_INIT(&self->killNow, AL_FALSE);
}
static void ALCsolarisBackend_Destruct(ALCsolarisBackend *self)
@@ -102,43 +105,67 @@ static void ALCsolarisBackend_Destruct(ALCsolarisBackend *self)
static int ALCsolarisBackend_mixerProc(void *ptr)
{
ALCsolarisBackend *self = ptr;
- ALCdevice *Device = STATIC_CAST(ALCbackend,self)->mDevice;
- ALint frameSize;
- int wrote;
+ ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
+ struct timeval timeout;
+ ALubyte *write_ptr;
+ ALint frame_size;
+ ALint to_write;
+ ssize_t wrote;
+ fd_set wfds;
+ int sret;
SetRTPriority();
althrd_setname(althrd_current(), MIXER_THREAD_NAME);
- frameSize = FrameSizeFromDevFmt(Device->FmtChans, Device->FmtType);
+ frame_size = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
- while(!self->killNow && Device->Connected)
+ ALCsolarisBackend_lock(self);
+ while(!ATOMIC_LOAD(&self->killNow, almemory_order_acquire) &&
+ ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
{
- ALint len = self->data_size;
- ALubyte *WritePtr = self->mix_data;
+ FD_ZERO(&wfds);
+ FD_SET(self->fd, &wfds);
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+
+ ALCsolarisBackend_unlock(self);
+ sret = select(self->fd+1, NULL, &wfds, NULL, &timeout);
+ ALCsolarisBackend_lock(self);
+ if(sret < 0)
+ {
+ if(errno == EINTR)
+ continue;
+ ERR("select failed: %s\n", strerror(errno));
+ aluHandleDisconnect(device, "Failed to wait for playback buffer: %s", strerror(errno));
+ break;
+ }
+ else if(sret == 0)
+ {
+ WARN("select timeout\n");
+ continue;
+ }
- aluMixData(Device, WritePtr, len/frameSize);
- while(len > 0 && !self->killNow)
+ write_ptr = self->mix_data;
+ to_write = self->data_size;
+ aluMixData(device, write_ptr, to_write/frame_size);
+ while(to_write > 0 && !ATOMIC_LOAD_SEQ(&self->killNow))
{
- wrote = write(self->fd, WritePtr, len);
+ wrote = write(self->fd, write_ptr, to_write);
if(wrote < 0)
{
- if(errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
- {
- ERR("write failed: %s\n", strerror(errno));
- ALCsolarisBackend_lock(self);
- aluHandleDisconnect(Device);
- ALCsolarisBackend_unlock(self);
- break;
- }
-
- al_nssleep(1000000);
- continue;
+ if(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
+ continue;
+ ERR("write failed: %s\n", strerror(errno));
+ aluHandleDisconnect(device, "Failed to write playback samples: %s",
+ strerror(errno));
+ break;
}
- len -= wrote;
- WritePtr += wrote;
+ to_write -= wrote;
+ write_ptr += wrote;
}
}
+ ALCsolarisBackend_unlock(self);
return 0;
}
@@ -161,23 +188,17 @@ static ALCenum ALCsolarisBackend_open(ALCsolarisBackend *self, const ALCchar *na
}
device = STATIC_CAST(ALCbackend,self)->mDevice;
- al_string_copy_cstr(&device->DeviceName, name);
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
}
-static void ALCsolarisBackend_close(ALCsolarisBackend *self)
-{
- close(self->fd);
- self->fd = -1;
-}
-
static ALCboolean ALCsolarisBackend_reset(ALCsolarisBackend *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
audio_info_t info;
- ALuint frameSize;
- int numChannels;
+ ALsizei frameSize;
+ ALsizei numChannels;
AUDIO_INITINFO(&info);
@@ -185,7 +206,7 @@ static ALCboolean ALCsolarisBackend_reset(ALCsolarisBackend *self)
if(device->FmtChans != DevFmtMono)
device->FmtChans = DevFmtStereo;
- numChannels = ChannelsFromDevFmt(device->FmtChans);
+ numChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
info.play.channels = numChannels;
switch(device->FmtType)
@@ -219,9 +240,9 @@ static ALCboolean ALCsolarisBackend_reset(ALCsolarisBackend *self)
return ALC_FALSE;
}
- if(ChannelsFromDevFmt(device->FmtChans) != info.play.channels)
+ if(ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder) != (ALsizei)info.play.channels)
{
- ERR("Could not set %d channels, got %d instead\n", ChannelsFromDevFmt(device->FmtChans), info.play.channels);
+ ERR("Failed to set %s, got %u channels instead\n", DevFmtChannelsString(device->FmtChans), info.play.channels);
return ALC_FALSE;
}
@@ -241,7 +262,9 @@ static ALCboolean ALCsolarisBackend_reset(ALCsolarisBackend *self)
SetDefaultChannelOrder(device);
free(self->mix_data);
- self->data_size = device->UpdateSize * FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ self->data_size = device->UpdateSize * FrameSizeFromDevFmt(
+ device->FmtChans, device->FmtType, device->AmbiOrder
+ );
self->mix_data = calloc(1, self->data_size);
return ALC_TRUE;
@@ -249,7 +272,7 @@ static ALCboolean ALCsolarisBackend_reset(ALCsolarisBackend *self)
static ALCboolean ALCsolarisBackend_start(ALCsolarisBackend *self)
{
- self->killNow = 0;
+ ATOMIC_STORE_SEQ(&self->killNow, AL_FALSE);
if(althrd_create(&self->thread, ALCsolarisBackend_mixerProc, self) != althrd_success)
return ALC_FALSE;
return ALC_TRUE;
@@ -259,10 +282,9 @@ static void ALCsolarisBackend_stop(ALCsolarisBackend *self)
{
int res;
- if(self->killNow)
+ if(ATOMIC_EXCHANGE_SEQ(&self->killNow, AL_TRUE))
return;
- self->killNow = 1;
althrd_join(self->thread, &res);
if(ioctl(self->fd, AUDIO_DRAIN) < 0)
@@ -280,7 +302,7 @@ ALCbackendFactory *ALCsolarisBackendFactory_getFactory(void);
static ALCboolean ALCsolarisBackendFactory_init(ALCsolarisBackendFactory *self);
static DECLARE_FORWARD(ALCsolarisBackendFactory, ALCbackendFactory, void, deinit)
static ALCboolean ALCsolarisBackendFactory_querySupport(ALCsolarisBackendFactory *self, ALCbackend_Type type);
-static void ALCsolarisBackendFactory_probe(ALCsolarisBackendFactory *self, enum DevProbe type);
+static void ALCsolarisBackendFactory_probe(ALCsolarisBackendFactory *self, enum DevProbe type, al_string *outnames);
static ALCbackend* ALCsolarisBackendFactory_createBackend(ALCsolarisBackendFactory *self, ALCdevice *device, ALCbackend_Type type);
DEFINE_ALCBACKENDFACTORY_VTABLE(ALCsolarisBackendFactory);
@@ -305,7 +327,7 @@ static ALCboolean ALCsolarisBackendFactory_querySupport(ALCsolarisBackendFactory
return ALC_FALSE;
}
-static void ALCsolarisBackendFactory_probe(ALCsolarisBackendFactory* UNUSED(self), enum DevProbe type)
+static void ALCsolarisBackendFactory_probe(ALCsolarisBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
switch(type)
{
@@ -315,7 +337,7 @@ static void ALCsolarisBackendFactory_probe(ALCsolarisBackendFactory* UNUSED(self
struct stat buf;
if(stat(solaris_driver, &buf) == 0)
#endif
- AppendAllDevicesList(solaris_device);
+ alstr_append_range(outnames, solaris_device, solaris_device+sizeof(solaris_device));
}
break;
diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/wasapi.c
index e8563d33..b974321b 100644
--- a/Alc/backends/mmdevapi.c
+++ b/Alc/backends/wasapi.c
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <memory.h>
+#include <wtypes.h>
#include <mmdeviceapi.h>
#include <audioclient.h>
#include <cguid.h>
@@ -40,9 +41,11 @@
#include "alMain.h"
#include "alu.h"
+#include "ringbuffer.h"
#include "threads.h"
#include "compat.h"
#include "alstring.h"
+#include "converter.h"
#include "backends/base.h"
@@ -52,6 +55,7 @@ DEFINE_GUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, 0x00000003, 0x0000, 0x0010, 0x80, 0
DEFINE_DEVPROPKEY(DEVPKEY_Device_FriendlyName, 0xa45c254e, 0xdf1c, 0x4efd, 0x80,0x20, 0x67,0xd1,0x46,0xa8,0x50,0xe0, 14);
DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_FormFactor, 0x1da5d803, 0xd492, 0x4edd, 0x8c,0x23, 0xe0,0xc0,0xff,0xee,0x7f,0x0e, 0);
+DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_GUID, 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23,0xe0, 0xc0,0xff,0xee,0x7f,0x0e, 4 );
#define MONO SPEAKER_FRONT_CENTER
#define STEREO (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT)
@@ -62,11 +66,21 @@ DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_FormFactor, 0x1da5d803, 0xd492, 0x4edd, 0x
#define X7DOT1 (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT|SPEAKER_SIDE_LEFT|SPEAKER_SIDE_RIGHT)
#define X7DOT1_WIDE (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT|SPEAKER_FRONT_LEFT_OF_CENTER|SPEAKER_FRONT_RIGHT_OF_CENTER)
-#define DEVNAME_TAIL " on OpenAL Soft"
+#define REFTIME_PER_SEC ((REFERENCE_TIME)10000000)
+
+#define DEVNAME_HEAD "OpenAL Soft on "
+
+
+/* Scales the given value using 64-bit integer math, ceiling the result. */
+static inline ALuint64 ScaleCeil(ALuint64 val, ALuint64 new_scale, ALuint64 old_scale)
+{
+ return (val*new_scale + old_scale-1) / old_scale;
+}
typedef struct {
al_string name;
+ al_string endpoint_guid; // obtained from PKEY_AudioEndpoint_GUID , set to "Unknown device GUID" if absent.
WCHAR *devid;
} DevMap;
TYPEDEF_VECTOR(DevMap, vector_DevMap)
@@ -75,11 +89,12 @@ static void clear_devlist(vector_DevMap *list)
{
#define CLEAR_DEVMAP(i) do { \
AL_STRING_DEINIT((i)->name); \
+ AL_STRING_DEINIT((i)->endpoint_guid); \
free((i)->devid); \
(i)->devid = NULL; \
} while(0)
VECTOR_FOR_EACH(DevMap, *list, CLEAR_DEVMAP);
- VECTOR_RESIZE(*list, 0);
+ VECTOR_RESIZE(*list, 0, 0);
#undef CLEAR_DEVMAP
}
@@ -104,6 +119,15 @@ typedef struct {
#define WM_USER_Enumerate (WM_USER+5)
#define WM_USER_Last (WM_USER+5)
+static const char MessageStr[WM_USER_Last+1-WM_USER][20] = {
+ "Open Device",
+ "Reset Device",
+ "Start Device",
+ "Stop Device",
+ "Close Device",
+ "Enumerate Devices",
+};
+
static inline void ReturnMsgResponse(ThreadRequest *req, HRESULT res)
{
req->result = res;
@@ -119,16 +143,21 @@ static HRESULT WaitForResponse(ThreadRequest *req)
}
-static void get_device_name(IMMDevice *device, al_string *name)
+static void get_device_name_and_guid(IMMDevice *device, al_string *name, al_string *guid)
{
IPropertyStore *ps;
PROPVARIANT pvname;
+ PROPVARIANT pvguid;
HRESULT hr;
+ alstr_copy_cstr(name, DEVNAME_HEAD);
+
hr = IMMDevice_OpenPropertyStore(device, STGM_READ, &ps);
if(FAILED(hr))
{
WARN("OpenPropertyStore failed: 0x%08lx\n", hr);
+ alstr_append_cstr(name, "Unknown Device Name");
+ if(guid!=NULL)alstr_copy_cstr(guid, "Unknown Device GUID");
return;
}
@@ -136,13 +165,39 @@ static void get_device_name(IMMDevice *device, al_string *name)
hr = IPropertyStore_GetValue(ps, (const PROPERTYKEY*)&DEVPKEY_Device_FriendlyName, &pvname);
if(FAILED(hr))
+ {
WARN("GetValue Device_FriendlyName failed: 0x%08lx\n", hr);
+ alstr_append_cstr(name, "Unknown Device Name");
+ }
else if(pvname.vt == VT_LPWSTR)
- al_string_copy_wcstr(name, pvname.pwszVal);
+ alstr_append_wcstr(name, pvname.pwszVal);
else
+ {
WARN("Unexpected PROPVARIANT type: 0x%04x\n", pvname.vt);
-
+ alstr_append_cstr(name, "Unknown Device Name");
+ }
PropVariantClear(&pvname);
+
+ if(guid!=NULL){
+ PropVariantInit(&pvguid);
+
+ hr = IPropertyStore_GetValue(ps, (const PROPERTYKEY*)&PKEY_AudioEndpoint_GUID, &pvguid);
+ if(FAILED(hr))
+ {
+ WARN("GetValue AudioEndpoint_GUID failed: 0x%08lx\n", hr);
+ alstr_copy_cstr(guid, "Unknown Device GUID");
+ }
+ else if(pvguid.vt == VT_LPWSTR)
+ alstr_copy_wcstr(guid, pvguid.pwszVal);
+ else
+ {
+ WARN("Unexpected PROPVARIANT type: 0x%04x\n", pvguid.vt);
+ alstr_copy_cstr(guid, "Unknown Device GUID");
+ }
+
+ PropVariantClear(&pvguid);
+ }
+
IPropertyStore_Release(ps);
}
@@ -176,7 +231,7 @@ static void get_device_formfactor(IMMDevice *device, EndpointFormFactor *formfac
}
-static void add_device(IMMDevice *device, LPCWSTR devid, vector_DevMap *list)
+static void add_device(IMMDevice *device, const WCHAR *devid, vector_DevMap *list)
{
int count = 0;
al_string tmpname;
@@ -184,40 +239,39 @@ static void add_device(IMMDevice *device, LPCWSTR devid, vector_DevMap *list)
AL_STRING_INIT(tmpname);
AL_STRING_INIT(entry.name);
+ AL_STRING_INIT(entry.endpoint_guid);
entry.devid = strdupW(devid);
- get_device_name(device, &tmpname);
+ get_device_name_and_guid(device, &tmpname, &entry.endpoint_guid);
while(1)
{
const DevMap *iter;
- al_string_copy(&entry.name, tmpname);
- if(count == 0)
- al_string_append_cstr(&entry.name, DEVNAME_TAIL);
- else
+ alstr_copy(&entry.name, tmpname);
+ if(count != 0)
{
char str[64];
- snprintf(str, sizeof(str), " #%d"DEVNAME_TAIL, count+1);
- al_string_append_cstr(&entry.name, str);
+ snprintf(str, sizeof(str), " #%d", count+1);
+ alstr_append_cstr(&entry.name, str);
}
-#define MATCH_ENTRY(i) (al_string_cmp(entry.name, (i)->name) == 0)
+#define MATCH_ENTRY(i) (alstr_cmp(entry.name, (i)->name) == 0)
VECTOR_FIND_IF(iter, const DevMap, *list, MATCH_ENTRY);
- if(iter == VECTOR_ITER_END(*list)) break;
+ if(iter == VECTOR_END(*list)) break;
#undef MATCH_ENTRY
count++;
}
- TRACE("Got device \"%s\", \"%ls\"\n", al_string_get_cstr(entry.name), entry.devid);
+ TRACE("Got device \"%s\", \"%s\", \"%ls\"\n", alstr_get_cstr(entry.name), alstr_get_cstr(entry.endpoint_guid), entry.devid);
VECTOR_PUSH_BACK(*list, entry);
AL_STRING_DEINIT(tmpname);
}
-static LPWSTR get_device_id(IMMDevice *device)
+static WCHAR *get_device_id(IMMDevice *device)
{
- LPWSTR devid;
+ WCHAR *devid;
HRESULT hr;
hr = IMMDevice_GetId(device, &devid);
@@ -234,7 +288,7 @@ static HRESULT probe_devices(IMMDeviceEnumerator *devenum, EDataFlow flowdir, ve
{
IMMDeviceCollection *coll;
IMMDevice *defdev = NULL;
- LPWSTR defdevid = NULL;
+ WCHAR *defdevid = NULL;
HRESULT hr;
UINT count;
UINT i;
@@ -251,11 +305,7 @@ static HRESULT probe_devices(IMMDeviceEnumerator *devenum, EDataFlow flowdir, ve
if(SUCCEEDED(hr) && count > 0)
{
clear_devlist(list);
- if(!VECTOR_RESERVE(*list, count))
- {
- IMMDeviceCollection_Release(coll);
- return E_OUTOFMEMORY;
- }
+ VECTOR_RESIZE(*list, 0, count);
hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum, flowdir,
eMultimedia, &defdev);
@@ -270,7 +320,7 @@ static HRESULT probe_devices(IMMDeviceEnumerator *devenum, EDataFlow flowdir, ve
for(i = 0;i < count;++i)
{
IMMDevice *device;
- LPWSTR devid;
+ WCHAR *devid;
hr = IMMDeviceCollection_Item(coll, i, &device);
if(FAILED(hr)) continue;
@@ -278,7 +328,7 @@ static HRESULT probe_devices(IMMDeviceEnumerator *devenum, EDataFlow flowdir, ve
devid = get_device_id(device);
if(devid)
{
- if(wcscmp(devid, defdevid) != 0)
+ if(!defdevid || wcscmp(devid, defdevid) != 0)
add_device(device, devid, list);
CoTaskMemFree(devid);
}
@@ -294,51 +344,51 @@ static HRESULT probe_devices(IMMDeviceEnumerator *devenum, EDataFlow flowdir, ve
/* Proxy interface used by the message handler. */
-struct ALCmmdevProxyVtable;
+struct ALCwasapiProxyVtable;
-typedef struct ALCmmdevProxy {
- const struct ALCmmdevProxyVtable *vtbl;
-} ALCmmdevProxy;
+typedef struct ALCwasapiProxy {
+ const struct ALCwasapiProxyVtable *vtbl;
+} ALCwasapiProxy;
-struct ALCmmdevProxyVtable {
- HRESULT (*const openProxy)(ALCmmdevProxy*);
- void (*const closeProxy)(ALCmmdevProxy*);
+struct ALCwasapiProxyVtable {
+ HRESULT (*const openProxy)(ALCwasapiProxy*);
+ void (*const closeProxy)(ALCwasapiProxy*);
- HRESULT (*const resetProxy)(ALCmmdevProxy*);
- HRESULT (*const startProxy)(ALCmmdevProxy*);
- void (*const stopProxy)(ALCmmdevProxy*);
+ HRESULT (*const resetProxy)(ALCwasapiProxy*);
+ HRESULT (*const startProxy)(ALCwasapiProxy*);
+ void (*const stopProxy)(ALCwasapiProxy*);
};
-#define DEFINE_ALCMMDEVPROXY_VTABLE(T) \
-DECLARE_THUNK(T, ALCmmdevProxy, HRESULT, openProxy) \
-DECLARE_THUNK(T, ALCmmdevProxy, void, closeProxy) \
-DECLARE_THUNK(T, ALCmmdevProxy, HRESULT, resetProxy) \
-DECLARE_THUNK(T, ALCmmdevProxy, HRESULT, startProxy) \
-DECLARE_THUNK(T, ALCmmdevProxy, void, stopProxy) \
+#define DEFINE_ALCWASAPIPROXY_VTABLE(T) \
+DECLARE_THUNK(T, ALCwasapiProxy, HRESULT, openProxy) \
+DECLARE_THUNK(T, ALCwasapiProxy, void, closeProxy) \
+DECLARE_THUNK(T, ALCwasapiProxy, HRESULT, resetProxy) \
+DECLARE_THUNK(T, ALCwasapiProxy, HRESULT, startProxy) \
+DECLARE_THUNK(T, ALCwasapiProxy, void, stopProxy) \
\
-static const struct ALCmmdevProxyVtable T##_ALCmmdevProxy_vtable = { \
- T##_ALCmmdevProxy_openProxy, \
- T##_ALCmmdevProxy_closeProxy, \
- T##_ALCmmdevProxy_resetProxy, \
- T##_ALCmmdevProxy_startProxy, \
- T##_ALCmmdevProxy_stopProxy, \
+static const struct ALCwasapiProxyVtable T##_ALCwasapiProxy_vtable = { \
+ T##_ALCwasapiProxy_openProxy, \
+ T##_ALCwasapiProxy_closeProxy, \
+ T##_ALCwasapiProxy_resetProxy, \
+ T##_ALCwasapiProxy_startProxy, \
+ T##_ALCwasapiProxy_stopProxy, \
}
-static void ALCmmdevProxy_Construct(ALCmmdevProxy* UNUSED(self)) { }
-static void ALCmmdevProxy_Destruct(ALCmmdevProxy* UNUSED(self)) { }
+static void ALCwasapiProxy_Construct(ALCwasapiProxy* UNUSED(self)) { }
+static void ALCwasapiProxy_Destruct(ALCwasapiProxy* UNUSED(self)) { }
-static DWORD CALLBACK ALCmmdevProxy_messageHandler(void *ptr)
+static DWORD CALLBACK ALCwasapiProxy_messageHandler(void *ptr)
{
ThreadRequest *req = ptr;
IMMDeviceEnumerator *Enumerator;
ALuint deviceCount = 0;
- ALCmmdevProxy *proxy;
+ ALCwasapiProxy *proxy;
HRESULT hr, cohr;
MSG msg;
TRACE("Starting message thread\n");
- cohr = CoInitialize(NULL);
+ cohr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if(FAILED(cohr))
{
WARN("Failed to initialize COM: 0x%08lx\n", cohr);
@@ -372,16 +422,20 @@ static DWORD CALLBACK ALCmmdevProxy_messageHandler(void *ptr)
TRACE("Starting message loop\n");
while(GetMessage(&msg, NULL, WM_USER_First, WM_USER_Last))
{
- TRACE("Got message %u (lparam=%p, wparam=%p)\n", msg.message, (void*)msg.lParam, (void*)msg.wParam);
+ TRACE("Got message \"%s\" (0x%04x, lparam=%p, wparam=%p)\n",
+ (msg.message >= WM_USER && msg.message <= WM_USER_Last) ?
+ MessageStr[msg.message-WM_USER] : "Unknown",
+ msg.message, (void*)msg.lParam, (void*)msg.wParam
+ );
switch(msg.message)
{
case WM_USER_OpenDevice:
req = (ThreadRequest*)msg.wParam;
- proxy = (ALCmmdevProxy*)msg.lParam;
+ proxy = (ALCwasapiProxy*)msg.lParam;
hr = cohr = S_OK;
if(++deviceCount == 1)
- hr = cohr = CoInitialize(NULL);
+ hr = cohr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if(SUCCEEDED(hr))
hr = V0(proxy,openProxy)();
if(FAILED(hr))
@@ -395,7 +449,7 @@ static DWORD CALLBACK ALCmmdevProxy_messageHandler(void *ptr)
case WM_USER_ResetDevice:
req = (ThreadRequest*)msg.wParam;
- proxy = (ALCmmdevProxy*)msg.lParam;
+ proxy = (ALCwasapiProxy*)msg.lParam;
hr = V0(proxy,resetProxy)();
ReturnMsgResponse(req, hr);
@@ -403,7 +457,7 @@ static DWORD CALLBACK ALCmmdevProxy_messageHandler(void *ptr)
case WM_USER_StartDevice:
req = (ThreadRequest*)msg.wParam;
- proxy = (ALCmmdevProxy*)msg.lParam;
+ proxy = (ALCwasapiProxy*)msg.lParam;
hr = V0(proxy,startProxy)();
ReturnMsgResponse(req, hr);
@@ -411,7 +465,7 @@ static DWORD CALLBACK ALCmmdevProxy_messageHandler(void *ptr)
case WM_USER_StopDevice:
req = (ThreadRequest*)msg.wParam;
- proxy = (ALCmmdevProxy*)msg.lParam;
+ proxy = (ALCwasapiProxy*)msg.lParam;
V0(proxy,stopProxy)();
ReturnMsgResponse(req, S_OK);
@@ -419,7 +473,7 @@ static DWORD CALLBACK ALCmmdevProxy_messageHandler(void *ptr)
case WM_USER_CloseDevice:
req = (ThreadRequest*)msg.wParam;
- proxy = (ALCmmdevProxy*)msg.lParam;
+ proxy = (ALCwasapiProxy*)msg.lParam;
V0(proxy,closeProxy)();
if(--deviceCount == 0)
@@ -433,7 +487,7 @@ static DWORD CALLBACK ALCmmdevProxy_messageHandler(void *ptr)
hr = cohr = S_OK;
if(++deviceCount == 1)
- hr = cohr = CoInitialize(NULL);
+ hr = cohr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if(SUCCEEDED(hr))
hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, &ptr);
if(SUCCEEDED(hr))
@@ -466,9 +520,9 @@ static DWORD CALLBACK ALCmmdevProxy_messageHandler(void *ptr)
}
-typedef struct ALCmmdevPlayback {
+typedef struct ALCwasapiPlayback {
DERIVE_FROM_TYPE(ALCbackend);
- DERIVE_FROM_TYPE(ALCmmdevProxy);
+ DERIVE_FROM_TYPE(ALCwasapiProxy);
WCHAR *devid;
@@ -479,43 +533,42 @@ typedef struct ALCmmdevPlayback {
HANDLE MsgEvent;
- volatile UINT32 Padding;
+ ATOMIC(UINT32) Padding;
- volatile int killNow;
+ ATOMIC(int) killNow;
althrd_t thread;
-} ALCmmdevPlayback;
-
-static int ALCmmdevPlayback_mixerProc(void *arg);
-
-static void ALCmmdevPlayback_Construct(ALCmmdevPlayback *self, ALCdevice *device);
-static void ALCmmdevPlayback_Destruct(ALCmmdevPlayback *self);
-static ALCenum ALCmmdevPlayback_open(ALCmmdevPlayback *self, const ALCchar *name);
-static HRESULT ALCmmdevPlayback_openProxy(ALCmmdevPlayback *self);
-static void ALCmmdevPlayback_close(ALCmmdevPlayback *self);
-static void ALCmmdevPlayback_closeProxy(ALCmmdevPlayback *self);
-static ALCboolean ALCmmdevPlayback_reset(ALCmmdevPlayback *self);
-static HRESULT ALCmmdevPlayback_resetProxy(ALCmmdevPlayback *self);
-static ALCboolean ALCmmdevPlayback_start(ALCmmdevPlayback *self);
-static HRESULT ALCmmdevPlayback_startProxy(ALCmmdevPlayback *self);
-static void ALCmmdevPlayback_stop(ALCmmdevPlayback *self);
-static void ALCmmdevPlayback_stopProxy(ALCmmdevPlayback *self);
-static DECLARE_FORWARD2(ALCmmdevPlayback, ALCbackend, ALCenum, captureSamples, ALCvoid*, ALCuint)
-static DECLARE_FORWARD(ALCmmdevPlayback, ALCbackend, ALCuint, availableSamples)
-static ALint64 ALCmmdevPlayback_getLatency(ALCmmdevPlayback *self);
-static DECLARE_FORWARD(ALCmmdevPlayback, ALCbackend, void, lock)
-static DECLARE_FORWARD(ALCmmdevPlayback, ALCbackend, void, unlock)
-DECLARE_DEFAULT_ALLOCATORS(ALCmmdevPlayback)
-
-DEFINE_ALCMMDEVPROXY_VTABLE(ALCmmdevPlayback);
-DEFINE_ALCBACKEND_VTABLE(ALCmmdevPlayback);
-
-
-static void ALCmmdevPlayback_Construct(ALCmmdevPlayback *self, ALCdevice *device)
+} ALCwasapiPlayback;
+
+static int ALCwasapiPlayback_mixerProc(void *arg);
+
+static void ALCwasapiPlayback_Construct(ALCwasapiPlayback *self, ALCdevice *device);
+static void ALCwasapiPlayback_Destruct(ALCwasapiPlayback *self);
+static ALCenum ALCwasapiPlayback_open(ALCwasapiPlayback *self, const ALCchar *name);
+static HRESULT ALCwasapiPlayback_openProxy(ALCwasapiPlayback *self);
+static void ALCwasapiPlayback_closeProxy(ALCwasapiPlayback *self);
+static ALCboolean ALCwasapiPlayback_reset(ALCwasapiPlayback *self);
+static HRESULT ALCwasapiPlayback_resetProxy(ALCwasapiPlayback *self);
+static ALCboolean ALCwasapiPlayback_start(ALCwasapiPlayback *self);
+static HRESULT ALCwasapiPlayback_startProxy(ALCwasapiPlayback *self);
+static void ALCwasapiPlayback_stop(ALCwasapiPlayback *self);
+static void ALCwasapiPlayback_stopProxy(ALCwasapiPlayback *self);
+static DECLARE_FORWARD2(ALCwasapiPlayback, ALCbackend, ALCenum, captureSamples, ALCvoid*, ALCuint)
+static DECLARE_FORWARD(ALCwasapiPlayback, ALCbackend, ALCuint, availableSamples)
+static ClockLatency ALCwasapiPlayback_getClockLatency(ALCwasapiPlayback *self);
+static DECLARE_FORWARD(ALCwasapiPlayback, ALCbackend, void, lock)
+static DECLARE_FORWARD(ALCwasapiPlayback, ALCbackend, void, unlock)
+DECLARE_DEFAULT_ALLOCATORS(ALCwasapiPlayback)
+
+DEFINE_ALCWASAPIPROXY_VTABLE(ALCwasapiPlayback);
+DEFINE_ALCBACKEND_VTABLE(ALCwasapiPlayback);
+
+
+static void ALCwasapiPlayback_Construct(ALCwasapiPlayback *self, ALCdevice *device)
{
- SET_VTABLE2(ALCmmdevPlayback, ALCbackend, self);
- SET_VTABLE2(ALCmmdevPlayback, ALCmmdevProxy, self);
+ SET_VTABLE2(ALCwasapiPlayback, ALCbackend, self);
+ SET_VTABLE2(ALCwasapiPlayback, ALCwasapiProxy, self);
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
- ALCmmdevProxy_Construct(STATIC_CAST(ALCmmdevProxy, self));
+ ALCwasapiProxy_Construct(STATIC_CAST(ALCwasapiProxy, self));
self->devid = NULL;
@@ -526,13 +579,30 @@ static void ALCmmdevPlayback_Construct(ALCmmdevPlayback *self, ALCdevice *device
self->MsgEvent = NULL;
- self->Padding = 0;
+ ATOMIC_INIT(&self->Padding, 0);
- self->killNow = 0;
+ ATOMIC_INIT(&self->killNow, 0);
}
-static void ALCmmdevPlayback_Destruct(ALCmmdevPlayback *self)
+static void ALCwasapiPlayback_Destruct(ALCwasapiPlayback *self)
{
+ if(self->MsgEvent)
+ {
+ ThreadRequest req = { self->MsgEvent, 0 };
+ if(PostThreadMessage(ThreadID, WM_USER_CloseDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCwasapiProxy, self)))
+ (void)WaitForResponse(&req);
+
+ CloseHandle(self->MsgEvent);
+ self->MsgEvent = NULL;
+ }
+
+ if(self->NotifyEvent)
+ CloseHandle(self->NotifyEvent);
+ self->NotifyEvent = NULL;
+
+ free(self->devid);
+ self->devid = NULL;
+
if(self->NotifyEvent != NULL)
CloseHandle(self->NotifyEvent);
self->NotifyEvent = NULL;
@@ -543,26 +613,26 @@ static void ALCmmdevPlayback_Destruct(ALCmmdevPlayback *self)
free(self->devid);
self->devid = NULL;
- ALCmmdevProxy_Destruct(STATIC_CAST(ALCmmdevProxy, self));
+ ALCwasapiProxy_Destruct(STATIC_CAST(ALCwasapiProxy, self));
ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}
-FORCE_ALIGN static int ALCmmdevPlayback_mixerProc(void *arg)
+FORCE_ALIGN static int ALCwasapiPlayback_mixerProc(void *arg)
{
- ALCmmdevPlayback *self = arg;
+ ALCwasapiPlayback *self = arg;
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
UINT32 buffer_len, written;
ALuint update_size, len;
BYTE *buffer;
HRESULT hr;
- hr = CoInitialize(NULL);
+ hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if(FAILED(hr))
{
- ERR("CoInitialize(NULL) failed: 0x%08lx\n", hr);
+ ERR("CoInitializeEx(NULL, COINIT_MULTITHREADED) failed: 0x%08lx\n", hr);
V0(device->Backend,lock)();
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "COM init failed: 0x%08lx", hr);
V0(device->Backend,unlock)();
return 1;
}
@@ -572,18 +642,18 @@ FORCE_ALIGN static int ALCmmdevPlayback_mixerProc(void *arg)
update_size = device->UpdateSize;
buffer_len = update_size * device->NumUpdates;
- while(!self->killNow)
+ while(!ATOMIC_LOAD(&self->killNow, almemory_order_relaxed))
{
hr = IAudioClient_GetCurrentPadding(self->client, &written);
if(FAILED(hr))
{
ERR("Failed to get padding: 0x%08lx\n", hr);
V0(device->Backend,lock)();
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failed to retrieve buffer padding: 0x%08lx", hr);
V0(device->Backend,unlock)();
break;
}
- self->Padding = written;
+ ATOMIC_STORE(&self->Padding, written, almemory_order_relaxed);
len = buffer_len - written;
if(len < update_size)
@@ -599,22 +669,22 @@ FORCE_ALIGN static int ALCmmdevPlayback_mixerProc(void *arg)
hr = IAudioRenderClient_GetBuffer(self->render, len, &buffer);
if(SUCCEEDED(hr))
{
- V0(device->Backend,lock)();
+ ALCwasapiPlayback_lock(self);
aluMixData(device, buffer, len);
- self->Padding = written + len;
- V0(device->Backend,unlock)();
+ ATOMIC_STORE(&self->Padding, written + len, almemory_order_relaxed);
+ ALCwasapiPlayback_unlock(self);
hr = IAudioRenderClient_ReleaseBuffer(self->render, len, 0);
}
if(FAILED(hr))
{
ERR("Failed to buffer data: 0x%08lx\n", hr);
V0(device->Backend,lock)();
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failed to send playback samples: 0x%08lx", hr);
V0(device->Backend,unlock)();
break;
}
}
- self->Padding = 0;
+ ATOMIC_STORE(&self->Padding, 0, almemory_order_release);
CoUninitialize();
return 0;
@@ -660,13 +730,12 @@ static ALCboolean MakeExtensible(WAVEFORMATEXTENSIBLE *out, const WAVEFORMATEX *
return ALC_TRUE;
}
-
-static ALCenum ALCmmdevPlayback_open(ALCmmdevPlayback *self, const ALCchar *deviceName)
+static ALCenum ALCwasapiPlayback_open(ALCwasapiPlayback *self, const ALCchar *deviceName)
{
HRESULT hr = S_OK;
- self->NotifyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- self->MsgEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ self->NotifyEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
+ self->MsgEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
if(self->NotifyEvent == NULL || self->MsgEvent == NULL)
{
ERR("Failed to create message events: %lu\n", GetLastError());
@@ -687,18 +756,32 @@ static ALCenum ALCmmdevPlayback_open(ALCmmdevPlayback *self, const ALCchar *devi
}
hr = E_FAIL;
-#define MATCH_NAME(i) (al_string_cmp_cstr((i)->name, deviceName) == 0)
+#define MATCH_NAME(i) (alstr_cmp_cstr((i)->name, deviceName) == 0 || \
+ alstr_cmp_cstr((i)->endpoint_guid, deviceName) == 0)
VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_NAME);
- if(iter == VECTOR_ITER_END(PlaybackDevices))
+#undef MATCH_NAME
+ if(iter == VECTOR_END(PlaybackDevices))
+ {
+ int len;
+ if((len=MultiByteToWideChar(CP_UTF8, 0, deviceName, -1, NULL, 0)) > 0)
+ {
+ WCHAR *wname = calloc(sizeof(WCHAR), len);
+ MultiByteToWideChar(CP_UTF8, 0, deviceName, -1, wname, len);
+#define MATCH_NAME(i) (wcscmp((i)->devid, wname) == 0)
+ VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_NAME);
+#undef MATCH_NAME
+ free(wname);
+ }
+ }
+ if(iter == VECTOR_END(PlaybackDevices))
WARN("Failed to find device name matching \"%s\"\n", deviceName);
else
{
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
self->devid = strdupW(iter->devid);
- al_string_copy(&device->DeviceName, iter->name);
+ alstr_copy(&device->DeviceName, iter->name);
hr = S_OK;
}
-#undef MATCH_NAME
}
}
@@ -707,7 +790,7 @@ static ALCenum ALCmmdevPlayback_open(ALCmmdevPlayback *self, const ALCchar *devi
ThreadRequest req = { self->MsgEvent, 0 };
hr = E_FAIL;
- if(PostThreadMessage(ThreadID, WM_USER_OpenDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCmmdevProxy, self)))
+ if(PostThreadMessage(ThreadID, WM_USER_OpenDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCwasapiProxy, self)))
hr = WaitForResponse(&req);
else
ERR("Failed to post thread message: %lu\n", GetLastError());
@@ -732,7 +815,7 @@ static ALCenum ALCmmdevPlayback_open(ALCmmdevPlayback *self, const ALCchar *devi
return ALC_NO_ERROR;
}
-static HRESULT ALCmmdevPlayback_openProxy(ALCmmdevPlayback *self)
+static HRESULT ALCwasapiPlayback_openProxy(ALCwasapiPlayback *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
void *ptr;
@@ -754,11 +837,8 @@ static HRESULT ALCmmdevPlayback_openProxy(ALCmmdevPlayback *self)
if(SUCCEEDED(hr))
{
self->client = ptr;
- if(al_string_empty(device->DeviceName))
- {
- get_device_name(self->mmdev, &device->DeviceName);
- al_string_append_cstr(&device->DeviceName, DEVNAME_TAIL);
- }
+ if(alstr_empty(device->DeviceName))
+ get_device_name_and_guid(self->mmdev, &device->DeviceName, NULL);
}
if(FAILED(hr))
@@ -772,24 +852,7 @@ static HRESULT ALCmmdevPlayback_openProxy(ALCmmdevPlayback *self)
}
-static void ALCmmdevPlayback_close(ALCmmdevPlayback *self)
-{
- ThreadRequest req = { self->MsgEvent, 0 };
-
- if(PostThreadMessage(ThreadID, WM_USER_CloseDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCmmdevProxy, self)))
- (void)WaitForResponse(&req);
-
- CloseHandle(self->MsgEvent);
- self->MsgEvent = NULL;
-
- CloseHandle(self->NotifyEvent);
- self->NotifyEvent = NULL;
-
- free(self->devid);
- self->devid = NULL;
-}
-
-static void ALCmmdevPlayback_closeProxy(ALCmmdevPlayback *self)
+static void ALCwasapiPlayback_closeProxy(ALCwasapiPlayback *self)
{
if(self->client)
IAudioClient_Release(self->client);
@@ -801,18 +864,18 @@ static void ALCmmdevPlayback_closeProxy(ALCmmdevPlayback *self)
}
-static ALCboolean ALCmmdevPlayback_reset(ALCmmdevPlayback *self)
+static ALCboolean ALCwasapiPlayback_reset(ALCwasapiPlayback *self)
{
ThreadRequest req = { self->MsgEvent, 0 };
HRESULT hr = E_FAIL;
- if(PostThreadMessage(ThreadID, WM_USER_ResetDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCmmdevProxy, self)))
+ if(PostThreadMessage(ThreadID, WM_USER_ResetDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCwasapiProxy, self)))
hr = WaitForResponse(&req);
return SUCCEEDED(hr) ? ALC_TRUE : ALC_FALSE;
}
-static HRESULT ALCmmdevPlayback_resetProxy(ALCmmdevPlayback *self)
+static HRESULT ALCwasapiPlayback_resetProxy(ALCwasapiPlayback *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
EndpointFormFactor formfactor = UnknownFormFactor;
@@ -850,8 +913,8 @@ static HRESULT ALCmmdevPlayback_resetProxy(ALCmmdevPlayback *self)
CoTaskMemFree(wfx);
wfx = NULL;
- buf_time = ((REFERENCE_TIME)device->UpdateSize*device->NumUpdates*10000000 +
- device->Frequency-1) / device->Frequency;
+ buf_time = ScaleCeil(device->UpdateSize*device->NumUpdates, REFTIME_PER_SEC,
+ device->Frequency);
if(!(device->Flags&DEVICE_FREQUENCY_REQUEST))
device->Frequency = OutputType.Format.nSamplesPerSec;
@@ -881,7 +944,7 @@ static HRESULT ALCmmdevPlayback_resetProxy(ALCmmdevPlayback *self)
OutputType.Format.nChannels = 1;
OutputType.dwChannelMask = MONO;
break;
- case DevFmtBFormat3D:
+ case DevFmtAmbi3D:
device->FmtChans = DevFmtStereo;
/*fall-through*/
case DevFmtStereo:
@@ -1022,7 +1085,9 @@ static HRESULT ALCmmdevPlayback_resetProxy(ALCmmdevPlayback *self)
OutputType.Samples.wValidBitsPerSample = OutputType.Format.wBitsPerSample;
}
get_device_formfactor(self->mmdev, &formfactor);
- device->IsHeadphones = (device->FmtChans == DevFmtStereo && formfactor == Headphones);
+ device->IsHeadphones = (device->FmtChans == DevFmtStereo &&
+ (formfactor == Headphones || formfactor == Headset)
+ );
SetDefaultWFXChannelOrder(device);
@@ -1038,7 +1103,7 @@ static HRESULT ALCmmdevPlayback_resetProxy(ALCmmdevPlayback *self)
hr = IAudioClient_GetDevicePeriod(self->client, &min_per, NULL);
if(SUCCEEDED(hr))
{
- min_len = (UINT32)((min_per*device->Frequency + 10000000-1) / 10000000);
+ min_len = (UINT32)ScaleCeil(min_per, device->Frequency, REFTIME_PER_SEC);
/* Find the nearest multiple of the period size to the update size */
if(min_len < device->UpdateSize)
min_len *= (device->UpdateSize + min_len/2)/min_len;
@@ -1070,18 +1135,18 @@ static HRESULT ALCmmdevPlayback_resetProxy(ALCmmdevPlayback *self)
}
-static ALCboolean ALCmmdevPlayback_start(ALCmmdevPlayback *self)
+static ALCboolean ALCwasapiPlayback_start(ALCwasapiPlayback *self)
{
ThreadRequest req = { self->MsgEvent, 0 };
HRESULT hr = E_FAIL;
- if(PostThreadMessage(ThreadID, WM_USER_StartDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCmmdevProxy, self)))
+ if(PostThreadMessage(ThreadID, WM_USER_StartDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCwasapiProxy, self)))
hr = WaitForResponse(&req);
return SUCCEEDED(hr) ? ALC_TRUE : ALC_FALSE;
}
-static HRESULT ALCmmdevPlayback_startProxy(ALCmmdevPlayback *self)
+static HRESULT ALCwasapiPlayback_startProxy(ALCwasapiPlayback *self)
{
HRESULT hr;
void *ptr;
@@ -1096,8 +1161,8 @@ static HRESULT ALCmmdevPlayback_startProxy(ALCmmdevPlayback *self)
if(SUCCEEDED(hr))
{
self->render = ptr;
- self->killNow = 0;
- if(althrd_create(&self->thread, ALCmmdevPlayback_mixerProc, self) != althrd_success)
+ ATOMIC_STORE(&self->killNow, 0, almemory_order_release);
+ if(althrd_create(&self->thread, ALCwasapiPlayback_mixerProc, self) != althrd_success)
{
if(self->render)
IAudioRenderClient_Release(self->render);
@@ -1112,21 +1177,21 @@ static HRESULT ALCmmdevPlayback_startProxy(ALCmmdevPlayback *self)
}
-static void ALCmmdevPlayback_stop(ALCmmdevPlayback *self)
+static void ALCwasapiPlayback_stop(ALCwasapiPlayback *self)
{
ThreadRequest req = { self->MsgEvent, 0 };
- if(PostThreadMessage(ThreadID, WM_USER_StopDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCmmdevProxy, self)))
+ if(PostThreadMessage(ThreadID, WM_USER_StopDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCwasapiProxy, self)))
(void)WaitForResponse(&req);
}
-static void ALCmmdevPlayback_stopProxy(ALCmmdevPlayback *self)
+static void ALCwasapiPlayback_stopProxy(ALCwasapiPlayback *self)
{
int res;
if(!self->render)
return;
- self->killNow = 1;
+ ATOMIC_STORE_SEQ(&self->killNow, 1);
althrd_join(self->thread, &res);
IAudioRenderClient_Release(self->render);
@@ -1135,16 +1200,24 @@ static void ALCmmdevPlayback_stopProxy(ALCmmdevPlayback *self)
}
-static ALint64 ALCmmdevPlayback_getLatency(ALCmmdevPlayback *self)
+static ClockLatency ALCwasapiPlayback_getClockLatency(ALCwasapiPlayback *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- return (ALint64)self->Padding * 1000000000 / device->Frequency;
+ ClockLatency ret;
+
+ ALCwasapiPlayback_lock(self);
+ ret.ClockTime = GetDeviceClockTime(device);
+ ret.Latency = ATOMIC_LOAD(&self->Padding, almemory_order_relaxed) * DEVICE_CLOCK_RES /
+ device->Frequency;
+ ALCwasapiPlayback_unlock(self);
+
+ return ret;
}
-typedef struct ALCmmdevCapture {
+typedef struct ALCwasapiCapture {
DERIVE_FROM_TYPE(ALCbackend);
- DERIVE_FROM_TYPE(ALCmmdevProxy);
+ DERIVE_FROM_TYPE(ALCwasapiProxy);
WCHAR *devid;
@@ -1155,43 +1228,44 @@ typedef struct ALCmmdevCapture {
HANDLE MsgEvent;
+ ChannelConverter *ChannelConv;
+ SampleConverter *SampleConv;
ll_ringbuffer_t *Ring;
- volatile int killNow;
+ ATOMIC(int) killNow;
althrd_t thread;
-} ALCmmdevCapture;
-
-static int ALCmmdevCapture_recordProc(void *arg);
-
-static void ALCmmdevCapture_Construct(ALCmmdevCapture *self, ALCdevice *device);
-static void ALCmmdevCapture_Destruct(ALCmmdevCapture *self);
-static ALCenum ALCmmdevCapture_open(ALCmmdevCapture *self, const ALCchar *name);
-static HRESULT ALCmmdevCapture_openProxy(ALCmmdevCapture *self);
-static void ALCmmdevCapture_close(ALCmmdevCapture *self);
-static void ALCmmdevCapture_closeProxy(ALCmmdevCapture *self);
-static DECLARE_FORWARD(ALCmmdevCapture, ALCbackend, ALCboolean, reset)
-static HRESULT ALCmmdevCapture_resetProxy(ALCmmdevCapture *self);
-static ALCboolean ALCmmdevCapture_start(ALCmmdevCapture *self);
-static HRESULT ALCmmdevCapture_startProxy(ALCmmdevCapture *self);
-static void ALCmmdevCapture_stop(ALCmmdevCapture *self);
-static void ALCmmdevCapture_stopProxy(ALCmmdevCapture *self);
-static ALCenum ALCmmdevCapture_captureSamples(ALCmmdevCapture *self, ALCvoid *buffer, ALCuint samples);
-static ALuint ALCmmdevCapture_availableSamples(ALCmmdevCapture *self);
-static DECLARE_FORWARD(ALCmmdevCapture, ALCbackend, ALint64, getLatency)
-static DECLARE_FORWARD(ALCmmdevCapture, ALCbackend, void, lock)
-static DECLARE_FORWARD(ALCmmdevCapture, ALCbackend, void, unlock)
-DECLARE_DEFAULT_ALLOCATORS(ALCmmdevCapture)
-
-DEFINE_ALCMMDEVPROXY_VTABLE(ALCmmdevCapture);
-DEFINE_ALCBACKEND_VTABLE(ALCmmdevCapture);
-
-
-static void ALCmmdevCapture_Construct(ALCmmdevCapture *self, ALCdevice *device)
+} ALCwasapiCapture;
+
+static int ALCwasapiCapture_recordProc(void *arg);
+
+static void ALCwasapiCapture_Construct(ALCwasapiCapture *self, ALCdevice *device);
+static void ALCwasapiCapture_Destruct(ALCwasapiCapture *self);
+static ALCenum ALCwasapiCapture_open(ALCwasapiCapture *self, const ALCchar *name);
+static HRESULT ALCwasapiCapture_openProxy(ALCwasapiCapture *self);
+static void ALCwasapiCapture_closeProxy(ALCwasapiCapture *self);
+static DECLARE_FORWARD(ALCwasapiCapture, ALCbackend, ALCboolean, reset)
+static HRESULT ALCwasapiCapture_resetProxy(ALCwasapiCapture *self);
+static ALCboolean ALCwasapiCapture_start(ALCwasapiCapture *self);
+static HRESULT ALCwasapiCapture_startProxy(ALCwasapiCapture *self);
+static void ALCwasapiCapture_stop(ALCwasapiCapture *self);
+static void ALCwasapiCapture_stopProxy(ALCwasapiCapture *self);
+static ALCenum ALCwasapiCapture_captureSamples(ALCwasapiCapture *self, ALCvoid *buffer, ALCuint samples);
+static ALuint ALCwasapiCapture_availableSamples(ALCwasapiCapture *self);
+static DECLARE_FORWARD(ALCwasapiCapture, ALCbackend, ClockLatency, getClockLatency)
+static DECLARE_FORWARD(ALCwasapiCapture, ALCbackend, void, lock)
+static DECLARE_FORWARD(ALCwasapiCapture, ALCbackend, void, unlock)
+DECLARE_DEFAULT_ALLOCATORS(ALCwasapiCapture)
+
+DEFINE_ALCWASAPIPROXY_VTABLE(ALCwasapiCapture);
+DEFINE_ALCBACKEND_VTABLE(ALCwasapiCapture);
+
+
+static void ALCwasapiCapture_Construct(ALCwasapiCapture *self, ALCdevice *device)
{
- SET_VTABLE2(ALCmmdevCapture, ALCbackend, self);
- SET_VTABLE2(ALCmmdevCapture, ALCmmdevProxy, self);
+ SET_VTABLE2(ALCwasapiCapture, ALCbackend, self);
+ SET_VTABLE2(ALCwasapiCapture, ALCwasapiProxy, self);
ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device);
- ALCmmdevProxy_Construct(STATIC_CAST(ALCmmdevProxy, self));
+ ALCwasapiProxy_Construct(STATIC_CAST(ALCwasapiProxy, self));
self->devid = NULL;
@@ -1202,50 +1276,64 @@ static void ALCmmdevCapture_Construct(ALCmmdevCapture *self, ALCdevice *device)
self->MsgEvent = NULL;
+ self->ChannelConv = NULL;
+ self->SampleConv = NULL;
self->Ring = NULL;
- self->killNow = 0;
+ ATOMIC_INIT(&self->killNow, 0);
}
-static void ALCmmdevCapture_Destruct(ALCmmdevCapture *self)
+static void ALCwasapiCapture_Destruct(ALCwasapiCapture *self)
{
- ll_ringbuffer_free(self->Ring);
- self->Ring = NULL;
+ if(self->MsgEvent)
+ {
+ ThreadRequest req = { self->MsgEvent, 0 };
+ if(PostThreadMessage(ThreadID, WM_USER_CloseDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCwasapiProxy, self)))
+ (void)WaitForResponse(&req);
+
+ CloseHandle(self->MsgEvent);
+ self->MsgEvent = NULL;
+ }
if(self->NotifyEvent != NULL)
CloseHandle(self->NotifyEvent);
self->NotifyEvent = NULL;
- if(self->MsgEvent != NULL)
- CloseHandle(self->MsgEvent);
- self->MsgEvent = NULL;
+
+ ll_ringbuffer_free(self->Ring);
+ self->Ring = NULL;
+
+ DestroySampleConverter(&self->SampleConv);
+ DestroyChannelConverter(&self->ChannelConv);
free(self->devid);
self->devid = NULL;
- ALCmmdevProxy_Destruct(STATIC_CAST(ALCmmdevProxy, self));
+ ALCwasapiProxy_Destruct(STATIC_CAST(ALCwasapiProxy, self));
ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
}
-FORCE_ALIGN int ALCmmdevCapture_recordProc(void *arg)
+FORCE_ALIGN int ALCwasapiCapture_recordProc(void *arg)
{
- ALCmmdevCapture *self = arg;
+ ALCwasapiCapture *self = arg;
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
+ ALfloat *samples = NULL;
+ size_t samplesmax = 0;
HRESULT hr;
- hr = CoInitialize(NULL);
+ hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if(FAILED(hr))
{
- ERR("CoInitialize(NULL) failed: 0x%08lx\n", hr);
+ ERR("CoInitializeEx(NULL, COINIT_MULTITHREADED) failed: 0x%08lx\n", hr);
V0(device->Backend,lock)();
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "COM init failed: 0x%08lx", hr);
V0(device->Backend,unlock)();
return 1;
}
althrd_setname(althrd_current(), RECORD_THREAD_NAME);
- while(!self->killNow)
+ while(!ATOMIC_LOAD(&self->killNow, almemory_order_relaxed))
{
UINT32 avail;
DWORD res;
@@ -1253,39 +1341,81 @@ FORCE_ALIGN int ALCmmdevCapture_recordProc(void *arg)
hr = IAudioCaptureClient_GetNextPacketSize(self->capture, &avail);
if(FAILED(hr))
ERR("Failed to get next packet size: 0x%08lx\n", hr);
- else while(avail > 0 && SUCCEEDED(hr))
+ else if(avail > 0)
{
UINT32 numsamples;
DWORD flags;
- BYTE *data;
+ BYTE *rdata;
hr = IAudioCaptureClient_GetBuffer(self->capture,
- &data, &numsamples, &flags, NULL, NULL
+ &rdata, &numsamples, &flags, NULL, NULL
);
if(FAILED(hr))
- {
ERR("Failed to get capture buffer: 0x%08lx\n", hr);
- break;
- }
-
- ll_ringbuffer_write(self->Ring, (char*)data, numsamples);
-
- hr = IAudioCaptureClient_ReleaseBuffer(self->capture, numsamples);
- if(FAILED(hr))
+ else
{
- ERR("Failed to release capture buffer: 0x%08lx\n", hr);
- break;
+ ll_ringbuffer_data_t data[2];
+ size_t dstframes = 0;
+
+ if(self->ChannelConv)
+ {
+ if(samplesmax < numsamples)
+ {
+ size_t newmax = RoundUp(numsamples, 4096);
+ ALfloat *tmp = al_calloc(DEF_ALIGN, newmax*2*sizeof(ALfloat));
+ al_free(samples);
+ samples = tmp;
+ samplesmax = newmax;
+ }
+ ChannelConverterInput(self->ChannelConv, rdata, samples, numsamples);
+ rdata = (BYTE*)samples;
+ }
+
+ ll_ringbuffer_get_write_vector(self->Ring, data);
+
+ if(self->SampleConv)
+ {
+ const ALvoid *srcdata = rdata;
+ ALsizei srcframes = numsamples;
+
+ dstframes = SampleConverterInput(self->SampleConv,
+ &srcdata, &srcframes, data[0].buf, (ALsizei)minz(data[0].len, INT_MAX)
+ );
+ if(srcframes > 0 && dstframes == data[0].len && data[1].len > 0)
+ {
+ /* If some source samples remain, all of the first dest
+ * block was filled, and there's space in the second
+ * dest block, do another run for the second block.
+ */
+ dstframes += SampleConverterInput(self->SampleConv,
+ &srcdata, &srcframes, data[1].buf, (ALsizei)minz(data[1].len, INT_MAX)
+ );
+ }
+ }
+ else
+ {
+ ALuint framesize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType,
+ device->AmbiOrder);
+ size_t len1 = minz(data[0].len, numsamples);
+ size_t len2 = minz(data[1].len, numsamples-len1);
+
+ memcpy(data[0].buf, rdata, len1*framesize);
+ if(len2 > 0)
+ memcpy(data[1].buf, rdata+len1*framesize, len2*framesize);
+ dstframes = len1 + len2;
+ }
+
+ ll_ringbuffer_write_advance(self->Ring, dstframes);
+
+ hr = IAudioCaptureClient_ReleaseBuffer(self->capture, numsamples);
+ if(FAILED(hr)) ERR("Failed to release capture buffer: 0x%08lx\n", hr);
}
-
- hr = IAudioCaptureClient_GetNextPacketSize(self->capture, &avail);
- if(FAILED(hr))
- ERR("Failed to get next packet size: 0x%08lx\n", hr);
}
if(FAILED(hr))
{
V0(device->Backend,lock)();
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failed to capture samples: 0x%08lx", hr);
V0(device->Backend,unlock)();
break;
}
@@ -1295,17 +1425,21 @@ FORCE_ALIGN int ALCmmdevCapture_recordProc(void *arg)
ERR("WaitForSingleObjectEx error: 0x%lx\n", res);
}
+ al_free(samples);
+ samples = NULL;
+ samplesmax = 0;
+
CoUninitialize();
return 0;
}
-static ALCenum ALCmmdevCapture_open(ALCmmdevCapture *self, const ALCchar *deviceName)
+static ALCenum ALCwasapiCapture_open(ALCwasapiCapture *self, const ALCchar *deviceName)
{
HRESULT hr = S_OK;
- self->NotifyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- self->MsgEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ self->NotifyEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
+ self->MsgEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
if(self->NotifyEvent == NULL || self->MsgEvent == NULL)
{
ERR("Failed to create message events: %lu\n", GetLastError());
@@ -1326,18 +1460,32 @@ static ALCenum ALCmmdevCapture_open(ALCmmdevCapture *self, const ALCchar *device
}
hr = E_FAIL;
-#define MATCH_NAME(i) (al_string_cmp_cstr((i)->name, deviceName) == 0)
+#define MATCH_NAME(i) (alstr_cmp_cstr((i)->name, deviceName) == 0 || \
+ alstr_cmp_cstr((i)->endpoint_guid, deviceName) == 0)
VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_NAME);
- if(iter == VECTOR_ITER_END(CaptureDevices))
+#undef MATCH_NAME
+ if(iter == VECTOR_END(CaptureDevices))
+ {
+ int len;
+ if((len=MultiByteToWideChar(CP_UTF8, 0, deviceName, -1, NULL, 0)) > 0)
+ {
+ WCHAR *wname = calloc(sizeof(WCHAR), len);
+ MultiByteToWideChar(CP_UTF8, 0, deviceName, -1, wname, len);
+#define MATCH_NAME(i) (wcscmp((i)->devid, wname) == 0)
+ VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_NAME);
+#undef MATCH_NAME
+ free(wname);
+ }
+ }
+ if(iter == VECTOR_END(CaptureDevices))
WARN("Failed to find device name matching \"%s\"\n", deviceName);
else
{
ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice;
self->devid = strdupW(iter->devid);
- al_string_copy(&device->DeviceName, iter->name);
+ alstr_copy(&device->DeviceName, iter->name);
hr = S_OK;
}
-#undef MATCH_NAME
}
}
@@ -1346,7 +1494,7 @@ static ALCenum ALCmmdevCapture_open(ALCmmdevCapture *self, const ALCchar *device
ThreadRequest req = { self->MsgEvent, 0 };
hr = E_FAIL;
- if(PostThreadMessage(ThreadID, WM_USER_OpenDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCmmdevProxy, self)))
+ if(PostThreadMessage(ThreadID, WM_USER_OpenDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCwasapiProxy, self)))
hr = WaitForResponse(&req);
else
ERR("Failed to post thread message: %lu\n", GetLastError());
@@ -1372,14 +1520,13 @@ static ALCenum ALCmmdevCapture_open(ALCmmdevCapture *self, const ALCchar *device
ThreadRequest req = { self->MsgEvent, 0 };
hr = E_FAIL;
- if(PostThreadMessage(ThreadID, WM_USER_ResetDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCmmdevProxy, self)))
+ if(PostThreadMessage(ThreadID, WM_USER_ResetDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCwasapiProxy, self)))
hr = WaitForResponse(&req);
else
ERR("Failed to post thread message: %lu\n", GetLastError());
if(FAILED(hr))
{
- ALCmmdevCapture_close(self);
if(hr == E_OUTOFMEMORY)
return ALC_OUT_OF_MEMORY;
return ALC_INVALID_VALUE;
@@ -1389,7 +1536,7 @@ static ALCenum ALCmmdevCapture_open(ALCmmdevCapture *self, const ALCchar *device
return ALC_NO_ERROR;
}
-static HRESULT ALCmmdevCapture_openProxy(ALCmmdevCapture *self)
+static HRESULT ALCwasapiCapture_openProxy(ALCwasapiCapture *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
void *ptr;
@@ -1411,11 +1558,8 @@ static HRESULT ALCmmdevCapture_openProxy(ALCmmdevCapture *self)
if(SUCCEEDED(hr))
{
self->client = ptr;
- if(al_string_empty(device->DeviceName))
- {
- get_device_name(self->mmdev, &device->DeviceName);
- al_string_append_cstr(&device->DeviceName, DEVNAME_TAIL);
- }
+ if(alstr_empty(device->DeviceName))
+ get_device_name_and_guid(self->mmdev, &device->DeviceName, NULL);
}
if(FAILED(hr))
@@ -1429,27 +1573,7 @@ static HRESULT ALCmmdevCapture_openProxy(ALCmmdevCapture *self)
}
-static void ALCmmdevCapture_close(ALCmmdevCapture *self)
-{
- ThreadRequest req = { self->MsgEvent, 0 };
-
- if(PostThreadMessage(ThreadID, WM_USER_CloseDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCmmdevProxy, self)))
- (void)WaitForResponse(&req);
-
- ll_ringbuffer_free(self->Ring);
- self->Ring = NULL;
-
- CloseHandle(self->MsgEvent);
- self->MsgEvent = NULL;
-
- CloseHandle(self->NotifyEvent);
- self->NotifyEvent = NULL;
-
- free(self->devid);
- self->devid = NULL;
-}
-
-static void ALCmmdevCapture_closeProxy(ALCmmdevCapture *self)
+static void ALCwasapiCapture_closeProxy(ALCwasapiCapture *self)
{
if(self->client)
IAudioClient_Release(self->client);
@@ -1461,11 +1585,12 @@ static void ALCmmdevCapture_closeProxy(ALCmmdevCapture *self)
}
-static HRESULT ALCmmdevCapture_resetProxy(ALCmmdevCapture *self)
+static HRESULT ALCwasapiCapture_resetProxy(ALCwasapiCapture *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
WAVEFORMATEXTENSIBLE OutputType;
WAVEFORMATEX *wfx = NULL;
+ enum DevFmtType srcType;
REFERENCE_TIME buf_time;
UINT32 buffer_len;
void *ptr = NULL;
@@ -1483,8 +1608,12 @@ static HRESULT ALCmmdevCapture_resetProxy(ALCmmdevCapture *self)
}
self->client = ptr;
- buf_time = ((REFERENCE_TIME)device->UpdateSize*device->NumUpdates*10000000 +
- device->Frequency-1) / device->Frequency;
+ buf_time = ScaleCeil(device->UpdateSize*device->NumUpdates, REFTIME_PER_SEC,
+ device->Frequency);
+ // Make sure buffer is at least 100ms in size
+ buf_time = maxu64(buf_time, REFTIME_PER_SEC/10);
+ device->UpdateSize = (ALuint)ScaleCeil(buf_time, device->Frequency, REFTIME_PER_SEC) /
+ device->NumUpdates;
OutputType.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
switch(device->FmtChans)
@@ -1518,38 +1647,33 @@ static HRESULT ALCmmdevCapture_resetProxy(ALCmmdevCapture *self)
OutputType.dwChannelMask = X7DOT1;
break;
- case DevFmtBFormat3D:
+ case DevFmtAmbi3D:
return E_FAIL;
}
switch(device->FmtType)
{
+ /* NOTE: Signedness doesn't matter, the converter will handle it. */
+ case DevFmtByte:
case DevFmtUByte:
OutputType.Format.wBitsPerSample = 8;
- OutputType.Samples.wValidBitsPerSample = 8;
OutputType.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
break;
case DevFmtShort:
+ case DevFmtUShort:
OutputType.Format.wBitsPerSample = 16;
- OutputType.Samples.wValidBitsPerSample = 16;
OutputType.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
break;
case DevFmtInt:
+ case DevFmtUInt:
OutputType.Format.wBitsPerSample = 32;
- OutputType.Samples.wValidBitsPerSample = 32;
OutputType.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
break;
case DevFmtFloat:
OutputType.Format.wBitsPerSample = 32;
- OutputType.Samples.wValidBitsPerSample = 32;
OutputType.SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
break;
-
- case DevFmtByte:
- case DevFmtUShort:
- case DevFmtUInt:
- WARN("%s capture samples not supported\n", DevFmtTypeString(device->FmtType));
- return E_FAIL;
}
+ OutputType.Samples.wValidBitsPerSample = OutputType.Format.wBitsPerSample;
OutputType.Format.nSamplesPerSec = device->Frequency;
OutputType.Format.nBlockAlign = OutputType.Format.nChannels *
@@ -1567,26 +1691,107 @@ static HRESULT ALCmmdevCapture_resetProxy(ALCmmdevCapture *self)
return hr;
}
- /* FIXME: We should do conversion/resampling if we didn't get a matching format. */
- if(wfx->nSamplesPerSec != OutputType.Format.nSamplesPerSec ||
- wfx->wBitsPerSample != OutputType.Format.wBitsPerSample ||
- wfx->nChannels != OutputType.Format.nChannels ||
- wfx->nBlockAlign != OutputType.Format.nBlockAlign)
+ DestroySampleConverter(&self->SampleConv);
+ DestroyChannelConverter(&self->ChannelConv);
+
+ if(wfx != NULL)
{
- ERR("Did not get matching format, wanted: %s %s %uhz, got: %d channel(s) %d-bit %luhz\n",
- DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType), device->Frequency,
- wfx->nChannels, wfx->wBitsPerSample, wfx->nSamplesPerSec);
+ if(!(wfx->nChannels == OutputType.Format.nChannels ||
+ (wfx->nChannels == 1 && OutputType.Format.nChannels == 2) ||
+ (wfx->nChannels == 2 && OutputType.Format.nChannels == 1)))
+ {
+ ERR("Failed to get matching format, wanted: %s %s %uhz, got: %d channel%s %d-bit %luhz\n",
+ DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType),
+ device->Frequency, wfx->nChannels, (wfx->nChannels==1)?"":"s", wfx->wBitsPerSample,
+ wfx->nSamplesPerSec);
+ CoTaskMemFree(wfx);
+ return E_FAIL;
+ }
+
+ if(!MakeExtensible(&OutputType, wfx))
+ {
+ CoTaskMemFree(wfx);
+ return E_FAIL;
+ }
CoTaskMemFree(wfx);
- return E_FAIL;
+ wfx = NULL;
}
- if(!MakeExtensible(&OutputType, wfx))
+ if(IsEqualGUID(&OutputType.SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))
{
- CoTaskMemFree(wfx);
+ if(OutputType.Format.wBitsPerSample == 8)
+ srcType = DevFmtUByte;
+ else if(OutputType.Format.wBitsPerSample == 16)
+ srcType = DevFmtShort;
+ else if(OutputType.Format.wBitsPerSample == 32)
+ srcType = DevFmtInt;
+ else
+ {
+ ERR("Unhandled integer bit depth: %d\n", OutputType.Format.wBitsPerSample);
+ return E_FAIL;
+ }
+ }
+ else if(IsEqualGUID(&OutputType.SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT))
+ {
+ if(OutputType.Format.wBitsPerSample == 32)
+ srcType = DevFmtFloat;
+ else
+ {
+ ERR("Unhandled float bit depth: %d\n", OutputType.Format.wBitsPerSample);
+ return E_FAIL;
+ }
+ }
+ else
+ {
+ ERR("Unhandled format sub-type\n");
return E_FAIL;
}
- CoTaskMemFree(wfx);
- wfx = NULL;
+
+ if(device->FmtChans == DevFmtMono && OutputType.Format.nChannels == 2)
+ {
+ self->ChannelConv = CreateChannelConverter(srcType, DevFmtStereo,
+ device->FmtChans);
+ if(!self->ChannelConv)
+ {
+ ERR("Failed to create %s stereo-to-mono converter\n", DevFmtTypeString(srcType));
+ return E_FAIL;
+ }
+ TRACE("Created %s stereo-to-mono converter\n", DevFmtTypeString(srcType));
+ /* The channel converter always outputs float, so change the input type
+ * for the resampler/type-converter.
+ */
+ srcType = DevFmtFloat;
+ }
+ else if(device->FmtChans == DevFmtStereo && OutputType.Format.nChannels == 1)
+ {
+ self->ChannelConv = CreateChannelConverter(srcType, DevFmtMono,
+ device->FmtChans);
+ if(!self->ChannelConv)
+ {
+ ERR("Failed to create %s mono-to-stereo converter\n", DevFmtTypeString(srcType));
+ return E_FAIL;
+ }
+ TRACE("Created %s mono-to-stereo converter\n", DevFmtTypeString(srcType));
+ srcType = DevFmtFloat;
+ }
+
+ if(device->Frequency != OutputType.Format.nSamplesPerSec || device->FmtType != srcType)
+ {
+ self->SampleConv = CreateSampleConverter(
+ srcType, device->FmtType, ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder),
+ OutputType.Format.nSamplesPerSec, device->Frequency
+ );
+ if(!self->SampleConv)
+ {
+ ERR("Failed to create converter for %s format, dst: %s %uhz, src: %s %luhz\n",
+ DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType),
+ device->Frequency, DevFmtTypeString(srcType), OutputType.Format.nSamplesPerSec);
+ return E_FAIL;
+ }
+ TRACE("Created converter for %s format, dst: %s %uhz, src: %s %luhz\n",
+ DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType),
+ device->Frequency, DevFmtTypeString(srcType), OutputType.Format.nSamplesPerSec);
+ }
hr = IAudioClient_Initialize(self->client,
AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
@@ -1605,9 +1810,12 @@ static HRESULT ALCmmdevCapture_resetProxy(ALCmmdevCapture *self)
return hr;
}
- buffer_len = maxu(device->UpdateSize*device->NumUpdates + 1, buffer_len);
+ buffer_len = maxu(device->UpdateSize*device->NumUpdates, buffer_len);
ll_ringbuffer_free(self->Ring);
- self->Ring = ll_ringbuffer_create(buffer_len, OutputType.Format.nBlockAlign);
+ self->Ring = ll_ringbuffer_create(buffer_len,
+ FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder),
+ false
+ );
if(!self->Ring)
{
ERR("Failed to allocate capture ring buffer\n");
@@ -1625,18 +1833,18 @@ static HRESULT ALCmmdevCapture_resetProxy(ALCmmdevCapture *self)
}
-static ALCboolean ALCmmdevCapture_start(ALCmmdevCapture *self)
+static ALCboolean ALCwasapiCapture_start(ALCwasapiCapture *self)
{
ThreadRequest req = { self->MsgEvent, 0 };
HRESULT hr = E_FAIL;
- if(PostThreadMessage(ThreadID, WM_USER_StartDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCmmdevProxy, self)))
+ if(PostThreadMessage(ThreadID, WM_USER_StartDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCwasapiProxy, self)))
hr = WaitForResponse(&req);
return SUCCEEDED(hr) ? ALC_TRUE : ALC_FALSE;
}
-static HRESULT ALCmmdevCapture_startProxy(ALCmmdevCapture *self)
+static HRESULT ALCwasapiCapture_startProxy(ALCwasapiCapture *self)
{
HRESULT hr;
void *ptr;
@@ -1653,8 +1861,8 @@ static HRESULT ALCmmdevCapture_startProxy(ALCmmdevCapture *self)
if(SUCCEEDED(hr))
{
self->capture = ptr;
- self->killNow = 0;
- if(althrd_create(&self->thread, ALCmmdevCapture_recordProc, self) != althrd_success)
+ ATOMIC_STORE(&self->killNow, 0, almemory_order_release);
+ if(althrd_create(&self->thread, ALCwasapiCapture_recordProc, self) != althrd_success)
{
ERR("Failed to start thread\n");
IAudioCaptureClient_Release(self->capture);
@@ -1673,21 +1881,21 @@ static HRESULT ALCmmdevCapture_startProxy(ALCmmdevCapture *self)
}
-static void ALCmmdevCapture_stop(ALCmmdevCapture *self)
+static void ALCwasapiCapture_stop(ALCwasapiCapture *self)
{
ThreadRequest req = { self->MsgEvent, 0 };
- if(PostThreadMessage(ThreadID, WM_USER_StopDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCmmdevProxy, self)))
+ if(PostThreadMessage(ThreadID, WM_USER_StopDevice, (WPARAM)&req, (LPARAM)STATIC_CAST(ALCwasapiProxy, self)))
(void)WaitForResponse(&req);
}
-static void ALCmmdevCapture_stopProxy(ALCmmdevCapture *self)
+static void ALCwasapiCapture_stopProxy(ALCwasapiCapture *self)
{
int res;
if(!self->capture)
return;
- self->killNow = 1;
+ ATOMIC_STORE_SEQ(&self->killNow, 1);
althrd_join(self->thread, &res);
IAudioCaptureClient_Release(self->capture);
@@ -1697,72 +1905,62 @@ static void ALCmmdevCapture_stopProxy(ALCmmdevCapture *self)
}
-ALuint ALCmmdevCapture_availableSamples(ALCmmdevCapture *self)
+ALuint ALCwasapiCapture_availableSamples(ALCwasapiCapture *self)
{
return (ALuint)ll_ringbuffer_read_space(self->Ring);
}
-ALCenum ALCmmdevCapture_captureSamples(ALCmmdevCapture *self, ALCvoid *buffer, ALCuint samples)
+ALCenum ALCwasapiCapture_captureSamples(ALCwasapiCapture *self, ALCvoid *buffer, ALCuint samples)
{
- if(ALCmmdevCapture_availableSamples(self) < samples)
+ if(ALCwasapiCapture_availableSamples(self) < samples)
return ALC_INVALID_VALUE;
ll_ringbuffer_read(self->Ring, buffer, samples);
return ALC_NO_ERROR;
}
-static inline void AppendAllDevicesList2(const DevMap *entry)
-{ AppendAllDevicesList(al_string_get_cstr(entry->name)); }
-static inline void AppendCaptureDeviceList2(const DevMap *entry)
-{ AppendCaptureDeviceList(al_string_get_cstr(entry->name)); }
-
-typedef struct ALCmmdevBackendFactory {
+typedef struct ALCwasapiBackendFactory {
DERIVE_FROM_TYPE(ALCbackendFactory);
-} ALCmmdevBackendFactory;
-#define ALCMMDEVBACKENDFACTORY_INITIALIZER { { GET_VTABLE2(ALCmmdevBackendFactory, ALCbackendFactory) } }
+} ALCwasapiBackendFactory;
+#define ALCWASAPIBACKENDFACTORY_INITIALIZER { { GET_VTABLE2(ALCwasapiBackendFactory, ALCbackendFactory) } }
-static ALCboolean ALCmmdevBackendFactory_init(ALCmmdevBackendFactory *self);
-static void ALCmmdevBackendFactory_deinit(ALCmmdevBackendFactory *self);
-static ALCboolean ALCmmdevBackendFactory_querySupport(ALCmmdevBackendFactory *self, ALCbackend_Type type);
-static void ALCmmdevBackendFactory_probe(ALCmmdevBackendFactory *self, enum DevProbe type);
-static ALCbackend* ALCmmdevBackendFactory_createBackend(ALCmmdevBackendFactory *self, ALCdevice *device, ALCbackend_Type type);
+static ALCboolean ALCwasapiBackendFactory_init(ALCwasapiBackendFactory *self);
+static void ALCwasapiBackendFactory_deinit(ALCwasapiBackendFactory *self);
+static ALCboolean ALCwasapiBackendFactory_querySupport(ALCwasapiBackendFactory *self, ALCbackend_Type type);
+static void ALCwasapiBackendFactory_probe(ALCwasapiBackendFactory *self, enum DevProbe type, al_string *outnames);
+static ALCbackend* ALCwasapiBackendFactory_createBackend(ALCwasapiBackendFactory *self, ALCdevice *device, ALCbackend_Type type);
-DEFINE_ALCBACKENDFACTORY_VTABLE(ALCmmdevBackendFactory);
+DEFINE_ALCBACKENDFACTORY_VTABLE(ALCwasapiBackendFactory);
-static BOOL MMDevApiLoad(void)
+static ALCboolean ALCwasapiBackendFactory_init(ALCwasapiBackendFactory* UNUSED(self))
{
static HRESULT InitResult;
+
+ VECTOR_INIT(PlaybackDevices);
+ VECTOR_INIT(CaptureDevices);
+
if(!ThreadHdl)
{
ThreadRequest req;
InitResult = E_FAIL;
- req.FinishedEvt = CreateEvent(NULL, FALSE, FALSE, NULL);
+ req.FinishedEvt = CreateEventW(NULL, FALSE, FALSE, NULL);
if(req.FinishedEvt == NULL)
ERR("Failed to create event: %lu\n", GetLastError());
else
{
- ThreadHdl = CreateThread(NULL, 0, ALCmmdevProxy_messageHandler, &req, 0, &ThreadID);
+ ThreadHdl = CreateThread(NULL, 0, ALCwasapiProxy_messageHandler, &req, 0, &ThreadID);
if(ThreadHdl != NULL)
InitResult = WaitForResponse(&req);
CloseHandle(req.FinishedEvt);
}
}
- return SUCCEEDED(InitResult);
-}
-static ALCboolean ALCmmdevBackendFactory_init(ALCmmdevBackendFactory* UNUSED(self))
-{
- VECTOR_INIT(PlaybackDevices);
- VECTOR_INIT(CaptureDevices);
-
- if(!MMDevApiLoad())
- return ALC_FALSE;
- return ALC_TRUE;
+ return SUCCEEDED(InitResult) ? ALC_TRUE : ALC_FALSE;
}
-static void ALCmmdevBackendFactory_deinit(ALCmmdevBackendFactory* UNUSED(self))
+static void ALCwasapiBackendFactory_deinit(ALCwasapiBackendFactory* UNUSED(self))
{
clear_devlist(&PlaybackDevices);
VECTOR_DEINIT(PlaybackDevices);
@@ -1779,23 +1977,18 @@ static void ALCmmdevBackendFactory_deinit(ALCmmdevBackendFactory* UNUSED(self))
}
}
-static ALCboolean ALCmmdevBackendFactory_querySupport(ALCmmdevBackendFactory* UNUSED(self), ALCbackend_Type type)
+static ALCboolean ALCwasapiBackendFactory_querySupport(ALCwasapiBackendFactory* UNUSED(self), ALCbackend_Type type)
{
- /* TODO: Disable capture with mmdevapi for now, since it doesn't do any
- * rechanneling or resampling; if the device is configured for 48000hz
- * stereo input, for example, and the app asks for 22050hz mono,
- * initialization will fail.
- */
- if(type == ALCbackend_Playback /*|| type == ALCbackend_Capture*/)
+ if(type == ALCbackend_Playback || type == ALCbackend_Capture)
return ALC_TRUE;
return ALC_FALSE;
}
-static void ALCmmdevBackendFactory_probe(ALCmmdevBackendFactory* UNUSED(self), enum DevProbe type)
+static void ALCwasapiBackendFactory_probe(ALCwasapiBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
ThreadRequest req = { NULL, 0 };
- req.FinishedEvt = CreateEvent(NULL, FALSE, FALSE, NULL);
+ req.FinishedEvt = CreateEventW(NULL, FALSE, FALSE, NULL);
if(req.FinishedEvt == NULL)
ERR("Failed to create event: %lu\n", GetLastError());
else
@@ -1805,32 +1998,38 @@ static void ALCmmdevBackendFactory_probe(ALCmmdevBackendFactory* UNUSED(self), e
hr = WaitForResponse(&req);
if(SUCCEEDED(hr)) switch(type)
{
+#define APPEND_OUTNAME(e) do { \
+ if(!alstr_empty((e)->name)) \
+ alstr_append_range(outnames, VECTOR_BEGIN((e)->name), \
+ VECTOR_END((e)->name)+1); \
+} while(0)
case ALL_DEVICE_PROBE:
- VECTOR_FOR_EACH(const DevMap, PlaybackDevices, AppendAllDevicesList2);
+ VECTOR_FOR_EACH(const DevMap, PlaybackDevices, APPEND_OUTNAME);
break;
case CAPTURE_DEVICE_PROBE:
- VECTOR_FOR_EACH(const DevMap, CaptureDevices, AppendCaptureDeviceList2);
+ VECTOR_FOR_EACH(const DevMap, CaptureDevices, APPEND_OUTNAME);
break;
+#undef APPEND_OUTNAME
}
CloseHandle(req.FinishedEvt);
req.FinishedEvt = NULL;
}
}
-static ALCbackend* ALCmmdevBackendFactory_createBackend(ALCmmdevBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type)
+static ALCbackend* ALCwasapiBackendFactory_createBackend(ALCwasapiBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type)
{
if(type == ALCbackend_Playback)
{
- ALCmmdevPlayback *backend;
- NEW_OBJ(backend, ALCmmdevPlayback)(device);
+ ALCwasapiPlayback *backend;
+ NEW_OBJ(backend, ALCwasapiPlayback)(device);
if(!backend) return NULL;
return STATIC_CAST(ALCbackend, backend);
}
if(type == ALCbackend_Capture)
{
- ALCmmdevCapture *backend;
- NEW_OBJ(backend, ALCmmdevCapture)(device);
+ ALCwasapiCapture *backend;
+ NEW_OBJ(backend, ALCwasapiCapture)(device);
if(!backend) return NULL;
return STATIC_CAST(ALCbackend, backend);
}
@@ -1839,8 +2038,8 @@ static ALCbackend* ALCmmdevBackendFactory_createBackend(ALCmmdevBackendFactory*
}
-ALCbackendFactory *ALCmmdevBackendFactory_getFactory(void)
+ALCbackendFactory *ALCwasapiBackendFactory_getFactory(void)
{
- static ALCmmdevBackendFactory factory = ALCMMDEVBACKENDFACTORY_INITIALIZER;
+ static ALCwasapiBackendFactory factory = ALCWASAPIBACKENDFACTORY_INITIALIZER;
return STATIC_CAST(ALCbackendFactory, &factory);
}
diff --git a/Alc/backends/wave.c b/Alc/backends/wave.c
index 6b47c611..390b2a5f 100644
--- a/Alc/backends/wave.c
+++ b/Alc/backends/wave.c
@@ -27,6 +27,7 @@
#include "alMain.h"
#include "alu.h"
+#include "alconfig.h"
#include "threads.h"
#include "compat.h"
@@ -56,16 +57,14 @@ static const ALubyte SUBTYPE_BFORMAT_FLOAT[] = {
static void fwrite16le(ALushort val, FILE *f)
{
- fputc(val&0xff, f);
- fputc((val>>8)&0xff, f);
+ ALubyte data[2] = { val&0xff, (val>>8)&0xff };
+ fwrite(data, 1, 2, f);
}
static void fwrite32le(ALuint val, FILE *f)
{
- fputc(val&0xff, f);
- fputc((val>>8)&0xff, f);
- fputc((val>>16)&0xff, f);
- fputc((val>>24)&0xff, f);
+ ALubyte data[4] = { val&0xff, (val>>8)&0xff, (val>>16)&0xff, (val>>24)&0xff };
+ fwrite(data, 1, 4, f);
}
@@ -78,22 +77,21 @@ typedef struct ALCwaveBackend {
ALvoid *mBuffer;
ALuint mSize;
- volatile int killNow;
+ ATOMIC(ALenum) killNow;
althrd_t thread;
} ALCwaveBackend;
static int ALCwaveBackend_mixerProc(void *ptr);
static void ALCwaveBackend_Construct(ALCwaveBackend *self, ALCdevice *device);
-static DECLARE_FORWARD(ALCwaveBackend, ALCbackend, void, Destruct)
+static void ALCwaveBackend_Destruct(ALCwaveBackend *self);
static ALCenum ALCwaveBackend_open(ALCwaveBackend *self, const ALCchar *name);
-static void ALCwaveBackend_close(ALCwaveBackend *self);
static ALCboolean ALCwaveBackend_reset(ALCwaveBackend *self);
static ALCboolean ALCwaveBackend_start(ALCwaveBackend *self);
static void ALCwaveBackend_stop(ALCwaveBackend *self);
static DECLARE_FORWARD2(ALCwaveBackend, ALCbackend, ALCenum, captureSamples, void*, ALCuint)
static DECLARE_FORWARD(ALCwaveBackend, ALCbackend, ALCuint, availableSamples)
-static DECLARE_FORWARD(ALCwaveBackend, ALCbackend, ALint64, getLatency)
+static DECLARE_FORWARD(ALCwaveBackend, ALCbackend, ClockLatency, getClockLatency)
static DECLARE_FORWARD(ALCwaveBackend, ALCbackend, void, lock)
static DECLARE_FORWARD(ALCwaveBackend, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCwaveBackend)
@@ -112,9 +110,17 @@ static void ALCwaveBackend_Construct(ALCwaveBackend *self, ALCdevice *device)
self->mBuffer = NULL;
self->mSize = 0;
- self->killNow = 1;
+ ATOMIC_INIT(&self->killNow, AL_TRUE);
}
+static void ALCwaveBackend_Destruct(ALCwaveBackend *self)
+{
+ if(self->mFile)
+ fclose(self->mFile);
+ self->mFile = NULL;
+
+ ALCbackend_Destruct(STATIC_CAST(ALCbackend, self));
+}
static int ALCwaveBackend_mixerProc(void *ptr)
{
@@ -129,7 +135,7 @@ static int ALCwaveBackend_mixerProc(void *ptr)
althrd_setname(althrd_current(), MIXER_THREAD_NAME);
- frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ frameSize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
done = 0;
if(altimespec_get(&start, AL_TIME_UTC) != AL_TIME_UTC)
@@ -137,7 +143,8 @@ static int ALCwaveBackend_mixerProc(void *ptr)
ERR("Failed to get starting time\n");
return 1;
}
- while(!self->killNow && device->Connected)
+ while(!ATOMIC_LOAD(&self->killNow, almemory_order_acquire) &&
+ ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
{
if(altimespec_get(&now, AL_TIME_UTC) != AL_TIME_UTC)
{
@@ -159,42 +166,46 @@ static int ALCwaveBackend_mixerProc(void *ptr)
al_nssleep(restTime);
else while(avail-done >= device->UpdateSize)
{
+ ALCwaveBackend_lock(self);
aluMixData(device, self->mBuffer, device->UpdateSize);
+ ALCwaveBackend_unlock(self);
done += device->UpdateSize;
if(!IS_LITTLE_ENDIAN)
{
ALuint bytesize = BytesFromDevFmt(device->FmtType);
- ALubyte *bytes = self->mBuffer;
ALuint i;
- if(bytesize == 1)
- {
- for(i = 0;i < self->mSize;i++)
- fputc(bytes[i], self->mFile);
- }
- else if(bytesize == 2)
+ if(bytesize == 2)
{
- for(i = 0;i < self->mSize;i++)
- fputc(bytes[i^1], self->mFile);
+ ALushort *samples = self->mBuffer;
+ ALuint len = self->mSize / 2;
+ for(i = 0;i < len;i++)
+ {
+ ALushort samp = samples[i];
+ samples[i] = (samp>>8) | (samp<<8);
+ }
}
else if(bytesize == 4)
{
- for(i = 0;i < self->mSize;i++)
- fputc(bytes[i^3], self->mFile);
+ ALuint *samples = self->mBuffer;
+ ALuint len = self->mSize / 4;
+ for(i = 0;i < len;i++)
+ {
+ ALuint samp = samples[i];
+ samples[i] = (samp>>24) | ((samp>>8)&0x0000ff00) |
+ ((samp<<8)&0x00ff0000) | (samp<<24);
+ }
}
}
- else
- {
- fs = fwrite(self->mBuffer, frameSize, device->UpdateSize,
- self->mFile);
- (void)fs;
- }
+
+ fs = fwrite(self->mBuffer, frameSize, device->UpdateSize, self->mFile);
+ (void)fs;
if(ferror(self->mFile))
{
ERR("Error writing to file\n");
ALCdevice_Lock(device);
- aluHandleDisconnect(device);
+ aluHandleDisconnect(device, "Failed to write playback samples");
ALCdevice_Unlock(device);
break;
}
@@ -226,18 +237,11 @@ static ALCenum ALCwaveBackend_open(ALCwaveBackend *self, const ALCchar *name)
}
device = STATIC_CAST(ALCbackend, self)->mDevice;
- al_string_copy_cstr(&device->DeviceName, name);
+ alstr_copy_cstr(&device->DeviceName, name);
return ALC_NO_ERROR;
}
-static void ALCwaveBackend_close(ALCwaveBackend *self)
-{
- if(self->mFile)
- fclose(self->mFile);
- self->mFile = NULL;
-}
-
static ALCboolean ALCwaveBackend_reset(ALCwaveBackend *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
@@ -249,7 +253,10 @@ static ALCboolean ALCwaveBackend_reset(ALCwaveBackend *self)
clearerr(self->mFile);
if(GetConfigValueBool(NULL, "wave", "bformat", 0))
- device->FmtChans = DevFmtBFormat3D;
+ {
+ device->FmtChans = DevFmtAmbi3D;
+ device->AmbiOrder = 1;
+ }
switch(device->FmtType)
{
@@ -277,20 +284,23 @@ static ALCboolean ALCwaveBackend_reset(ALCwaveBackend *self)
case DevFmtX51Rear: chanmask = 0x01 | 0x02 | 0x04 | 0x08 | 0x010 | 0x020; break;
case DevFmtX61: chanmask = 0x01 | 0x02 | 0x04 | 0x08 | 0x100 | 0x200 | 0x400; break;
case DevFmtX71: chanmask = 0x01 | 0x02 | 0x04 | 0x08 | 0x010 | 0x020 | 0x200 | 0x400; break;
- case DevFmtBFormat3D:
+ case DevFmtAmbi3D:
+ /* .amb output requires FuMa */
+ device->AmbiLayout = AmbiLayout_FuMa;
+ device->AmbiScale = AmbiNorm_FuMa;
isbformat = 1;
chanmask = 0;
break;
}
bits = BytesFromDevFmt(device->FmtType) * 8;
- channels = ChannelsFromDevFmt(device->FmtChans);
+ channels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
- fprintf(self->mFile, "RIFF");
+ fputs("RIFF", self->mFile);
fwrite32le(0xFFFFFFFF, self->mFile); // 'RIFF' header len; filled in at close
- fprintf(self->mFile, "WAVE");
+ fputs("WAVE", self->mFile);
- fprintf(self->mFile, "fmt ");
+ fputs("fmt ", self->mFile);
fwrite32le(40, self->mFile); // 'fmt ' header len; 40 bytes for EXTENSIBLE
// 16-bit val, format type id (extensible: 0xFFFE)
@@ -312,11 +322,12 @@ static ALCboolean ALCwaveBackend_reset(ALCwaveBackend *self)
// 32-bit val, channel mask
fwrite32le(chanmask, self->mFile);
// 16 byte GUID, sub-type format
- val = fwrite(((bits==32) ? (isbformat ? SUBTYPE_BFORMAT_FLOAT : SUBTYPE_FLOAT) :
- (isbformat ? SUBTYPE_BFORMAT_PCM : SUBTYPE_PCM)), 1, 16, self->mFile);
+ val = fwrite((device->FmtType == DevFmtFloat) ?
+ (isbformat ? SUBTYPE_BFORMAT_FLOAT : SUBTYPE_FLOAT) :
+ (isbformat ? SUBTYPE_BFORMAT_PCM : SUBTYPE_PCM), 1, 16, self->mFile);
(void)val;
- fprintf(self->mFile, "data");
+ fputs("data", self->mFile);
fwrite32le(0xFFFFFFFF, self->mFile); // 'data' header len; filled in at close
if(ferror(self->mFile))
@@ -335,7 +346,9 @@ static ALCboolean ALCwaveBackend_start(ALCwaveBackend *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- self->mSize = device->UpdateSize * FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ self->mSize = device->UpdateSize * FrameSizeFromDevFmt(
+ device->FmtChans, device->FmtType, device->AmbiOrder
+ );
self->mBuffer = malloc(self->mSize);
if(!self->mBuffer)
{
@@ -343,7 +356,7 @@ static ALCboolean ALCwaveBackend_start(ALCwaveBackend *self)
return ALC_FALSE;
}
- self->killNow = 0;
+ ATOMIC_STORE(&self->killNow, AL_FALSE, almemory_order_release);
if(althrd_create(&self->thread, ALCwaveBackend_mixerProc, self) != althrd_success)
{
free(self->mBuffer);
@@ -361,10 +374,8 @@ static void ALCwaveBackend_stop(ALCwaveBackend *self)
long size;
int res;
- if(self->killNow)
+ if(ATOMIC_EXCHANGE(&self->killNow, AL_TRUE, almemory_order_acq_rel))
return;
-
- self->killNow = 1;
althrd_join(self->thread, &res);
free(self->mBuffer);
@@ -392,7 +403,7 @@ ALCbackendFactory *ALCwaveBackendFactory_getFactory(void);
static ALCboolean ALCwaveBackendFactory_init(ALCwaveBackendFactory *self);
static DECLARE_FORWARD(ALCwaveBackendFactory, ALCbackendFactory, void, deinit)
static ALCboolean ALCwaveBackendFactory_querySupport(ALCwaveBackendFactory *self, ALCbackend_Type type);
-static void ALCwaveBackendFactory_probe(ALCwaveBackendFactory *self, enum DevProbe type);
+static void ALCwaveBackendFactory_probe(ALCwaveBackendFactory *self, enum DevProbe type, al_string *outnames);
static ALCbackend* ALCwaveBackendFactory_createBackend(ALCwaveBackendFactory *self, ALCdevice *device, ALCbackend_Type type);
DEFINE_ALCBACKENDFACTORY_VTABLE(ALCwaveBackendFactory);
@@ -416,12 +427,12 @@ static ALCboolean ALCwaveBackendFactory_querySupport(ALCwaveBackendFactory* UNUS
return ALC_FALSE;
}
-static void ALCwaveBackendFactory_probe(ALCwaveBackendFactory* UNUSED(self), enum DevProbe type)
+static void ALCwaveBackendFactory_probe(ALCwaveBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
switch(type)
{
case ALL_DEVICE_PROBE:
- AppendAllDevicesList(waveDevice);
+ alstr_append_range(outnames, waveDevice, waveDevice+sizeof(waveDevice));
break;
case CAPTURE_DEVICE_PROBE:
break;
diff --git a/Alc/backends/winmm.c b/Alc/backends/winmm.c
index bf97ef2e..0d4a02b8 100644
--- a/Alc/backends/winmm.c
+++ b/Alc/backends/winmm.c
@@ -29,6 +29,7 @@
#include "alMain.h"
#include "alu.h"
+#include "ringbuffer.h"
#include "threads.h"
#include "backends/base.h"
@@ -37,7 +38,7 @@
#define WAVE_FORMAT_IEEE_FLOAT 0x0003
#endif
-#define DEVNAME_TAIL " on OpenAL Soft"
+#define DEVNAME_HEAD "OpenAL Soft on "
static vector_al_string PlaybackDevices;
@@ -45,8 +46,8 @@ static vector_al_string CaptureDevices;
static void clear_devlist(vector_al_string *list)
{
- VECTOR_FOR_EACH(al_string, *list, al_string_deinit);
- VECTOR_RESIZE(*list, 0);
+ VECTOR_FOR_EACH(al_string, *list, alstr_reset);
+ VECTOR_RESIZE(*list, 0, 0);
}
@@ -58,7 +59,7 @@ static void ProbePlaybackDevices(void)
clear_devlist(&PlaybackDevices);
numdevs = waveOutGetNumDevs();
- VECTOR_RESERVE(PlaybackDevices, numdevs);
+ VECTOR_RESIZE(PlaybackDevices, 0, numdevs);
for(i = 0;i < numdevs;i++)
{
WAVEOUTCAPSW WaveCaps;
@@ -71,24 +72,23 @@ static void ProbePlaybackDevices(void)
ALuint count = 0;
while(1)
{
- al_string_copy_wcstr(&dname, WaveCaps.szPname);
- if(count == 0)
- al_string_append_cstr(&dname, DEVNAME_TAIL);
- else
+ alstr_copy_cstr(&dname, DEVNAME_HEAD);
+ alstr_append_wcstr(&dname, WaveCaps.szPname);
+ if(count != 0)
{
char str[64];
- snprintf(str, sizeof(str), " #%d"DEVNAME_TAIL, count+1);
- al_string_append_cstr(&dname, str);
+ snprintf(str, sizeof(str), " #%d", count+1);
+ alstr_append_cstr(&dname, str);
}
count++;
-#define MATCH_ENTRY(i) (al_string_cmp(dname, *(i)) == 0)
+#define MATCH_ENTRY(i) (alstr_cmp(dname, *(i)) == 0)
VECTOR_FIND_IF(iter, const al_string, PlaybackDevices, MATCH_ENTRY);
- if(iter == VECTOR_ITER_END(PlaybackDevices)) break;
+ if(iter == VECTOR_END(PlaybackDevices)) break;
#undef MATCH_ENTRY
}
- TRACE("Got device \"%s\", ID %u\n", al_string_get_cstr(dname), i);
+ TRACE("Got device \"%s\", ID %u\n", alstr_get_cstr(dname), i);
}
VECTOR_PUSH_BACK(PlaybackDevices, dname);
}
@@ -102,7 +102,7 @@ static void ProbeCaptureDevices(void)
clear_devlist(&CaptureDevices);
numdevs = waveInGetNumDevs();
- VECTOR_RESERVE(CaptureDevices, numdevs);
+ VECTOR_RESIZE(CaptureDevices, 0, numdevs);
for(i = 0;i < numdevs;i++)
{
WAVEINCAPSW WaveCaps;
@@ -115,24 +115,23 @@ static void ProbeCaptureDevices(void)
ALuint count = 0;
while(1)
{
- al_string_copy_wcstr(&dname, WaveCaps.szPname);
- if(count == 0)
- al_string_append_cstr(&dname, DEVNAME_TAIL);
- else
+ alstr_copy_cstr(&dname, DEVNAME_HEAD);
+ alstr_append_wcstr(&dname, WaveCaps.szPname);
+ if(count != 0)
{
char str[64];
- snprintf(str, sizeof(str), " #%d"DEVNAME_TAIL, count+1);
- al_string_append_cstr(&dname, str);
+ snprintf(str, sizeof(str), " #%d", count+1);
+ alstr_append_cstr(&dname, str);
}
count++;
-#define MATCH_ENTRY(i) (al_string_cmp(dname, *(i)) == 0)
+#define MATCH_ENTRY(i) (alstr_cmp(dname, *(i)) == 0)
VECTOR_FIND_IF(iter, const al_string, CaptureDevices, MATCH_ENTRY);
- if(iter == VECTOR_ITER_END(CaptureDevices)) break;
+ if(iter == VECTOR_END(CaptureDevices)) break;
#undef MATCH_ENTRY
}
- TRACE("Got device \"%s\", ID %u\n", al_string_get_cstr(dname), i);
+ TRACE("Got device \"%s\", ID %u\n", alstr_get_cstr(dname), i);
}
VECTOR_PUSH_BACK(CaptureDevices, dname);
}
@@ -149,7 +148,7 @@ typedef struct ALCwinmmPlayback {
WAVEFORMATEX Format;
- volatile ALboolean killNow;
+ ATOMIC(ALenum) killNow;
althrd_t thread;
} ALCwinmmPlayback;
@@ -160,13 +159,12 @@ static void CALLBACK ALCwinmmPlayback_waveOutProc(HWAVEOUT device, UINT msg, DWO
static int ALCwinmmPlayback_mixerProc(void *arg);
static ALCenum ALCwinmmPlayback_open(ALCwinmmPlayback *self, const ALCchar *name);
-static void ALCwinmmPlayback_close(ALCwinmmPlayback *self);
static ALCboolean ALCwinmmPlayback_reset(ALCwinmmPlayback *self);
static ALCboolean ALCwinmmPlayback_start(ALCwinmmPlayback *self);
static void ALCwinmmPlayback_stop(ALCwinmmPlayback *self);
static DECLARE_FORWARD2(ALCwinmmPlayback, ALCbackend, ALCenum, captureSamples, ALCvoid*, ALCuint)
static DECLARE_FORWARD(ALCwinmmPlayback, ALCbackend, ALCuint, availableSamples)
-static DECLARE_FORWARD(ALCwinmmPlayback, ALCbackend, ALint64, getLatency)
+static DECLARE_FORWARD(ALCwinmmPlayback, ALCbackend, ClockLatency, getClockLatency)
static DECLARE_FORWARD(ALCwinmmPlayback, ALCbackend, void, lock)
static DECLARE_FORWARD(ALCwinmmPlayback, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCwinmmPlayback)
@@ -182,7 +180,7 @@ static void ALCwinmmPlayback_Construct(ALCwinmmPlayback *self, ALCdevice *device
InitRef(&self->WaveBuffersCommitted, 0);
self->OutHdl = NULL;
- self->killNow = AL_TRUE;
+ ATOMIC_INIT(&self->killNow, AL_TRUE);
}
static void ALCwinmmPlayback_Destruct(ALCwinmmPlayback *self)
@@ -226,7 +224,7 @@ FORCE_ALIGN static int ALCwinmmPlayback_mixerProc(void *arg)
if(msg.message != WOM_DONE)
continue;
- if(self->killNow)
+ if(ATOMIC_LOAD(&self->killNow, almemory_order_acquire))
{
if(ReadRef(&self->WaveBuffersCommitted) == 0)
break;
@@ -234,8 +232,10 @@ FORCE_ALIGN static int ALCwinmmPlayback_mixerProc(void *arg)
}
WaveHdr = ((WAVEHDR*)msg.lParam);
+ ALCwinmmPlayback_lock(self);
aluMixData(device, WaveHdr->lpData, WaveHdr->dwBufferLength /
self->Format.nBlockAlign);
+ ALCwinmmPlayback_unlock(self);
// Send buffer back to play more data
waveOutWrite(self->OutHdl, WaveHdr, sizeof(WAVEHDR));
@@ -257,14 +257,14 @@ static ALCenum ALCwinmmPlayback_open(ALCwinmmPlayback *self, const ALCchar *devi
ProbePlaybackDevices();
// Find the Device ID matching the deviceName if valid
-#define MATCH_DEVNAME(iter) (!al_string_empty(*(iter)) && \
- (!deviceName || al_string_cmp_cstr(*(iter), deviceName) == 0))
+#define MATCH_DEVNAME(iter) (!alstr_empty(*(iter)) && \
+ (!deviceName || alstr_cmp_cstr(*(iter), deviceName) == 0))
VECTOR_FIND_IF(iter, const al_string, PlaybackDevices, MATCH_DEVNAME);
- if(iter == VECTOR_ITER_END(PlaybackDevices))
+ if(iter == VECTOR_END(PlaybackDevices))
return ALC_INVALID_VALUE;
#undef MATCH_DEVNAME
- DeviceID = (UINT)(iter - VECTOR_ITER_BEGIN(PlaybackDevices));
+ DeviceID = (UINT)(iter - VECTOR_BEGIN(PlaybackDevices));
retry_open:
memset(&self->Format, 0, sizeof(WAVEFORMATEX));
@@ -300,7 +300,7 @@ retry_open:
goto failure;
}
- al_string_copy(&device->DeviceName, VECTOR_ELEM(PlaybackDevices, DeviceID));
+ alstr_copy(&device->DeviceName, VECTOR_ELEM(PlaybackDevices, DeviceID));
return ALC_NO_ERROR;
failure:
@@ -311,9 +311,6 @@ failure:
return ALC_INVALID_VALUE;
}
-static void ALCwinmmPlayback_close(ALCwinmmPlayback* UNUSED(self))
-{ }
-
static ALCboolean ALCwinmmPlayback_reset(ALCwinmmPlayback *self)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
@@ -374,7 +371,7 @@ static ALCboolean ALCwinmmPlayback_start(ALCwinmmPlayback *self)
ALint BufferSize;
ALuint i;
- self->killNow = AL_FALSE;
+ ATOMIC_STORE(&self->killNow, AL_FALSE, almemory_order_release);
if(althrd_create(&self->thread, ALCwinmmPlayback_mixerProc, self) != althrd_success)
return ALC_FALSE;
@@ -382,7 +379,7 @@ static ALCboolean ALCwinmmPlayback_start(ALCwinmmPlayback *self)
// Create 4 Buffers
BufferSize = device->UpdateSize*device->NumUpdates / 4;
- BufferSize *= FrameSizeFromDevFmt(device->FmtChans, device->FmtType);
+ BufferSize *= FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder);
BufferData = calloc(4, BufferSize);
for(i = 0;i < 4;i++)
@@ -405,11 +402,8 @@ static void ALCwinmmPlayback_stop(ALCwinmmPlayback *self)
void *buffer = NULL;
int i;
- if(self->killNow)
+ if(ATOMIC_EXCHANGE(&self->killNow, AL_TRUE, almemory_order_acq_rel))
return;
-
- // Set flag to stop processing headers
- self->killNow = AL_TRUE;
althrd_join(self->thread, &i);
// Release the wave buffers
@@ -432,11 +426,11 @@ typedef struct ALCwinmmCapture {
HWAVEIN InHdl;
- RingBuffer *Ring;
+ ll_ringbuffer_t *Ring;
WAVEFORMATEX Format;
- volatile ALboolean killNow;
+ ATOMIC(ALenum) killNow;
althrd_t thread;
} ALCwinmmCapture;
@@ -447,13 +441,12 @@ static void CALLBACK ALCwinmmCapture_waveInProc(HWAVEIN device, UINT msg, DWORD_
static int ALCwinmmCapture_captureProc(void *arg);
static ALCenum ALCwinmmCapture_open(ALCwinmmCapture *self, const ALCchar *name);
-static void ALCwinmmCapture_close(ALCwinmmCapture *self);
static DECLARE_FORWARD(ALCwinmmCapture, ALCbackend, ALCboolean, reset)
static ALCboolean ALCwinmmCapture_start(ALCwinmmCapture *self);
static void ALCwinmmCapture_stop(ALCwinmmCapture *self);
static ALCenum ALCwinmmCapture_captureSamples(ALCwinmmCapture *self, ALCvoid *buffer, ALCuint samples);
static ALCuint ALCwinmmCapture_availableSamples(ALCwinmmCapture *self);
-static DECLARE_FORWARD(ALCwinmmCapture, ALCbackend, ALint64, getLatency)
+static DECLARE_FORWARD(ALCwinmmCapture, ALCbackend, ClockLatency, getClockLatency)
static DECLARE_FORWARD(ALCwinmmCapture, ALCbackend, void, lock)
static DECLARE_FORWARD(ALCwinmmCapture, ALCbackend, void, unlock)
DECLARE_DEFAULT_ALLOCATORS(ALCwinmmCapture)
@@ -469,11 +462,38 @@ static void ALCwinmmCapture_Construct(ALCwinmmCapture *self, ALCdevice *device)
InitRef(&self->WaveBuffersCommitted, 0);
self->InHdl = NULL;
- self->killNow = AL_TRUE;
+ ATOMIC_INIT(&self->killNow, AL_TRUE);
}
static void ALCwinmmCapture_Destruct(ALCwinmmCapture *self)
{
+ void *buffer = NULL;
+ int i;
+
+ /* Tell the processing thread to quit and wait for it to do so. */
+ if(!ATOMIC_EXCHANGE(&self->killNow, AL_TRUE, almemory_order_acq_rel))
+ {
+ PostThreadMessage(self->thread, WM_QUIT, 0, 0);
+
+ althrd_join(self->thread, &i);
+
+ /* Make sure capture is stopped and all pending buffers are flushed. */
+ waveInReset(self->InHdl);
+
+ // Release the wave buffers
+ for(i = 0;i < 4;i++)
+ {
+ waveInUnprepareHeader(self->InHdl, &self->WaveBuffer[i], sizeof(WAVEHDR));
+ if(i == 0) buffer = self->WaveBuffer[i].lpData;
+ self->WaveBuffer[i].lpData = NULL;
+ }
+ free(buffer);
+ }
+
+ ll_ringbuffer_free(self->Ring);
+ self->Ring = NULL;
+
+ // Close the Wave device
if(self->InHdl)
waveInClose(self->InHdl);
self->InHdl = 0;
@@ -512,12 +532,13 @@ static int ALCwinmmCapture_captureProc(void *arg)
continue;
/* Don't wait for other buffers to finish before quitting. We're
* closing so we don't need them. */
- if(self->killNow)
+ if(ATOMIC_LOAD(&self->killNow, almemory_order_acquire))
break;
WaveHdr = ((WAVEHDR*)msg.lParam);
- WriteRingBuffer(self->Ring, (ALubyte*)WaveHdr->lpData,
- WaveHdr->dwBytesRecorded/self->Format.nBlockAlign);
+ ll_ringbuffer_write(self->Ring, WaveHdr->lpData,
+ WaveHdr->dwBytesRecorded / self->Format.nBlockAlign
+ );
// Send buffer back to capture more data
waveInAddBuffer(self->InHdl, WaveHdr, sizeof(WAVEHDR));
@@ -543,13 +564,13 @@ static ALCenum ALCwinmmCapture_open(ALCwinmmCapture *self, const ALCchar *name)
ProbeCaptureDevices();
// Find the Device ID matching the deviceName if valid
-#define MATCH_DEVNAME(iter) (!al_string_empty(*(iter)) && (!name || al_string_cmp_cstr(*iter, name) == 0))
+#define MATCH_DEVNAME(iter) (!alstr_empty(*(iter)) && (!name || alstr_cmp_cstr(*iter, name) == 0))
VECTOR_FIND_IF(iter, const al_string, CaptureDevices, MATCH_DEVNAME);
- if(iter == VECTOR_ITER_END(CaptureDevices))
+ if(iter == VECTOR_END(CaptureDevices))
return ALC_INVALID_VALUE;
#undef MATCH_DEVNAME
- DeviceID = (UINT)(iter - VECTOR_ITER_BEGIN(CaptureDevices));
+ DeviceID = (UINT)(iter - VECTOR_BEGIN(CaptureDevices));
switch(device->FmtChans)
{
@@ -562,7 +583,7 @@ static ALCenum ALCwinmmCapture_open(ALCwinmmCapture *self, const ALCchar *name)
case DevFmtX51Rear:
case DevFmtX61:
case DevFmtX71:
- case DevFmtBFormat3D:
+ case DevFmtAmbi3D:
return ALC_INVALID_ENUM;
}
@@ -583,7 +604,7 @@ static ALCenum ALCwinmmCapture_open(ALCwinmmCapture *self, const ALCchar *name)
memset(&self->Format, 0, sizeof(WAVEFORMATEX));
self->Format.wFormatTag = ((device->FmtType == DevFmtFloat) ?
WAVE_FORMAT_IEEE_FLOAT : WAVE_FORMAT_PCM);
- self->Format.nChannels = ChannelsFromDevFmt(device->FmtChans);
+ self->Format.nChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
self->Format.wBitsPerSample = BytesFromDevFmt(device->FmtType) * 8;
self->Format.nBlockAlign = self->Format.wBitsPerSample *
self->Format.nChannels / 8;
@@ -605,7 +626,7 @@ static ALCenum ALCwinmmCapture_open(ALCwinmmCapture *self, const ALCchar *name)
if(CapturedDataSize < (self->Format.nSamplesPerSec / 10))
CapturedDataSize = self->Format.nSamplesPerSec / 10;
- self->Ring = CreateRingBuffer(self->Format.nBlockAlign, CapturedDataSize);
+ self->Ring = ll_ringbuffer_create(CapturedDataSize, self->Format.nBlockAlign, false);
if(!self->Ring) goto failure;
InitRef(&self->WaveBuffersCommitted, 0);
@@ -631,11 +652,11 @@ static ALCenum ALCwinmmCapture_open(ALCwinmmCapture *self, const ALCchar *name)
IncrementRef(&self->WaveBuffersCommitted);
}
- self->killNow = AL_FALSE;
+ ATOMIC_STORE(&self->killNow, AL_FALSE, almemory_order_release);
if(althrd_create(&self->thread, ALCwinmmCapture_captureProc, self) != althrd_success)
goto failure;
- al_string_copy(&device->DeviceName, VECTOR_ELEM(CaptureDevices, DeviceID));
+ alstr_copy(&device->DeviceName, VECTOR_ELEM(CaptureDevices, DeviceID));
return ALC_NO_ERROR;
failure:
@@ -646,8 +667,7 @@ failure:
free(BufferData);
}
- if(self->Ring)
- DestroyRingBuffer(self->Ring);
+ ll_ringbuffer_free(self->Ring);
self->Ring = NULL;
if(self->InHdl)
@@ -657,37 +677,6 @@ failure:
return ALC_INVALID_VALUE;
}
-static void ALCwinmmCapture_close(ALCwinmmCapture *self)
-{
- void *buffer = NULL;
- int i;
-
- /* Tell the processing thread to quit and wait for it to do so. */
- self->killNow = AL_TRUE;
- PostThreadMessage(self->thread, WM_QUIT, 0, 0);
-
- althrd_join(self->thread, &i);
-
- /* Make sure capture is stopped and all pending buffers are flushed. */
- waveInReset(self->InHdl);
-
- // Release the wave buffers
- for(i = 0;i < 4;i++)
- {
- waveInUnprepareHeader(self->InHdl, &self->WaveBuffer[i], sizeof(WAVEHDR));
- if(i == 0) buffer = self->WaveBuffer[i].lpData;
- self->WaveBuffer[i].lpData = NULL;
- }
- free(buffer);
-
- DestroyRingBuffer(self->Ring);
- self->Ring = NULL;
-
- // Close the Wave device
- waveInClose(self->InHdl);
- self->InHdl = NULL;
-}
-
static ALCboolean ALCwinmmCapture_start(ALCwinmmCapture *self)
{
waveInStart(self->InHdl);
@@ -701,27 +690,16 @@ static void ALCwinmmCapture_stop(ALCwinmmCapture *self)
static ALCenum ALCwinmmCapture_captureSamples(ALCwinmmCapture *self, ALCvoid *buffer, ALCuint samples)
{
- ReadRingBuffer(self->Ring, buffer, samples);
+ ll_ringbuffer_read(self->Ring, buffer, samples);
return ALC_NO_ERROR;
}
static ALCuint ALCwinmmCapture_availableSamples(ALCwinmmCapture *self)
{
- return RingBufferSize(self->Ring);
+ return (ALCuint)ll_ringbuffer_read_space(self->Ring);
}
-static inline void AppendAllDevicesList2(const al_string *name)
-{
- if(!al_string_empty(*name))
- AppendAllDevicesList(al_string_get_cstr(*name));
-}
-static inline void AppendCaptureDeviceList2(const al_string *name)
-{
- if(!al_string_empty(*name))
- AppendCaptureDeviceList(al_string_get_cstr(*name));
-}
-
typedef struct ALCwinmmBackendFactory {
DERIVE_FROM_TYPE(ALCbackendFactory);
} ALCwinmmBackendFactory;
@@ -730,7 +708,7 @@ typedef struct ALCwinmmBackendFactory {
static ALCboolean ALCwinmmBackendFactory_init(ALCwinmmBackendFactory *self);
static void ALCwinmmBackendFactory_deinit(ALCwinmmBackendFactory *self);
static ALCboolean ALCwinmmBackendFactory_querySupport(ALCwinmmBackendFactory *self, ALCbackend_Type type);
-static void ALCwinmmBackendFactory_probe(ALCwinmmBackendFactory *self, enum DevProbe type);
+static void ALCwinmmBackendFactory_probe(ALCwinmmBackendFactory *self, enum DevProbe type, al_string *outnames);
static ALCbackend* ALCwinmmBackendFactory_createBackend(ALCwinmmBackendFactory *self, ALCdevice *device, ALCbackend_Type type);
DEFINE_ALCBACKENDFACTORY_VTABLE(ALCwinmmBackendFactory);
@@ -760,19 +738,24 @@ static ALCboolean ALCwinmmBackendFactory_querySupport(ALCwinmmBackendFactory* UN
return ALC_FALSE;
}
-static void ALCwinmmBackendFactory_probe(ALCwinmmBackendFactory* UNUSED(self), enum DevProbe type)
+static void ALCwinmmBackendFactory_probe(ALCwinmmBackendFactory* UNUSED(self), enum DevProbe type, al_string *outnames)
{
switch(type)
{
+#define APPEND_OUTNAME(n) do { \
+ if(!alstr_empty(*(n))) \
+ alstr_append_range(outnames, VECTOR_BEGIN(*(n)), VECTOR_END(*(n))+1); \
+} while(0)
case ALL_DEVICE_PROBE:
ProbePlaybackDevices();
- VECTOR_FOR_EACH(const al_string, PlaybackDevices, AppendAllDevicesList2);
+ VECTOR_FOR_EACH(const al_string, PlaybackDevices, APPEND_OUTNAME);
break;
case CAPTURE_DEVICE_PROBE:
ProbeCaptureDevices();
- VECTOR_FOR_EACH(const al_string, CaptureDevices, AppendCaptureDeviceList2);
+ VECTOR_FOR_EACH(const al_string, CaptureDevices, APPEND_OUTNAME);
break;
+#undef APPEND_OUTNAME
}
}
diff --git a/Alc/bformatdec.c b/Alc/bformatdec.c
new file mode 100644
index 00000000..5233d06f
--- /dev/null
+++ b/Alc/bformatdec.c
@@ -0,0 +1,492 @@
+
+#include "config.h"
+
+#include "bformatdec.h"
+#include "ambdec.h"
+#include "filters/splitter.h"
+#include "alu.h"
+
+#include "bool.h"
+#include "threads.h"
+#include "almalloc.h"
+
+
+/* NOTE: These are scale factors as applied to Ambisonics content. Decoder
+ * coefficients should be divided by these values to get proper N3D scalings.
+ */
+const ALfloat N3D2N3DScale[MAX_AMBI_COEFFS] = {
+ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f
+};
+const ALfloat SN3D2N3DScale[MAX_AMBI_COEFFS] = {
+ 1.000000000f, /* ACN 0 (W), sqrt(1) */
+ 1.732050808f, /* ACN 1 (Y), sqrt(3) */
+ 1.732050808f, /* ACN 2 (Z), sqrt(3) */
+ 1.732050808f, /* ACN 3 (X), sqrt(3) */
+ 2.236067978f, /* ACN 4 (V), sqrt(5) */
+ 2.236067978f, /* ACN 5 (T), sqrt(5) */
+ 2.236067978f, /* ACN 6 (R), sqrt(5) */
+ 2.236067978f, /* ACN 7 (S), sqrt(5) */
+ 2.236067978f, /* ACN 8 (U), sqrt(5) */
+ 2.645751311f, /* ACN 9 (Q), sqrt(7) */
+ 2.645751311f, /* ACN 10 (O), sqrt(7) */
+ 2.645751311f, /* ACN 11 (M), sqrt(7) */
+ 2.645751311f, /* ACN 12 (K), sqrt(7) */
+ 2.645751311f, /* ACN 13 (L), sqrt(7) */
+ 2.645751311f, /* ACN 14 (N), sqrt(7) */
+ 2.645751311f, /* ACN 15 (P), sqrt(7) */
+};
+const ALfloat FuMa2N3DScale[MAX_AMBI_COEFFS] = {
+ 1.414213562f, /* ACN 0 (W), sqrt(2) */
+ 1.732050808f, /* ACN 1 (Y), sqrt(3) */
+ 1.732050808f, /* ACN 2 (Z), sqrt(3) */
+ 1.732050808f, /* ACN 3 (X), sqrt(3) */
+ 1.936491673f, /* ACN 4 (V), sqrt(15)/2 */
+ 1.936491673f, /* ACN 5 (T), sqrt(15)/2 */
+ 2.236067978f, /* ACN 6 (R), sqrt(5) */
+ 1.936491673f, /* ACN 7 (S), sqrt(15)/2 */
+ 1.936491673f, /* ACN 8 (U), sqrt(15)/2 */
+ 2.091650066f, /* ACN 9 (Q), sqrt(35/8) */
+ 1.972026594f, /* ACN 10 (O), sqrt(35)/3 */
+ 2.231093404f, /* ACN 11 (M), sqrt(224/45) */
+ 2.645751311f, /* ACN 12 (K), sqrt(7) */
+ 2.231093404f, /* ACN 13 (L), sqrt(224/45) */
+ 1.972026594f, /* ACN 14 (N), sqrt(35)/3 */
+ 2.091650066f, /* ACN 15 (P), sqrt(35/8) */
+};
+
+
+#define HF_BAND 0
+#define LF_BAND 1
+#define NUM_BANDS 2
+
+/* These points are in AL coordinates! */
+static const ALfloat Ambi3DPoints[8][3] = {
+ { -0.577350269f, 0.577350269f, -0.577350269f },
+ { 0.577350269f, 0.577350269f, -0.577350269f },
+ { -0.577350269f, 0.577350269f, 0.577350269f },
+ { 0.577350269f, 0.577350269f, 0.577350269f },
+ { -0.577350269f, -0.577350269f, -0.577350269f },
+ { 0.577350269f, -0.577350269f, -0.577350269f },
+ { -0.577350269f, -0.577350269f, 0.577350269f },
+ { 0.577350269f, -0.577350269f, 0.577350269f },
+};
+static const ALfloat Ambi3DDecoder[8][MAX_AMBI_COEFFS] = {
+ { 0.125f, 0.125f, 0.125f, 0.125f },
+ { 0.125f, -0.125f, 0.125f, 0.125f },
+ { 0.125f, 0.125f, 0.125f, -0.125f },
+ { 0.125f, -0.125f, 0.125f, -0.125f },
+ { 0.125f, 0.125f, -0.125f, 0.125f },
+ { 0.125f, -0.125f, -0.125f, 0.125f },
+ { 0.125f, 0.125f, -0.125f, -0.125f },
+ { 0.125f, -0.125f, -0.125f, -0.125f },
+};
+static const ALfloat Ambi3DDecoderHFScale[MAX_AMBI_COEFFS] = {
+ 2.0f,
+ 1.15470054f, 1.15470054f, 1.15470054f
+};
+
+
+/* NOTE: BandSplitter filters are unused with single-band decoding */
+typedef struct BFormatDec {
+ ALuint Enabled; /* Bitfield of enabled channels. */
+
+ union {
+ alignas(16) ALfloat Dual[MAX_OUTPUT_CHANNELS][NUM_BANDS][MAX_AMBI_COEFFS];
+ alignas(16) ALfloat Single[MAX_OUTPUT_CHANNELS][MAX_AMBI_COEFFS];
+ } Matrix;
+
+ BandSplitter XOver[MAX_AMBI_COEFFS];
+
+ ALfloat (*Samples)[BUFFERSIZE];
+ /* These two alias into Samples */
+ ALfloat (*SamplesHF)[BUFFERSIZE];
+ ALfloat (*SamplesLF)[BUFFERSIZE];
+
+ alignas(16) ALfloat ChannelMix[BUFFERSIZE];
+
+ struct {
+ BandSplitter XOver;
+ ALfloat Gains[NUM_BANDS];
+ } UpSampler[4];
+
+ ALsizei NumChannels;
+ ALboolean DualBand;
+} BFormatDec;
+
+BFormatDec *bformatdec_alloc()
+{
+ return al_calloc(16, sizeof(BFormatDec));
+}
+
+void bformatdec_free(BFormatDec **dec)
+{
+ if(dec && *dec)
+ {
+ al_free((*dec)->Samples);
+ (*dec)->Samples = NULL;
+ (*dec)->SamplesHF = NULL;
+ (*dec)->SamplesLF = NULL;
+
+ al_free(*dec);
+ *dec = NULL;
+ }
+}
+
+void bformatdec_reset(BFormatDec *dec, const AmbDecConf *conf, ALsizei chancount, ALuint srate, const ALsizei chanmap[MAX_OUTPUT_CHANNELS])
+{
+ static const ALsizei map2DTo3D[MAX_AMBI2D_COEFFS] = {
+ 0, 1, 3, 4, 8, 9, 15
+ };
+ const ALfloat *coeff_scale = N3D2N3DScale;
+ bool periphonic;
+ ALfloat ratio;
+ ALsizei i;
+
+ al_free(dec->Samples);
+ dec->Samples = NULL;
+ dec->SamplesHF = NULL;
+ dec->SamplesLF = NULL;
+
+ dec->NumChannels = chancount;
+ dec->Samples = al_calloc(16, dec->NumChannels*2 * sizeof(dec->Samples[0]));
+ dec->SamplesHF = dec->Samples;
+ dec->SamplesLF = dec->SamplesHF + dec->NumChannels;
+
+ dec->Enabled = 0;
+ for(i = 0;i < conf->NumSpeakers;i++)
+ dec->Enabled |= 1 << chanmap[i];
+
+ if(conf->CoeffScale == ADS_SN3D)
+ coeff_scale = SN3D2N3DScale;
+ else if(conf->CoeffScale == ADS_FuMa)
+ coeff_scale = FuMa2N3DScale;
+
+ memset(dec->UpSampler, 0, sizeof(dec->UpSampler));
+ ratio = 400.0f / (ALfloat)srate;
+ for(i = 0;i < 4;i++)
+ bandsplit_init(&dec->UpSampler[i].XOver, ratio);
+ if((conf->ChanMask&AMBI_PERIPHONIC_MASK))
+ {
+ periphonic = true;
+
+ dec->UpSampler[0].Gains[HF_BAND] = (conf->ChanMask > 0x1ff) ? W_SCALE_3H3P :
+ (conf->ChanMask > 0xf) ? W_SCALE_2H2P : 1.0f;
+ dec->UpSampler[0].Gains[LF_BAND] = 1.0f;
+ for(i = 1;i < 4;i++)
+ {
+ dec->UpSampler[i].Gains[HF_BAND] = (conf->ChanMask > 0x1ff) ? XYZ_SCALE_3H3P :
+ (conf->ChanMask > 0xf) ? XYZ_SCALE_2H2P : 1.0f;
+ dec->UpSampler[i].Gains[LF_BAND] = 1.0f;
+ }
+ }
+ else
+ {
+ periphonic = false;
+
+ dec->UpSampler[0].Gains[HF_BAND] = (conf->ChanMask > 0x1ff) ? W_SCALE_3H0P :
+ (conf->ChanMask > 0xf) ? W_SCALE_2H0P : 1.0f;
+ dec->UpSampler[0].Gains[LF_BAND] = 1.0f;
+ for(i = 1;i < 3;i++)
+ {
+ dec->UpSampler[i].Gains[HF_BAND] = (conf->ChanMask > 0x1ff) ? XYZ_SCALE_3H0P :
+ (conf->ChanMask > 0xf) ? XYZ_SCALE_2H0P : 1.0f;
+ dec->UpSampler[i].Gains[LF_BAND] = 1.0f;
+ }
+ dec->UpSampler[3].Gains[HF_BAND] = 0.0f;
+ dec->UpSampler[3].Gains[LF_BAND] = 0.0f;
+ }
+
+ memset(&dec->Matrix, 0, sizeof(dec->Matrix));
+ if(conf->FreqBands == 1)
+ {
+ dec->DualBand = AL_FALSE;
+ for(i = 0;i < conf->NumSpeakers;i++)
+ {
+ ALsizei chan = chanmap[i];
+ ALfloat gain;
+ ALsizei j, k;
+
+ if(!periphonic)
+ {
+ for(j = 0,k = 0;j < MAX_AMBI2D_COEFFS;j++)
+ {
+ ALsizei l = map2DTo3D[j];
+ if(j == 0) gain = conf->HFOrderGain[0];
+ else if(j == 1) gain = conf->HFOrderGain[1];
+ else if(j == 3) gain = conf->HFOrderGain[2];
+ else if(j == 5) gain = conf->HFOrderGain[3];
+ if((conf->ChanMask&(1<<l)))
+ dec->Matrix.Single[chan][j] = conf->HFMatrix[i][k++] / coeff_scale[l] *
+ gain;
+ }
+ }
+ else
+ {
+ for(j = 0,k = 0;j < MAX_AMBI_COEFFS;j++)
+ {
+ if(j == 0) gain = conf->HFOrderGain[0];
+ else if(j == 1) gain = conf->HFOrderGain[1];
+ else if(j == 4) gain = conf->HFOrderGain[2];
+ else if(j == 9) gain = conf->HFOrderGain[3];
+ if((conf->ChanMask&(1<<j)))
+ dec->Matrix.Single[chan][j] = conf->HFMatrix[i][k++] / coeff_scale[j] *
+ gain;
+ }
+ }
+ }
+ }
+ else
+ {
+ dec->DualBand = AL_TRUE;
+
+ ratio = conf->XOverFreq / (ALfloat)srate;
+ for(i = 0;i < MAX_AMBI_COEFFS;i++)
+ bandsplit_init(&dec->XOver[i], ratio);
+
+ ratio = powf(10.0f, conf->XOverRatio / 40.0f);
+ for(i = 0;i < conf->NumSpeakers;i++)
+ {
+ ALsizei chan = chanmap[i];
+ ALfloat gain;
+ ALsizei j, k;
+
+ if(!periphonic)
+ {
+ for(j = 0,k = 0;j < MAX_AMBI2D_COEFFS;j++)
+ {
+ ALsizei l = map2DTo3D[j];
+ if(j == 0) gain = conf->HFOrderGain[0] * ratio;
+ else if(j == 1) gain = conf->HFOrderGain[1] * ratio;
+ else if(j == 3) gain = conf->HFOrderGain[2] * ratio;
+ else if(j == 5) gain = conf->HFOrderGain[3] * ratio;
+ if((conf->ChanMask&(1<<l)))
+ dec->Matrix.Dual[chan][HF_BAND][j] = conf->HFMatrix[i][k++] /
+ coeff_scale[l] * gain;
+ }
+ for(j = 0,k = 0;j < MAX_AMBI2D_COEFFS;j++)
+ {
+ ALsizei l = map2DTo3D[j];
+ if(j == 0) gain = conf->LFOrderGain[0] / ratio;
+ else if(j == 1) gain = conf->LFOrderGain[1] / ratio;
+ else if(j == 3) gain = conf->LFOrderGain[2] / ratio;
+ else if(j == 5) gain = conf->LFOrderGain[3] / ratio;
+ if((conf->ChanMask&(1<<l)))
+ dec->Matrix.Dual[chan][LF_BAND][j] = conf->LFMatrix[i][k++] /
+ coeff_scale[l] * gain;
+ }
+ }
+ else
+ {
+ for(j = 0,k = 0;j < MAX_AMBI_COEFFS;j++)
+ {
+ if(j == 0) gain = conf->HFOrderGain[0] * ratio;
+ else if(j == 1) gain = conf->HFOrderGain[1] * ratio;
+ else if(j == 4) gain = conf->HFOrderGain[2] * ratio;
+ else if(j == 9) gain = conf->HFOrderGain[3] * ratio;
+ if((conf->ChanMask&(1<<j)))
+ dec->Matrix.Dual[chan][HF_BAND][j] = conf->HFMatrix[i][k++] /
+ coeff_scale[j] * gain;
+ }
+ for(j = 0,k = 0;j < MAX_AMBI_COEFFS;j++)
+ {
+ if(j == 0) gain = conf->LFOrderGain[0] / ratio;
+ else if(j == 1) gain = conf->LFOrderGain[1] / ratio;
+ else if(j == 4) gain = conf->LFOrderGain[2] / ratio;
+ else if(j == 9) gain = conf->LFOrderGain[3] / ratio;
+ if((conf->ChanMask&(1<<j)))
+ dec->Matrix.Dual[chan][LF_BAND][j] = conf->LFMatrix[i][k++] /
+ coeff_scale[j] * gain;
+ }
+ }
+ }
+ }
+}
+
+
+void bformatdec_process(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo)
+{
+ ALsizei chan, i;
+
+ OutBuffer = ASSUME_ALIGNED(OutBuffer, 16);
+ if(dec->DualBand)
+ {
+ for(i = 0;i < dec->NumChannels;i++)
+ bandsplit_process(&dec->XOver[i], dec->SamplesHF[i], dec->SamplesLF[i],
+ InSamples[i], SamplesToDo);
+
+ for(chan = 0;chan < OutChannels;chan++)
+ {
+ if(!(dec->Enabled&(1<<chan)))
+ continue;
+
+ memset(dec->ChannelMix, 0, SamplesToDo*sizeof(ALfloat));
+ MixRowSamples(dec->ChannelMix, dec->Matrix.Dual[chan][HF_BAND],
+ dec->SamplesHF, dec->NumChannels, 0, SamplesToDo
+ );
+ MixRowSamples(dec->ChannelMix, dec->Matrix.Dual[chan][LF_BAND],
+ dec->SamplesLF, dec->NumChannels, 0, SamplesToDo
+ );
+
+ for(i = 0;i < SamplesToDo;i++)
+ OutBuffer[chan][i] += dec->ChannelMix[i];
+ }
+ }
+ else
+ {
+ for(chan = 0;chan < OutChannels;chan++)
+ {
+ if(!(dec->Enabled&(1<<chan)))
+ continue;
+
+ memset(dec->ChannelMix, 0, SamplesToDo*sizeof(ALfloat));
+ MixRowSamples(dec->ChannelMix, dec->Matrix.Single[chan], InSamples,
+ dec->NumChannels, 0, SamplesToDo);
+
+ for(i = 0;i < SamplesToDo;i++)
+ OutBuffer[chan][i] += dec->ChannelMix[i];
+ }
+ }
+}
+
+
+void bformatdec_upSample(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei InChannels, ALsizei SamplesToDo)
+{
+ ALsizei i;
+
+ /* This up-sampler leverages the differences observed in dual-band second-
+ * and third-order decoder matrices compared to first-order. For the same
+ * output channel configuration, the low-frequency matrix has identical
+ * coefficients in the shared input channels, while the high-frequency
+ * matrix has extra scalars applied to the W channel and X/Y/Z channels.
+ * Mixing the first-order content into the higher-order stream with the
+ * appropriate counter-scales applied to the HF response results in the
+ * subsequent higher-order decode generating the same response as a first-
+ * order decode.
+ */
+ for(i = 0;i < InChannels;i++)
+ {
+ /* First, split the first-order components into low and high frequency
+ * bands.
+ */
+ bandsplit_process(&dec->UpSampler[i].XOver,
+ dec->Samples[HF_BAND], dec->Samples[LF_BAND],
+ InSamples[i], SamplesToDo
+ );
+
+ /* Now write each band to the output. */
+ MixRowSamples(OutBuffer[i], dec->UpSampler[i].Gains,
+ dec->Samples, NUM_BANDS, 0, SamplesToDo
+ );
+ }
+}
+
+
+#define INVALID_UPSAMPLE_INDEX INT_MAX
+
+static ALsizei GetACNIndex(const BFChannelConfig *chans, ALsizei numchans, ALsizei acn)
+{
+ ALsizei i;
+ for(i = 0;i < numchans;i++)
+ {
+ if(chans[i].Index == acn)
+ return i;
+ }
+ return INVALID_UPSAMPLE_INDEX;
+}
+#define GetChannelForACN(b, a) GetACNIndex((b).Ambi.Map, (b).NumChannels, (a))
+
+typedef struct AmbiUpsampler {
+ alignas(16) ALfloat Samples[NUM_BANDS][BUFFERSIZE];
+
+ BandSplitter XOver[4];
+
+ ALfloat Gains[4][MAX_OUTPUT_CHANNELS][NUM_BANDS];
+} AmbiUpsampler;
+
+AmbiUpsampler *ambiup_alloc()
+{
+ return al_calloc(16, sizeof(AmbiUpsampler));
+}
+
+void ambiup_free(struct AmbiUpsampler **ambiup)
+{
+ if(ambiup)
+ {
+ al_free(*ambiup);
+ *ambiup = NULL;
+ }
+}
+
+void ambiup_reset(struct AmbiUpsampler *ambiup, const ALCdevice *device, ALfloat w_scale, ALfloat xyz_scale)
+{
+ ALfloat ratio;
+ ALsizei i;
+
+ ratio = 400.0f / (ALfloat)device->Frequency;
+ for(i = 0;i < 4;i++)
+ bandsplit_init(&ambiup->XOver[i], ratio);
+
+ memset(ambiup->Gains, 0, sizeof(ambiup->Gains));
+ if(device->Dry.CoeffCount > 0)
+ {
+ ALfloat encgains[8][MAX_OUTPUT_CHANNELS];
+ ALsizei j;
+ size_t k;
+
+ for(k = 0;k < COUNTOF(Ambi3DPoints);k++)
+ {
+ ALfloat coeffs[MAX_AMBI_COEFFS] = { 0.0f };
+ CalcDirectionCoeffs(Ambi3DPoints[k], 0.0f, coeffs);
+ ComputePanGains(&device->Dry, coeffs, 1.0f, encgains[k]);
+ }
+
+ /* Combine the matrices that do the in->virt and virt->out conversions
+ * so we get a single in->out conversion. NOTE: the Encoder matrix
+ * (encgains) and output are transposed, so the input channels line up
+ * with the rows and the output channels line up with the columns.
+ */
+ for(i = 0;i < 4;i++)
+ {
+ for(j = 0;j < device->Dry.NumChannels;j++)
+ {
+ ALdouble gain = 0.0;
+ for(k = 0;k < COUNTOF(Ambi3DDecoder);k++)
+ gain += (ALdouble)Ambi3DDecoder[k][i] * encgains[k][j];
+ ambiup->Gains[i][j][HF_BAND] = (ALfloat)(gain * Ambi3DDecoderHFScale[i]);
+ ambiup->Gains[i][j][LF_BAND] = (ALfloat)gain;
+ }
+ }
+ }
+ else
+ {
+ for(i = 0;i < 4;i++)
+ {
+ ALsizei index = GetChannelForACN(device->Dry, i);
+ if(index != INVALID_UPSAMPLE_INDEX)
+ {
+ ALfloat scale = device->Dry.Ambi.Map[index].Scale;
+ ambiup->Gains[i][index][HF_BAND] = scale * ((i==0) ? w_scale : xyz_scale);
+ ambiup->Gains[i][index][LF_BAND] = scale;
+ }
+ }
+ }
+}
+
+void ambiup_process(struct AmbiUpsampler *ambiup, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo)
+{
+ ALsizei i, j;
+
+ for(i = 0;i < 4;i++)
+ {
+ bandsplit_process(&ambiup->XOver[i],
+ ambiup->Samples[HF_BAND], ambiup->Samples[LF_BAND],
+ InSamples[i], SamplesToDo
+ );
+
+ for(j = 0;j < OutChannels;j++)
+ MixRowSamples(OutBuffer[j], ambiup->Gains[i][j],
+ ambiup->Samples, NUM_BANDS, 0, SamplesToDo
+ );
+ }
+}
diff --git a/Alc/bformatdec.h b/Alc/bformatdec.h
new file mode 100644
index 00000000..2d7d1d62
--- /dev/null
+++ b/Alc/bformatdec.h
@@ -0,0 +1,57 @@
+#ifndef BFORMATDEC_H
+#define BFORMATDEC_H
+
+#include "alMain.h"
+
+
+/* These are the necessary scales for first-order HF responses to play over
+ * higher-order 2D (non-periphonic) decoders.
+ */
+#define W_SCALE_2H0P 1.224744871f /* sqrt(1.5) */
+#define XYZ_SCALE_2H0P 1.0f
+#define W_SCALE_3H0P 1.414213562f /* sqrt(2) */
+#define XYZ_SCALE_3H0P 1.082392196f
+
+/* These are the necessary scales for first-order HF responses to play over
+ * higher-order 3D (periphonic) decoders.
+ */
+#define W_SCALE_2H2P 1.341640787f /* sqrt(1.8) */
+#define XYZ_SCALE_2H2P 1.0f
+#define W_SCALE_3H3P 1.695486018f
+#define XYZ_SCALE_3H3P 1.136697713f
+
+
+/* NOTE: These are scale factors as applied to Ambisonics content. Decoder
+ * coefficients should be divided by these values to get proper N3D scalings.
+ */
+const ALfloat N3D2N3DScale[MAX_AMBI_COEFFS];
+const ALfloat SN3D2N3DScale[MAX_AMBI_COEFFS];
+const ALfloat FuMa2N3DScale[MAX_AMBI_COEFFS];
+
+
+struct AmbDecConf;
+struct BFormatDec;
+struct AmbiUpsampler;
+
+
+struct BFormatDec *bformatdec_alloc();
+void bformatdec_free(struct BFormatDec **dec);
+void bformatdec_reset(struct BFormatDec *dec, const struct AmbDecConf *conf, ALsizei chancount, ALuint srate, const ALsizei chanmap[MAX_OUTPUT_CHANNELS]);
+
+/* Decodes the ambisonic input to the given output channels. */
+void bformatdec_process(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo);
+
+/* Up-samples a first-order input to the decoder's configuration. */
+void bformatdec_upSample(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei InChannels, ALsizei SamplesToDo);
+
+
+/* Stand-alone first-order upsampler. Kept here because it shares some stuff
+ * with bformatdec. Assumes a periphonic (4-channel) input mix!
+ */
+struct AmbiUpsampler *ambiup_alloc();
+void ambiup_free(struct AmbiUpsampler **ambiup);
+void ambiup_reset(struct AmbiUpsampler *ambiup, const ALCdevice *device, ALfloat w_scale, ALfloat xyz_scale);
+
+void ambiup_process(struct AmbiUpsampler *ambiup, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo);
+
+#endif /* BFORMATDEC_H */
diff --git a/Alc/bs2b.c b/Alc/bs2b.c
index 6c3f052b..e235e547 100644
--- a/Alc/bs2b.c
+++ b/Alc/bs2b.c
@@ -129,4 +129,59 @@ void bs2b_clear(struct bs2b *bs2b)
memset(&bs2b->last_sample, 0, sizeof(bs2b->last_sample));
} /* bs2b_clear */
-extern inline void bs2b_cross_feed(struct bs2b *bs2b, float *restrict samples);
+void bs2b_cross_feed(struct bs2b *bs2b, float *restrict Left, float *restrict Right, int SamplesToDo)
+{
+ float lsamples[128][2];
+ float rsamples[128][2];
+ int base;
+
+ for(base = 0;base < SamplesToDo;)
+ {
+ int todo = mini(128, SamplesToDo-base);
+ int i;
+
+ /* Process left input */
+ lsamples[0][0] = bs2b->a0_lo*Left[0] +
+ bs2b->b1_lo*bs2b->last_sample[0].lo;
+ lsamples[0][1] = bs2b->a0_hi*Left[0] +
+ bs2b->a1_hi*bs2b->last_sample[0].asis +
+ bs2b->b1_hi*bs2b->last_sample[0].hi;
+ for(i = 1;i < todo;i++)
+ {
+ lsamples[i][0] = bs2b->a0_lo*Left[i] +
+ bs2b->b1_lo*lsamples[i-1][0];
+ lsamples[i][1] = bs2b->a0_hi*Left[i] +
+ bs2b->a1_hi*Left[i-1] +
+ bs2b->b1_hi*lsamples[i-1][1];
+ }
+ bs2b->last_sample[0].asis = Left[i-1];
+ bs2b->last_sample[0].lo = lsamples[i-1][0];
+ bs2b->last_sample[0].hi = lsamples[i-1][1];
+
+ /* Process right input */
+ rsamples[0][0] = bs2b->a0_lo*Right[0] +
+ bs2b->b1_lo*bs2b->last_sample[1].lo;
+ rsamples[0][1] = bs2b->a0_hi*Right[0] +
+ bs2b->a1_hi*bs2b->last_sample[1].asis +
+ bs2b->b1_hi*bs2b->last_sample[1].hi;
+ for(i = 1;i < todo;i++)
+ {
+ rsamples[i][0] = bs2b->a0_lo*Right[i] +
+ bs2b->b1_lo*rsamples[i-1][0];
+ rsamples[i][1] = bs2b->a0_hi*Right[i] +
+ bs2b->a1_hi*Right[i-1] +
+ bs2b->b1_hi*rsamples[i-1][1];
+ }
+ bs2b->last_sample[1].asis = Right[i-1];
+ bs2b->last_sample[1].lo = rsamples[i-1][0];
+ bs2b->last_sample[1].hi = rsamples[i-1][1];
+
+ /* Crossfeed */
+ for(i = 0;i < todo;i++)
+ *(Left++) = lsamples[i][1] + rsamples[i][0];
+ for(i = 0;i < todo;i++)
+ *(Right++) = rsamples[i][1] + lsamples[i][0];
+
+ base += todo;
+ }
+} /* bs2b_cross_feed */
diff --git a/Alc/bsinc.c b/Alc/bsinc.c
deleted file mode 100644
index f795120f..00000000
--- a/Alc/bsinc.c
+++ /dev/null
@@ -1,981 +0,0 @@
-
-#include "config.h"
-
-#include "AL/al.h"
-#include "align.h"
-
-/* Table of windowed sinc coefficients and deltas. This 11th order filter
- * has a rejection of -60 dB, yielding a transition width of ~0.302
- * (normalized frequency). Order increases when downsampling to a limit of
- * one octave, after which the quality of the filter (transition width)
- * suffers to reduce the CPU cost. The bandlimiting will cut all sound after
- * downsampling by ~2.73 octaves.
- */
-alignas(16) const ALfloat bsincTab[18840] =
-{
- /* 24, 0 */ +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f, +0.000000000e+00f,
-
- /* 24, 0 */ +1.501390780e-03f, +3.431804419e-03f, +6.512803185e-03f, +1.091425387e-02f, +1.664594540e-02f, +2.351091132e-02f, +3.109255671e-02f, +3.878419288e-02f, +4.586050701e-02f, +5.158058002e-02f, +5.530384985e-02f, +5.659614054e-02f, +5.530384985e-02f, +5.158058002e-02f, +4.586050701e-02f, +3.878419288e-02f, +3.109255671e-02f, +2.351091132e-02f, +1.664594540e-02f, +1.091425387e-02f, +6.512803185e-03f, +3.431804419e-03f, +1.501390780e-03f, +4.573885647e-04f,
- /* 24, 1 */ +1.413186400e-03f, +3.279858311e-03f, +6.282638036e-03f, +1.059932179e-02f, +1.625135142e-02f, +2.305547031e-02f, +3.060840342e-02f, +3.831365198e-02f, +4.545054680e-02f, +5.127577001e-02f, +5.513916011e-02f, +5.659104154e-02f, +5.545895049e-02f, +5.187752167e-02f, +4.626513642e-02f, +3.925233583e-02f, +3.157717954e-02f, +2.396921539e-02f, +1.704503934e-02f, +1.123445076e-02f, +6.748179094e-03f, +3.588275667e-03f, +1.593065611e-03f, +5.022154476e-04f,
- /* 24, 2 */ +1.328380648e-03f, +3.132379333e-03f, +6.057656813e-03f, +1.028967374e-02f, +1.586133102e-02f, +2.260301890e-02f, +3.012488684e-02f, +3.784089895e-02f, +4.503543229e-02f, +5.096323022e-02f, +5.496495842e-02f, +5.657574693e-02f, +5.560438923e-02f, +5.216645963e-02f, +4.666426010e-02f, +3.971789474e-02f, +3.206210284e-02f, +2.443025293e-02f, +1.744855617e-02f, +1.155988996e-02f, +6.988790100e-03f, +3.749328623e-03f, +1.688282347e-03f, +5.494305796e-04f,
- /* 24, 3 */ +1.246901403e-03f, +2.989308098e-03f, +5.837830254e-03f, +9.985325752e-03f, +1.547595434e-02f, +2.215368059e-02f, +2.964217216e-02f, +3.736611920e-02f, +4.461534144e-02f, +5.064310236e-02f, +5.478132634e-02f, +5.655026396e-02f, +5.574009777e-02f, +5.244726189e-02f, +4.705770477e-02f, +4.018068337e-02f, +3.254715574e-02f, +2.489389144e-02f, +1.785641537e-02f, +1.189054572e-02f, +7.234657995e-03f, +3.915018340e-03f, +1.787112015e-03f, +5.991047395e-04f,
- /* 24, 4 */ +1.168676301e-03f, +2.850583915e-03f, +5.623126723e-03f, +9.686290690e-03f, +1.509528803e-02f, +2.170757578e-02f, +2.916042250e-02f, +3.688949768e-02f, +4.419045351e-02f, +5.031553118e-02f, +5.458834968e-02f, +5.651460469e-02f, +5.586601230e-02f, +5.271979985e-02f, +4.744529894e-02f, +4.064051541e-02f, +3.303216567e-02f, +2.535999546e-02f, +1.826853297e-02f, +1.222638897e-02f, +7.485801959e-03f, +4.085398290e-03f, +1.889625146e-03f, +6.513091287e-04f,
- /* 24, 5 */ +1.093632798e-03f, +2.716144855e-03f, +5.413512274e-03f, +9.392578266e-03f, +1.471939531e-02f, +2.126482169e-02f, +2.867979883e-02f, +3.641121873e-02f, +4.376094899e-02f, +4.998066438e-02f, +5.438611851e-02f, +5.646878599e-02f, +5.598207354e-02f, +5.298394839e-02f, +4.782687301e-02f, +4.109720465e-02f, +3.351695842e-02f, +2.582842673e-02f, +1.868482156e-02f, +1.256738733e-02f, +7.742238512e-03f, +4.260520294e-03f, +1.995891717e-03f, +7.061153220e-04f,
- /* 24, 6 */ +1.021698233e-03f, +2.585927824e-03f, +5.208950715e-03f, +9.104195104e-03f, +1.434833590e-02f, +2.082553239e-02f, +2.820045990e-02f, +3.593146595e-02f, +4.332700946e-02f, +4.963865252e-02f, +5.417472708e-02f, +5.641282954e-02f, +5.608822683e-02f, +5.323958602e-02f, +4.820225940e-02f, +4.155056502e-02f, +3.400135826e-02f, +2.629904416e-02f, +1.910519032e-02f, +1.291350505e-02f, +8.003981455e-03f, +4.440434453e-03f, +2.105981077e-03f, +7.635952183e-04f,
- /* 24, 7 */ +9.527998831e-04f, +2.459868628e-03f, +5.009403670e-03f, +8.821144768e-03f, +1.398216608e-02f, +2.038981869e-02f, +2.772256216e-02f, +3.545042216e-02f, +4.288881749e-02f, +4.928964888e-02f, +5.395427373e-02f, +5.634676181e-02f, +5.618442211e-02f, +5.348659488e-02f, +4.857129262e-02f, +4.200041076e-02f, +3.448518802e-02f, +2.677170395e-02f, +1.952954505e-02f, +1.326470299e-02f, +8.271041819e-03f, +4.625189083e-03f, +2.219961884e-03f, +8.238209888e-04f,
- /* 24, 8 */ +8.868650246e-04f, +2.337902042e-03f, +4.814830642e-03f, +8.543427812e-03f, +1.362093865e-02f, +1.995778816e-02f, +2.724625964e-02f, +3.496826923e-02f, +4.244655653e-02f, +4.893380942e-02f, +5.372486088e-02f, +5.627061400e-02f, +5.627061400e-02f, +5.372486088e-02f, +4.893380942e-02f, +4.244655653e-02f, +3.496826923e-02f, +2.724625964e-02f, +1.995778816e-02f, +1.362093865e-02f, +8.543427812e-03f, +4.814830642e-03f, +2.337902042e-03f, +8.868650246e-04f,
- /* 24, 9 */ +8.238209888e-04f, +2.219961884e-03f, +4.625189083e-03f, +8.271041819e-03f, +1.326470299e-02f, +1.952954505e-02f, +2.677170395e-02f, +3.448518802e-02f, +4.200041076e-02f, +4.857129262e-02f, +5.348659488e-02f, +5.618442211e-02f, +5.634676181e-02f, +5.395427373e-02f, +4.928964888e-02f, +4.288881749e-02f, +3.545042216e-02f, +2.772256216e-02f, +2.038981869e-02f, +1.398216608e-02f, +8.821144768e-03f, +5.009403670e-03f, +2.459868628e-03f, +9.527998831e-04f,
- /* 24,10 */ +7.635952183e-04f, +2.105981077e-03f, +4.440434453e-03f, +8.003981455e-03f, +1.291350505e-02f, +1.910519032e-02f, +2.629904416e-02f, +3.400135826e-02f, +4.155056502e-02f, +4.820225940e-02f, +5.323958602e-02f, +5.608822683e-02f, +5.641282954e-02f, +5.417472708e-02f, +4.963865252e-02f, +4.332700946e-02f, +3.593146595e-02f, +2.820045990e-02f, +2.082553239e-02f, +1.434833590e-02f, +9.104195104e-03f, +5.208950715e-03f, +2.585927824e-03f, +1.021698233e-03f,
- /* 24,11 */ +7.061153220e-04f, +1.995891717e-03f, +4.260520294e-03f, +7.742238512e-03f, +1.256738733e-02f, +1.868482156e-02f, +2.582842673e-02f, +3.351695842e-02f, +4.109720465e-02f, +4.782687301e-02f, +5.298394839e-02f, +5.598207354e-02f, +5.646878599e-02f, +5.438611851e-02f, +4.998066438e-02f, +4.376094899e-02f, +3.641121873e-02f, +2.867979883e-02f, +2.126482169e-02f, +1.471939531e-02f, +9.392578266e-03f, +5.413512274e-03f, +2.716144855e-03f, +1.093632798e-03f,
- /* 24,12 */ +6.513091287e-04f, +1.889625146e-03f, +4.085398290e-03f, +7.485801959e-03f, +1.222638897e-02f, +1.826853297e-02f, +2.535999546e-02f, +3.303216567e-02f, +4.064051541e-02f, +4.744529894e-02f, +5.271979985e-02f, +5.586601230e-02f, +5.651460469e-02f, +5.458834968e-02f, +5.031553118e-02f, +4.419045351e-02f, +3.688949768e-02f, +2.916042250e-02f, +2.170757578e-02f, +1.509528803e-02f, +9.686290690e-03f, +5.623126723e-03f, +2.850583915e-03f, +1.168676301e-03f,
- /* 24,13 */ +5.991047395e-04f, +1.787112015e-03f, +3.915018340e-03f, +7.234657995e-03f, +1.189054572e-02f, +1.785641537e-02f, +2.489389144e-02f, +3.254715574e-02f, +4.018068337e-02f, +4.705770477e-02f, +5.244726189e-02f, +5.574009777e-02f, +5.655026396e-02f, +5.478132634e-02f, +5.064310236e-02f, +4.461534144e-02f, +3.736611920e-02f, +2.964217216e-02f, +2.215368059e-02f, +1.547595434e-02f, +9.985325752e-03f, +5.837830254e-03f, +2.989308098e-03f, +1.246901403e-03f,
- /* 24,14 */ +5.494305796e-04f, +1.688282347e-03f, +3.749328623e-03f, +6.988790100e-03f, +1.155988996e-02f, +1.744855617e-02f, +2.443025293e-02f, +3.206210284e-02f, +3.971789474e-02f, +4.666426010e-02f, +5.216645963e-02f, +5.560438923e-02f, +5.657574693e-02f, +5.496495842e-02f, +5.096323022e-02f, +4.503543229e-02f, +3.784089895e-02f, +3.012488684e-02f, +2.260301890e-02f, +1.586133102e-02f, +1.028967374e-02f, +6.057656813e-03f, +3.132379333e-03f, +1.328380648e-03f,
- /* 24,15 */ +5.022154476e-04f, +1.593065611e-03f, +3.588275667e-03f, +6.748179094e-03f, +1.123445076e-02f, +1.704503934e-02f, +2.396921539e-02f, +3.157717954e-02f, +3.925233583e-02f, +4.626513642e-02f, +5.187752167e-02f, +5.545895049e-02f, +5.659104154e-02f, +5.513916011e-02f, +5.127577001e-02f, +4.545054680e-02f, +3.831365198e-02f, +3.060840342e-02f, +2.305547031e-02f, +1.625135142e-02f, +1.059932179e-02f, +6.282638036e-03f, +3.279858311e-03f, +1.413186400e-03f,
- /* 24, 0 */ -1.127794091e-03f, -1.412146034e-03f, -3.831821143e-04f, +3.227045776e-03f, +1.066768284e-02f, +2.270769386e-02f, +3.918787347e-02f, +5.876378120e-02f, +7.897914846e-02f, +9.670702233e-02f, +1.088639494e-01f, +1.131922811e-01f, +1.088639494e-01f, +9.670702233e-02f, +7.897914846e-02f, +5.876378120e-02f, +3.918787347e-02f, +2.270769386e-02f, +1.066768284e-02f, +3.227045776e-03f, -3.831821143e-04f, -1.412146034e-03f, -1.127794091e-03f, -4.881068065e-04f,
- /* 24, 1 */ -1.090580766e-03f, -1.420873386e-03f, -5.091873886e-04f, +2.900756187e-03f, +1.007202248e-02f, +2.181774373e-02f, +3.804709217e-02f, +5.749143322e-02f, +7.775467878e-02f, +9.573284944e-02f, +1.083163184e-01f, +1.131750947e-01f, +1.093805191e-01f, +9.765915788e-02f, +8.019389052e-02f, +6.003885715e-02f, +4.034112484e-02f, +2.361538773e-02f, +1.128161899e-02f, +3.568453927e-03f, -2.470940015e-04f, -1.398398357e-03f, -1.163769773e-03f, -5.264712252e-04f,
- /* 24, 2 */ -1.052308046e-03f, -1.424863695e-03f, -6.254426725e-04f, +2.589304991e-03f, +9.494532203e-03f, +2.094570441e-02f, +3.691925193e-02f, +5.622252667e-02f, +7.652128881e-02f, +9.473734332e-02f, +1.077380418e-01f, +1.131235487e-01f, +1.098656350e-01f, +9.858856505e-02f, +8.139809812e-02f, +6.131593665e-02f, +4.150635732e-02f, +2.454063933e-02f, +1.191392194e-02f, +3.925253463e-03f, -1.005901154e-04f, -1.379341793e-03f, -1.198322390e-03f, -5.655319713e-04f,
- /* 24, 3 */ -1.013146991e-03f, -1.424394748e-03f, -7.322803183e-04f, +2.292405169e-03f, +8.935092066e-03f, +2.009172411e-02f, +3.580480556e-02f, +5.495776346e-02f, +7.527978553e-02f, +9.372122042e-02f, +1.071295572e-01f, +1.130376830e-01f, +1.103189277e-01f, +9.949456662e-02f, +8.259096568e-02f, +6.259428489e-02f, +4.268306423e-02f, +2.548324354e-02f, +1.256466766e-02f, +4.297709369e-03f, +5.666214823e-05f, -1.354682733e-03f, -1.231259367e-03f, -6.052075404e-04f,
- /* 24, 4 */ -9.732614753e-04f, -1.419738627e-03f, -8.300317840e-04f, +2.009763334e-03f, +8.393568260e-03f, +1.925593236e-02f, +3.470418745e-02f, +5.369783330e-02f, +7.403097485e-02f, +9.268520876e-02f, +1.064913245e-01f, +1.129175635e-01f, +1.107400515e-01f, +1.003764999e-01f, +8.377168968e-02f, +6.387315732e-02f, +4.387072153e-02f, +2.644297610e-02f, +1.323391671e-02f, +4.686078310e-03f, +2.249946366e-04f, -1.324122762e-03f, -1.262381011e-03f, -6.454100415e-04f,
- /* 24, 5 */ -9.328082015e-04f, -1.411161525e-03f, -9.190272443e-04f, +1.741080225e-03f, +7.869813543e-03f, +1.843844016e-02f, +3.361781336e-02f, +5.244341325e-02f, +7.277566076e-02f, +9.163004717e-02f, +1.058238246e-01f, +1.127632829e-01f, +1.111286847e-01f, +1.012337173e-01f, +8.493946948e-02f, +6.515180031e-02f, +4.506878807e-02f, +2.741959349e-02f, +1.392171386e-02f, +5.090608136e-03f, +4.047380047e-04f, -1.287358924e-03f, -1.291480556e-03f, -6.860450823e-04f,
- /* 24, 6 */ -8.919367204e-04f, -1.398923562e-03f, -9.995952120e-04f, +1.486051192e-03f, +7.363667669e-03f, +1.763934022e-02f, +3.254608027e-02f, +5.119516710e-02f, +7.151464464e-02f, +9.055648452e-02f, +1.051275597e-01f, +1.125749599e-01f, +1.114845301e-01f, +1.020655875e-01f, +8.609350809e-02f, +6.642945179e-02f, +4.627670593e-02f, +2.841283293e-02f, +1.462808772e-02f, +5.511537402e-03f, +5.962212734e-04f, -1.244083985e-03f, -1.318344226e-03f, -7.270116618e-04f,
- /* 24, 7 */ -8.507894667e-04f, -1.383278624e-03f, -1.072062171e-03f, +1.244366682e-03f, +6.874957829e-03f, +1.685870710e-02f, +3.148936626e-02f, +4.995374490e-02f, +7.024872443e-02f, +8.946527894e-02f, +1.044030520e-01f, +1.123527394e-01f, +1.118073151e-01f, +1.028714955e-01f, +8.723301301e-02f, +6.770534195e-02f, +4.749390083e-02f, +2.942241233e-02f, +1.535305047e-02f, +5.949094883e-03f, +7.997713791e-04f, -1.193986722e-03f, -1.342751302e-03f, -7.682020711e-04f,
- /* 24, 8 */ -8.095018024e-04f, -1.364474212e-03f, -1.136752219e-03f, +1.015712718e-03f, +6.403499096e-03f, +1.609659749e-02f, +3.044803032e-02f, +4.871978245e-02f, +6.897869391e-02f, +8.835719701e-02f, +1.036508436e-01f, +1.120967923e-01f, +1.120967923e-01f, +1.036508436e-01f, +8.835719701e-02f, +6.897869391e-02f, +4.871978245e-02f, +3.044803032e-02f, +1.609659749e-02f, +6.403499096e-03f, +1.015712718e-03f, -1.136752219e-03f, -1.364474212e-03f, -8.095018024e-04f,
- /* 24, 9 */ -7.682020711e-04f, -1.342751302e-03f, -1.193986722e-03f, +7.997713791e-04f, +5.949094883e-03f, +1.535305047e-02f, +2.942241233e-02f, +4.749390083e-02f, +6.770534195e-02f, +8.723301301e-02f, +1.028714955e-01f, +1.118073151e-01f, +1.123527394e-01f, +1.044030520e-01f, +8.946527894e-02f, +7.024872443e-02f, +4.995374490e-02f, +3.148936626e-02f, +1.685870710e-02f, +6.874957829e-03f, +1.244366682e-03f, -1.072062171e-03f, -1.383278624e-03f, -8.507894667e-04f,
- /* 24,10 */ -7.270116618e-04f, -1.318344226e-03f, -1.244083985e-03f, +5.962212734e-04f, +5.511537402e-03f, +1.462808772e-02f, +2.841283293e-02f, +4.627670593e-02f, +6.642945179e-02f, +8.609350809e-02f, +1.020655875e-01f, +1.114845301e-01f, +1.125749599e-01f, +1.051275597e-01f, +9.055648452e-02f, +7.151464464e-02f, +5.119516710e-02f, +3.254608027e-02f, +1.763934022e-02f, +7.363667669e-03f, +1.486051192e-03f, -9.995952120e-04f, -1.398923562e-03f, -8.919367204e-04f,
- /* 24,11 */ -6.860450823e-04f, -1.291480556e-03f, -1.287358924e-03f, +4.047380047e-04f, +5.090608136e-03f, +1.392171386e-02f, +2.741959349e-02f, +4.506878807e-02f, +6.515180031e-02f, +8.493946948e-02f, +1.012337173e-01f, +1.111286847e-01f, +1.127632829e-01f, +1.058238246e-01f, +9.163004717e-02f, +7.277566076e-02f, +5.244341325e-02f, +3.361781336e-02f, +1.843844016e-02f, +7.869813543e-03f, +1.741080225e-03f, -9.190272443e-04f, -1.411161525e-03f, -9.328082015e-04f,
- /* 24,12 */ -6.454100415e-04f, -1.262381011e-03f, -1.324122762e-03f, +2.249946366e-04f, +4.686078310e-03f, +1.323391671e-02f, +2.644297610e-02f, +4.387072153e-02f, +6.387315732e-02f, +8.377168968e-02f, +1.003764999e-01f, +1.107400515e-01f, +1.129175635e-01f, +1.064913245e-01f, +9.268520876e-02f, +7.403097485e-02f, +5.369783330e-02f, +3.470418745e-02f, +1.925593236e-02f, +8.393568260e-03f, +2.009763334e-03f, -8.300317840e-04f, -1.419738627e-03f, -9.732614753e-04f,
- /* 24,13 */ -6.052075404e-04f, -1.231259367e-03f, -1.354682733e-03f, +5.666214823e-05f, +4.297709369e-03f, +1.256466766e-02f, +2.548324354e-02f, +4.268306423e-02f, +6.259428489e-02f, +8.259096568e-02f, +9.949456662e-02f, +1.103189277e-01f, +1.130376830e-01f, +1.071295572e-01f, +9.372122042e-02f, +7.527978553e-02f, +5.495776346e-02f, +3.580480556e-02f, +2.009172411e-02f, +8.935092066e-03f, +2.292405169e-03f, -7.322803183e-04f, -1.424394748e-03f, -1.013146991e-03f,
- /* 24,14 */ -5.655319713e-04f, -1.198322390e-03f, -1.379341793e-03f, -1.005901154e-04f, +3.925253463e-03f, +1.191392194e-02f, +2.454063933e-02f, +4.150635732e-02f, +6.131593665e-02f, +8.139809812e-02f, +9.858856505e-02f, +1.098656350e-01f, +1.131235487e-01f, +1.077380418e-01f, +9.473734332e-02f, +7.652128881e-02f, +5.622252667e-02f, +3.691925193e-02f, +2.094570441e-02f, +9.494532203e-03f, +2.589304991e-03f, -6.254426725e-04f, -1.424863695e-03f, -1.052308046e-03f,
- /* 24,15 */ -5.264712252e-04f, -1.163769773e-03f, -1.398398357e-03f, -2.470940015e-04f, +3.568453927e-03f, +1.128161899e-02f, +2.361538773e-02f, +4.034112484e-02f, +6.003885715e-02f, +8.019389052e-02f, +9.765915788e-02f, +1.093805191e-01f, +1.131750947e-01f, +1.083163184e-01f, +9.573284944e-02f, +7.775467878e-02f, +5.749143322e-02f, +3.804709217e-02f, +2.181774373e-02f, +1.007202248e-02f, +2.900756187e-03f, -5.091873886e-04f, -1.420873386e-03f, -1.090580766e-03f,
- /* 24, 0 */ -6.542299160e-04f, -2.850723396e-03f, -6.490258587e-03f, -9.960104872e-03f, -9.809478345e-03f, -1.578994128e-03f, +1.829834548e-02f, +5.025161588e-02f, +9.015425381e-02f, +1.297327779e-01f, +1.589915292e-01f, +1.697884216e-01f, +1.589915292e-01f, +1.297327779e-01f, +9.015425381e-02f, +5.025161588e-02f, +1.829834548e-02f, -1.578994128e-03f, -9.809478345e-03f, -9.960104872e-03f, -6.490258587e-03f, -2.850723396e-03f, -6.542299160e-04f, +6.349952235e-05f,
- /* 24, 1 */ -5.715660670e-04f, -2.664319167e-03f, -6.241370053e-03f, -9.805460951e-03f, -1.000906214e-02f, -2.409006146e-03f, +1.668518463e-02f, +4.795494216e-02f, +8.756853655e-02f, +1.274593023e-01f, +1.576392865e-01f, +1.697451719e-01f, +1.602699418e-01f, +1.319653222e-01f, +9.273931864e-02f, +5.258078166e-02f, +1.996024013e-02f, -7.024321916e-04f, -9.578061730e-03f, -1.010098516e-02f, -6.739131402e-03f, -3.043301383e-03f, -7.429059724e-04f, +4.968305000e-05f,
- /* 24, 2 */ -4.947700224e-04f, -2.484234158e-03f, -5.993080931e-03f, -9.638098137e-03f, -1.017794029e-02f, -3.193110201e-03f, +1.512113085e-02f, +4.569233080e-02f, +8.498458400e-02f, +1.251473534e-01f, +1.562147818e-01f, +1.696154741e-01f, +1.614730379e-01f, +1.341545065e-01f, +9.532128436e-02f, +5.494080034e-02f, +2.167042077e-02f, +2.212715669e-04f, -9.313697641e-03f, -1.022703863e-02f, -6.987342300e-03f, -3.241882098e-03f, -8.377276082e-04f, +3.267464436e-05f,
- /* 24, 3 */ -4.236872966e-04f, -2.310589033e-03f, -5.745975157e-03f, -9.459041324e-03f, -1.031725016e-02f, -3.931996122e-03f, +1.360648366e-02f, +4.346528177e-02f, +8.240478048e-02f, +1.227994149e-01f, +1.547196623e-01f, +1.693994819e-01f, +1.625994153e-01f, +1.362979353e-01f, +9.789767810e-02f, +5.732996534e-02f, +2.342836441e-02f, +1.192656872e-03f, -9.015286272e-03f, -1.033718507e-02f, -7.234214214e-03f, -3.446268223e-03f, -9.388162067e-04f, +1.226776811e-05f,
- /* 24, 4 */ -3.581542611e-04f, -2.143480447e-03f, -5.500605429e-03f, -9.269294257e-03f, -1.042813706e-02f, -4.626399385e-03f, +1.214146970e-02f, +4.127522351e-02f, +7.983147433e-02f, +1.204179923e-01f, +1.531556516e-01f, +1.690974512e-01f, +1.636477581e-01f, +1.383932498e-01f, +1.004660042e-01f, +5.974650439e-02f, +2.523347234e-02f, +2.212209196e-03f, -8.681745020e-03f, -1.043032883e-02f, -7.479039479e-03f, -3.656235461e-03f, -1.046280200e-03f, -1.174474466e-05f,
- /* 24, 5 */ -2.979990698e-04f, -1.982981877e-03f, -5.257493218e-03f, -9.069838305e-03f, -1.051175200e-02f, -5.277098842e-03f, +1.072624378e-02f, +3.912351177e-02f, +7.726697481e-02f, +1.180056089e-01f, +1.515245471e-01f, +1.687097397e-01f, +1.646168392e-01f, +1.404381320e-01f, +1.030237476e-01f, +6.218858132e-02f, +2.708506973e-02f, +3.280357753e-03f, -8.312010872e-03f, -1.050536039e-02f, -7.721080180e-03f, -3.871531888e-03f, -1.160214103e-03f, -3.957001380e-05f,
- /* 24, 6 */ -2.430425717e-04f, -1.829144469e-03f, -5.017128860e-03f, -8.861631306e-03f, -1.056924947e-02f, -5.884914422e-03f, +9.360889972e-03f, +3.701142868e-02f, +7.471354913e-02f, +1.155648023e-01f, +1.498282170e-01f, +1.682368061e-01f, +1.655055219e-01f, +1.424303080e-01f, +1.055683777e-01f, +6.465429798e-02f, +2.898240538e-02f, +4.397473555e-03f, -7.905042791e-03f, -1.056115807e-02f, -7.959568583e-03f, -4.091877352e-03f, -1.280697546e-03f, -7.141440876e-05f,
- /* 24, 7 */ -1.930992056e-04f, -1.681997919e-03f, -4.779971710e-03f, -8.645606504e-03f, -1.060178532e-02f, -6.450704795e-03f, +8.045422842e-03f, +3.494018190e-02f, +7.217341954e-02f, +1.130981205e-01f, +1.480685972e-01f, +1.676792097e-01f, +1.663127619e-01f, +1.443675516e-01f, +1.080973515e-01f, +6.714169632e-02f, +3.092465153e-02f, +5.563867546e-03f, -7.459824124e-03f, -1.059658974e-02f, -8.193707637e-03f, -4.316962918e-03f, -1.407794310e-03f, -1.074828157e-04f,
- /* 24, 8 */ -1.479778772e-04f, -1.541551365e-03f, -4.546450360e-03f, -8.422671559e-03f, -1.061051465e-02f, -6.975365011e-03f, +6.779788805e-03f, +3.291090392e-02f, +6.964876056e-02f, +1.106081178e-01f, +1.462476880e-01f, +1.670376092e-01f, +1.670376092e-01f, +1.462476880e-01f, +1.106081178e-01f, +6.964876056e-02f, +3.291090392e-02f, +6.779788805e-03f, -6.975365011e-03f, -1.061051465e-02f, -8.422671559e-03f, -4.546450360e-03f, -1.541551365e-03f, -1.479778772e-04f,
- /* 24, 9 */ -1.074828157e-04f, -1.407794310e-03f, -4.316962918e-03f, -8.193707637e-03f, -1.059658974e-02f, -7.459824124e-03f, +5.563867546e-03f, +3.092465153e-02f, +6.714169632e-02f, +1.080973515e-01f, +1.443675516e-01f, +1.663127619e-01f, +1.676792097e-01f, +1.480685972e-01f, +1.130981205e-01f, +7.217341954e-02f, +3.494018190e-02f, +8.045422842e-03f, -6.450704795e-03f, -1.060178532e-02f, -8.645606504e-03f, -4.779971710e-03f, -1.681997919e-03f, -1.930992056e-04f,
- /* 24,10 */ -7.141440876e-05f, -1.280697546e-03f, -4.091877352e-03f, -7.959568583e-03f, -1.056115807e-02f, -7.905042791e-03f, +4.397473555e-03f, +2.898240538e-02f, +6.465429798e-02f, +1.055683777e-01f, +1.424303080e-01f, +1.655055219e-01f, +1.682368061e-01f, +1.498282170e-01f, +1.155648023e-01f, +7.471354913e-02f, +3.701142868e-02f, +9.360889972e-03f, -5.884914422e-03f, -1.056924947e-02f, -8.861631306e-03f, -5.017128860e-03f, -1.829144469e-03f, -2.430425717e-04f,
- /* 24,11 */ -3.957001380e-05f, -1.160214103e-03f, -3.871531888e-03f, -7.721080180e-03f, -1.050536039e-02f, -8.312010872e-03f, +3.280357753e-03f, +2.708506973e-02f, +6.218858132e-02f, +1.030237476e-01f, +1.404381320e-01f, +1.646168392e-01f, +1.687097397e-01f, +1.515245471e-01f, +1.180056089e-01f, +7.726697481e-02f, +3.912351177e-02f, +1.072624378e-02f, -5.277098842e-03f, -1.051175200e-02f, -9.069838305e-03f, -5.257493218e-03f, -1.982981877e-03f, -2.979990698e-04f,
- /* 24,12 */ -1.174474466e-05f, -1.046280200e-03f, -3.656235461e-03f, -7.479039479e-03f, -1.043032883e-02f, -8.681745020e-03f, +2.212209196e-03f, +2.523347234e-02f, +5.974650439e-02f, +1.004660042e-01f, +1.383932498e-01f, +1.636477581e-01f, +1.690974512e-01f, +1.531556516e-01f, +1.204179923e-01f, +7.983147433e-02f, +4.127522351e-02f, +1.214146970e-02f, -4.626399385e-03f, -1.042813706e-02f, -9.269294257e-03f, -5.500605429e-03f, -2.143480447e-03f, -3.581542611e-04f,
- /* 24,13 */ +1.226776811e-05f, -9.388162067e-04f, -3.446268223e-03f, -7.234214214e-03f, -1.033718507e-02f, -9.015286272e-03f, +1.192656872e-03f, +2.342836441e-02f, +5.732996534e-02f, +9.789767810e-02f, +1.362979353e-01f, +1.625994153e-01f, +1.693994819e-01f, +1.547196623e-01f, +1.227994149e-01f, +8.240478048e-02f, +4.346528177e-02f, +1.360648366e-02f, -3.931996122e-03f, -1.031725016e-02f, -9.459041324e-03f, -5.745975157e-03f, -2.310589033e-03f, -4.236872966e-04f,
- /* 24,14 */ +3.267464436e-05f, -8.377276082e-04f, -3.241882098e-03f, -6.987342300e-03f, -1.022703863e-02f, -9.313697641e-03f, +2.212715669e-04f, +2.167042077e-02f, +5.494080034e-02f, +9.532128436e-02f, +1.341545065e-01f, +1.614730379e-01f, +1.696154741e-01f, +1.562147818e-01f, +1.251473534e-01f, +8.498458400e-02f, +4.569233080e-02f, +1.512113085e-02f, -3.193110201e-03f, -1.017794029e-02f, -9.638098137e-03f, -5.993080931e-03f, -2.484234158e-03f, -4.947700224e-04f,
- /* 24,15 */ +4.968305000e-05f, -7.429059724e-04f, -3.043301383e-03f, -6.739131402e-03f, -1.010098516e-02f, -9.578061730e-03f, -7.024321916e-04f, +1.996024013e-02f, +5.258078166e-02f, +9.273931864e-02f, +1.319653222e-01f, +1.602699418e-01f, +1.697451719e-01f, +1.576392865e-01f, +1.274593023e-01f, +8.756853655e-02f, +4.795494216e-02f, +1.668518463e-02f, -2.409006146e-03f, -1.000906214e-02f, -9.805460951e-03f, -6.241370053e-03f, -2.664319167e-03f, -5.715660670e-04f,
- /* 24, 0 */ +1.619229527e-03f, +2.585184252e-03f, +7.650378125e-04f, -6.171975840e-03f, -1.695416291e-02f, -2.423274385e-02f, -1.612533623e-02f, +1.737483974e-02f, +7.628093610e-02f, +1.465254238e-01f, +2.041060488e-01f, +2.263845622e-01f, +2.041060488e-01f, +1.465254238e-01f, +7.628093610e-02f, +1.737483974e-02f, -1.612533623e-02f, -2.423274385e-02f, -1.695416291e-02f, -6.171975840e-03f, +7.650378125e-04f, +2.585184252e-03f, +1.619229527e-03f, +4.203426526e-04f,
- /* 24, 1 */ +1.531668339e-03f, +2.575087939e-03f, +1.015030141e-03f, -5.584253498e-03f, -1.627529113e-02f, -2.409742304e-02f, -1.730694612e-02f, +1.446720847e-02f, +7.205349539e-02f, +1.422361210e-01f, +2.013530187e-01f, +2.262942875e-01f, +2.067165090e-01f, +1.507648574e-01f, +8.055624103e-02f, +2.038667606e-02f, -1.484111026e-02f, -2.430745079e-02f, -1.762106127e-02f, -6.776879595e-03f, +4.938567092e-04f, +2.584413048e-03f, +1.706479068e-03f, +4.743886054e-04f,
- /* 24, 2 */ +1.444251783e-03f, +2.554897668e-03f, +1.244217996e-03f, -5.014646771e-03f, -1.558700841e-02f, -2.390468713e-02f, -1.838770218e-02f, +1.166535016e-02f, +6.787901036e-02f, +1.379034790e-01f, +1.984620386e-01f, +2.260236194e-01f, +2.091800031e-01f, +1.549479100e-01f, +8.487414623e-02f, +2.350091114e-02f, -1.345266938e-02f, -2.431836796e-02f, -1.827334019e-02f, -7.397926552e-03f, +2.011593926e-04f, +2.571998910e-03f, +1.792931314e-03f, +5.318997770e-04f,
- /* 24, 3 */ +1.357406375e-03f, +2.525382259e-03f, +1.453038602e-03f, -4.463987325e-03f, -1.489178967e-02f, -2.365774922e-02f, -1.936952211e-02f, +8.970595311e-03f, +6.376239146e-02f, +1.335340325e-01f, +1.954379419e-01f, +2.255730254e-01f, +2.114923689e-01f, +1.590681020e-01f, +8.922922426e-02f, +2.671549986e-02f, -1.195858585e-02f, -2.426235104e-02f, -1.890827435e-02f, -8.033973302e-03f, -1.133208208e-04f, +2.547167581e-03f, +1.878071789e-03f, +5.928148062e-04f,
- /* 24, 4 */ +1.271528621e-03f, +2.487303056e-03f, +1.641978155e-03f, -3.933006021e-03f, -1.419201875e-02f, -2.335982837e-02f, -2.025447087e-02f, +6.384038515e-03f, +5.970836021e-02f, +1.291343068e-01f, +1.922857641e-01f, +2.249432832e-01f, +2.136496877e-01f, +1.631190001e-01f, +9.361589375e-02f, +3.002815853e-02f, -1.035761042e-02f, -2.413629608e-02f, -1.952306378e-02f, -8.683770335e-03f, -4.497860188e-04f, +2.509149105e-03f, +1.961357874e-03f, +6.570484107e-04f,
- /* 24, 5 */ +1.186984902e-03f, +2.441411339e-03f, +1.811567846e-03f, -3.422334900e-03f, -1.348998519e-02f, -2.301414142e-02f, -2.104475231e-02f, +3.906540614e-03f, +5.572144173e-02f, +1.247108046e-01f, +1.890107314e-01f, +2.241354793e-01f, +2.156482934e-01f, +1.670942309e-01f, +9.802842938e-02f, +3.343636564e-02f, -8.648679404e-03f, -2.393714847e-02f, -2.011483893e-02f, -9.345961431e-03f, -8.083699235e-04f, +2.457181100e-03f, +2.042219659e-03f, +7.244903794e-04f,
- /* 24, 6 */ +1.104111497e-03f, +2.388445882e-03f, +1.962379900e-03f, -2.932509404e-03f, -1.278788140e-02f, -2.262389503e-02f, -2.174270056e-02f, +1.538731332e-03f, +5.180595798e-02f, +1.202699924e-01f, +1.856182490e-01f, +2.231510062e-01f, +2.174847808e-01f, +1.709874949e-01f, +1.024609723e-01f, +3.693736330e-02f, -6.830921421e-03f, -2.366191192e-02f, -2.068066597e-02f, -1.001908338e-02f, -1.189134206e-03f, +2.390512141e-03f, +2.120060933e-03f, +7.950046334e-04f,
- /* 24, 7 */ +1.023214729e-03f, +2.329130668e-03f, +2.095023622e-03f, -2.463970822e-03f, -1.208780014e-02f, -2.219227795e-02f, -2.235077131e-02f, -7.189875350e-04f, +4.796602143e-02f, +1.158182872e-01f, +1.821138888e-01f, +2.219915591e-01f, +2.191560137e-01f, +1.747925803e-01f, +1.069075413e-01f, +4.052815924e-02f, -4.903663772e-03f, -2.330765754e-02f, -2.121755248e-02f, -1.070156599e-02f, -1.592064902e-03f, +2.308405249e-03f, +2.194260355e-03f, +8.684283615e-04f,
- /* 24, 8 */ +9.445712380e-04f, +2.264172764e-03f, +2.210141486e-03f, -2.017068943e-03f, -1.139173248e-02f, -2.172245353e-02f, -2.287153293e-02f, -2.866438416e-03f, +4.420552946e-02f, +1.113620436e-01f, +1.785033768e-01f, +2.206591322e-01f, +2.206591322e-01f, +1.785033768e-01f, +1.113620436e-01f, +4.420552946e-02f, -2.866438416e-03f, -2.287153293e-02f, -2.172245353e-02f, -1.139173248e-02f, -2.017068943e-03f, +2.210141486e-03f, +2.264172764e-03f, +9.445712380e-04f,
- /* 24, 9 */ +8.684283615e-04f, +2.194260355e-03f, +2.308405249e-03f, -1.592064902e-03f, -1.070156599e-02f, -2.121755248e-02f, -2.330765754e-02f, -4.903663772e-03f, +4.052815924e-02f, +1.069075413e-01f, +1.747925803e-01f, +2.191560137e-01f, +2.219915591e-01f, +1.821138888e-01f, +1.158182872e-01f, +4.796602143e-02f, -7.189875350e-04f, -2.235077131e-02f, -2.219227795e-02f, -1.208780014e-02f, -2.463970822e-03f, +2.095023622e-03f, +2.329130668e-03f, +1.023214729e-03f,
- /* 24,10 */ +7.950046334e-04f, +2.120060933e-03f, +2.390512141e-03f, -1.189134206e-03f, -1.001908338e-02f, -2.068066597e-02f, -2.366191192e-02f, -6.830921421e-03f, +3.693736330e-02f, +1.024609723e-01f, +1.709874949e-01f, +2.174847808e-01f, +2.231510062e-01f, +1.856182490e-01f, +1.202699924e-01f, +5.180595798e-02f, +1.538731332e-03f, -2.174270056e-02f, -2.262389503e-02f, -1.278788140e-02f, -2.932509404e-03f, +1.962379900e-03f, +2.388445882e-03f, +1.104111497e-03f,
- /* 24,11 */ +7.244903794e-04f, +2.042219659e-03f, +2.457181100e-03f, -8.083699235e-04f, -9.345961431e-03f, -2.011483893e-02f, -2.393714847e-02f, -8.648679404e-03f, +3.343636564e-02f, +9.802842938e-02f, +1.670942309e-01f, +2.156482934e-01f, +2.241354793e-01f, +1.890107314e-01f, +1.247108046e-01f, +5.572144173e-02f, +3.906540614e-03f, -2.104475231e-02f, -2.301414142e-02f, -1.348998519e-02f, -3.422334900e-03f, +1.811567846e-03f, +2.441411339e-03f, +1.186984902e-03f,
- /* 24,12 */ +6.570484107e-04f, +1.961357874e-03f, +2.509149105e-03f, -4.497860188e-04f, -8.683770335e-03f, -1.952306378e-02f, -2.413629608e-02f, -1.035761042e-02f, +3.002815853e-02f, +9.361589375e-02f, +1.631190001e-01f, +2.136496877e-01f, +2.249432832e-01f, +1.922857641e-01f, +1.291343068e-01f, +5.970836021e-02f, +6.384038515e-03f, -2.025447087e-02f, -2.335982837e-02f, -1.419201875e-02f, -3.933006021e-03f, +1.641978155e-03f, +2.487303056e-03f, +1.271528621e-03f,
- /* 24,13 */ +5.928148062e-04f, +1.878071789e-03f, +2.547167581e-03f, -1.133208208e-04f, -8.033973302e-03f, -1.890827435e-02f, -2.426235104e-02f, -1.195858585e-02f, +2.671549986e-02f, +8.922922426e-02f, +1.590681020e-01f, +2.114923689e-01f, +2.255730254e-01f, +1.954379419e-01f, +1.335340325e-01f, +6.376239146e-02f, +8.970595311e-03f, -1.936952211e-02f, -2.365774922e-02f, -1.489178967e-02f, -4.463987325e-03f, +1.453038602e-03f, +2.525382259e-03f, +1.357406375e-03f,
- /* 24,14 */ +5.318997770e-04f, +1.792931314e-03f, +2.571998910e-03f, +2.011593926e-04f, -7.397926552e-03f, -1.827334019e-02f, -2.431836796e-02f, -1.345266938e-02f, +2.350091114e-02f, +8.487414623e-02f, +1.549479100e-01f, +2.091800031e-01f, +2.260236194e-01f, +1.984620386e-01f, +1.379034790e-01f, +6.787901036e-02f, +1.166535016e-02f, -1.838770218e-02f, -2.390468713e-02f, -1.558700841e-02f, -5.014646771e-03f, +1.244217996e-03f, +2.554897668e-03f, +1.444251783e-03f,
- /* 24,15 */ +4.743886054e-04f, +1.706479068e-03f, +2.584413048e-03f, +4.938567092e-04f, -6.776879595e-03f, -1.762106127e-02f, -2.430745079e-02f, -1.484111026e-02f, +2.038667606e-02f, +8.055624103e-02f, +1.507648574e-01f, +2.067165090e-01f, +2.262942875e-01f, +2.013530187e-01f, +1.422361210e-01f, +7.205349539e-02f, +1.446720847e-02f, -1.730694612e-02f, -2.409742304e-02f, -1.627529113e-02f, -5.584253498e-03f, +1.015030141e-03f, +2.575087939e-03f, +1.531668339e-03f,
- /* 24, 0 */ -5.620806651e-04f, +1.786951327e-03f, +6.445247430e-03f, +8.135220753e-03f, -1.055728075e-03f, -2.182587186e-02f, -3.862210468e-02f, -2.392616717e-02f, +4.121375257e-02f, +1.449837419e-01f, +2.427850309e-01f, +2.829807027e-01f, +2.427850309e-01f, +1.449837419e-01f, +4.121375257e-02f, -2.392616717e-02f, -3.862210468e-02f, -2.182587186e-02f, -1.055728075e-03f, +8.135220753e-03f, +6.445247430e-03f, +1.786951327e-03f, -5.620806651e-04f, -5.120724112e-04f,
- /* 24, 1 */ -6.104492932e-04f, +1.548760636e-03f, +6.159105160e-03f, +8.277197332e-03f, -7.779733613e-05f, -2.039475337e-02f, -3.819819741e-02f, -2.624621678e-02f, +3.569722776e-02f, +1.380982730e-01f, +2.379020609e-01f, +2.828154582e-01f, +2.474326717e-01f, +1.518487179e-01f, +4.689321837e-02f, -2.139810919e-02f, -3.892035913e-02f, -2.324619800e-02f, -2.084809535e-03f, +7.948411519e-03f, +6.721048149e-03f, +2.036121529e-03f, -5.037148469e-04f, -5.469834647e-04f,
- /* 24, 2 */ -6.493280747e-04f, +1.322056610e-03f, +5.864617557e-03f, +8.376206823e-03f, +8.476165560e-04f, -1.895882060e-02f, -3.765599422e-02f, -2.836041007e-02f, +3.035103267e-02f, +1.312062799e-01f, +2.327950895e-01f, +2.823201223e-01f, +2.518341522e-01f, +1.586790922e-01f, +5.272765217e-02f, -1.866041870e-02f, -3.908572584e-02f, -2.464952038e-02f, -3.163389088e-03f, +7.715013258e-03f, +6.984447000e-03f, +2.295668536e-03f, -4.348733531e-04f, -5.801620624e-04f,
- /* 24, 3 */ -6.792484933e-04f, +1.107253309e-03f, +5.563710253e-03f, +8.434210700e-03f, +1.719427448e-03f, -1.752380524e-02f, -3.700294628e-02f, -3.027140813e-02f, +2.518195985e-02f, +1.243215533e-01f, +2.274759065e-01f, +2.814958870e-01f, +2.559791715e-01f, +1.654606562e-01f, +5.870851072e-02f, -1.571201688e-02f, -3.911111998e-02f, -2.602940857e-02f, -4.289522020e-03f, +7.433392157e-03f, +7.233326681e-03f, +2.564892035e-03f, -3.551113499e-04f, -6.111213026e-04f,
- /* 24, 4 */ -7.007615573e-04f, +9.046745282e-04f, +5.258232435e-03f, +8.453253159e-03f, +2.536821717e-03f, -1.609518093e-02f, -3.624657153e-02f, -3.198236083e-02f, +2.019619593e-02f, +1.174576676e-01f, +2.219567270e-01f, +2.803447347e-01f, +2.598579915e-01f, +1.721791413e-01f, +6.482669661e-02f, -1.255238605e-02f, -3.898963496e-02f, -2.737922870e-02f, -5.460966964e-03f, +7.102050305e-03f, +7.465520628e-03f, +2.842992490e-03f, -2.640225027e-04f, -6.393525967e-04f,
- /* 24, 5 */ -7.144333056e-04f, +7.145569834e-04f, +4.949951622e-03f, +8.435448103e-03f, +3.299249997e-03f, -1.467815287e-02f, -3.539442781e-02f, -3.349688539e-02f, +1.539931407e-02f, +1.106279448e-01f, +2.162501543e-01f, +2.788694321e-01f, +2.634614666e-01f, +1.788202595e-01f, +7.107257652e-02f, -9.181583996e-03f, -3.871457066e-02f, -2.869216031e-02f, -6.675182397e-03f, +6.719638981e-03f, +7.678821339e-03f, +3.129069982e-03f, -1.612438490e-04f, -6.643278432e-04f,
- /* 24, 6 */ -7.208404573e-04f, +5.370537968e-04f, +4.640549073e-03f, +8.382966356e-03f, +4.006418111e-03f, -1.327764882e-02f, -3.445408633e-02f, -3.481904366e-02f, +1.079626845e-02f, +1.038454185e-01f, +2.103691410e-01f, +2.770735210e-01f, +2.667810728e-01f, +1.853697450e-01f, +7.743600141e-02f, -5.600256400e-03f, -3.827946167e-02f, -2.996121443e-02f, -7.929324241e-03f, +6.284971816e-03f, +7.870989279e-03f, +3.422123547e-03f, -4.646067064e-05f, -6.855018549e-04f,
- /* 24, 7 */ -7.205662235e-04f, +3.722382714e-04f, +4.331615834e-03f, +8.298023138e-03f, +4.658277300e-03f, -1.189831143e-02f, -3.343310598e-02f, -3.595331849e-02f, +6.391391026e-03f, +9.712280024e-02f, +2.043269499e-01f, +2.749613076e-01f, +2.698089343e-01f, +1.918133956e-01f, +8.390632879e-02f, -1.809647645e-03f, -3.767810524e-02f, -3.117925279e-02f, -9.220244622e-03f, +5.797037759e-03f, +8.039762345e-03f, +3.721051017e-03f, +8.058866307e-05f, -7.023150347e-04f,
- /* 24, 8 */ -7.141962964e-04f, +2.201079121e-04f, +4.024649403e-03f, +8.182865872e-03f, +5.255013788e-03f, -1.054449181e-02f, -3.233900821e-02f, -3.690458903e-02f, +2.188390323e-03f, +9.047244679e-02f, +1.981371140e-01f, +2.725378483e-01f, +2.725378483e-01f, +1.981371140e-01f, +9.047244679e-02f, +2.188390323e-03f, -3.690458903e-02f, -3.233900821e-02f, -1.054449181e-02f, +5.255013788e-03f, +8.182865872e-03f, +4.024649403e-03f, +2.201079121e-04f, -7.141962964e-04f,
- /* 24, 9 */ -7.023150347e-04f, +8.058866307e-05f, +3.721051017e-03f, +8.039762345e-03f, +5.797037759e-03f, -9.220244622e-03f, -3.117925279e-02f, -3.767810524e-02f, -1.809647645e-03f, +8.390632879e-02f, +1.918133956e-01f, +2.698089343e-01f, +2.749613076e-01f, +2.043269499e-01f, +9.712280024e-02f, +6.391391026e-03f, -3.595331849e-02f, -3.343310598e-02f, -1.189831143e-02f, +4.658277300e-03f, +8.298023138e-03f, +4.331615834e-03f, +3.722382714e-04f, -7.205662235e-04f,
- /* 24,10 */ -6.855018549e-04f, -4.646067064e-05f, +3.422123547e-03f, +7.870989279e-03f, +6.284971816e-03f, -7.929324241e-03f, -2.996121443e-02f, -3.827946167e-02f, -5.600256400e-03f, +7.743600141e-02f, +1.853697450e-01f, +2.667810728e-01f, +2.770735210e-01f, +2.103691410e-01f, +1.038454185e-01f, +1.079626845e-02f, -3.481904366e-02f, -3.445408633e-02f, -1.327764882e-02f, +4.006418111e-03f, +8.382966356e-03f, +4.640549073e-03f, +5.370537968e-04f, -7.208404573e-04f,
- /* 24,11 */ -6.643278432e-04f, -1.612438490e-04f, +3.129069982e-03f, +7.678821339e-03f, +6.719638981e-03f, -6.675182397e-03f, -2.869216031e-02f, -3.871457066e-02f, -9.181583996e-03f, +7.107257652e-02f, +1.788202595e-01f, +2.634614666e-01f, +2.788694321e-01f, +2.162501543e-01f, +1.106279448e-01f, +1.539931407e-02f, -3.349688539e-02f, -3.539442781e-02f, -1.467815287e-02f, +3.299249997e-03f, +8.435448103e-03f, +4.949951622e-03f, +7.145569834e-04f, -7.144333056e-04f,
- /* 24,12 */ -6.393525967e-04f, -2.640225027e-04f, +2.842992490e-03f, +7.465520628e-03f, +7.102050305e-03f, -5.460966964e-03f, -2.737922870e-02f, -3.898963496e-02f, -1.255238605e-02f, +6.482669661e-02f, +1.721791413e-01f, +2.598579915e-01f, +2.803447347e-01f, +2.219567270e-01f, +1.174576676e-01f, +2.019619593e-02f, -3.198236083e-02f, -3.624657153e-02f, -1.609518093e-02f, +2.536821717e-03f, +8.453253159e-03f, +5.258232435e-03f, +9.046745282e-04f, -7.007615573e-04f,
- /* 24,13 */ -6.111213026e-04f, -3.551113499e-04f, +2.564892035e-03f, +7.233326681e-03f, +7.433392157e-03f, -4.289522020e-03f, -2.602940857e-02f, -3.911111998e-02f, -1.571201688e-02f, +5.870851072e-02f, +1.654606562e-01f, +2.559791715e-01f, +2.814958870e-01f, +2.274759065e-01f, +1.243215533e-01f, +2.518195985e-02f, -3.027140813e-02f, -3.700294628e-02f, -1.752380524e-02f, +1.719427448e-03f, +8.434210700e-03f, +5.563710253e-03f, +1.107253309e-03f, -6.792484933e-04f,
- /* 24,14 */ -5.801620624e-04f, -4.348733531e-04f, +2.295668536e-03f, +6.984447000e-03f, +7.715013258e-03f, -3.163389088e-03f, -2.464952038e-02f, -3.908572584e-02f, -1.866041870e-02f, +5.272765217e-02f, +1.586790922e-01f, +2.518341522e-01f, +2.823201223e-01f, +2.327950895e-01f, +1.312062799e-01f, +3.035103267e-02f, -2.836041007e-02f, -3.765599422e-02f, -1.895882060e-02f, +8.476165560e-04f, +8.376206823e-03f, +5.864617557e-03f, +1.322056610e-03f, -6.493280747e-04f,
- /* 24,15 */ -5.469834647e-04f, -5.037148469e-04f, +2.036121529e-03f, +6.721048149e-03f, +7.948411519e-03f, -2.084809535e-03f, -2.324619800e-02f, -3.892035913e-02f, -2.139810919e-02f, +4.689321837e-02f, +1.518487179e-01f, +2.474326717e-01f, +2.828154582e-01f, +2.379020609e-01f, +1.380982730e-01f, +3.569722776e-02f, -2.624621678e-02f, -3.819819741e-02f, -2.039475337e-02f, -7.779733613e-05f, +8.277197332e-03f, +6.159105160e-03f, +1.548760636e-03f, -6.104492932e-04f,
- /* 24, 0 */ -1.197013499e-03f, -3.320493122e-03f, -1.144245270e-03f, +8.577337679e-03f, +1.627759141e-02f, +3.152522439e-03f, -3.255249254e-02f, -5.362651723e-02f, -5.304244056e-03f, +1.253006387e-01f, +2.738089134e-01f, +3.395768433e-01f, +2.738089134e-01f, +1.253006387e-01f, -5.304244056e-03f, -5.362651723e-02f, -3.255249254e-02f, +3.152522439e-03f, +1.627759141e-02f, +8.577337679e-03f, -1.144245270e-03f, -3.320493122e-03f, -1.197013499e-03f, +1.261205705e-04f,
- /* 24, 1 */ -1.060573898e-03f, -3.246029352e-03f, -1.514205592e-03f, +7.849505167e-03f, +1.622707505e-02f, +4.797556391e-03f, -3.017446993e-02f, -5.385088872e-02f, -1.098434059e-02f, +1.155960124e-01f, +2.659858985e-01f, +3.393017042e-01f, +2.812897341e-01f, +1.350895441e-01f, +7.263382766e-04f, -5.311639759e-02f, -3.488122370e-02f, +1.404407443e-03f, +1.624118609e-02f, +9.301572693e-03f, -7.399572733e-04f, -3.377916464e-03f, -1.338504197e-03f, +9.901282259e-05f,
- /* 24, 2 */ -9.298712414e-04f, -3.156277727e-03f, -1.849729696e-03f, +7.122444811e-03f, +1.609438844e-02f, +6.335978542e-03f, -2.776122262e-02f, -5.380213751e-02f, -1.630850202e-02f, +1.060004951e-01f, +2.578448120e-01f, +3.384771755e-01f, +2.884051592e-01f, +1.449371908e-01f, +7.100538384e-03f, -5.230860749e-02f, -3.714619841e-02f, -4.425295608e-04f, +1.611336946e-02f, +1.001762126e-02f, -3.016869975e-04f, -3.416553196e-03f, -1.484263468e-03f, +6.526428163e-05f,
- /* 24, 3 */ -8.054954021e-04f, -3.052984548e-03f, -2.150934111e-03f, +6.400291527e-03f, +1.588450664e-02f, +7.764974256e-03f, -2.532636892e-02f, -5.349351937e-02f, -2.127269005e-02f, +9.653812261e-02f, +2.494105998e-01f, +3.371059190e-01f, +2.951330020e-01f, +1.548174220e-01f, +1.381006797e-02f, -5.119199897e-02f, -3.933260713e-02f, -2.383292518e-03f, +1.588995194e-02f, +1.072069264e-02f, +1.699725421e-04f, -3.434676821e-03f, -1.633412152e-03f, +2.453170435e-05f,
- /* 24, 4 */ -6.879416803e-04f, -2.937877889e-03f, -2.418147761e-03f, +5.686932142e-03f, +1.560259046e-02f, +9.082429619e-03f, -2.288303213e-02f, -5.293884648e-02f, -2.587426360e-02f, +8.723205545e-02f, +2.407089312e-01f, +3.351923590e-01f, +3.014521813e-01f, +1.647035561e-01f, +2.084522321e-02f, -4.975626781e-02f, -4.142535273e-02f, -4.412143180e-03f, +1.556708209e-02f, +1.140581394e-02f, +6.741710759e-04f, -3.430594409e-03f, -1.784975276e-03f, -2.348660763e-05f,
- /* 24, 5 */ -5.776128643e-04f, -2.812656385e-03f, -2.651898517e-03f, +4.985994150e-03f, +1.525394912e-02f, +1.028691298e-02f, -2.044379769e-02f, -5.215241275e-02f, -3.011195925e-02f, +7.810450253e-02f, +2.317660961e-01f, +3.327426635e-01f, +3.073428069e-01f, +1.745684830e-01f, +2.819489579e-02f, -4.799202051e-02f, -4.340911052e-02f, -6.522599631e-03f, +1.514128438e-02f, +1.206785167e-02f, +1.209792693e-03f, -3.402660968e-03f, -1.937883690e-03f, -7.904503123e-05f,
- /* 24, 6 */ -4.748218959e-04f, -2.678978820e-03f, -2.852899102e-03f, +4.300836533e-03f, +1.484400357e-02f, +1.137765361e-02f, -1.802067434e-02f, -5.114891871e-02f, -3.398586582e-02f, +6.917664952e-02f, +2.226089010e-01f, +3.297647184e-01f, +3.127862620e-01f, +1.843847637e-01f, +3.584659036e-02f, -4.589083871e-02f, -4.526839113e-02f, -8.707438641e-03f, +1.460949637e-02f, +1.270153536e-02f, +1.775448814e-03f, -3.349294247e-03f, -2.090976552e-03f, -1.423449116e-04f,
- /* 24, 7 */ -3.797950945e-04f, -2.538454547e-03f, -3.022032460e-03f, +3.634542645e-03f, +1.437825069e-02f, +1.235451773e-02f, -1.562505912e-02f, -4.994339647e-02f, -3.749739364e-02f, +6.046859273e-02f, +2.132645624e-01f, +3.262680950e-01f, +3.177652787e-01f, +1.941247325e-01f, +4.378644843e-02f, -4.344534054e-02f, -4.698760595e-02f, -1.095870195e-02f, +1.396910503e-02f, +1.330148306e-02f, +2.369472628e-03f, -3.268989872e-03f, -2.243004675e-03f, -2.135289700e-04f,
- /* 24, 8 */ -2.926758839e-04f, -2.392634763e-03f, -3.160336722e-03f, +2.989915102e-03f, +1.386222860e-02f, +1.321798203e-02f, -1.326770657e-02f, -4.855113496e-02f, -4.064923848e-02f, +5.199927852e-02f, +2.037606007e-01f, +3.222640100e-01f, +3.222640100e-01f, +2.037606007e-01f, +5.199927852e-02f, -4.064923848e-02f, -4.855113496e-02f, -1.326770657e-02f, +1.321798203e-02f, +1.386222860e-02f, +2.989915102e-03f, -3.160336722e-03f, -2.392634763e-03f, -2.926758839e-04f,
- /* 24, 9 */ -2.135289700e-04f, -2.243004675e-03f, -3.268989872e-03f, +2.369472628e-03f, +1.330148306e-02f, +1.396910503e-02f, -1.095870195e-02f, -4.698760595e-02f, -4.344534054e-02f, +4.378644843e-02f, +1.941247325e-01f, +3.177652787e-01f, +3.262680950e-01f, +2.132645624e-01f, +6.046859273e-02f, -3.749739364e-02f, -4.994339647e-02f, -1.562505912e-02f, +1.235451773e-02f, +1.437825069e-02f, +3.634542645e-03f, -3.022032460e-03f, -2.538454547e-03f, -3.797950945e-04f,
- /* 24,10 */ -1.423449116e-04f, -2.090976552e-03f, -3.349294247e-03f, +1.775448814e-03f, +1.270153536e-02f, +1.460949637e-02f, -8.707438641e-03f, -4.526839113e-02f, -4.589083871e-02f, +3.584659036e-02f, +1.843847637e-01f, +3.127862620e-01f, +3.297647184e-01f, +2.226089010e-01f, +6.917664952e-02f, -3.398586582e-02f, -5.114891871e-02f, -1.802067434e-02f, +1.137765361e-02f, +1.484400357e-02f, +4.300836533e-03f, -2.852899102e-03f, -2.678978820e-03f, -4.748218959e-04f,
- /* 24,11 */ -7.904503123e-05f, -1.937883690e-03f, -3.402660968e-03f, +1.209792693e-03f, +1.206785167e-02f, +1.514128438e-02f, -6.522599631e-03f, -4.340911052e-02f, -4.799202051e-02f, +2.819489579e-02f, +1.745684830e-01f, +3.073428069e-01f, +3.327426635e-01f, +2.317660961e-01f, +7.810450253e-02f, -3.011195925e-02f, -5.215241275e-02f, -2.044379769e-02f, +1.028691298e-02f, +1.525394912e-02f, +4.985994150e-03f, -2.651898517e-03f, -2.812656385e-03f, -5.776128643e-04f,
- /* 24,12 */ -2.348660763e-05f, -1.784975276e-03f, -3.430594409e-03f, +6.741710759e-04f, +1.140581394e-02f, +1.556708209e-02f, -4.412143180e-03f, -4.142535273e-02f, -4.975626781e-02f, +2.084522321e-02f, +1.647035561e-01f, +3.014521813e-01f, +3.351923590e-01f, +2.407089312e-01f, +8.723205545e-02f, -2.587426360e-02f, -5.293884648e-02f, -2.288303213e-02f, +9.082429619e-03f, +1.560259046e-02f, +5.686932142e-03f, -2.418147761e-03f, -2.937877889e-03f, -6.879416803e-04f,
- /* 24,13 */ +2.453170435e-05f, -1.633412152e-03f, -3.434676821e-03f, +1.699725421e-04f, +1.072069264e-02f, +1.588995194e-02f, -2.383292518e-03f, -3.933260713e-02f, -5.119199897e-02f, +1.381006797e-02f, +1.548174220e-01f, +2.951330020e-01f, +3.371059190e-01f, +2.494105998e-01f, +9.653812261e-02f, -2.127269005e-02f, -5.349351937e-02f, -2.532636892e-02f, +7.764974256e-03f, +1.588450664e-02f, +6.400291527e-03f, -2.150934111e-03f, -3.052984548e-03f, -8.054954021e-04f,
- /* 24,14 */ +6.526428163e-05f, -1.484263468e-03f, -3.416553196e-03f, -3.016869975e-04f, +1.001762126e-02f, +1.611336946e-02f, -4.425295608e-04f, -3.714619841e-02f, -5.230860749e-02f, +7.100538384e-03f, +1.449371908e-01f, +2.884051592e-01f, +3.384771755e-01f, +2.578448120e-01f, +1.060004951e-01f, -1.630850202e-02f, -5.380213751e-02f, -2.776122262e-02f, +6.335978542e-03f, +1.609438844e-02f, +7.122444811e-03f, -1.849729696e-03f, -3.156277727e-03f, -9.298712414e-04f,
- /* 24,15 */ +9.901282259e-05f, -1.338504197e-03f, -3.377916464e-03f, -7.399572733e-04f, +9.301572693e-03f, +1.624118609e-02f, +1.404407443e-03f, -3.488122370e-02f, -5.311639759e-02f, +7.263382766e-04f, +1.350895441e-01f, +2.812897341e-01f, +3.393017042e-01f, +2.659858985e-01f, +1.155960124e-01f, -1.098434059e-02f, -5.385088872e-02f, -3.017446993e-02f, +4.797556391e-03f, +1.622707505e-02f, +7.849505167e-03f, -1.514205592e-03f, -3.246029352e-03f, -1.060573898e-03f,
- /* 20, 0 */ -4.161478318e-03f, -1.410215661e-03f, +1.216462436e-02f, +1.839753508e-02f, -1.019572218e-02f, -5.576407638e-02f, -3.857794503e-02f, +9.869941459e-02f, +2.903842315e-01f, +3.819037908e-01f, +2.903842315e-01f, +9.869941459e-02f, -3.857794503e-02f, -5.576407638e-02f, -1.019572218e-02f, +1.839753508e-02f, +1.216462436e-02f, -1.410215661e-03f, -4.161478318e-03f, -1.002136091e-03f,
- /* 20, 1 */ -4.024812873e-03f, -1.935046598e-03f, +1.120868183e-02f, +1.884704309e-02f, -7.349314558e-03f, -5.377462232e-02f, -4.306909662e-02f, +8.713841011e-02f, +2.797272456e-01f, +3.815142140e-01f, +3.006231905e-01f, +1.105090175e-01f, -3.357053763e-02f, -5.750258783e-02f, -1.313424017e-02f, +1.779561475e-02f, +1.309754391e-02f, -8.338854378e-04f, -4.274968522e-03f, -1.184613130e-03f,
- /* 20, 2 */ -3.867923854e-03f, -2.407896178e-03f, +1.023778220e-02f, +1.914947854e-02f, -4.608279480e-03f, -5.155911253e-02f, -4.704785126e-02f, +7.585987841e-02f, +2.686929243e-01f, +3.803470604e-01f, +3.104047352e-01f, +1.225315522e-01f, -2.804532708e-02f, -5.896552129e-02f, -1.615031726e-02f, +1.703673197e-02f, +1.399907244e-02f, -2.069933478e-04f, -4.362323551e-03f, -1.376799150e-03f,
- /* 20, 3 */ -3.693729756e-03f, -2.828715617e-03f, +9.259646102e-03f, +1.931089692e-02f, -1.984565051e-03f, -4.914254142e-02f, -5.052030051e-02f, +6.489576800e-02f, +2.573230589e-01f, +3.784070525e-01f, +3.196909791e-01f, +1.347297046e-01f, -2.200314505e-02f, -6.012863981e-02f, -1.922814732e-02f, +1.611719780e-02f, +1.486058724e-02f, +4.690483654e-04f, -4.420601658e-03f, -1.577606548e-03f,
- /* 20, 4 */ -3.505092707e-03f, -3.197865053e-03f, +8.281610454e-03f, +1.933799402e-02f, +5.112106557e-04f, -4.654987033e-02f, -5.349467921e-02f, +5.427598051e-02f, +2.456603330e-01f, +3.757020336e-01f, +3.284457292e-01f, +1.470646693e-01f, -1.544725782e-02f, -6.096825350e-02f, -2.235071271e-02f, +1.503425320e-02f, +1.567326271e-02f, +1.192336051e-03f, -4.446907145e-03f, -1.785766437e-03f,
- /* 20, 5 */ -3.304797071e-03f, -3.516087186e-03f, +7.310594668e-03f, +1.923802927e-02f, +2.869766685e-03f, -4.380589142e-02f, -5.598126618e-02f, +4.402826232e-02f, +2.337481127e-01f, +3.722429273e-01f, +3.366346688e-01f, +1.594963158e-01f, -8.383409345e-03f, -6.146136934e-02f, -2.549983702e-02f, +1.378613431e-02f, +1.642812632e-02f, +1.960461229e-03f, -4.438419451e-03f, -1.999828319e-03f,
- /* 20, 6 */ -3.095529963e-03f, -3.784479230e-03f, +6.353071566e-03f, +1.901874863e-02f, +5.083157654e-03f, -4.093509653e-02f, -5.799227582e-02f, +3.417810958e-02f, +2.216302330e-01f, +3.680436800e-01f, +3.442255330e-01f, +1.719833640e-01f, -8.198514564e-04f, -6.158584092e-02f, -2.865624686e-02f, +1.237213363e-02f, +1.711611824e-02f, +2.770500592e-03f, -4.392423280e-03f, -2.218161540e-03f,
- /* 20, 7 */ -2.879863731e-03f, -4.004463491e-03f, +5.415043050e-03f, +1.868830751e-02f, +7.144763866e-03f, -3.796155187e-02f, -5.954174144e-02f, +2.474868675e-02f, +2.093507858e-01f, +3.631211887e-01f, +3.511882735e-01f, +1.844835679e-01f, +7.232639407e-03f, -6.132051750e-02f, -3.179964276e-02f, +1.079265669e-02f, +1.772815465e-02f, +3.619009684e-03f, -4.306339536e-03f, -2.438958613e-03f,
- /* 20, 8 */ -2.660240473e-03f, -4.177756859e-03f, +4.502020476e-03f, +1.825519424e-02f, +9.049273418e-03f, -3.490877898e-02f, -6.064539119e-02f, +1.576075912e-02f, +1.969539074e-01f, +3.574952133e-01f, +3.574952133e-01f, +1.969539074e-01f, +1.576075912e-02f, -6.064539119e-02f, -3.490877898e-02f, +9.049273418e-03f, +1.825519424e-02f, +4.502020476e-03f, -4.177756859e-03f, -2.660240473e-03f,
- /* 20, 9 */ -2.438958613e-03f, -4.306339536e-03f, +3.619009684e-03f, +1.772815465e-02f, +1.079265669e-02f, -3.179964276e-02f, -6.132051750e-02f, +7.232639407e-03f, +1.844835679e-01f, +3.511882735e-01f, +3.631211887e-01f, +2.093507858e-01f, +2.474868675e-02f, -5.954174144e-02f, -3.796155187e-02f, +7.144763866e-03f, +1.868830751e-02f, +5.415043050e-03f, -4.004463491e-03f, -2.879863731e-03f,
- /* 20,10 */ -2.218161540e-03f, -4.392423280e-03f, +2.770500592e-03f, +1.711611824e-02f, +1.237213363e-02f, -2.865624686e-02f, -6.158584092e-02f, -8.198514564e-04f, +1.719833640e-01f, +3.442255330e-01f, +3.680436800e-01f, +2.216302330e-01f, +3.417810958e-02f, -5.799227582e-02f, -4.093509653e-02f, +5.083157654e-03f, +1.901874863e-02f, +6.353071566e-03f, -3.784479230e-03f, -3.095529963e-03f,
- /* 20,11 */ -1.999828319e-03f, -4.438419451e-03f, +1.960461229e-03f, +1.642812632e-02f, +1.378613431e-02f, -2.549983702e-02f, -6.146136934e-02f, -8.383409345e-03f, +1.594963158e-01f, +3.366346688e-01f, +3.722429273e-01f, +2.337481127e-01f, +4.402826232e-02f, -5.598126618e-02f, -4.380589142e-02f, +2.869766685e-03f, +1.923802927e-02f, +7.310594668e-03f, -3.516087186e-03f, -3.304797071e-03f,
- /* 20,12 */ -1.785766437e-03f, -4.446907145e-03f, +1.192336051e-03f, +1.567326271e-02f, +1.503425320e-02f, -2.235071271e-02f, -6.096825350e-02f, -1.544725782e-02f, +1.470646693e-01f, +3.284457292e-01f, +3.757020336e-01f, +2.456603330e-01f, +5.427598051e-02f, -5.349467921e-02f, -4.654987033e-02f, +5.112106557e-04f, +1.933799402e-02f, +8.281610454e-03f, -3.197865053e-03f, -3.505092707e-03f,
- /* 20,13 */ -1.577606548e-03f, -4.420601658e-03f, +4.690483654e-04f, +1.486058724e-02f, +1.611719780e-02f, -1.922814732e-02f, -6.012863981e-02f, -2.200314505e-02f, +1.347297046e-01f, +3.196909791e-01f, +3.784070525e-01f, +2.573230589e-01f, +6.489576800e-02f, -5.052030051e-02f, -4.914254142e-02f, -1.984565051e-03f, +1.931089692e-02f, +9.259646102e-03f, -2.828715617e-03f, -3.693729756e-03f,
- /* 20,14 */ -1.376799150e-03f, -4.362323551e-03f, -2.069933478e-04f, +1.399907244e-02f, +1.703673197e-02f, -1.615031726e-02f, -5.896552129e-02f, -2.804532708e-02f, +1.225315522e-01f, +3.104047352e-01f, +3.803470604e-01f, +2.686929243e-01f, +7.585987841e-02f, -4.704785126e-02f, -5.155911253e-02f, -4.608279480e-03f, +1.914947854e-02f, +1.023778220e-02f, -2.407896178e-03f, -3.867923854e-03f,
- /* 20,15 */ -1.184613130e-03f, -4.274968522e-03f, -8.338854378e-04f, +1.309754391e-02f, +1.779561475e-02f, -1.313424017e-02f, -5.750258783e-02f, -3.357053763e-02f, +1.105090175e-01f, +3.006231905e-01f, +3.815142140e-01f, +2.797272456e-01f, +8.713841011e-02f, -4.306909662e-02f, -5.377462232e-02f, -7.349314558e-03f, +1.884704309e-02f, +1.120868183e-02f, -1.935046598e-03f, -4.024812873e-03f,
- /* 20, 0 */ -1.329352252e-03f, -4.865562069e-03f, +1.662947600e-03f, +1.893743982e-02f, +1.052975469e-02f, -4.314924294e-02f, -6.168215525e-02f, +6.793829558e-02f, +3.007295231e-01f, +4.214013440e-01f, +3.007295231e-01f, +6.793829558e-02f, -6.168215525e-02f, -4.314924294e-02f, +1.052975469e-02f, +1.893743982e-02f, +1.662947600e-03f, -4.865562069e-03f, -1.329352252e-03f, +0.000000000e+00f,
- /* 20, 1 */ -1.106503038e-03f, -4.784011640e-03f, +7.620481209e-04f, +1.810159639e-02f, +1.258770510e-02f, -3.946126222e-02f, -6.412166469e-02f, +5.516844650e-02f, +2.870012762e-01f, +4.208780002e-01f, +3.139874692e-01f, +8.118253044e-02f, -5.860314053e-02f, -4.671882663e-02f, +8.254179692e-03f, +1.967037055e-02f, +2.622520317e-03f, -4.905078775e-03f, -1.565095816e-03f, +0.000000000e+00f,
- /* 20, 2 */ -8.979094201e-04f, -4.664743082e-03f, -7.633034189e-05f, +1.717630323e-02f, +1.442449893e-02f, -3.568911340e-02f, -6.594250862e-02f, +4.291292121e-02f, +2.728656387e-01f, +4.193105477e-01f, +3.267137817e-01f, +9.485763802e-02f, -5.486676259e-02f, -5.013477905e-02f, +5.766539049e-03f, +2.028700325e-02f, +3.636071544e-03f, -4.898357639e-03f, -1.812078842e-03f, +3.513221827e-04f,
- /* 20, 3 */ -7.046452899e-04f, -4.512131585e-03f, -8.491713087e-04f, +1.617498084e-02f, +1.603855621e-02f, -3.186582692e-02f, -6.716828458e-02f, +3.120792005e-02f, +2.583867198e-01f, +4.167067067e-01f, +3.388490774e-01f, +1.089167196e-01f, -5.045835457e-02f, -5.336106841e-02f, +3.074480429e-03f, +2.077415592e-02f, +4.698051453e-03f, -4.841360048e-03f, -2.068349661e-03f, +3.288882594e-04f,
- /* 20, 4 */ -5.275063595e-04f, -4.330562617e-03f, -1.554266965e-03f, +1.511089362e-02f, +1.743016199e-02f, -2.802305698e-02f, -6.782511100e-02f, +2.008577030e-02f, +2.436294448e-01f, +4.130792899e-01f, +3.503362849e-01f, +1.233097059e-01f, -4.536663323e-02f, -5.636108634e-02f, +1.877878266e-04f, +2.111898038e-02f, +5.802054958e-03f, -4.730268616e-03f, -2.331660076e-03f, +2.941732022e-04f,
- /* 20, 5 */ -3.670219514e-04f, -4.124385552e-03f, -2.190189120e-03f, +1.399704337e-02f, +1.860136846e-02f, -2.419092016e-02f, -6.794137953e-02f, +9.574818877e-03f, +2.286591711e-01f, +4.084461208e-01f, +3.611209950e-01f, +1.379835966e-01f, -3.958387309e-02f, -5.909788086e-02f, -2.881585959e-03f, +2.130909659e-02f, +6.940829951e-03f, -4.561544087e-03f, -2.599469210e-03f, +2.461206998e-04f,
- /* 20, 6 */ -2.234691091e-04f, -3.897870552e-03f, -2.756254356e-03f, +1.284607053e-02f, +1.955588746e-02f, -2.039785121e-02f, -6.754749865e-02f, -3.006469464e-04f, +2.135413047e-01f, +4.028299211e-01f, +3.711517965e-01f, +1.528827232e-01f, -3.310606021e-02f, -6.153439984e-02f, -6.119502817e-03f, +2.133272965e-02f, +8.106294302e-03f, -4.331982887e-03f, -2.868951124e-03f, +1.837671888e-04f,
- /* 20, 7 */ -9.688872179e-05f, -3.655168976e-03f, -3.252484018e-03f, +1.167016373e-02f, +2.029897446e-02f, -1.667047641e-02f, -6.667563061e-02f, -9.520450398e-03f, +1.983409219e-01f, +3.962581664e-01f, +3.803805952e-01f, +1.679490334e-01f, -2.593302438e-02f, -6.363374348e-02f, -9.509639499e-03f, +2.117884859e-02f, +9.289561904e-03f, -4.038774728e-03f, -3.137006363e-03f, +1.062635081e-04f,
- /* 20, 8 */ +1.289664191e-05f, -3.400277535e-03f, -3.679559671e-03f, +1.048097797e-02f, +2.083730557e-02f, -1.303350512e-02f, -6.535942396e-02f, -1.806854797e-02f, +1.831223958e-01f, +3.887629129e-01f, +3.887629129e-01f, +1.831223958e-01f, -1.806854797e-02f, -6.535942396e-02f, -1.303350512e-02f, +2.083730557e-02f, +1.048097797e-02f, -3.679559671e-03f, -3.400277535e-03f, +1.289664191e-05f,
- /* 20, 9 */ +1.062635081e-04f, -3.137006363e-03f, -4.038774728e-03f, +9.289561904e-03f, +2.117884859e-02f, -9.509639499e-03f, -6.363374348e-02f, -2.593302438e-02f, +1.679490334e-01f, +3.803805952e-01f, +3.962581664e-01f, +1.983409219e-01f, -9.520450398e-03f, -6.667563061e-02f, -1.667047641e-02f, +2.029897446e-02f, +1.167016373e-02f, -3.252484018e-03f, -3.655168976e-03f, -9.688872179e-05f,
- /* 20,10 */ +1.837671888e-04f, -2.868951124e-03f, -4.331982887e-03f, +8.106294302e-03f, +2.133272965e-02f, -6.119502817e-03f, -6.153439984e-02f, -3.310606021e-02f, +1.528827232e-01f, +3.711517965e-01f, +4.028299211e-01f, +2.135413047e-01f, -3.006469464e-04f, -6.754749865e-02f, -2.039785121e-02f, +1.955588746e-02f, +1.284607053e-02f, -2.756254356e-03f, -3.897870552e-03f, -2.234691091e-04f,
- /* 20,11 */ +2.461206998e-04f, -2.599469210e-03f, -4.561544087e-03f, +6.940829951e-03f, +2.130909659e-02f, -2.881585959e-03f, -5.909788086e-02f, -3.958387309e-02f, +1.379835966e-01f, +3.611209950e-01f, +4.084461208e-01f, +2.286591711e-01f, +9.574818877e-03f, -6.794137953e-02f, -2.419092016e-02f, +1.860136846e-02f, +1.399704337e-02f, -2.190189120e-03f, -4.124385552e-03f, -3.670219514e-04f,
- /* 20,12 */ +2.941732022e-04f, -2.331660076e-03f, -4.730268616e-03f, +5.802054958e-03f, +2.111898038e-02f, +1.877878266e-04f, -5.636108634e-02f, -4.536663323e-02f, +1.233097059e-01f, +3.503362849e-01f, +4.130792899e-01f, +2.436294448e-01f, +2.008577030e-02f, -6.782511100e-02f, -2.802305698e-02f, +1.743016199e-02f, +1.511089362e-02f, -1.554266965e-03f, -4.330562617e-03f, -5.275063595e-04f,
- /* 20,13 */ +3.288882594e-04f, -2.068349661e-03f, -4.841360048e-03f, +4.698051453e-03f, +2.077415592e-02f, +3.074480429e-03f, -5.336106841e-02f, -5.045835457e-02f, +1.089167196e-01f, +3.388490774e-01f, +4.167067067e-01f, +2.583867198e-01f, +3.120792005e-02f, -6.716828458e-02f, -3.186582692e-02f, +1.603855621e-02f, +1.617498084e-02f, -8.491713087e-04f, -4.512131585e-03f, -7.046452899e-04f,
- /* 20,14 */ +3.513221827e-04f, -1.812078842e-03f, -4.898357639e-03f, +3.636071544e-03f, +2.028700325e-02f, +5.766539049e-03f, -5.013477905e-02f, -5.486676259e-02f, +9.485763802e-02f, +3.267137817e-01f, +4.193105477e-01f, +2.728656387e-01f, +4.291292121e-02f, -6.594250862e-02f, -3.568911340e-02f, +1.442449893e-02f, +1.717630323e-02f, -7.633034189e-05f, -4.664743082e-03f, -8.979094201e-04f,
- /* 20,15 */ +0.000000000e+00f, -1.565095816e-03f, -4.905078775e-03f, +2.622520317e-03f, +1.967037055e-02f, +8.254179692e-03f, -4.671882663e-02f, -5.860314053e-02f, +8.118253044e-02f, +3.139874692e-01f, +4.208780002e-01f, +2.870012762e-01f, +5.516844650e-02f, -6.412166469e-02f, -3.946126222e-02f, +1.258770510e-02f, +1.810159639e-02f, +7.620481209e-04f, -4.784011640e-03f, -1.106503038e-03f,
- /* 20, 0 */ +3.735125865e-04f, -2.550984103e-03f, -4.871486096e-03f, +1.016287769e-02f, +2.252246682e-02f, -2.231523982e-02f, -7.431762424e-02f, +3.414137659e-02f, +3.062278786e-01f, +4.608988972e-01f, +3.062278786e-01f, +3.414137659e-02f, -7.431762424e-02f, -2.231523982e-02f, +2.252246682e-02f, +1.016287769e-02f, -4.871486096e-03f, -2.550984103e-03f, +3.735125865e-04f, +0.000000000e+00f,
- /* 20, 1 */ +3.929324583e-04f, -2.236335973e-03f, -5.106050653e-03f, +8.748210493e-03f, +2.303691111e-02f, -1.786093260e-02f, -7.411924916e-02f, +2.086992015e-02f, +2.890848421e-01f, +4.602142272e-01f, +3.228796668e-01f, +4.817530421e-02f, -7.382833631e-02f, -2.685541297e-02f, +2.174514756e-02f, +1.158816420e-02f, -4.555417854e-03f, -2.871502680e-03f, +3.387491377e-04f, +0.000000000e+00f,
- /* 20, 2 */ +0.000000000e+00f, -1.931175707e-03f, -5.263447672e-03f, +7.357928950e-03f, +2.330080531e-02f, -1.352771902e-02f, -7.327813327e-02f, +8.401230311e-03f, +2.715429904e-01f, +4.581642525e-01f, +3.389493512e-01f, +6.292517925e-02f, -7.260941515e-02f, -3.144322519e-02f, +2.069454672e-02f, +1.300917115e-02f, -4.154170312e-03f, -3.193828376e-03f, +2.870815261e-04f, +0.000000000e+00f,
- /* 20, 3 */ +0.000000000e+00f, -1.638662038e-03f, -5.348575554e-03f, +6.004591146e-03f, +2.332816092e-02f, -9.347674729e-03f, -7.184169597e-02f, -3.230759097e-03f, +2.536956771e-01f, +4.547610488e-01f, +3.543483057e-01f, +7.833843581e-02f, -7.062228683e-02f, -3.603763775e-02f, +1.936240016e-02f, +1.440996064e-02f, -3.664825055e-03f, -3.513472060e-03f, +2.170808154e-04f, +0.000000000e+00f,
- /* 20, 4 */ +0.000000000e+00f, -1.361489293e-03f, -5.366796329e-03f, +4.699488665e-03f, +2.313444000e-02f, -5.349604768e-03f, -6.985939290e-02f, -1.399855627e-02f, +2.356365195e-01f, +4.500246402e-01f, +3.689907742e-01f, +9.435670405e-02f, -6.783220328e-02f, -4.059502103e-02f, +1.774280068e-02f, +1.577366666e-02f, -3.085314600e-03f, -3.825546457e-03f, +1.274866066e-04f, +0.000000000e+00f,
- /* 20, 5 */ +0.000000000e+00f, -1.101888322e-03f, -5.323837897e-03f, +3.452605627e-03f, +2.273631696e-02f, -1.558959414e-03f, -6.738225311e-02f, -2.388113922e-02f, +2.174587480e-01f, +4.439828472e-01f, +3.827944964e-01f, +1.109160995e-01f, -6.420865295e-02f, -4.506940842e-02f, +1.583239979e-02f, +1.708262332e-02f, -2.414511840e-03f, -4.124801502e-03f, +1.724424543e-05f, +0.000000000e+00f,
- /* 20, 6 */ +0.000000000e+00f, -8.616336525e-04f, -5.225698259e-03f, +2.272594520e-03f, +2.215144089e-02f, +2.002216238e-03f, -6.446241843e-02f, -3.286393171e-02f, +1.992545658e-01f, +4.366710759e-01f, +3.956813102e-01f, +1.279475618e-01f, -5.972574809e-02f, -4.941278189e-02f, +1.363059437e-02f, +1.831850983e-02f, -1.652313816e-03f, -4.405667401e-03f, -1.144582079e-04f, +0.000000000e+00f,
- /* 20, 7 */ +0.000000000e+00f, -6.420563626e-04f, -5.078552799e-03f, +1.166768183e-03f, +2.139820068e-02f, +5.315299677e-03f, -6.115268907e-02f, -4.093872873e-02f, +1.811145256e-01f, +4.281320500e-01f, +4.075777294e-01f, +1.453772407e-01f, -5.436258502e-02f, -5.357538755e-02f, +1.113969540e-02f, +1.946251142e-02f, -7.997184460e-04f, -4.662305323e-03f, -2.681538305e-04f, +0.000000000e+00f,
- /* 20, 8 */ +0.000000000e+00f, -4.440621234e-04f, -4.888665552e-03f, +1.411071672e-04f, +2.049549532e-02f, +8.365076494e-03f, -5.750607943e-02f, -4.810357305e-02f, +1.631269271e-01f, +4.184154881e-01f, +4.184154881e-01f, +1.631269271e-01f, -4.810357305e-02f, -5.750607943e-02f, +8.365076494e-03f, +2.049549532e-02f, +1.411071672e-04f, -4.888665552e-03f, -4.440621234e-04f, +0.000000000e+00f,
- /* 20, 9 */ +0.000000000e+00f, -2.681538305e-04f, -4.662305323e-03f, -7.997184460e-04f, +1.946251142e-02f, +1.113969540e-02f, -5.357538755e-02f, -5.436258502e-02f, +1.453772407e-01f, +4.075777294e-01f, +4.281320500e-01f, +1.811145256e-01f, -4.093872873e-02f, -6.115268907e-02f, +5.315299677e-03f, +2.139820068e-02f, +1.166768183e-03f, -5.078552799e-03f, -6.420563626e-04f, +0.000000000e+00f,
- /* 20,10 */ +0.000000000e+00f, -1.144582079e-04f, -4.405667401e-03f, -1.652313816e-03f, +1.831850983e-02f, +1.363059437e-02f, -4.941278189e-02f, -5.972574809e-02f, +1.279475618e-01f, +3.956813102e-01f, +4.366710759e-01f, +1.992545658e-01f, -3.286393171e-02f, -6.446241843e-02f, +2.002216238e-03f, +2.215144089e-02f, +2.272594520e-03f, -5.225698259e-03f, -8.616336525e-04f, +0.000000000e+00f,
- /* 20,11 */ +0.000000000e+00f, +1.724424543e-05f, -4.124801502e-03f, -2.414511840e-03f, +1.708262332e-02f, +1.583239979e-02f, -4.506940842e-02f, -6.420865295e-02f, +1.109160995e-01f, +3.827944964e-01f, +4.439828472e-01f, +2.174587480e-01f, -2.388113922e-02f, -6.738225311e-02f, -1.558959414e-03f, +2.273631696e-02f, +3.452605627e-03f, -5.323837897e-03f, -1.101888322e-03f, +0.000000000e+00f,
- /* 20,12 */ +0.000000000e+00f, +1.274866066e-04f, -3.825546457e-03f, -3.085314600e-03f, +1.577366666e-02f, +1.774280068e-02f, -4.059502103e-02f, -6.783220328e-02f, +9.435670405e-02f, +3.689907742e-01f, +4.500246402e-01f, +2.356365195e-01f, -1.399855627e-02f, -6.985939290e-02f, -5.349604768e-03f, +2.313444000e-02f, +4.699488665e-03f, -5.366796329e-03f, -1.361489293e-03f, +0.000000000e+00f,
- /* 20,13 */ +0.000000000e+00f, +2.170808154e-04f, -3.513472060e-03f, -3.664825055e-03f, +1.440996064e-02f, +1.936240016e-02f, -3.603763775e-02f, -7.062228683e-02f, +7.833843581e-02f, +3.543483057e-01f, +4.547610488e-01f, +2.536956771e-01f, -3.230759097e-03f, -7.184169597e-02f, -9.347674729e-03f, +2.332816092e-02f, +6.004591146e-03f, -5.348575554e-03f, -1.638662038e-03f, +0.000000000e+00f,
- /* 20,14 */ +0.000000000e+00f, +2.870815261e-04f, -3.193828376e-03f, -4.154170312e-03f, +1.300917115e-02f, +2.069454672e-02f, -3.144322519e-02f, -7.260941515e-02f, +6.292517925e-02f, +3.389493512e-01f, +4.581642525e-01f, +2.715429904e-01f, +8.401230311e-03f, -7.327813327e-02f, -1.352771902e-02f, +2.330080531e-02f, +7.357928950e-03f, -5.263447672e-03f, -1.931175707e-03f, +0.000000000e+00f,
- /* 20,15 */ +0.000000000e+00f, +3.387491377e-04f, -2.871502680e-03f, -4.555417854e-03f, +1.158816420e-02f, +2.174514756e-02f, -2.685541297e-02f, -7.382833631e-02f, +4.817530421e-02f, +3.228796668e-01f, +4.602142272e-01f, +2.890848421e-01f, +2.086992015e-02f, -7.411924916e-02f, -1.786093260e-02f, +2.303691111e-02f, +8.748210493e-03f, -5.106050653e-03f, -2.236335973e-03f, +3.929324583e-04f,
- /* 16, 0 */ -4.898743621e-03f, -8.679086087e-05f, +2.336043359e-02f, +2.135055302e-04f, -7.556698393e-02f, -3.418085064e-04f, +3.068350485e-01f, +5.003964504e-01f, +3.068350485e-01f, -3.418085064e-04f, -7.556698393e-02f, +2.135055302e-04f, +2.336043359e-02f, -8.679086087e-05f, -4.898743621e-03f, +1.466795211e-05f,
- /* 16, 1 */ -4.577177643e-03f, -1.168030162e-03f, +2.231338881e-02f, +4.259286102e-03f, -7.256190983e-02f, -1.325523148e-02f, +2.859961851e-01f, +4.995203198e-01f, +3.272077887e-01f, +1.366916740e-02f, -7.794631959e-02f, -4.137969722e-03f, +2.421268789e-02f, +1.104119466e-03f, -5.186216174e-03f, -1.424716020e-04f,
- /* 16, 2 */ -4.229744004e-03f, -2.135347302e-03f, +2.109817837e-02f, +7.975999347e-03f, -6.900371451e-02f, -2.503996167e-02f, +2.648211478e-01f, +4.968980143e-01f, +3.469854770e-01f, +2.873680235e-02f, -7.962890015e-02f, -8.766610174e-03f, +2.484400873e-02f, +2.398541233e-03f, -5.431090074e-03f, -3.278051009e-04f,
- /* 16, 3 */ -3.864289504e-03f, -2.986316790e-03f, +1.974155805e-02f, +1.134537917e-02f, -6.496587406e-02f, -3.567459207e-02f, +2.434398342e-01f, +4.925477372e-01f, +3.660412816e-01f, +4.481051979e-02f, -8.054606315e-02f, -1.363873477e-02f, +2.522910176e-02f, +3.788344934e-03f, -5.624692566e-03f, -5.415628140e-04f,
- /* 16, 4 */ -3.488195595e-03f, -3.720237037e-03f, +1.827008292e-02f, +1.435416313e-02f, -6.052200094e-02f, -4.514733704e-02f, +2.219810322e-01f, +4.864996469e-01f, +3.842515379e-01f, +6.183022559e-02f, -8.063225815e-02f, -1.871557408e-02f, +2.534390000e-02f, +5.263393235e-03f, -5.758306879e-03f, -7.834433658e-04f,
- /* 16, 5 */ -3.108305495e-03f, -4.338012209e-03f, +1.670979794e-02f, +1.699394035e-02f, -5.574514781e-02f, -5.345583367e-02f, +2.005713869e-01f, +4.787955863e-01f, +4.014968013e-01f, +7.972656727e-02f, -7.982580067e-02f, -2.395339311e-02f, +2.516595041e-02f, +6.811528665e-03f, -5.823306183e-03f, -1.052565974e-03f,
- /* 16, 6 */ -2.730865011e-03f, -4.842020290e-03f, +1.508595356e-02f, +1.926095418e-02f, -5.070714412e-02f, -6.060686010e-02f, +1.793344024e-01f, +4.694887096e-01f, +4.176628724e-01f, +9.842128660e-02f, -7.806961406e-02f, -2.930367505e-02f, +2.467480385e-02f, +8.418588685e-03f, -5.811296621e-03f, -1.347428958e-03f,
- /* 16, 7 */ -2.361477017e-03f, -5.235970004e-03f, +1.342274837e-02f, +2.115586371e-02f, -4.547797122e-02f, -6.661597542e-02f, +1.583894867e-01f, +4.586430086e-01f, +4.326417845e-01f, +1.178276637e-01f, -7.531195111e-02f, -3.471336612e-02f, +2.385240383e-02f, +1.006844961e-02f, -5.714267850e-03f, -1.665875716e-03f,
- /* 16, 8 */ -2.005069351e-03f, -5.524749278e-03f, +1.174310057e-02f, +2.268346885e-02f, -4.012518151e-02f, -7.150708699e-02f, +1.378510501e-01f, +4.463327434e-01f, +4.463327434e-01f, +1.378510501e-01f, -7.150708699e-02f, -4.012518151e-02f, +2.268346885e-02f, +1.174310057e-02f, -5.524749278e-03f, -2.005069351e-03f,
- /* 16, 9 */ -1.665875716e-03f, -5.714267850e-03f, +1.006844961e-02f, +2.385240383e-02f, -3.471336612e-02f, -7.531195111e-02f, +1.178276637e-01f, +4.326417845e-01f, +4.586430086e-01f, +1.583894867e-01f, -6.661597542e-02f, -4.547797122e-02f, +2.115586371e-02f, +1.342274837e-02f, -5.235970004e-03f, -2.361477017e-03f,
- /* 16,10 */ -1.347428958e-03f, -5.811296621e-03f, +8.418588685e-03f, +2.467480385e-02f, -2.930367505e-02f, -7.806961406e-02f, +9.842128660e-02f, +4.176628724e-01f, +4.694887096e-01f, +1.793344024e-01f, -6.060686010e-02f, -5.070714412e-02f, +1.926095418e-02f, +1.508595356e-02f, -4.842020290e-03f, -2.730865011e-03f,
- /* 16,11 */ -1.052565974e-03f, -5.823306183e-03f, +6.811528665e-03f, +2.516595041e-02f, -2.395339311e-02f, -7.982580067e-02f, +7.972656727e-02f, +4.014968013e-01f, +4.787955863e-01f, +2.005713869e-01f, -5.345583367e-02f, -5.574514781e-02f, +1.699394035e-02f, +1.670979794e-02f, -4.338012209e-03f, -3.108305495e-03f,
- /* 16,12 */ -7.834433658e-04f, -5.758306879e-03f, +5.263393235e-03f, +2.534390000e-02f, -1.871557408e-02f, -8.063225815e-02f, +6.183022559e-02f, +3.842515379e-01f, +4.864996469e-01f, +2.219810322e-01f, -4.514733704e-02f, -6.052200094e-02f, +1.435416313e-02f, +1.827008292e-02f, -3.720237037e-03f, -3.488195595e-03f,
- /* 16,13 */ -5.415628140e-04f, -5.624692566e-03f, +3.788344934e-03f, +2.522910176e-02f, -1.363873477e-02f, -8.054606315e-02f, +4.481051979e-02f, +3.660412816e-01f, +4.925477372e-01f, +2.434398342e-01f, -3.567459207e-02f, -6.496587406e-02f, +1.134537917e-02f, +1.974155805e-02f, -2.986316790e-03f, -3.864289504e-03f,
- /* 16,14 */ -3.278051009e-04f, -5.431090074e-03f, +2.398541233e-03f, +2.484400873e-02f, -8.766610174e-03f, -7.962890015e-02f, +2.873680235e-02f, +3.469854770e-01f, +4.968980143e-01f, +2.648211478e-01f, -2.503996167e-02f, -6.900371451e-02f, +7.975999347e-03f, +2.109817837e-02f, -2.135347302e-03f, -4.229744004e-03f,
- /* 16,15 */ -1.424716020e-04f, -5.186216174e-03f, +1.104119466e-03f, +2.421268789e-02f, -4.137969722e-03f, -7.794631959e-02f, +1.366916740e-02f, +3.272077887e-01f, +4.995203198e-01f, +2.859961851e-01f, -1.325523148e-02f, -7.256190983e-02f, +4.259286102e-03f, +2.231338881e-02f, -1.168030162e-03f, -4.577177643e-03f,
- /* 16, 0 */ -1.854349243e-03f, -5.842655877e-03f, +1.571555836e-02f, +1.847159410e-02f, -6.634453543e-02f, -3.320569278e-02f, +3.025932104e-01f, +5.398940036e-01f, +3.025932104e-01f, -3.320569278e-02f, -6.634453543e-02f, +1.847159410e-02f, +1.571555836e-02f, -5.842655877e-03f, -1.854349243e-03f, +0.000000000e+00f,
- /* 16, 1 */ -1.480579358e-03f, -6.106700866e-03f, +1.376986381e-02f, +2.107103425e-02f, -6.084498265e-02f, -4.482173865e-02f, +2.778559558e-01f, +5.387937054e-01f, +3.269511876e-01f, -2.013603096e-02f, -7.140657205e-02f, +1.540395578e-02f, +1.762103499e-02f, -5.450677830e-03f, -2.253515747e-03f, +0.000000000e+00f,
- /* 16, 2 */ -1.136163241e-03f, -6.251562574e-03f, +1.181432209e-02f, +2.320368920e-02f, -5.500558000e-02f, -5.497544958e-02f, +2.529151163e-01f, +5.355017071e-01f, +3.507537104e-01f, -5.635398845e-03f, -7.593183970e-02f, +1.187314151e-02f, +1.945395611e-02f, -4.923375547e-03f, -2.673102395e-03f, +0.000000000e+00f,
- /* 16, 3 */ -8.240613879e-04f, -6.287094834e-03f, +9.877041313e-03f, +2.487696888e-02f, -4.892141083e-02f, -6.367164518e-02f, +2.279442418e-01f, +5.300446041e-01f, +3.738258052e-01f, +1.025938806e-02f, -7.982055919e-02f, +7.890985370e-03f, +2.118036474e-02f, -4.254967852e-03f, -3.107109230e-03f, +0.000000000e+00f,
- /* 16, 4 */ -5.462770218e-04f, -6.224002243e-03f, +7.983624178e-03f, +2.610378910e-02f, -4.268405269e-02f, -7.092815895e-02f, +2.031131300e-01f, +5.224664143e-01f, +3.959953988e-01f, +2.749725254e-02f, -8.297353764e-02f, +3.476439880e-03f, +2.276508169e-02f, -3.441527233e-03f, -3.548528769e-03f, +4.634120047e-04f,
- /* 16, 5 */ -3.039101756e-04f, -6.073592210e-03f, +6.156978545e-03f, +2.690203687e-02f, -3.638073666e-02f, -7.677518685e-02f, +1.785862812e-01f, +5.128281199e-01f, +4.170950072e-01f, +4.601292009e-02f, -8.529332152e-02f, -1.344195268e-03f, +2.417214928e-02f, -2.481210963e-03f, -3.989383394e-03f, +4.400286560e-04f,
- /* 16, 6 */ -9.722433303e-05f, -5.847536081e-03f, +4.417180930e-03f, +2.729400173e-02f, -3.009359622e-02f, -8.125451993e-02f, +1.545214364e-01f, +5.012070337e-01f, +4.369633957e-01f, +6.572714234e-02f, -8.668537697e-02f, -6.537129252e-03f, +2.536531778e-02f, -1.374474827e-03f, -4.420785166e-03f, +3.921992729e-04f,
- /* 16, 7 */ +7.427658644e-05f, -5.557642708e-03f, +2.781391675e-03f, +2.730578215e-02f, -2.389901141e-02f, -8.441867356e-02f, +1.310682124e-01f, +4.876959980e-01f, +4.554471907e-01f, +8.654708074e-02f, -8.705928349e-02f, -1.206102709e-02f, +2.630856978e-02f, -1.242645535e-04f, -4.833018707e-03f, +3.169896142e-04f,
- /* 16, 8 */ +2.117631665e-04f, -5.215647395e-03f, +1.263819875e-03f, +2.696667686e-02f, -1.786705263e-02f, -8.632992647e-02f, +1.083668491e-01f, +4.724024249e-01f, +4.724024249e-01f, +1.083668491e-01f, -8.632992647e-02f, -1.786705263e-02f, +2.696667686e-02f, +1.263819875e-03f, -5.215647395e-03f, +2.117631665e-04f,
- /* 16, 9 */ +3.169896142e-04f, -4.833018707e-03f, -1.242645535e-04f, +2.630856978e-02f, -1.206102709e-02f, -8.705928349e-02f, +8.654708074e-02f, +4.554471907e-01f, +4.876959980e-01f, +1.310682124e-01f, -8.441867356e-02f, -2.389901141e-02f, +2.730578215e-02f, +2.781391675e-03f, -5.557642708e-03f, +7.427658644e-05f,
- /* 16,10 */ +3.921992729e-04f, -4.420785166e-03f, -1.374474827e-03f, +2.536531778e-02f, -6.537129252e-03f, -8.668537697e-02f, +6.572714234e-02f, +4.369633957e-01f, +5.012070337e-01f, +1.545214364e-01f, -8.125451993e-02f, -3.009359622e-02f, +2.729400173e-02f, +4.417180930e-03f, -5.847536081e-03f, -9.722433303e-05f,
- /* 16,11 */ +4.400286560e-04f, -3.989383394e-03f, -2.481210963e-03f, +2.417214928e-02f, -1.344195268e-03f, -8.529332152e-02f, +4.601292009e-02f, +4.170950072e-01f, +5.128281199e-01f, +1.785862812e-01f, -7.677518685e-02f, -3.638073666e-02f, +2.690203687e-02f, +6.156978545e-03f, -6.073592210e-03f, -3.039101756e-04f,
- /* 16,12 */ +4.634120047e-04f, -3.548528769e-03f, -3.441527233e-03f, +2.276508169e-02f, +3.476439880e-03f, -8.297353764e-02f, +2.749725254e-02f, +3.959953988e-01f, +5.224664143e-01f, +2.031131300e-01f, -7.092815895e-02f, -4.268405269e-02f, +2.610378910e-02f, +7.983624178e-03f, -6.224002243e-03f, -5.462770218e-04f,
- /* 16,13 */ +0.000000000e+00f, -3.107109230e-03f, -4.254967852e-03f, +2.118036474e-02f, +7.890985370e-03f, -7.982055919e-02f, +1.025938806e-02f, +3.738258052e-01f, +5.300446041e-01f, +2.279442418e-01f, -6.367164518e-02f, -4.892141083e-02f, +2.487696888e-02f, +9.877041313e-03f, -6.287094834e-03f, -8.240613879e-04f,
- /* 16,14 */ +0.000000000e+00f, -2.673102395e-03f, -4.923375547e-03f, +1.945395611e-02f, +1.187314151e-02f, -7.593183970e-02f, -5.635398845e-03f, +3.507537104e-01f, +5.355017071e-01f, +2.529151163e-01f, -5.497544958e-02f, -5.500558000e-02f, +2.320368920e-02f, +1.181432209e-02f, -6.251562574e-03f, -1.136163241e-03f,
- /* 16,15 */ +0.000000000e+00f, -2.253515747e-03f, -5.450677830e-03f, +1.762103499e-02f, +1.540395578e-02f, -7.140657205e-02f, -2.013603096e-02f, +3.269511876e-01f, +5.387937054e-01f, +2.778559558e-01f, -4.482173865e-02f, -6.084498265e-02f, +2.107103425e-02f, +1.376986381e-02f, -6.106700866e-03f, -1.480579358e-03f,
- /* 16, 0 */ +2.517634455e-04f, -5.956310854e-03f, +5.008864062e-03f, +2.864631470e-02f, -4.909056125e-02f, -6.235528720e-02f, +2.936293584e-01f, +5.793915568e-01f, +2.936293584e-01f, -6.235528720e-02f, -4.909056125e-02f, +2.864631470e-02f, +5.008864062e-03f, -5.956310854e-03f, +2.517634455e-04f, +0.000000000e+00f,
- /* 16, 1 */ +3.647589216e-04f, -5.559366521e-03f, +3.110945653e-03f, +2.922667528e-02f, -4.185408685e-02f, -7.174125192e-02f, +2.648835910e-01f, +5.780318135e-01f, +3.221602930e-01f, -5.117389488e-02f, -5.619351824e-02f, +2.755457966e-02f, +7.032385926e-03f, -6.289189967e-03f, +9.939782505e-05f, +0.000000000e+00f,
- /* 16, 2 */ +4.414886472e-04f, -5.113535158e-03f, +1.357910925e-03f, +2.932892142e-02f, -3.459618474e-02f, -7.936172697e-02f, +2.361522790e-01f, +5.739652427e-01f, +3.502436629e-01f, -3.818535953e-02f, -6.304412145e-02f, +2.592390265e-02f, +9.158035052e-03f, -6.542440674e-03f, -9.477253367e-05f, +0.000000000e+00f,
- /* 16, 3 */ +4.855802427e-04f, -4.633347213e-03f, -2.351453324e-04f, +2.899108127e-02f, -2.742112952e-02f, -8.526380919e-02f, +2.076588264e-01f, +5.672296697e-01f, +3.776458156e-01f, -2.339704980e-02f, -6.951800781e-02f, +2.373330296e-02f, +1.135820669e-02f, -6.700410184e-03f, -3.323676319e-04f, +0.000000000e+00f,
- /* 16, 4 */ +0.000000000e+00f, -4.132457962e-03f, -1.657230762e-03f, +2.825501306e-02f, -2.042447313e-02f, -8.951050933e-02f, +1.796184274e-01f, +5.578876325e-01f, +4.041347532e-01f, -6.836060229e-03f, -7.548664793e-02f, +2.096923455e-02f, +1.360131724e-02f, -6.747680557e-03f, -6.140535745e-04f, +0.000000000e+00f,
- /* 16, 5 */ +0.000000000e+00f, -3.623457200e-03f, -2.901306411e-03f, +2.716546883e-02f, -1.369230379e-02f, -9.217934767e-02f, +1.522358833e-01f, +5.460256322e-01f, +4.294827240e-01f, +1.145038182e-02f, -8.081883229e-02f, +1.762637069e-02f, +1.585203938e-02f, -6.669417793e-03f, -9.394126333e-04f, +0.000000000e+00f,
- /* 16, 6 */ +0.000000000e+00f, -3.117716971e-03f, -3.964078879e-03f, +2.576917487e-02f, -7.300675124e-03f, -9.336081470e-02f, +1.257035893e-01f, +5.317530991e-01f, +4.534687988e-01f, +3.139475616e-02f, -8.538226676e-02f, +1.370830904e-02f, +1.807162423e-02f, -6.451740247e-03f, -1.306826648e-03f, +0.000000000e+00f,
- /* 16, 7 */ +0.000000000e+00f, -2.625277441e-03f, -4.845741482e-03f, +2.411394259e-02f, -1.315205805e-03f, -9.315672206e-02f, +1.001997139e-01f, +5.152010878e-01f, +4.758813956e-01f, +5.290934542e-02f, -8.904525833e-02f, +9.228181275e-03f, +2.021831098e-02f, -6.082100328e-03f, -1.713377737e-03f, +0.000000000e+00f,
- /* 16, 8 */ +0.000000000e+00f, -2.154770219e-03f, -5.549672684e-03f, +2.224782226e-02f, +4.209152176e-03f, -9.167847004e-02f, +7.588659143e-02f, +4.965207199e-01f, +4.965207199e-01f, +7.588659143e-02f, -9.167847004e-02f, +4.209152176e-03f, +2.224782226e-02f, -5.549672684e-03f, -2.154770219e-03f, +0.000000000e+00f,
- /* 16, 9 */ +0.000000000e+00f, -1.713377737e-03f, -6.082100328e-03f, +2.021831098e-02f, +9.228181275e-03f, -8.904525833e-02f, +5.290934542e-02f, +4.758813956e-01f, +5.152010878e-01f, +1.001997139e-01f, -9.315672206e-02f, -1.315205805e-03f, +2.411394259e-02f, -4.845741482e-03f, -2.625277441e-03f, +0.000000000e+00f,
- /* 16,10 */ +0.000000000e+00f, -1.306826648e-03f, -6.451740247e-03f, +1.807162423e-02f, +1.370830904e-02f, -8.538226676e-02f, +3.139475616e-02f, +4.534687988e-01f, +5.317530991e-01f, +1.257035893e-01f, -9.336081470e-02f, -7.300675124e-03f, +2.576917487e-02f, -3.964078879e-03f, -3.117716971e-03f, +0.000000000e+00f,
- /* 16,11 */ +0.000000000e+00f, -9.394126333e-04f, -6.669417793e-03f, +1.585203938e-02f, +1.762637069e-02f, -8.081883229e-02f, +1.145038182e-02f, +4.294827240e-01f, +5.460256322e-01f, +1.522358833e-01f, -9.217934767e-02f, -1.369230379e-02f, +2.716546883e-02f, -2.901306411e-03f, -3.623457200e-03f, +0.000000000e+00f,
- /* 16,12 */ +0.000000000e+00f, -6.140535745e-04f, -6.747680557e-03f, +1.360131724e-02f, +2.096923455e-02f, -7.548664793e-02f, -6.836060229e-03f, +4.041347532e-01f, +5.578876325e-01f, +1.796184274e-01f, -8.951050933e-02f, -2.042447313e-02f, +2.825501306e-02f, -1.657230762e-03f, -4.132457962e-03f, +0.000000000e+00f,
- /* 16,13 */ +0.000000000e+00f, -3.323676319e-04f, -6.700410184e-03f, +1.135820669e-02f, +2.373330296e-02f, -6.951800781e-02f, -2.339704980e-02f, +3.776458156e-01f, +5.672296697e-01f, +2.076588264e-01f, -8.526380919e-02f, -2.742112952e-02f, +2.899108127e-02f, -2.351453324e-04f, -4.633347213e-03f, +4.855802427e-04f,
- /* 16,14 */ +0.000000000e+00f, -9.477253367e-05f, -6.542440674e-03f, +9.158035052e-03f, +2.592390265e-02f, -6.304412145e-02f, -3.818535953e-02f, +3.502436629e-01f, +5.739652427e-01f, +2.361522790e-01f, -7.936172697e-02f, -3.459618474e-02f, +2.932892142e-02f, +1.357910925e-03f, -5.113535158e-03f, +4.414886472e-04f,
- /* 16,15 */ +0.000000000e+00f, +9.939782505e-05f, -6.289189967e-03f, +7.032385926e-03f, +2.755457966e-02f, -5.619351824e-02f, -5.117389488e-02f, +3.221602930e-01f, +5.780318135e-01f, +2.648835910e-01f, -7.174125192e-02f, -4.185408685e-02f, +2.922667528e-02f, +3.110945653e-03f, -5.559366521e-03f, +3.647589216e-04f,
- /* 12, 0 */ -3.638165547e-03f, +2.979985982e-02f, -2.723323293e-02f, -8.605047059e-02f, +2.801520768e-01f, +6.188891100e-01f, +2.801520768e-01f, -8.605047059e-02f, -2.723323293e-02f, +2.979985982e-02f, -3.638165547e-03f, -3.041512814e-03f,
- /* 12, 1 */ -4.749738186e-03f, +2.841159300e-02f, -1.933319589e-02f, -9.237133076e-02f, +2.473915856e-01f, +6.172320760e-01f, +3.129551421e-01f, -7.764805088e-02f, -3.538029377e-02f, +3.077779188e-02f, -2.305275216e-03f, -3.612081594e-03f,
- /* 12, 2 */ -5.642312008e-03f, +2.667449885e-02f, -1.178831271e-02f, -9.669686191e-02f, +2.149632830e-01f, +6.122785731e-01f, +3.455026876e-01f, -6.709962705e-02f, -4.365285408e-02f, +3.128617370e-02f, -7.534120996e-04f, -4.192641091e-03f,
- /* 12, 3 */ -6.322395719e-03f, +2.465107974e-02f, -4.692548813e-03f, -9.913294928e-02f, +1.831448749e-01f, +6.040811565e-01f, +3.774917553e-01f, -5.436442589e-02f, -5.191703591e-02f, +3.126943445e-02f, +1.010002855e-03f, -4.769140004e-03f,
- /* 12, 4 */ -6.800166749e-03f, +2.240361196e-02f, +1.874795505e-03f, -9.980279721e-02f, +1.521989634e-01f, +5.927266195e-01f, +4.086182709e-01f, -3.942694703e-02f, -6.002791415e-02f, +3.067703358e-02f, +2.972136287e-03f, -5.325763732e-03f,
- /* 12, 5 */ -7.088917510e-03f, +1.999301835e-02f, +7.849320649e-03f, -9.884443272e-02f, +1.223701278e-01f, +5.783348068e-01f, +4.385808709e-01f, -2.229824534e-02f, -6.783107929e-02f, +2.946485483e-02f, +5.114495497e-03f, -5.845139328e-03f,
- /* 12, 6 */ -7.204483224e-03f, +1.747784955e-02f, +1.318150805e-02f, -9.640809295e-02f, +9.388232321e-02f, +5.610569814e-01f, +4.670847512e-01f, -3.016864363e-03f, -7.516444191e-02f, +2.759658236e-02f, +7.412783505e-03f, -6.308600966e-03f,
- /* 12, 7 */ -7.164664930e-03f, +1.491338589e-02f, +1.783645872e-02f, -9.265354184e-02f, +6.693662660e-02f, +5.410737692e-01f, +4.938454794e-01f, +1.835060492e-02f, -8.186025948e-02f, +2.504503167e-02f, +9.836867291e-03f, -6.696514785e-03f,
- /* 12, 8 */ -6.988660420e-03f, +1.235086875e-02f, +2.179340724e-02f, -8.774736114e-02f, +4.170935934e-02f, +5.185927134e-01f, +5.185927134e-01f, +4.170935934e-02f, -8.774736114e-02f, +2.179340724e-02f, +1.235086875e-02f, -6.988660420e-03f,
- /* 12, 9 */ -6.696514785e-03f, +9.836867291e-03f, +2.504503167e-02f, -8.186025948e-02f, +1.835060492e-02f, +4.938454794e-01f, +5.410737692e-01f, +6.693662660e-02f, -9.265354184e-02f, +1.783645872e-02f, +1.491338589e-02f, -7.164664930e-03f,
- /* 12,10 */ -6.308600966e-03f, +7.412783505e-03f, +2.759658236e-02f, -7.516444191e-02f, -3.016864363e-03f, +4.670847512e-01f, +5.610569814e-01f, +9.388232321e-02f, -9.640809295e-02f, +1.318150805e-02f, +1.747784955e-02f, -7.204483224e-03f,
- /* 12,11 */ -5.845139328e-03f, +5.114495497e-03f, +2.946485483e-02f, -6.783107929e-02f, -2.229824534e-02f, +4.385808709e-01f, +5.783348068e-01f, +1.223701278e-01f, -9.884443272e-02f, +7.849320649e-03f, +1.999301835e-02f, -7.088917510e-03f,
- /* 12,12 */ -5.325763732e-03f, +2.972136287e-03f, +3.067703358e-02f, -6.002791415e-02f, -3.942694703e-02f, +4.086182709e-01f, +5.927266195e-01f, +1.521989634e-01f, -9.980279721e-02f, +1.874795505e-03f, +2.240361196e-02f, -6.800166749e-03f,
- /* 12,13 */ -4.769140004e-03f, +1.010002855e-03f, +3.126943445e-02f, -5.191703591e-02f, -5.436442589e-02f, +3.774917553e-01f, +6.040811565e-01f, +1.831448749e-01f, -9.913294928e-02f, -4.692548813e-03f, +2.465107974e-02f, -6.322395719e-03f,
- /* 12,14 */ -4.192641091e-03f, -7.534120996e-04f, +3.128617370e-02f, -4.365285408e-02f, -6.709962705e-02f, +3.455026876e-01f, +6.122785731e-01f, +2.149632830e-01f, -9.669686191e-02f, -1.178831271e-02f, +2.667449885e-02f, -5.642312008e-03f,
- /* 12,15 */ -3.612081594e-03f, -2.305275216e-03f, +3.077779188e-02f, -3.538029377e-02f, -7.764805088e-02f, +3.129551421e-01f, +6.172320760e-01f, +2.473915856e-01f, -9.237133076e-02f, -1.933319589e-02f, +2.841159300e-02f, -4.749738186e-03f,
- /* 12, 0 */ -7.562702671e-03f, +2.362257603e-02f, -4.531854693e-03f, -1.030173373e-01f, +2.624467795e-01f, +6.583866631e-01f, +2.624467795e-01f, -1.030173373e-01f, -4.531854693e-03f, +2.362257603e-02f, -7.562702671e-03f, -3.516889901e-04f,
- /* 12, 1 */ -7.668183010e-03f, +2.087771707e-02f, +2.839059860e-03f, -1.056218320e-01f, +2.257778124e-01f, +6.563919279e-01f, +2.995227467e-01f, -9.814415944e-02f, -1.254420342e-02f, +2.617709089e-02f, -7.250906804e-03f, -7.142430143e-04f,
- /* 12, 2 */ -7.590423774e-03f, +1.801705410e-02f, +9.487879886e-03f, -1.061169074e-01f, +1.898705313e-01f, +6.504316937e-01f, +3.366347146e-01f, -9.086648783e-02f, -2.109702270e-02f, +2.846338313e-02f, -6.712315500e-03f, -1.140764971e-03f,
- /* 12, 3 */ -7.354275530e-03f, +1.511050856e-02f, +1.535418598e-02f, -1.046816488e-01f, +1.550586973e-01f, +6.405775033e-01f, +3.734003416e-01f, -8.107535131e-02f, -3.006937567e-02f, +3.040170317e-02f, -5.929880498e-03f, -1.628307909e-03f,
- /* 12, 4 */ -6.985575046e-03f, +1.222230420e-02f, +2.039736787e-02f, -1.015111601e-01f, +1.216509697e-01f, +6.269473635e-01f, +4.094311989e-01f, -6.869168809e-02f, -3.932109040e-02f, +3.191206547e-02f, -4.890814148e-03f, -2.171433859e-03f,
- /* 12, 5 */ -6.510406524e-03f, +9.410098002e-03f, +2.459585213e-02f, -9.681266365e-02f, +8.992722338e-02f, +6.097039216e-01f, +4.443382217e-01f, -5.366903171e-02f, -4.869391429e-02f, +3.291602689e-02f, -3.587389454e-03f, -2.762058981e-03f,
- /* 12, 6 */ -5.954426605e-03f, +6.724324555e-03f, +2.794602403e-02f, -9.080157573e-02f, +6.013541337e-02f, +5.890519583e-01f, +4.777372670e-01f, -3.599575069e-02f, -5.801308453e-02f, +3.333857894e-02f, -2.017687876e-03f, -3.389362400e-03f,
- /* 12, 7 */ -5.342264546e-03f, +4.207752570e-03f, +3.046088231e-02f, -8.369763050e-02f, +3.248902822e-02f, +5.652352421e-01f, +5.092546840e-01f, -1.569678608e-02f, -6.708930595e-02f, +3.311011989e-02f, -1.862710466e-04f, -4.039767889e-03f,
- /* 12, 8 */ -4.697006242e-03f, +1.895247343e-03f, +3.216846911e-02f, -7.572111885e-02f, +7.165160645e-03f, +5.385328020e-01f, +5.385328020e-01f, +7.165160645e-03f, -7.572111885e-02f, +3.216846911e-02f, +1.895247343e-03f, -4.697006242e-03f,
- /* 12, 9 */ -4.039767889e-03f, -1.862710466e-04f, +3.311011989e-02f, -6.708930595e-02f, -1.569678608e-02f, +5.092546840e-01f, +5.652352421e-01f, +3.248902822e-02f, -8.369763050e-02f, +3.046088231e-02f, +4.207752570e-03f, -5.342264546e-03f,
- /* 12,10 */ -3.389362400e-03f, -2.017687876e-03f, +3.333857894e-02f, -5.801308453e-02f, -3.599575069e-02f, +4.777372670e-01f, +5.890519583e-01f, +6.013541337e-02f, -9.080157573e-02f, +2.794602403e-02f, +6.724324555e-03f, -5.954426605e-03f,
- /* 12,11 */ -2.762058981e-03f, -3.587389454e-03f, +3.291602689e-02f, -4.869391429e-02f, -5.366903171e-02f, +4.443382217e-01f, +6.097039216e-01f, +8.992722338e-02f, -9.681266365e-02f, +2.459585213e-02f, +9.410098002e-03f, -6.510406524e-03f,
- /* 12,12 */ -2.171433859e-03f, -4.890814148e-03f, +3.191206547e-02f, -3.932109040e-02f, -6.869168809e-02f, +4.094311989e-01f, +6.269473635e-01f, +1.216509697e-01f, -1.015111601e-01f, +2.039736787e-02f, +1.222230420e-02f, -6.985575046e-03f,
- /* 12,13 */ -1.628307909e-03f, -5.929880498e-03f, +3.040170317e-02f, -3.006937567e-02f, -8.107535131e-02f, +3.734003416e-01f, +6.405775033e-01f, +1.550586973e-01f, -1.046816488e-01f, +1.535418598e-02f, +1.511050856e-02f, -7.354275530e-03f,
- /* 12,14 */ -1.140764971e-03f, -6.712315500e-03f, +2.846338313e-02f, -2.109702270e-02f, -9.086648783e-02f, +3.366347146e-01f, +6.504316937e-01f, +1.898705313e-01f, -1.061169074e-01f, +9.487879886e-03f, +1.801705410e-02f, -7.590423774e-03f,
- /* 12,15 */ -7.142430143e-04f, -7.250906804e-03f, +2.617709089e-02f, -1.254420342e-02f, -9.814415944e-02f, +2.995227467e-01f, +6.563919279e-01f, +2.257778124e-01f, -1.056218320e-01f, +2.839059860e-03f, +2.087771707e-02f, -7.668183010e-03f,
- /* 12, 0 */ -7.009786996e-03f, +1.344312953e-02f, +1.557210222e-02f, -1.125190619e-01f, +2.408695221e-01f, +6.978842163e-01f, +2.408695221e-01f, -1.125190619e-01f, +1.557210222e-02f, +1.344312953e-02f, -7.009786996e-03f, +6.003640016e-04f,
- /* 12, 1 */ -6.398742119e-03f, +1.026913982e-02f, +2.132332546e-02f, -1.110115061e-01f, +2.005160832e-01f, +6.955088069e-01f, +2.821133540e-01f, -1.117099281e-01f, +8.845385329e-03f, +1.669708199e-02f, -7.518519523e-03f, +5.590854556e-04f,
- /* 12, 2 */ -5.716737920e-03f, +7.240001966e-03f, +2.606967700e-02f, -1.074325911e-01f, +1.614746033e-01f, +6.884146462e-01f, +3.237982615e-01f, -1.083606220e-01f, +1.198165974e-03f, +1.995657080e-02f, -7.892366537e-03f, +4.637249154e-04f,
- /* 12, 3 */ -4.993154633e-03f, +4.410399512e-03f, +2.980590100e-02f, -1.020439692e-01f, +1.241329667e-01f, +6.766973789e-01f, +3.654537522e-01f, -1.022748781e-01f, -7.287927063e-03f, +2.313861998e-02f, -8.098411048e-03f, +3.063703263e-04f,
- /* 12, 4 */ -4.254780730e-03f, +1.824453005e-03f, +3.254896791e-02f, -9.511805181e-02f, +8.884019172e-02f, +6.605145641e-01f, +4.065952670e-01f, -9.328874484e-02f, -1.650412301e-02f, +2.615301189e-02f, -8.104377377e-03f, +8.035370630e-05f,
- /* 12, 5 */ -3.525333045e-03f, -4.843426812e-04f, +3.433584064e-02f, -8.693252112e-02f, +5.590207404e-02f, +6.400829406e-01f, +4.467316931e-01f, -8.127529114e-02f, -2.631456917e-02f, +2.890390773e-02f, -7.879705669e-03f, -2.193022854e-04f,
- /* 12, 6 */ -2.825116890e-03f, -2.492908449e-03f, +3.522097401e-02f, -7.776502604e-02f, +2.557772128e-02f, +6.156746770e-01f, +4.853731430e-01f, -6.614880956e-02f, -3.655698883e-02f, +3.129176395e-02f, -7.396691856e-03f, -5.954441701e-04f,
- /* 12, 7 */ -2.170822930e-03f, -4.188126176e-03f, +3.527362061e-02f, -6.788815999e-02f, -1.922977207e-03f, +5.876126808e-01f, +5.220388545e-01f, -4.786841211e-02f, -4.704395826e-02f, +3.321551909e-02f, -6.631665064e-03f, -1.048370326e-03f,
- /* 12, 8 */ -1.575453811e-03f, -5.566170902e-03f, +3.457501660e-02f, -5.756481055e-02f, -2.644092188e-02f, +5.562650609e-01f, +5.562650609e-01f, -2.644092188e-02f, -5.756481055e-02f, +3.457501660e-02f, -5.566170902e-03f, -1.575453811e-03f,
- /* 12, 9 */ -1.048370326e-03f, -6.631665064e-03f, +3.321551909e-02f, -4.704395826e-02f, -4.786841211e-02f, +5.220388545e-01f, +5.876126808e-01f, -1.922977207e-03f, -6.788815999e-02f, +3.527362061e-02f, -4.188126176e-03f, -2.170822930e-03f,
- /* 12,10 */ -5.954441701e-04f, -7.396691856e-03f, +3.129176395e-02f, -3.655698883e-02f, -6.614880956e-02f, +4.853731430e-01f, +6.156746770e-01f, +2.557772128e-02f, -7.776502604e-02f, +3.522097401e-02f, -2.492908449e-03f, -2.825116890e-03f,
- /* 12,11 */ -2.193022854e-04f, -7.879705669e-03f, +2.890390773e-02f, -2.631456917e-02f, -8.127529114e-02f, +4.467316931e-01f, +6.400829406e-01f, +5.590207404e-02f, -8.693252112e-02f, +3.433584064e-02f, -4.843426812e-04f, -3.525333045e-03f,
- /* 12,12 */ +8.035370630e-05f, -8.104377377e-03f, +2.615301189e-02f, -1.650412301e-02f, -9.328874484e-02f, +4.065952670e-01f, +6.605145641e-01f, +8.884019172e-02f, -9.511805181e-02f, +3.254896791e-02f, +1.824453005e-03f, -4.254780730e-03f,
- /* 12,13 */ +3.063703263e-04f, -8.098411048e-03f, +2.313861998e-02f, -7.287927063e-03f, -1.022748781e-01f, +3.654537522e-01f, +6.766973789e-01f, +1.241329667e-01f, -1.020439692e-01f, +2.980590100e-02f, +4.410399512e-03f, -4.993154633e-03f,
- /* 12,14 */ +4.637249154e-04f, -7.892366537e-03f, +1.995657080e-02f, +1.198165974e-03f, -1.083606220e-01f, +3.237982615e-01f, +6.884146462e-01f, +1.614746033e-01f, -1.074325911e-01f, +2.606967700e-02f, +7.240001966e-03f, -5.716737920e-03f,
- /* 12,15 */ +5.590854556e-04f, -7.518519523e-03f, +1.669708199e-02f, +8.845385329e-03f, -1.117099281e-01f, +2.821133540e-01f, +6.955088069e-01f, +2.005160832e-01f, -1.110115061e-01f, +2.132332546e-02f, +1.026913982e-02f, -6.398742119e-03f,
-
- /* 24, 0 */ +1.501390780e-03f, +3.431804419e-03f, +6.512803185e-03f, +1.091425387e-02f, +1.664594540e-02f, +2.351091132e-02f, +3.109255671e-02f, +3.878419288e-02f, +4.586050701e-02f, +5.158058002e-02f, +5.530384985e-02f, +5.659614054e-02f, +5.530384985e-02f, +5.158058002e-02f, +4.586050701e-02f, +3.878419288e-02f, +3.109255671e-02f, +2.351091132e-02f, +1.664594540e-02f, +1.091425387e-02f, +6.512803185e-03f, +3.431804419e-03f, +1.501390780e-03f, +4.573885647e-04f,
- /* 24, 1 */ +1.413186400e-03f, +3.279858311e-03f, +6.282638036e-03f, +1.059932179e-02f, +1.625135142e-02f, +2.305547031e-02f, +3.060840342e-02f, +3.831365198e-02f, +4.545054680e-02f, +5.127577001e-02f, +5.513916011e-02f, +5.659104154e-02f, +5.545895049e-02f, +5.187752167e-02f, +4.626513642e-02f, +3.925233583e-02f, +3.157717954e-02f, +2.396921539e-02f, +1.704503934e-02f, +1.123445076e-02f, +6.748179094e-03f, +3.588275667e-03f, +1.593065611e-03f, +5.022154476e-04f,
- /* 24, 2 */ +1.328380648e-03f, +3.132379333e-03f, +6.057656813e-03f, +1.028967374e-02f, +1.586133102e-02f, +2.260301890e-02f, +3.012488684e-02f, +3.784089895e-02f, +4.503543229e-02f, +5.096323022e-02f, +5.496495842e-02f, +5.657574693e-02f, +5.560438923e-02f, +5.216645963e-02f, +4.666426010e-02f, +3.971789474e-02f, +3.206210284e-02f, +2.443025293e-02f, +1.744855617e-02f, +1.155988996e-02f, +6.988790100e-03f, +3.749328623e-03f, +1.688282347e-03f, +5.494305796e-04f,
- /* 24, 3 */ +1.246901403e-03f, +2.989308098e-03f, +5.837830254e-03f, +9.985325752e-03f, +1.547595434e-02f, +2.215368059e-02f, +2.964217216e-02f, +3.736611920e-02f, +4.461534144e-02f, +5.064310236e-02f, +5.478132634e-02f, +5.655026396e-02f, +5.574009777e-02f, +5.244726189e-02f, +4.705770477e-02f, +4.018068337e-02f, +3.254715574e-02f, +2.489389144e-02f, +1.785641537e-02f, +1.189054572e-02f, +7.234657995e-03f, +3.915018340e-03f, +1.787112015e-03f, +5.991047395e-04f,
- /* 24, 4 */ +1.168676301e-03f, +2.850583915e-03f, +5.623126723e-03f, +9.686290690e-03f, +1.509528803e-02f, +2.170757578e-02f, +2.916042250e-02f, +3.688949768e-02f, +4.419045351e-02f, +5.031553118e-02f, +5.458834968e-02f, +5.651460469e-02f, +5.586601230e-02f, +5.271979985e-02f, +4.744529894e-02f, +4.064051541e-02f, +3.303216567e-02f, +2.535999546e-02f, +1.826853297e-02f, +1.222638897e-02f, +7.485801959e-03f, +4.085398290e-03f, +1.889625146e-03f, +6.513091287e-04f,
- /* 24, 5 */ +1.093632798e-03f, +2.716144855e-03f, +5.413512274e-03f, +9.392578266e-03f, +1.471939531e-02f, +2.126482169e-02f, +2.867979883e-02f, +3.641121873e-02f, +4.376094899e-02f, +4.998066438e-02f, +5.438611851e-02f, +5.646878599e-02f, +5.598207354e-02f, +5.298394839e-02f, +4.782687301e-02f, +4.109720465e-02f, +3.351695842e-02f, +2.582842673e-02f, +1.868482156e-02f, +1.256738733e-02f, +7.742238512e-03f, +4.260520294e-03f, +1.995891717e-03f, +7.061153220e-04f,
- /* 24, 6 */ +1.021698233e-03f, +2.585927824e-03f, +5.208950715e-03f, +9.104195104e-03f, +1.434833590e-02f, +2.082553239e-02f, +2.820045990e-02f, +3.593146595e-02f, +4.332700946e-02f, +4.963865252e-02f, +5.417472708e-02f, +5.641282954e-02f, +5.608822683e-02f, +5.323958602e-02f, +4.820225940e-02f, +4.155056502e-02f, +3.400135826e-02f, +2.629904416e-02f, +1.910519032e-02f, +1.291350505e-02f, +8.003981455e-03f, +4.440434453e-03f, +2.105981077e-03f, +7.635952183e-04f,
- /* 24, 7 */ +9.527998831e-04f, +2.459868628e-03f, +5.009403670e-03f, +8.821144768e-03f, +1.398216608e-02f, +2.038981869e-02f, +2.772256216e-02f, +3.545042216e-02f, +4.288881749e-02f, +4.928964888e-02f, +5.395427373e-02f, +5.634676181e-02f, +5.618442211e-02f, +5.348659488e-02f, +4.857129262e-02f, +4.200041076e-02f, +3.448518802e-02f, +2.677170395e-02f, +1.952954505e-02f, +1.326470299e-02f, +8.271041819e-03f, +4.625189083e-03f, +2.219961884e-03f, +8.238209888e-04f,
- /* 24, 8 */ +8.868650246e-04f, +2.337902042e-03f, +4.814830642e-03f, +8.543427812e-03f, +1.362093865e-02f, +1.995778816e-02f, +2.724625964e-02f, +3.496826923e-02f, +4.244655653e-02f, +4.893380942e-02f, +5.372486088e-02f, +5.627061400e-02f, +5.627061400e-02f, +5.372486088e-02f, +4.893380942e-02f, +4.244655653e-02f, +3.496826923e-02f, +2.724625964e-02f, +1.995778816e-02f, +1.362093865e-02f, +8.543427812e-03f, +4.814830642e-03f, +2.337902042e-03f, +8.868650246e-04f,
- /* 24, 9 */ +8.238209888e-04f, +2.219961884e-03f, +4.625189083e-03f, +8.271041819e-03f, +1.326470299e-02f, +1.952954505e-02f, +2.677170395e-02f, +3.448518802e-02f, +4.200041076e-02f, +4.857129262e-02f, +5.348659488e-02f, +5.618442211e-02f, +5.634676181e-02f, +5.395427373e-02f, +4.928964888e-02f, +4.288881749e-02f, +3.545042216e-02f, +2.772256216e-02f, +2.038981869e-02f, +1.398216608e-02f, +8.821144768e-03f, +5.009403670e-03f, +2.459868628e-03f, +9.527998831e-04f,
- /* 24,10 */ +7.635952183e-04f, +2.105981077e-03f, +4.440434453e-03f, +8.003981455e-03f, +1.291350505e-02f, +1.910519032e-02f, +2.629904416e-02f, +3.400135826e-02f, +4.155056502e-02f, +4.820225940e-02f, +5.323958602e-02f, +5.608822683e-02f, +5.641282954e-02f, +5.417472708e-02f, +4.963865252e-02f, +4.332700946e-02f, +3.593146595e-02f, +2.820045990e-02f, +2.082553239e-02f, +1.434833590e-02f, +9.104195104e-03f, +5.208950715e-03f, +2.585927824e-03f, +1.021698233e-03f,
- /* 24,11 */ +7.061153220e-04f, +1.995891717e-03f, +4.260520294e-03f, +7.742238512e-03f, +1.256738733e-02f, +1.868482156e-02f, +2.582842673e-02f, +3.351695842e-02f, +4.109720465e-02f, +4.782687301e-02f, +5.298394839e-02f, +5.598207354e-02f, +5.646878599e-02f, +5.438611851e-02f, +4.998066438e-02f, +4.376094899e-02f, +3.641121873e-02f, +2.867979883e-02f, +2.126482169e-02f, +1.471939531e-02f, +9.392578266e-03f, +5.413512274e-03f, +2.716144855e-03f, +1.093632798e-03f,
- /* 24,12 */ +6.513091287e-04f, +1.889625146e-03f, +4.085398290e-03f, +7.485801959e-03f, +1.222638897e-02f, +1.826853297e-02f, +2.535999546e-02f, +3.303216567e-02f, +4.064051541e-02f, +4.744529894e-02f, +5.271979985e-02f, +5.586601230e-02f, +5.651460469e-02f, +5.458834968e-02f, +5.031553118e-02f, +4.419045351e-02f, +3.688949768e-02f, +2.916042250e-02f, +2.170757578e-02f, +1.509528803e-02f, +9.686290690e-03f, +5.623126723e-03f, +2.850583915e-03f, +1.168676301e-03f,
- /* 24,13 */ +5.991047395e-04f, +1.787112015e-03f, +3.915018340e-03f, +7.234657995e-03f, +1.189054572e-02f, +1.785641537e-02f, +2.489389144e-02f, +3.254715574e-02f, +4.018068337e-02f, +4.705770477e-02f, +5.244726189e-02f, +5.574009777e-02f, +5.655026396e-02f, +5.478132634e-02f, +5.064310236e-02f, +4.461534144e-02f, +3.736611920e-02f, +2.964217216e-02f, +2.215368059e-02f, +1.547595434e-02f, +9.985325752e-03f, +5.837830254e-03f, +2.989308098e-03f, +1.246901403e-03f,
- /* 24,14 */ +5.494305796e-04f, +1.688282347e-03f, +3.749328623e-03f, +6.988790100e-03f, +1.155988996e-02f, +1.744855617e-02f, +2.443025293e-02f, +3.206210284e-02f, +3.971789474e-02f, +4.666426010e-02f, +5.216645963e-02f, +5.560438923e-02f, +5.657574693e-02f, +5.496495842e-02f, +5.096323022e-02f, +4.503543229e-02f, +3.784089895e-02f, +3.012488684e-02f, +2.260301890e-02f, +1.586133102e-02f, +1.028967374e-02f, +6.057656813e-03f, +3.132379333e-03f, +1.328380648e-03f,
- /* 24,15 */ +5.022154476e-04f, +1.593065611e-03f, +3.588275667e-03f, +6.748179094e-03f, +1.123445076e-02f, +1.704503934e-02f, +2.396921539e-02f, +3.157717954e-02f, +3.925233583e-02f, +4.626513642e-02f, +5.187752167e-02f, +5.545895049e-02f, +5.659104154e-02f, +5.513916011e-02f, +5.127577001e-02f, +4.545054680e-02f, +3.831365198e-02f, +3.060840342e-02f, +2.305547031e-02f, +1.625135142e-02f, +1.059932179e-02f, +6.282638036e-03f, +3.279858311e-03f, +1.413186400e-03f,
- /* 24, 0 */ -2.629184871e-03f, -4.843950453e-03f, -6.895985300e-03f, -7.687208098e-03f, -5.978262553e-03f, -8.032174656e-04f, +8.095316761e-03f, +1.997958831e-02f, +3.311864145e-02f, +4.512644231e-02f, +5.356009950e-02f, +5.659614054e-02f, +5.356009950e-02f, +4.512644231e-02f, +3.311864145e-02f, +1.997958831e-02f, +8.095316761e-03f, -8.032174656e-04f, -5.978262553e-03f, -7.687208098e-03f, -6.895985300e-03f, -4.843950453e-03f, -2.629184871e-03f, -9.454953712e-04f,
- /* 24, 1 */ -2.503767166e-03f, -4.700731697e-03f, -6.791825424e-03f, -7.698565601e-03f, -6.179328945e-03f, -1.237726578e-03f, +7.438688744e-03f, +1.917778123e-02f, +3.230413198e-02f, +4.445707943e-02f, +5.317715832e-02f, +5.658405316e-02f, +5.392156860e-02f, +4.578163621e-02f, +3.392875410e-02f, +2.078652132e-02f, +8.763945305e-03f, -3.538276542e-04f, -5.763420347e-03f, -7.665996832e-03f, -6.995273095e-03f, -4.986674025e-03f, -2.756835384e-03f, -1.028686673e-03f,
- /* 24, 2 */ -2.380688695e-03f, -4.557243028e-03f, -6.683099486e-03f, -7.700368745e-03f, -6.366798820e-03f, -1.657314491e-03f, +6.794365087e-03f, +1.838162773e-02f, +3.148585651e-02f, +4.377411309e-02f, +5.277308334e-02f, +5.654780182e-02f, +5.426124576e-02f, +4.642210542e-02f, +3.473383802e-02f, +2.159804191e-02f, +9.444254477e-03f, +1.103863968e-04f, -5.534634231e-03f, -7.634636496e-03f, -7.089380216e-03f, -5.128670417e-03f, -2.886604737e-03f, -1.114962551e-03f,
- /* 24, 3 */ -2.260048394e-03f, -4.413702845e-03f, -6.570110572e-03f, -7.692920583e-03f, -6.540862270e-03f, -2.061956485e-03f, +6.162633403e-03f, +1.759164425e-02f, +3.066444409e-02f, +4.307811806e-02f, +5.234823086e-02f, +5.648741902e-02f, +5.457882991e-02f, +4.704730472e-02f, +3.553326091e-02f, +2.241360152e-02f, +1.013590849e-02f, +5.893521078e-04f, -5.291747706e-03f, -7.592836347e-03f, -7.177995846e-03f, -5.269701073e-03f, -3.018371382e-03f, -1.204312280e-03f,
- /* 24, 4 */ -2.141937776e-03f, -4.270322542e-03f, -6.453158507e-03f, -7.676527355e-03f, -6.701719772e-03f, -2.451643421e-03f, +5.543764951e-03f, +1.680833562e-02f, +2.984052134e-02f, +4.236967758e-02f, +5.190297478e-02f, +5.640295884e-02f, +5.487403917e-02f, +4.765670002e-02f, +3.632639074e-02f, +2.323264190e-02f, +1.083855586e-02f, +1.082980638e-03f, -5.034616251e-03f, -7.540310660e-03f, -7.260807322e-03f, -5.409521052e-03f, -3.152006158e-03f, -1.296719170e-03f,
- /* 24, 5 */ -2.026441000e-03f, -4.127306381e-03f, -6.332539518e-03f, -7.651498041e-03f, -6.849581767e-03f, -2.826381528e-03f, +4.938014526e-03f, +1.603219452e-02f, +2.901471178e-02f, +4.164938279e-02f, +5.143770614e-02f, +5.629449693e-02f, +5.514661113e-02f, +4.824976895e-02f, +3.711259647e-02f, +2.405459566e-02f, +1.155182965e-02f, +1.591166761e-03f, -4.763107701e-03f, -7.476779193e-03f, -7.337500507e-03f, -5.547879217e-03f, -3.287372274e-03f, -1.392160404e-03f,
- /* 24, 6 */ -1.913634953e-03f, -3.984851387e-03f, -6.208545927e-03f, -7.618143912e-03f, -6.984668233e-03f, -3.186192169e-03f, +4.345620369e-03f, +1.526370115e-02f, +2.818763519e-02f, +4.091783200e-02f, +5.095283267e-02f, +5.616213037e-02f, +5.539630322e-02f, +4.882600150e-02f, +3.789124869e-02f, +2.487888677e-02f, +1.227534767e-02f, +2.113788767e-03f, -4.477102606e-03f, -7.401967644e-03f, -7.407760182e-03f, -5.684518438e-03f, -3.424325302e-03f, -1.490606880e-03f,
- /* 24, 7 */ -1.803589350e-03f, -3.843147252e-03f, -6.081465840e-03f, -7.576778087e-03f, -7.107208249e-03f, -3.531111592e-03f, +3.766804102e-03f, +1.450332275e-02f, +2.735990694e-02f, +4.017563005e-02f, +5.044877831e-02f, +5.600597761e-02f, +5.562289296e-02f, +4.938490059e-02f, +3.866172039e-02f, +2.570493119e-02f, +1.300871280e-02f, +2.650708377e-03f, -4.176494585e-03f, -7.315608112e-03f, -7.471270440e-03f, -5.819175805e-03f, -3.562713186e-03f, -1.592023060e-03f,
- /* 24, 8 */ -1.696366827e-03f, -3.702376254e-03f, -5.951582861e-03f, -7.527715094e-03f, -7.217439556e-03f, -3.861190662e-03f, +3.201770681e-03f, +1.375151322e-02f, +2.653213738e-02f, +3.942338759e-02f, +4.992598268e-02f, +5.582617825e-02f, +5.582617825e-02f, +4.992598268e-02f, +3.942338759e-02f, +2.653213738e-02f, +1.375151322e-02f, +3.201770681e-03f, -3.861190662e-03f, -7.217439556e-03f, -7.527715094e-03f, -5.951582861e-03f, -3.702376254e-03f, -1.696366827e-03f,
- /* 24, 9 */ -1.592023060e-03f, -3.562713186e-03f, -5.819175805e-03f, -7.471270440e-03f, -7.315608112e-03f, -4.176494585e-03f, +2.650708377e-03f, +1.300871280e-02f, +2.570493119e-02f, +3.866172039e-02f, +4.938490059e-02f, +5.562289296e-02f, +5.600597761e-02f, +5.044877831e-02f, +4.017563005e-02f, +2.735990694e-02f, +1.450332275e-02f, +3.766804102e-03f, -3.531111592e-03f, -7.107208249e-03f, -7.576778087e-03f, -6.081465840e-03f, -3.843147252e-03f, -1.803589350e-03f,
- /* 24,10 */ -1.490606880e-03f, -3.424325302e-03f, -5.684518438e-03f, -7.407760182e-03f, -7.401967644e-03f, -4.477102606e-03f, +2.113788767e-03f, +1.227534767e-02f, +2.487888677e-02f, +3.789124869e-02f, +4.882600150e-02f, +5.539630322e-02f, +5.616213037e-02f, +5.095283267e-02f, +4.091783200e-02f, +2.818763519e-02f, +1.526370115e-02f, +4.345620369e-03f, -3.186192169e-03f, -6.984668233e-03f, -7.618143912e-03f, -6.208545927e-03f, -3.984851387e-03f, -1.913634953e-03f,
- /* 24,11 */ -1.392160404e-03f, -3.287372274e-03f, -5.547879217e-03f, -7.337500507e-03f, -7.476779193e-03f, -4.763107701e-03f, +1.591166761e-03f, +1.155182965e-02f, +2.405459566e-02f, +3.711259647e-02f, +4.824976895e-02f, +5.514661113e-02f, +5.629449693e-02f, +5.143770614e-02f, +4.164938279e-02f, +2.901471178e-02f, +1.603219452e-02f, +4.938014526e-03f, -2.826381528e-03f, -6.849581767e-03f, -7.651498041e-03f, -6.332539518e-03f, -4.127306381e-03f, -2.026441000e-03f,
- /* 24,12 */ -1.296719170e-03f, -3.152006158e-03f, -5.409521052e-03f, -7.260807322e-03f, -7.540310660e-03f, -5.034616251e-03f, +1.082980638e-03f, +1.083855586e-02f, +2.323264190e-02f, +3.632639074e-02f, +4.765670002e-02f, +5.487403917e-02f, +5.640295884e-02f, +5.190297478e-02f, +4.236967758e-02f, +2.984052134e-02f, +1.680833562e-02f, +5.543764951e-03f, -2.451643421e-03f, -6.701719772e-03f, -7.676527355e-03f, -6.453158507e-03f, -4.270322542e-03f, -2.141937776e-03f,
- /* 24,13 */ -1.204312280e-03f, -3.018371382e-03f, -5.269701073e-03f, -7.177995846e-03f, -7.592836347e-03f, -5.291747706e-03f, +5.893521078e-04f, +1.013590849e-02f, +2.241360152e-02f, +3.553326091e-02f, +4.704730472e-02f, +5.457882991e-02f, +5.648741902e-02f, +5.234823086e-02f, +4.307811806e-02f, +3.066444409e-02f, +1.759164425e-02f, +6.162633403e-03f, -2.061956485e-03f, -6.540862270e-03f, -7.692920583e-03f, -6.570110572e-03f, -4.413702845e-03f, -2.260048394e-03f,
- /* 24,14 */ -1.114962551e-03f, -2.886604737e-03f, -5.128670417e-03f, -7.089380216e-03f, -7.634636496e-03f, -5.534634231e-03f, +1.103863968e-04f, +9.444254477e-03f, +2.159804191e-02f, +3.473383802e-02f, +4.642210542e-02f, +5.426124576e-02f, +5.654780182e-02f, +5.277308334e-02f, +4.377411309e-02f, +3.148585651e-02f, +1.838162773e-02f, +6.794365087e-03f, -1.657314491e-03f, -6.366798820e-03f, -7.700368745e-03f, -6.683099486e-03f, -4.557243028e-03f, -2.380688695e-03f,
- /* 24,15 */ -1.028686673e-03f, -2.756835384e-03f, -4.986674025e-03f, -6.995273095e-03f, -7.665996832e-03f, -5.763420347e-03f, -3.538276542e-04f, +8.763945305e-03f, +2.078652132e-02f, +3.392875410e-02f, +4.578163621e-02f, +5.392156860e-02f, +5.658405316e-02f, +5.317715832e-02f, +4.445707943e-02f, +3.230413198e-02f, +1.917778123e-02f, +7.438688744e-03f, -1.237726578e-03f, -6.179328945e-03f, -7.698565601e-03f, -6.791825424e-03f, -4.700731697e-03f, -2.503767166e-03f,
- /* 24, 0 */ +4.735641749e-04f, -1.438577362e-03f, -6.107076473e-03f, -1.318715065e-02f, -2.047716119e-02f, -2.428668798e-02f, -2.088952800e-02f, -8.512165320e-03f, +1.117510535e-02f, +3.302575560e-02f, +5.012757987e-02f, +5.659614054e-02f, +5.012757987e-02f, +3.302575560e-02f, +1.117510535e-02f, -8.512165320e-03f, -2.088952800e-02f, -2.428668798e-02f, -2.047716119e-02f, -1.318715065e-02f, -6.107076473e-03f, -1.438577362e-03f, +4.735641749e-04f, +5.516063288e-04f,
- /* 24, 1 */ +5.190146993e-04f, -1.243445781e-03f, -5.732182665e-03f, -1.270621714e-02f, -2.008108462e-02f, -2.422674988e-02f, -2.136190754e-02f, -9.536491055e-03f, +9.813857768e-03f, +3.172645287e-02f, +4.932296812e-02f, +5.657007725e-02f, +5.088942272e-02f, +3.430616434e-02f, +1.254542812e-02f, -7.458075491e-03f, -2.038088472e-02f, -2.431781992e-02f, -2.085968072e-02f, -1.366943909e-02f, -6.492037400e-03f, -1.644903025e-03f, +4.208638005e-04f, +5.761542752e-04f,
- /* 24, 2 */ +5.575380238e-04f, -1.059370463e-03f, -5.367638258e-03f, -1.222740313e-02f, -1.967247249e-02f, -2.413881461e-02f, -2.179812108e-02f, -1.053019587e-02f, +8.463295193e-03f, +3.041001010e-02f, +4.847674006e-02f, +5.649192540e-02f, +5.160740292e-02f, +3.556594146e-02f, +1.392318625e-02f, -6.375136316e-03f, -1.983593655e-02f, -2.431936776e-02f, -2.122761958e-02f, -1.415229209e-02f, -6.886752185e-03f, -1.862540304e-03f, +3.605947820e-04f, +5.982066157e-04f,
- /* 24, 3 */ +5.894596941e-04f, -8.861942853e-04f, -5.013694839e-03f, -1.175144649e-02f, -1.925234223e-02f, -2.402372023e-02f, -2.219832191e-02f, -1.149248169e-02f, +7.124994951e-03f, +2.907819451e-02f, +4.759010507e-02f, +5.636179897e-02f, +5.228048761e-02f, +3.680336864e-02f, +1.530671242e-02f, -5.264319552e-03f, -1.925469982e-02f, -2.429058667e-02f, -2.157995394e-02f, -1.463489443e-02f, -7.290876362e-03f, -2.091585491e-03f, +2.924431607e-04f, +6.174753085e-04f,
- /* 24, 4 */ +6.151072142e-04f, -7.237418200e-04f, -4.670573645e-03f, -1.127905759e-02f, -1.882170532e-02f, -2.388233174e-02f, -2.256271775e-02f, -1.242260980e-02f, +5.800499486e-03f, +2.773278351e-02f, +4.666432713e-02f, +5.617988770e-02f, +5.290770668e-02f, +3.801674993e-02f, +1.669431448e-02f, -4.126652928e-03f, -1.863724919e-02f, -2.423076690e-02f, -2.191566174e-02f, -1.511640714e-02f, -7.704034115e-03f, -2.332112699e-03f, +2.161008111e-04f, +6.336652968e-04f,
- /* 24, 5 */ +6.348091316e-04f, -5.718203517e-04f, -4.338465973e-03f, -1.081091853e-02f, -1.838156554e-02f, -2.371553901e-02f, -2.289156957e-02f, -1.331990148e-02f, +4.491314051e-03f, +2.637556170e-02f, +4.570072248e-02f, +5.594645674e-02f, +5.348815454e-02f, +3.920441468e-02f, +1.808427811e-02f, -2.963218986e-03f, -1.798371833e-02f, -2.413923574e-02f, -2.223372473e-02f, -1.559596853e-02f, -8.125818185e-03f, -2.584172964e-03f, +1.312664533e-04f, +6.464750685e-04f,
- /* 24, 6 */ +6.488941487e-04f, -4.302209069e-04f, -4.017533648e-03f, -1.034768250e-02f, -1.793291714e-02f, -2.352425464e-02f, -2.318519030e-02f, -1.418373842e-02f, +3.198904487e-03f, +2.500831779e-02f, +4.470065727e-02f, +5.566184614e-02f, +5.402099181e-02f, +4.036472049e-02f, +1.947486957e-02f, -1.775153809e-03f, -1.729430055e-02f, -2.401535937e-02f, -2.253313051e-02f, -1.607269547e-02f, -8.555789856e-03f, -2.847793367e-03f, +3.764667972e-05f, +6.555972530e-04f,
- /* 24, 7 */ +6.576902611e-04f, -2.987192943e-04f, -3.707909539e-03f, -9.889973186e-03f, -1.747674315e-02f, -2.330941189e-02f, -2.344394342e-02f, -1.501356300e-02f, +1.924695104e-03f, +2.363284155e-02f, +4.366554511e-02f, +5.532647026e-02f, +5.450544680e-02f, +4.149605616e-02f, +2.086433852e-02f, -5.636456344e-04f, -1.656924930e-02f, -2.385854478e-02f, -2.281287459e-02f, -1.654568462e-02f, -8.993479016e-03f, -3.122976195e-03f, -6.504300803e-05f, +6.607192554e-04f,
- /* 24, 8 */ +6.615239252e-04f, -1.770771536e-04f, -3.409698141e-03f, -9.438384277e-03f, -1.701401374e-02f, -2.307196251e-02f, -2.366824152e-02f, -1.580887853e-02f, +6.700666468e-04f, +2.225092083e-02f, +4.259684448e-02f, +5.494081698e-02f, +5.494081698e-02f, +4.259684448e-02f, +2.225092083e-02f, +6.700666468e-04f, -1.580887853e-02f, -2.366824152e-02f, -2.307196251e-02f, -1.701401374e-02f, -9.438384277e-03f, -3.409698141e-03f, -1.770771536e-04f, +6.615239252e-04f,
- /* 24, 9 */ +6.607192554e-04f, -6.504300803e-05f, -3.122976195e-03f, -8.993479016e-03f, -1.654568462e-02f, -2.281287459e-02f, -2.385854478e-02f, -1.656924930e-02f, -5.636456344e-04f, +2.086433852e-02f, +4.149605616e-02f, +5.450544680e-02f, +5.532647026e-02f, +4.366554511e-02f, +2.363284155e-02f, +1.924695104e-03f, -1.501356300e-02f, -2.344394342e-02f, -2.330941189e-02f, -1.747674315e-02f, -9.889973186e-03f, -3.707909539e-03f, -2.987192943e-04f, +6.576902611e-04f,
- /* 24,10 */ +6.555972530e-04f, +3.764667972e-05f, -2.847793367e-03f, -8.555789856e-03f, -1.607269547e-02f, -2.253313051e-02f, -2.401535937e-02f, -1.729430055e-02f, -1.775153809e-03f, +1.947486957e-02f, +4.036472049e-02f, +5.402099181e-02f, +5.566184614e-02f, +4.470065727e-02f, +2.500831779e-02f, +3.198904487e-03f, -1.418373842e-02f, -2.318519030e-02f, -2.352425464e-02f, -1.793291714e-02f, -1.034768250e-02f, -4.017533648e-03f, -4.302209069e-04f, +6.488941487e-04f,
- /* 24,11 */ +6.464750685e-04f, +1.312664533e-04f, -2.584172964e-03f, -8.125818185e-03f, -1.559596853e-02f, -2.223372473e-02f, -2.413923574e-02f, -1.798371833e-02f, -2.963218986e-03f, +1.808427811e-02f, +3.920441468e-02f, +5.348815454e-02f, +5.594645674e-02f, +4.570072248e-02f, +2.637556170e-02f, +4.491314051e-03f, -1.331990148e-02f, -2.289156957e-02f, -2.371553901e-02f, -1.838156554e-02f, -1.081091853e-02f, -4.338465973e-03f, -5.718203517e-04f, +6.348091316e-04f,
- /* 24,12 */ +6.336652968e-04f, +2.161008111e-04f, -2.332112699e-03f, -7.704034115e-03f, -1.511640714e-02f, -2.191566174e-02f, -2.423076690e-02f, -1.863724919e-02f, -4.126652928e-03f, +1.669431448e-02f, +3.801674993e-02f, +5.290770668e-02f, +5.617988770e-02f, +4.666432713e-02f, +2.773278351e-02f, +5.800499486e-03f, -1.242260980e-02f, -2.256271775e-02f, -2.388233174e-02f, -1.882170532e-02f, -1.127905759e-02f, -4.670573645e-03f, -7.237418200e-04f, +6.151072142e-04f,
- /* 24,13 */ +6.174753085e-04f, +2.924431607e-04f, -2.091585491e-03f, -7.290876362e-03f, -1.463489443e-02f, -2.157995394e-02f, -2.429058667e-02f, -1.925469982e-02f, -5.264319552e-03f, +1.530671242e-02f, +3.680336864e-02f, +5.228048761e-02f, +5.636179897e-02f, +4.759010507e-02f, +2.907819451e-02f, +7.124994951e-03f, -1.149248169e-02f, -2.219832191e-02f, -2.402372023e-02f, -1.925234223e-02f, -1.175144649e-02f, -5.013694839e-03f, -8.861942853e-04f, +5.894596941e-04f,
- /* 24,14 */ +5.982066157e-04f, +3.605947820e-04f, -1.862540304e-03f, -6.886752185e-03f, -1.415229209e-02f, -2.122761958e-02f, -2.431936776e-02f, -1.983593655e-02f, -6.375136316e-03f, +1.392318625e-02f, +3.556594146e-02f, +5.160740292e-02f, +5.649192540e-02f, +4.847674006e-02f, +3.041001010e-02f, +8.463295193e-03f, -1.053019587e-02f, -2.179812108e-02f, -2.413881461e-02f, -1.967247249e-02f, -1.222740313e-02f, -5.367638258e-03f, -1.059370463e-03f, +5.575380238e-04f,
- /* 24,15 */ +5.761542752e-04f, +4.208638005e-04f, -1.644903025e-03f, -6.492037400e-03f, -1.366943909e-02f, -2.085968072e-02f, -2.431781992e-02f, -2.038088472e-02f, -7.458075491e-03f, +1.254542812e-02f, +3.430616434e-02f, +5.088942272e-02f, +5.657007725e-02f, +4.932296812e-02f, +3.172645287e-02f, +9.813857768e-03f, -9.536491055e-03f, -2.136190754e-02f, -2.422674988e-02f, -2.008108462e-02f, -1.270621714e-02f, -5.732182665e-03f, -1.243445781e-03f, +5.190146993e-04f,
- /* 24, 0 */ +2.273459443e-03f, +5.435907648e-03f, +7.255296399e-03f, +3.788129032e-03f, -7.144684562e-03f, -2.265374973e-02f, -3.442368170e-02f, -3.287677614e-02f, -1.387331771e-02f, +1.679264590e-02f, +4.511451955e-02f, +5.659614054e-02f, +4.511451955e-02f, +1.679264590e-02f, -1.387331771e-02f, -3.287677614e-02f, -3.442368170e-02f, -2.265374973e-02f, -7.144684562e-03f, +3.788129032e-03f, +7.255296399e-03f, +5.435907648e-03f, +2.273459443e-03f, +3.568431303e-04f,
- /* 24, 1 */ +2.103234406e-03f, +5.239407106e-03f, +7.256400195e-03f, +4.221207454e-03f, -6.266228991e-03f, -2.168841690e-02f, -3.399213075e-02f, -3.348773370e-02f, -1.551504116e-02f, +1.477681868e-02f, +4.371373211e-02f, +5.654911556e-02f, +4.644656718e-02f, +1.879953521e-02f, -1.218307761e-02f, -3.219410560e-02f, -3.480135038e-02f, -2.360501860e-02f, -8.042999544e-03f, +3.324105568e-03f, +7.232988111e-03f, +5.627714430e-03f, +2.449385040e-03f, +4.247055554e-04f,
- /* 24, 2 */ +1.939021806e-03f, +5.039131826e-03f, +7.237298926e-03f, +4.623451366e-03f, -5.409068119e-03f, -2.071157693e-02f, -3.350883303e-02f, -3.402698064e-02f, -1.710557364e-02f, +1.275612557e-02f, +4.224725679e-02f, +5.640814528e-02f, +4.770696520e-02f, +2.079340350e-02f, -1.044713814e-02f, -3.143988919e-02f, -3.512309015e-02f, -2.453963953e-02f, -8.959642554e-03f, +2.829112073e-03f, +7.188501693e-03f, +5.813881008e-03f, +2.630658922e-03f, +4.992251326e-04f,
- /* 24, 3 */ +1.781093672e-03f, +4.835971292e-03f, +7.199013760e-03f, +4.995053998e-03f, -4.574539506e-03f, -1.972575310e-02f, -3.297600576e-02f, -3.449468646e-02f, -1.864238902e-02f, +1.073461753e-02f, +4.071827965e-02f, +5.617354343e-02f, +4.889295364e-02f, +2.277016679e-02f, -8.668453837e-03f, -3.061446547e-02f, -3.538695026e-02f, -2.545500791e-02f, -9.892988076e-03f, +2.303211764e-03f, +7.120893393e-03f, +5.993435804e-03f, +2.816887995e-03f, +5.805470381e-04f,
- /* 24, 4 */ +1.629682882e-03f, +4.630783503e-03f, +7.142583584e-03f, +5.336288236e-03f, -3.763881685e-03f, -1.873342898e-02f, -3.239594057e-02f, -3.489118499e-02f, -2.012311412e-02f, +8.716314532e-03f, +3.913011251e-02f, +5.584583195e-02f, +5.000192959e-02f, +2.472575033e-02f, -6.850110412e-03f, -2.971834586e-02f, -3.559108276e-02f, -2.634850527e-02f, -1.084131876e-02f, +1.746558492e-03f, +7.029253460e-03f, +6.165384566e-03f, +3.007638074e-03f, +6.687931554e-04f,
- /* 24, 5 */ +1.484983972e-03f, +4.424393216e-03f, +7.069061064e-03f, +5.647503405e-03f, -2.978233194e-03f, -1.773704257e-02f, -3.177099609e-02f, -3.521697115e-02f, -2.154553308e-02f, +6.705195776e-03f, +3.748618427e-02f, +5.542573963e-02f, +5.103145416e-02f, +2.665609886e-02f, -4.995318215e-03f, -2.875221569e-02f, -3.573374914e-02f, -2.721750622e-02f, -1.180282806e-02f, +1.159398961e-03f, +6.912710257e-03f, +6.328712988e-03f, +3.202433762e-03f, +7.640603932e-04f,
- /* 24, 6 */ +1.347154069e-03f, +4.217590351e-03f, +6.979508760e-03f, +5.929121902e-03f, -2.218631929e-03f, -1.673898061e-02f, -3.110359053e-02f, -3.547269735e-02f, -2.290759116e-02f, +4.705190128e-03f, +3.579003198e-02f, +5.491420012e-02f, +5.197925890e-02f, +2.855718684e-02f, -3.107405323e-03f, -2.771693469e-02f, -3.581332680e-02f, -2.805938547e-02f, -1.277562317e-02f, +5.420746921e-04f, +6.770434377e-03f, +6.482389493e-03f, +3.400758480e-03f, +8.664190421e-04f,
- /* 24, 7 */ +1.216313935e-03f, +4.011128586e-03f, +6.874995333e-03f, +6.181635683e-03f, -1.486014823e-03f, -1.574157316e-02f, -3.039619415e-02f, -3.565916944e-02f, -2.420739811e-02f, +2.720166717e-03f, +3.404529163e-02f, +5.431234943e-02f, +5.284325182e-02f, +3.042502866e-02f, -1.189810237e-03f, -2.661353708e-02f, -3.582831530e-02f, -2.887152508e-02f, -1.375772836e-02f, -1.049762569e-04f, +6.601642735e-03f, +6.625368167e-03f, +3.602054665e-03f, +9.759111772e-04f,
- /* 24, 8 */ +1.092549115e-03f, +3.805724130e-03f, +6.756591845e-03f, +6.405602617e-03f, -7.812178358e-04f, -1.474708852e-02f, -2.965132174e-02f, -3.577734234e-02f, -2.544323110e-02f, +7.539257812e-04f, +3.225568873e-02f, +5.362152294e-02f, +5.362152294e-02f, +3.225568873e-02f, +7.539257812e-04f, -2.544323110e-02f, -3.577734234e-02f, -2.965132174e-02f, -1.474708852e-02f, -7.812178358e-04f, +6.405602617e-03f, +6.756591845e-03f, +3.805724130e-03f, +1.092549115e-03f,
- /* 24, 9 */ +9.759111772e-04f, +3.602054665e-03f, +6.625368167e-03f, +6.601642735e-03f, -1.049762569e-04f, -1.375772836e-02f, -2.887152508e-02f, -3.582831530e-02f, -2.661353708e-02f, -1.189810237e-03f, +3.042502866e-02f, +5.284325182e-02f, +5.431234943e-02f, +3.404529163e-02f, +2.720166717e-03f, -2.420739811e-02f, -3.565916944e-02f, -3.039619415e-02f, -1.574157316e-02f, -1.486014823e-03f, +6.181635683e-03f, +6.874995333e-03f, +4.011128586e-03f, +1.216313935e-03f,
- /* 24,10 */ +8.664190421e-04f, +3.400758480e-03f, +6.482389493e-03f, +6.770434377e-03f, +5.420746921e-04f, -1.277562317e-02f, -2.805938547e-02f, -3.581332680e-02f, -2.771693469e-02f, -3.107405323e-03f, +2.855718684e-02f, +5.197925890e-02f, +5.491420012e-02f, +3.579003198e-02f, +4.705190128e-03f, -2.290759116e-02f, -3.547269735e-02f, -3.110359053e-02f, -1.673898061e-02f, -2.218631929e-03f, +5.929121902e-03f, +6.979508760e-03f, +4.217590351e-03f, +1.347154069e-03f,
- /* 24,11 */ +7.640603932e-04f, +3.202433762e-03f, +6.328712988e-03f, +6.912710257e-03f, +1.159398961e-03f, -1.180282806e-02f, -2.721750622e-02f, -3.573374914e-02f, -2.875221569e-02f, -4.995318215e-03f, +2.665609886e-02f, +5.103145416e-02f, +5.542573963e-02f, +3.748618427e-02f, +6.705195776e-03f, -2.154553308e-02f, -3.521697115e-02f, -3.177099609e-02f, -1.773704257e-02f, -2.978233194e-03f, +5.647503405e-03f, +7.069061064e-03f, +4.424393216e-03f, +1.484983972e-03f,
- /* 24,12 */ +6.687931554e-04f, +3.007638074e-03f, +6.165384566e-03f, +7.029253460e-03f, +1.746558492e-03f, -1.084131876e-02f, -2.634850527e-02f, -3.559108276e-02f, -2.971834586e-02f, -6.850110412e-03f, +2.472575033e-02f, +5.000192959e-02f, +5.584583195e-02f, +3.913011251e-02f, +8.716314532e-03f, -2.012311412e-02f, -3.489118499e-02f, -3.239594057e-02f, -1.873342898e-02f, -3.763881685e-03f, +5.336288236e-03f, +7.142583584e-03f, +4.630783503e-03f, +1.629682882e-03f,
- /* 24,13 */ +5.805470381e-04f, +2.816887995e-03f, +5.993435804e-03f, +7.120893393e-03f, +2.303211764e-03f, -9.892988076e-03f, -2.545500791e-02f, -3.538695026e-02f, -3.061446547e-02f, -8.668453837e-03f, +2.277016679e-02f, +4.889295364e-02f, +5.617354343e-02f, +4.071827965e-02f, +1.073461753e-02f, -1.864238902e-02f, -3.449468646e-02f, -3.297600576e-02f, -1.972575310e-02f, -4.574539506e-03f, +4.995053998e-03f, +7.199013760e-03f, +4.835971292e-03f, +1.781093672e-03f,
- /* 24,14 */ +4.992251326e-04f, +2.630658922e-03f, +5.813881008e-03f, +7.188501693e-03f, +2.829112073e-03f, -8.959642554e-03f, -2.453963953e-02f, -3.512309015e-02f, -3.143988919e-02f, -1.044713814e-02f, +2.079340350e-02f, +4.770696520e-02f, +5.640814528e-02f, +4.224725679e-02f, +1.275612557e-02f, -1.710557364e-02f, -3.402698064e-02f, -3.350883303e-02f, -2.071157693e-02f, -5.409068119e-03f, +4.623451366e-03f, +7.237298926e-03f, +5.039131826e-03f, +1.939021806e-03f,
- /* 24,15 */ +4.247055554e-04f, +2.449385040e-03f, +5.627714430e-03f, +7.232988111e-03f, +3.324105568e-03f, -8.042999544e-03f, -2.360501860e-02f, -3.480135038e-02f, -3.219410560e-02f, -1.218307761e-02f, +1.879953521e-02f, +4.644656718e-02f, +5.654911556e-02f, +4.371373211e-02f, +1.477681868e-02f, -1.551504116e-02f, -3.348773370e-02f, -3.399213075e-02f, -2.168841690e-02f, -6.266228991e-03f, +4.221207454e-03f, +7.256400195e-03f, +5.239407106e-03f, +2.103234406e-03f,
- /* 24, 0 */ -2.181310192e-03f, -7.982329251e-04f, +5.680209618e-03f, +1.430719659e-02f, +1.589843483e-02f, +2.406871994e-03f, -2.249676846e-02f, -4.130100690e-02f, -3.506718353e-02f, -1.541681908e-03f, +3.867898214e-02f, +5.659614054e-02f, +3.867898214e-02f, -1.541681908e-03f, -3.506718353e-02f, -4.130100690e-02f, -2.249676846e-02f, +2.406871994e-03f, +1.589843483e-02f, +1.430719659e-02f, +5.680209618e-03f, -7.982329251e-04f, -2.181310192e-03f, -9.324150638e-04f,
- /* 24, 1 */ -2.142117633e-03f, -1.026327303e-03f, +5.144075019e-03f, +1.386145083e-02f, +1.619749380e-02f, +3.702669669e-03f, -2.089125129e-02f, -4.071342524e-02f, -3.635626763e-02f, -4.137848013e-03f, +3.654904222e-02f, +5.652117066e-02f, +4.071616274e-02f, +1.083860427e-03f, -3.366302266e-02f, -4.178478525e-02f, -2.407924887e-02f, +1.061252794e-03f, +1.553625174e-02f, +1.472529111e-02f, +6.227191439e-03f, -5.482915187e-04f, -2.210193915e-03f, -1.021372070e-03f,
- /* 24, 2 */ -2.093579858e-03f, -1.232841058e-03f, +4.620399561e-03f, +1.339085359e-02f, +1.643462496e-02f, +4.945866528e-03f, -1.926829204e-02f, -4.002576024e-02f, -3.752797769e-02f, -6.697199080e-03f, +3.433305089e-02f, +5.629650283e-02f, +4.265414906e-02f, +3.731182183e-03f, -3.214649405e-02f, -4.216132985e-02f, -2.563305646e-02f, -3.311524193e-04f, +1.510995111e-02f, +1.511293981e-02f, +6.783287607e-03f, -2.763303743e-04f, -2.227804667e-03f, -1.112061839e-03f,
- /* 24, 3 */ -2.036654869e-03f, -1.418128950e-03f, +4.110671651e-03f, +1.289819803e-02f, +1.661121711e-02f, +6.133943976e-03f, -1.763342417e-02f, -3.924200344e-02f, -3.858043162e-02f, -9.212479159e-03f, +3.203796457e-02f, +5.592286159e-02f, +4.448680259e-02f, +6.392554173e-03f, -3.052071354e-02f, -4.242751674e-02f, -2.715253413e-02f, -1.767057534e-03f, +1.461875233e-02f, +1.546736546e-02f, +7.346647501e-03f, +1.772445414e-05f, -2.233183138e-03f, -1.203936109e-03f,
- /* 24, 4 */ -1.972290178e-03f, -1.582628528e-03f, +3.616254280e-03f, +1.238625918e-02f, +1.672884047e-02f, +7.264647438e-03f, -1.599210066e-02f, -3.836639935e-02f, -3.951216427e-02f, -1.167663915e-02f, +2.967096294e-02f, +5.540145153e-02f, +4.620830373e-02f, +9.060141131e-03f, -2.878919714e-02f, -4.258054458e-02f, -2.863202454e-02f, -3.242932618e-03f, +1.406209682e-02f, +1.578582064e-02f, +7.915306646e-03f, +3.338433846e-04f, -2.225380377e-03f, -1.296401007e-03f,
- /* 24, 5 */ -1.901418208e-03f, -1.726854356e-03f, +3.138383775e-03f, +1.185778300e-02f, +1.678923519e-02f, +8.335988548e-03f, -1.434967550e-02f, -3.740342600e-02f, -4.032212766e-02f, -1.408285985e-02f, +2.723942290e-02f, +5.473395280e-02f, +4.781317317e-02f, +1.172602857e-02f, -2.695585286e-02f, -4.261794963e-02f, -3.006589126e-02f, -4.755011838e-03f, +1.343965653e-02f, +1.606560041e-02f, +8.487191262e-03f, +6.718888821e-04f, -2.203463508e-03f, -1.388818223e-03f,
- /* 24, 6 */ -1.824951954e-03f, -1.851392085e-03f, +2.678169173e-03f, +1.131547576e-02f, +1.679429951e-02f, +9.346246206e-03f, -1.271138577e-02f, -3.635777499e-02f, -4.100968953e-02f, -1.642457396e-02f, +2.475089197e-02f, +5.392251484e-02f, +4.929629202e-02f, +1.438225015e-02f, -2.502497093e-02f, -4.253761970e-02f, -3.144854025e-02f, -6.299302508e-03f, +1.275134172e-02f, +1.630405519e-02f, +9.060123484e-03f, +1.031611407e-03f, -2.166521604e-03f, -1.480506488e-03f,
- /* 24, 7 */ -1.743780953e-03f, -1.956892396e-03f, +2.236592212e-03f, +1.076199396e-02f, +1.674607744e-02f, +1.029396653e-02f, -1.108233467e-02f, -3.523433096e-02f, -4.157463041e-02f, -1.869548696e-02f, +2.221306113e-02f, +5.296974848e-02f, +5.065292065e-02f, +1.702081530e-02f, -2.300121251e-02f, -4.233780689e-02f, -3.277444146e-02f, -7.871595256e-03f, +1.199730786e-02f, +1.649860375e-02f, +9.631827247e-03f, +1.412645767e-03f, -2.113671692e-03f, -1.570743396e-03f,
- /* 24, 8 */ -1.658767534e-03f, -2.044064852e-03f, +1.814507917e-03f, +1.019993481e-02f, +1.664674627e-02f, +1.117796172e-02f, -9.467475281e-03f, -3.403815061e-02f, -4.201713914e-02f, -2.088959684e-02f, +1.963373727e-02f, +5.187871616e-02f, +5.187871616e-02f, +1.963373727e-02f, -2.088959684e-02f, -4.201713914e-02f, -3.403815061e-02f, -9.467475281e-03f, +1.117796172e-02f, +1.664674627e-02f, +1.019993481e-02f, +1.814507917e-03f, -2.044064852e-03f, -1.658767534e-03f,
- /* 24, 9 */ -1.570743396e-03f, -2.113671692e-03f, +1.412645767e-03f, +9.631827247e-03f, +1.649860375e-02f, +1.199730786e-02f, -7.871595256e-03f, -3.277444146e-02f, -4.233780689e-02f, -2.300121251e-02f, +1.702081530e-02f, +5.065292065e-02f, +5.296974848e-02f, +2.221306113e-02f, -1.869548696e-02f, -4.157463041e-02f, -3.523433096e-02f, -1.108233467e-02f, +1.029396653e-02f, +1.674607744e-02f, +1.076199396e-02f, +2.236592212e-03f, -1.956892396e-03f, -1.743780953e-03f,
- /* 24,10 */ -1.480506488e-03f, -2.166521604e-03f, +1.031611407e-03f, +9.060123484e-03f, +1.630405519e-02f, +1.275134172e-02f, -6.299302508e-03f, -3.144854025e-02f, -4.253761970e-02f, -2.502497093e-02f, +1.438225015e-02f, +4.929629202e-02f, +5.392251484e-02f, +2.475089197e-02f, -1.642457396e-02f, -4.100968953e-02f, -3.635777499e-02f, -1.271138577e-02f, +9.346246206e-03f, +1.679429951e-02f, +1.131547576e-02f, +2.678169173e-03f, -1.851392085e-03f, -1.824951954e-03f,
- /* 24,11 */ -1.388818223e-03f, -2.203463508e-03f, +6.718888821e-04f, +8.487191262e-03f, +1.606560041e-02f, +1.343965653e-02f, -4.755011838e-03f, -3.006589126e-02f, -4.261794963e-02f, -2.695585286e-02f, +1.172602857e-02f, +4.781317317e-02f, +5.473395280e-02f, +2.723942290e-02f, -1.408285985e-02f, -4.032212766e-02f, -3.740342600e-02f, -1.434967550e-02f, +8.335988548e-03f, +1.678923519e-02f, +1.185778300e-02f, +3.138383775e-03f, -1.726854356e-03f, -1.901418208e-03f,
- /* 24,12 */ -1.296401007e-03f, -2.225380377e-03f, +3.338433846e-04f, +7.915306646e-03f, +1.578582064e-02f, +1.406209682e-02f, -3.242932618e-03f, -2.863202454e-02f, -4.258054458e-02f, -2.878919714e-02f, +9.060141131e-03f, +4.620830373e-02f, +5.540145153e-02f, +2.967096294e-02f, -1.167663915e-02f, -3.951216427e-02f, -3.836639935e-02f, -1.599210066e-02f, +7.264647438e-03f, +1.672884047e-02f, +1.238625918e-02f, +3.616254280e-03f, -1.582628528e-03f, -1.972290178e-03f,
- /* 24,13 */ -1.203936109e-03f, -2.233183138e-03f, +1.772445414e-05f, +7.346647501e-03f, +1.546736546e-02f, +1.461875233e-02f, -1.767057534e-03f, -2.715253413e-02f, -4.242751674e-02f, -3.052071354e-02f, +6.392554173e-03f, +4.448680259e-02f, +5.592286159e-02f, +3.203796457e-02f, -9.212479159e-03f, -3.858043162e-02f, -3.924200344e-02f, -1.763342417e-02f, +6.133943976e-03f, +1.661121711e-02f, +1.289819803e-02f, +4.110671651e-03f, -1.418128950e-03f, -2.036654869e-03f,
- /* 24,14 */ -1.112061839e-03f, -2.227804667e-03f, -2.763303743e-04f, +6.783287607e-03f, +1.511293981e-02f, +1.510995111e-02f, -3.311524193e-04f, -2.563305646e-02f, -4.216132985e-02f, -3.214649405e-02f, +3.731182183e-03f, +4.265414906e-02f, +5.629650283e-02f, +3.433305089e-02f, -6.697199080e-03f, -3.752797769e-02f, -4.002576024e-02f, -1.926829204e-02f, +4.945866528e-03f, +1.643462496e-02f, +1.339085359e-02f, +4.620399561e-03f, -1.232841058e-03f, -2.093579858e-03f,
- /* 24,15 */ -1.021372070e-03f, -2.210193915e-03f, -5.482915187e-04f, +6.227191439e-03f, +1.472529111e-02f, +1.553625174e-02f, +1.061252794e-03f, -2.407924887e-02f, -4.178478525e-02f, -3.366302266e-02f, +1.083860427e-03f, +4.071616274e-02f, +5.652117066e-02f, +3.654904222e-02f, -4.137848013e-03f, -3.635626763e-02f, -4.071342524e-02f, -2.089125129e-02f, +3.702669669e-03f, +1.619749380e-02f, +1.386145083e-02f, +5.144075019e-03f, -1.026327303e-03f, -2.142117633e-03f,
- /* 24, 0 */ -6.349328336e-04f, -5.107444449e-03f, -7.589492700e-03f, +4.421169254e-04f, +1.733331948e-02f, +2.497839430e-02f, +6.069612140e-03f, -2.970035006e-02f, -4.651799663e-02f, -1.968310326e-02f, +3.102388246e-02f, +5.659614054e-02f, +3.102388246e-02f, -1.968310326e-02f, -4.651799663e-02f, -2.970035006e-02f, +6.069612140e-03f, +2.497839430e-02f, +1.733331948e-02f, +4.421169254e-04f, -7.589492700e-03f, -5.107444449e-03f, -6.349328336e-04f, +6.381929817e-04f,
- /* 24, 1 */ -4.501246045e-04f, -4.794789988e-03f, -7.673310752e-03f, -4.276921651e-04f, +1.630487239e-02f, +2.519230977e-02f, +8.023727481e-03f, -2.760467194e-02f, -4.668156835e-02f, -2.250226055e-02f, +2.808383767e-02f, +5.648624601e-02f, +3.385706239e-02f, -1.675917373e-02f, -4.616688010e-02f, -3.171828840e-02f, +4.039135426e-03f, +2.465060544e-02f, +1.832599562e-02f, +1.353161175e-03f, -7.461005422e-03f, -5.414037993e-03f, -8.347893499e-04f, +6.459962873e-04f,
- /* 24, 2 */ -2.805431667e-04f, -4.478334337e-03f, -7.714347254e-03f, -1.253762011e-03f, +1.524677189e-02f, +2.529479915e-02f, +9.894771606e-03f, -2.544172743e-02f, -4.665953469e-02f, -2.520578478e-02f, +2.504972253e-02f, +5.615705320e-02f, +3.657100703e-02f, -1.374190145e-02f, -4.562711379e-02f, -3.364818878e-02f, +1.939527429e-03f, +2.420699082e-02f, +1.927675855e-02f, +2.302607998e-03f, -7.286133997e-03f, -5.712221732e-03f, -1.049390115e-03f, +6.454263440e-04f,
- /* 24, 3 */ -1.262469087e-04f, -4.160237857e-03f, -7.714644364e-03f, -2.033919173e-03f, +1.416507919e-02f, +2.528877950e-02f, +1.167657735e-02f, -2.322211124e-02f, -4.645464989e-02f, -2.778343069e-02f, +2.193469332e-02f, +5.561003206e-02f, +3.915383052e-02f, -1.064323425e-02f, -4.489844274e-02f, -3.547998209e-02f, -2.214871506e-04f, +2.364611605e-02f, +2.017947396e-02f, +3.287300483e-03f, -7.063354139e-03f, -5.999568857e-03f, -1.278300802e-03f, +6.356530069e-04f,
- /* 24, 4 */ +1.281987696e-05f, -3.842552418e-03f, -7.676380196e-03f, -2.766321017e-03f, +1.306576874e-02f, +2.517761055e-02f, +1.336353941e-02f, -2.095648565e-02f, -4.607045954e-02f, -3.022561220e-02f, +1.875220414e-02f, +5.484762432e-02f, +4.159418981e-02f, -7.475585158e-03f, -4.398147340e-02f, -3.720388175e-02f, -2.435717775e-03f, +2.296708552e-02f, +2.102804905e-02f, +4.303763633e-03f, -6.791349552e-03f, -6.273586899e-03f, -1.520952773e-03f, +6.158659890e-04f,
- /* 24, 5 */ +1.368204413e-04f, -3.527213369e-03f, -7.601850138e-03f, -3.449453954e-03f, +1.195469912e-02f, +2.496506585e-02f, +1.495063011e-02f, -1.865552736e-02f, -4.551127331e-02f, -3.252344226e-02f, +1.551594186e-02f, +5.387323140e-02f, +4.388134039e-02f, -4.251776447e-03f, -4.287768073e-02f, -3.881043651e-02f, -4.694539858e-03f, +2.216956067e-02f, +2.181646678e-02f, +5.348212687e-03f, -6.469028645e-03f, -6.531730950e-03f, -1.776639841e-03f, +5.852828120e-04f,
- /* 24, 6 */ +2.460185614e-04f, -3.216032617e-03f, -7.493448175e-03f, -4.082129823e-03f, +1.083758546e-02f, +2.465530244e-02f, +1.643341199e-02f, -1.632987505e-02f, -4.478213426e-02f, -3.466876896e-02f, +1.223976005e-02f, +5.269119738e-02f, +4.600518917e-02f, -9.849812576e-04f, -4.158941105e-02f, -4.029058231e-02f, -6.988929457e-03f, +2.125377578e-02f, +2.253882061e-02f, +6.416563547e-03f, -6.095540465e-03f, -6.771417794e-03f, -2.044515881e-03f, +5.431569434e-04f,
- /* 24, 7 */ +3.407711290e-04f, -2.910692818e-03f, -7.353648294e-03f, -4.663480492e-03f, +9.719973395e-03f, +2.425282916e-02f, +1.780804686e-02f, -1.399007798e-02f, -4.388878466e-02f, -3.665420751e-02f, +8.937612534e-03f, +5.130678745e-02f, +4.795634432e-02f, +2.311336934e-03f, -4.011988036e-02f, -4.163569289e-02f, -9.309500719e-03f, +2.022055084e-02f, +2.318934965e-02f, +7.504445299e-03f, -5.670289717e-03f, -6.990040888e-03f, -2.323593338e-03f, +4.887860648e-04f,
- /* 24, 8 */ +4.215204125e-04f, -2.612742676e-03f, -7.184986124e-03f, -5.192950770e-03f, +8.607214812e-03f, +2.376247385e-02f, +1.907130164e-02f, -1.164654593e-02f, -4.283762880e-02f, -3.847316827e-02f, +5.623486691e-03f, +4.972616165e-02f, +4.972616165e-02f, +5.623486691e-03f, -3.847316827e-02f, -4.283762880e-02f, -1.164654593e-02f, +1.907130164e-02f, +2.376247385e-02f, +8.607214812e-03f, -5.192950770e-03f, -7.184986124e-03f, -2.612742676e-03f, +4.215204125e-04f,
- /* 24, 9 */ +4.887860648e-04f, -2.323593338e-03f, -6.990040888e-03f, -5.670289717e-03f, +7.504445299e-03f, +2.318934965e-02f, +2.022055084e-02f, -9.309500719e-03f, -4.163569289e-02f, -4.011988036e-02f, +2.311336934e-03f, +4.795634432e-02f, +5.130678745e-02f, +8.937612534e-03f, -3.665420751e-02f, -4.388878466e-02f, -1.399007798e-02f, +1.780804686e-02f, +2.425282916e-02f, +9.719973395e-03f, -4.663480492e-03f, -7.353648294e-03f, -2.910692818e-03f, +3.407711290e-04f,
- /* 24,10 */ +5.431569434e-04f, -2.044515881e-03f, -6.771417794e-03f, -6.095540465e-03f, +6.416563547e-03f, +2.253882061e-02f, +2.125377578e-02f, -6.988929457e-03f, -4.029058231e-02f, -4.158941105e-02f, -9.849812576e-04f, +4.600518917e-02f, +5.269119738e-02f, +1.223976005e-02f, -3.466876896e-02f, -4.478213426e-02f, -1.632987505e-02f, +1.643341199e-02f, +2.465530244e-02f, +1.083758546e-02f, -4.082129823e-03f, -7.493448175e-03f, -3.216032617e-03f, +2.460185614e-04f,
- /* 24,11 */ +5.852828120e-04f, -1.776639841e-03f, -6.531730950e-03f, -6.469028645e-03f, +5.348212687e-03f, +2.181646678e-02f, +2.216956067e-02f, -4.694539858e-03f, -3.881043651e-02f, -4.287768073e-02f, -4.251776447e-03f, +4.388134039e-02f, +5.387323140e-02f, +1.551594186e-02f, -3.252344226e-02f, -4.551127331e-02f, -1.865552736e-02f, +1.495063011e-02f, +2.496506585e-02f, +1.195469912e-02f, -3.449453954e-03f, -7.601850138e-03f, -3.527213369e-03f, +1.368204413e-04f,
- /* 24,12 */ +6.158659890e-04f, -1.520952773e-03f, -6.273586899e-03f, -6.791349552e-03f, +4.303763633e-03f, +2.102804905e-02f, +2.296708552e-02f, -2.435717775e-03f, -3.720388175e-02f, -4.398147340e-02f, -7.475585158e-03f, +4.159418981e-02f, +5.484762432e-02f, +1.875220414e-02f, -3.022561220e-02f, -4.607045954e-02f, -2.095648565e-02f, +1.336353941e-02f, +2.517761055e-02f, +1.306576874e-02f, -2.766321017e-03f, -7.676380196e-03f, -3.842552418e-03f, +1.281987696e-05f,
- /* 24,13 */ +6.356530069e-04f, -1.278300802e-03f, -5.999568857e-03f, -7.063354139e-03f, +3.287300483e-03f, +2.017947396e-02f, +2.364611605e-02f, -2.214871506e-04f, -3.547998209e-02f, -4.489844274e-02f, -1.064323425e-02f, +3.915383052e-02f, +5.561003206e-02f, +2.193469332e-02f, -2.778343069e-02f, -4.645464989e-02f, -2.322211124e-02f, +1.167657735e-02f, +2.528877950e-02f, +1.416507919e-02f, -2.033919173e-03f, -7.714644364e-03f, -4.160237857e-03f, -1.262469087e-04f,
- /* 24,14 */ +6.454263440e-04f, -1.049390115e-03f, -5.712221732e-03f, -7.286133997e-03f, +2.302607998e-03f, +1.927675855e-02f, +2.420699082e-02f, +1.939527429e-03f, -3.364818878e-02f, -4.562711379e-02f, -1.374190145e-02f, +3.657100703e-02f, +5.615705320e-02f, +2.504972253e-02f, -2.520578478e-02f, -4.665953469e-02f, -2.544172743e-02f, +9.894771606e-03f, +2.529479915e-02f, +1.524677189e-02f, -1.253762011e-03f, -7.714347254e-03f, -4.478334337e-03f, -2.805431667e-04f,
- /* 24,15 */ +6.459962873e-04f, -8.347893499e-04f, -5.414037993e-03f, -7.461005422e-03f, +1.353161175e-03f, +1.832599562e-02f, +2.465060544e-02f, +4.039135426e-03f, -3.171828840e-02f, -4.616688010e-02f, -1.675917373e-02f, +3.385706239e-02f, +5.648624601e-02f, +2.808383767e-02f, -2.250226055e-02f, -4.668156835e-02f, -2.760467194e-02f, +8.023727481e-03f, +2.519230977e-02f, +1.630487239e-02f, -4.276921651e-04f, -7.673310752e-03f, -4.794789988e-03f, -4.501246045e-04f,
- /* 24, 0 */ +1.197013499e-03f, +3.320493122e-03f, -3.017233048e-03f, -9.987553340e-03f, -4.112967049e-03f, +1.524501264e-02f, +2.235677036e-02f, -2.137559158e-03f, -3.327370097e-02f, -2.660122408e-02f, +1.657531807e-02f, +4.232694754e-02f, +1.657531807e-02f, -2.660122408e-02f, -3.327370097e-02f, -2.137559158e-03f, +2.235677036e-02f, +1.524501264e-02f, -4.112967049e-03f, -9.987553340e-03f, -3.017233048e-03f, +2.318357031e-03f, +1.197013499e-03f, -1.261205705e-04f,
- /* 24, 1 */ +1.060573898e-03f, +3.246029352e-03f, -2.510607281e-03f, -9.784551764e-03f, -5.018393221e-03f, +1.404948670e-02f, +2.282515537e-02f, +7.626640355e-05f, -3.208475603e-02f, -2.845760231e-02f, +1.374134711e-02f, +4.221250979e-02f, +1.933345641e-02f, -2.458052660e-02f, -3.429687591e-02f, -4.386190237e-03f, +2.174698353e-02f, +1.639120730e-02f, -3.143642175e-03f, -1.013545813e-02f, -3.535011248e-03f, +2.193303334e-03f, +1.338504197e-03f, -9.901282259e-05f,
- /* 24, 2 */ +9.298712414e-04f, +3.156277727e-03f, -2.018194158e-03f, -9.530340989e-03f, -5.856606243e-03f, +1.281349999e-02f, +2.315294314e-02f, +2.243024978e-03f, -3.073934924e-02f, -3.014061672e-02f, +1.084811230e-02f, +4.186988491e-02f, +2.199957595e-02f, -2.240563854e-02f, -3.514586546e-02f, -6.656913804e-03f, +2.099588115e-02f, +1.747926153e-02f, -2.114297018e-03f, -1.022461460e-02f, -4.060636553e-03f, +2.039754046e-03f, +1.484263468e-03f, -6.526428163e-05f,
- /* 24, 3 */ +8.054954021e-04f, +3.052984548e-03f, -1.542795645e-03f, -9.229007144e-03f, -6.624860539e-03f, +1.154592266e-02f, +2.334180387e-02f, +4.350977952e-03f, -2.924761047e-02f, -3.164235460e-02f, +7.912459038e-03f, +4.130113344e-02f, +2.455797710e-02f, -2.008771737e-02f, -3.581321303e-02f, -8.936640836e-03f, +2.010445982e-02f, +1.850049032e-02f, -1.029364704e-03f, -1.025164428e-02f, -4.590574200e-03f, +1.857070273e-03f, +1.633412152e-03f, -2.453170435e-05f,
- /* 24, 4 */ +6.879416803e-04f, +2.937877889e-03f, -1.086944946e-03f, -8.884797195e-03f, -7.320980005e-03f, +1.025556440e-02f, +2.339424278e-02f, +6.388976156e-03f, -2.762041561e-02f, -3.295607494e-02f, +4.951401864e-03f, +4.050967459e-02f, +2.699354793e-02f, -1.763888677e-02f, -3.629248103e-02f, -1.121198570e-02f, +1.907464002e-02f, +1.944639638e-02f, +1.061806254e-04f, -1.021347789e-02f, -5.121078221e-03f, +1.644827972e-03f, +1.784975276e-03f, +2.348660763e-05f,
- /* 24, 5 */ +5.776128643e-04f, +2.812656385e-03f, -6.528985547e-04f, -8.502081335e-03f, -7.943354450e-03f, +8.951116293e-03f, +2.331356438e-02f, +8.346521334e-03f, -2.586930694e-02f, -3.407624020e-02f, +1.982016505e-03f, +3.950026382e-02f, +2.929186185e-02f, -1.507216716e-02f, -3.657830513e-02f, -1.346934883e-02f, +1.790927350e-02f, +2.030873394e-02f, +1.286841938e-03f, -1.010739044e-02f, -5.648212144e-03f, +1.402832649e-03f, +1.937883690e-03f, +7.904503123e-05f,
- /* 24, 6 */ +4.748218959e-04f, +2.678978820e-03f, -2.426308611e-04f, -8.085315763e-03f, -8.490932000e-03f, +7.641095022e-03f, +2.310383199e-02f, +1.021382218e-02f, -2.400641001e-02f, -3.499853994e-02f, -9.786680537e-04f, +3.827896159e-02f, +3.143927100e-02f, -1.240139974e-02f, -3.666644182e-02f, -1.569500220e-02f, +1.661214427e-02f, +2.107957227e-02f, +2.506621864e-03f, -9.931034771e-03f, -6.167872094e-03f, +1.131132707e-03f, +2.090976552e-03f, +1.423449116e-04f,
- /* 24, 7 */ +3.797950945e-04f, +2.538454547e-03f, +1.421687298e-04f, -7.639006136e-03f, -8.963207645e-03f, +6.333789781e-03f, +2.276982298e-02f, +1.198184460e-02f, -2.204434780e-02f, -3.571990598e-02f, -3.913776625e-03f, +3.685309369e-02f, +3.342299483e-02f, -9.641164594e-03f, -3.655380902e-02f, -1.787517696e-02f, +1.518796320e-02f, +2.175135864e-02f, +3.759049618e-03f, -9.682473374e-03f, -6.675812165e-03f, +8.300312585e-04f, +2.243004675e-03f, +2.135289700e-04f,
- /* 24, 8 */ +2.926758839e-04f, +2.392634763e-03f, +5.000962484e-04f, -7.167671961e-03f, -9.360208124e-03f, +5.037212205e-03f, +2.231697999e-02f, +1.364235598e-02f, -1.999615271e-02f, -3.623851940e-02f, -6.806693291e-03f, +3.523120326e-02f, +3.523120326e-02f, -6.806693291e-03f, -3.623851940e-02f, -1.999615271e-02f, +1.364235598e-02f, +2.231697999e-02f, +5.037212205e-03f, -9.360208124e-03f, -7.167671961e-03f, +5.000962484e-04f, +2.392634763e-03f, +2.926758839e-04f,
- /* 24, 9 */ +2.135289700e-04f, +2.243004675e-03f, +8.300312585e-04f, -6.675812165e-03f, -9.682473374e-03f, +3.759049618e-03f, +2.175135864e-02f, +1.518796320e-02f, -1.787517696e-02f, -3.655380902e-02f, -9.641164594e-03f, +3.342299483e-02f, +3.685309369e-02f, -3.913776625e-03f, -3.571990598e-02f, -2.204434780e-02f, +1.198184460e-02f, +2.276982298e-02f, +6.333789781e-03f, -8.963207645e-03f, -7.639006136e-03f, +1.421687298e-04f, +2.538454547e-03f, +3.797950945e-04f,
- /* 24,10 */ +1.423449116e-04f, +2.090976552e-03f, +1.131132707e-03f, -6.167872094e-03f, -9.931034771e-03f, +2.506621864e-03f, +2.107957227e-02f, +1.661214427e-02f, -1.569500220e-02f, -3.666644182e-02f, -1.240139974e-02f, +3.143927100e-02f, +3.827896159e-02f, -9.786680537e-04f, -3.499853994e-02f, -2.400641001e-02f, +1.021382218e-02f, +2.310383199e-02f, +7.641095022e-03f, -8.490932000e-03f, -8.085315763e-03f, -2.426308611e-04f, +2.678978820e-03f, +4.748218959e-04f,
- /* 24,11 */ +7.904503123e-05f, +1.937883690e-03f, +1.402832649e-03f, -5.648212144e-03f, -1.010739044e-02f, +1.286841938e-03f, +2.030873394e-02f, +1.790927350e-02f, -1.346934883e-02f, -3.657830513e-02f, -1.507216716e-02f, +2.929186185e-02f, +3.950026382e-02f, +1.982016505e-03f, -3.407624020e-02f, -2.586930694e-02f, +8.346521334e-03f, +2.331356438e-02f, +8.951116293e-03f, -7.943354450e-03f, -8.502081335e-03f, -6.528985547e-04f, +2.812656385e-03f, +5.776128643e-04f,
- /* 24,12 */ +2.348660763e-05f, +1.784975276e-03f, +1.644827972e-03f, -5.121078221e-03f, -1.021347789e-02f, +1.061806254e-04f, +1.944639638e-02f, +1.907464002e-02f, -1.121198570e-02f, -3.629248103e-02f, -1.763888677e-02f, +2.699354793e-02f, +4.050967459e-02f, +4.951401864e-03f, -3.295607494e-02f, -2.762041561e-02f, +6.388976156e-03f, +2.339424278e-02f, +1.025556440e-02f, -7.320980005e-03f, -8.884797195e-03f, -1.086944946e-03f, +2.937877889e-03f, +6.879416803e-04f,
- /* 24,13 */ -2.453170435e-05f, +1.633412152e-03f, +1.857070273e-03f, -4.590574200e-03f, -1.025164428e-02f, -1.029364704e-03f, +1.850049032e-02f, +2.010445982e-02f, -8.936640836e-03f, -3.581321303e-02f, -2.008771737e-02f, +2.455797710e-02f, +4.130113344e-02f, +7.912459038e-03f, -3.164235460e-02f, -2.924761047e-02f, +4.350977952e-03f, +2.334180387e-02f, +1.154592266e-02f, -6.624860539e-03f, -9.229007144e-03f, -1.542795645e-03f, +3.052984548e-03f, +8.054954021e-04f,
- /* 24,14 */ -6.526428163e-05f, +1.484263468e-03f, +2.039754046e-03f, -4.060636553e-03f, -1.022461460e-02f, -2.114297018e-03f, +1.747926153e-02f, +2.099588115e-02f, -6.656913804e-03f, -3.514586546e-02f, -2.240563854e-02f, +2.199957595e-02f, +4.186988491e-02f, +1.084811230e-02f, -3.014061672e-02f, -3.073934924e-02f, +2.243024978e-03f, +2.315294314e-02f, +1.281349999e-02f, -5.856606243e-03f, -9.530340989e-03f, -2.018194158e-03f, +3.156277727e-03f, +9.298712414e-04f,
- /* 24,15 */ -9.901282259e-05f, +1.338504197e-03f, +2.193303334e-03f, -3.535011248e-03f, -1.013545813e-02f, -3.143642175e-03f, +1.639120730e-02f, +2.174698353e-02f, -4.386190237e-03f, -3.429687591e-02f, -2.458052660e-02f, +1.933345641e-02f, +4.221250979e-02f, +1.374134711e-02f, -2.845760231e-02f, -3.208475603e-02f, +7.626640355e-05f, +2.282515537e-02f, +1.404948670e-02f, -5.018393221e-03f, -9.784551764e-03f, -2.510607281e-03f, +3.246029352e-03f, +1.060573898e-03f,
- /* 20, 0 */ +2.832126065e-03f, -3.455346407e-03f, -1.050167676e-02f, +5.399047405e-04f, +2.072547687e-02f, +1.261483344e-02f, -2.310421022e-02f, -3.076111900e-02f, +1.034529168e-02f, +3.949755319e-02f, +1.034529168e-02f, -3.076111900e-02f, -2.310421022e-02f, +1.261483344e-02f, +2.072547687e-02f, +5.399047405e-04f, -1.050167676e-02f, -3.455346407e-03f, +2.832126065e-03f, +1.002136091e-03f,
- /* 20, 1 */ +2.918309836e-03f, -2.848965042e-03f, -1.044663371e-02f, -7.454467031e-04f, +1.993701966e-02f, +1.431336010e-02f, -2.105256806e-02f, -3.196996361e-02f, +7.274030562e-03f, +3.936378623e-02f, +1.336427867e-02f, -2.932648708e-02f, -2.503260290e-02f, +1.078376120e-02f, +2.138841986e-02f, +1.874755806e-03f, -1.047502359e-02f, -4.071193337e-03f, +2.709872705e-03f, +1.184613130e-03f,
- /* 20, 2 */ +2.970014434e-03f, -2.256846905e-03f, -1.031411254e-02f, -1.973175306e-03f, +1.903277841e-02f, +1.586999913e-02f, -1.889465735e-02f, -3.294695719e-02f, +4.172714360e-03f, +3.896348732e-02f, +1.630904655e-02f, -2.767391419e-02f, -2.682143551e-02f, +8.830742245e-03f, +2.191685631e-02f, +3.250271284e-03f, -1.036300090e-02f, -4.691364292e-03f, +2.550244709e-03f, +1.728121332e-03f,
- /* 20, 3 */ +2.989084466e-03f, -1.683415968e-03f, -1.010881741e-02f, -3.135916081e-03f, +1.802312126e-02f, +1.727671449e-02f, -1.664798407e-02f, -3.368784795e-02f, +1.063660935e-03f, +3.829965427e-02f, +1.915809828e-02f, -2.581298498e-02f, -2.845520951e-02f, +6.767571398e-03f, +2.230262774e-02f, +4.656958119e-03f, -1.016253578e-02f, -5.310408414e-03f, +2.352251997e-03f, +1.906494808e-03f,
- /* 20, 4 */ +2.977586348e-03f, -1.132697564e-03f, -9.835877420e-03f, -4.227100403e-03f, +1.691895133e-02f, +1.852681335e-02f, -1.433043179e-02f, -3.419021020e-02f, -2.030888217e-03f, +3.737725626e-02f, +2.189055571e-02f, -2.375496340e-02f, -2.991937541e-02f, +4.607167163e-03f, +2.253850054e-02f, +6.084727180e-03f, -9.871207756e-03f, -5.922604667e-03f, +2.115247068e-03f, +2.079939639e-03f,
- /* 20, 5 */ +2.937775120e-03f, -6.082983663e-04f, -9.500783787e-03f, -5.240985904e-03f, +1.573160178e-02f, +1.961497125e-02f, -1.196011335e-02f, -3.445344345e-02f, -5.088941581e-03f, +3.620319350e-02f, +2.448632622e-02f, -2.151271924e-02f, -3.120046374e-02f, +2.363488482e-03f, +2.261825107e-02f, +7.522962281e-03f, -9.487296369e-03f, -6.522005316e-03f, +1.838950241e-03f, +2.245949018e-03f,
- /* 20, 6 */ +2.872060854e-03f, -1.133913219e-04f, -9.109325922e-03f, -6.172678101e-03f, +1.447272980e-02f, +2.053724533e-02f, -9.555222824e-03f, -3.447875653e-02f, -8.088928223e-03f, +3.478624106e-02f, +2.692626358e-02f, -1.910064083e-02f, -3.228620876e-02f, +5.144107936e-05f, +2.253674404e-02f, +8.960596019e-03f, -9.009823935e-03f, -7.102483479e-03f, +1.523472156e-03f, +2.401928729e-03f,
- /* 20, 7 */ +2.782975009e-03f, +3.492945151e-04f, -8.667527067e-03f, -7.018143782e-03f, +1.315421060e-02f, +2.129107545e-02f, -7.133889173e-03f, -3.426913715e-02f, -1.100986395e-02f, +3.313697764e-02f, +2.919232167e-02f, -1.653453452e-02f, -3.316566379e-02f, -2.313225982e-03f, +2.229000326e-02f, +1.038619190e-02f, -8.438592747e-03f, -7.657784411e-03f, +1.169333173e-03f, +2.545222121e-03f,
- /* 20, 8 */ +2.673137115e-03f, +7.774793244e-04f, -8.181580147e-03f, -7.774216267e-03f, +1.178803215e-02f, +2.187527386e-02f, -4.714032773e-03f, -3.382930709e-02f, -1.383151166e-02f, +3.126769968e-02f, +3.126769968e-02f, -1.383151166e-02f, -3.382930709e-02f, -4.714032773e-03f, +2.187527386e-02f, +1.178803215e-02f, -7.774216267e-03f, -8.181580147e-03f, +7.774793244e-04f, +2.673137115e-03f,
- /* 20, 9 */ +2.545222121e-03f, +1.169333173e-03f, -7.657784411e-03f, -8.438592747e-03f, +1.038619190e-02f, +2.229000326e-02f, -2.313225982e-03f, -3.316566379e-02f, -1.653453452e-02f, +2.919232167e-02f, +3.313697764e-02f, -1.100986395e-02f, -3.426913715e-02f, -7.133889173e-03f, +2.129107545e-02f, +1.315421060e-02f, -7.018143782e-03f, -8.667527067e-03f, +3.492945151e-04f, +2.782975009e-03f,
- /* 20,10 */ +2.401928729e-03f, +1.523472156e-03f, -7.102483479e-03f, -9.009823935e-03f, +8.960596019e-03f, +2.253674404e-02f, +5.144107936e-05f, -3.228620876e-02f, -1.910064083e-02f, +2.692626358e-02f, +3.478624106e-02f, -8.088928223e-03f, -3.447875653e-02f, -9.555222824e-03f, +2.053724533e-02f, +1.447272980e-02f, -6.172678101e-03f, -9.109325922e-03f, -1.133913219e-04f, +2.872060854e-03f,
- /* 20,11 */ +2.245949018e-03f, +1.838950241e-03f, -6.522005316e-03f, -9.487296369e-03f, +7.522962281e-03f, +2.261825107e-02f, +2.363488482e-03f, -3.120046374e-02f, -2.151271924e-02f, +2.448632622e-02f, +3.620319350e-02f, -5.088941581e-03f, -3.445344345e-02f, -1.196011335e-02f, +1.961497125e-02f, +1.573160178e-02f, -5.240985904e-03f, -9.500783787e-03f, -6.082983663e-04f, +2.937775120e-03f,
- /* 20,12 */ +2.079939639e-03f, +2.115247068e-03f, -5.922604667e-03f, -9.871207756e-03f, +6.084727180e-03f, +2.253850054e-02f, +4.607167163e-03f, -2.991937541e-02f, -2.375496340e-02f, +2.189055571e-02f, +3.737725626e-02f, -2.030888217e-03f, -3.419021020e-02f, -1.433043179e-02f, +1.852681335e-02f, +1.691895133e-02f, -4.227100403e-03f, -9.835877420e-03f, -1.132697564e-03f, +2.977586348e-03f,
- /* 20,13 */ +1.906494808e-03f, +2.352251997e-03f, -5.310408414e-03f, -1.016253578e-02f, +4.656958119e-03f, +2.230262774e-02f, +6.767571398e-03f, -2.845520951e-02f, -2.581298498e-02f, +1.915809828e-02f, +3.829965427e-02f, +1.063660935e-03f, -3.368784795e-02f, -1.664798407e-02f, +1.727671449e-02f, +1.802312126e-02f, -3.135916081e-03f, -1.010881741e-02f, -1.683415968e-03f, +2.989084466e-03f,
- /* 20,14 */ +1.728121332e-03f, +2.550244709e-03f, -4.691364292e-03f, -1.036300090e-02f, +3.250271284e-03f, +2.191685631e-02f, +8.830742245e-03f, -2.682143551e-02f, -2.767391419e-02f, +1.630904655e-02f, +3.896348732e-02f, +4.172714360e-03f, -3.294695719e-02f, -1.889465735e-02f, +1.586999913e-02f, +1.903277841e-02f, -1.973175306e-03f, -1.031411254e-02f, -2.256846905e-03f, +2.970014434e-03f,
- /* 20,15 */ +1.184613130e-03f, +2.709872705e-03f, -4.071193337e-03f, -1.047502359e-02f, +1.874755806e-03f, +2.138841986e-02f, +1.078376120e-02f, -2.503260290e-02f, -2.932648708e-02f, +1.336427867e-02f, +3.936378623e-02f, +7.274030562e-03f, -3.196996361e-02f, -2.105256806e-02f, +1.431336010e-02f, +1.993701966e-02f, -7.454467031e-04f, -1.044663371e-02f, -2.848965042e-03f, +2.918309836e-03f,
- /* 20, 0 */ +1.702864838e-03f, +2.314577966e-03f, -6.534433696e-03f, -8.774562126e-03f, +1.199271213e-02f, +2.083400312e-02f, -1.263546899e-02f, -3.379691899e-02f, +5.498355442e-03f, +3.949755319e-02f, +5.498355442e-03f, -3.379691899e-02f, -1.263546899e-02f, +2.083400312e-02f, +1.199271213e-02f, -8.774562126e-03f, -6.534433696e-03f, +2.314577966e-03f, +1.702864838e-03f, +0.000000000e+00f,
- /* 20, 1 */ +1.499435496e-03f, +2.547675666e-03f, -5.868098774e-03f, -9.353385898e-03f, +1.044920601e-02f, +2.160032962e-02f, -9.997584470e-03f, -3.429852636e-02f, +2.083565903e-03f, +3.933622696e-02f, +8.892197588e-03f, -3.300722623e-02f, -1.522519578e-02f, +1.986341365e-02f, +1.349096787e-02f, -8.082206357e-03f, -7.177938171e-03f, +2.033576095e-03f, +1.903844954e-03f, +0.000000000e+00f,
- /* 20, 2 */ +8.979094201e-04f, +2.733567376e-03f, -5.187117330e-03f, -9.818374279e-03f, +8.876306372e-03f, +2.216139438e-02f, -7.335624654e-03f, -3.451169090e-02f, -1.322648265e-03f, +3.885370480e-02f, +1.223556951e-02f, -3.193245877e-02f, -1.774265256e-02f, +1.869155385e-02f, +1.492800767e-02f, -7.277832099e-03f, -7.790241855e-03f, +1.704529263e-03f, +2.099160368e-03f, -3.513221827e-04f,
- /* 20, 3 */ +7.046452899e-04f, +2.873469547e-03f, -4.499404245e-03f, -1.017038969e-02f, +7.289604703e-03f, +2.251815219e-02f, -4.673411391e-03f, -3.443867914e-02f, -4.691042688e-03f, +3.805434209e-02f, +1.549922824e-02f, -3.057828381e-02f, -2.016393226e-02f, +1.732343066e-02f, +1.628791973e-02f, -6.364195274e-03f, -8.362876507e-03f, +1.327887989e-03f, +2.285430476e-03f, -3.288882594e-04f,
- /* 20, 4 */ +5.275063595e-04f, +2.969073324e-03f, -3.812529364e-03f, -1.041140495e-02f, +5.704278009e-03f, +2.267345221e-02f, -2.034281900e-03f, -3.408432658e-02f, -7.992925296e-03f, +3.694535030e-02f, +1.865448932e-02f, -2.895300188e-02f, -2.246557005e-02f, +1.576606531e-02f, +1.755501285e-02f, -5.345313722e-03f, -8.887369558e-03f, +9.047221591e-04f, +2.459146683e-03f, -2.941732022e-04f,
- /* 20, 5 */ +3.670219514e-04f, +3.022497230e-03f, -3.133648777e-03f, -1.054443774e-02f, +4.134948499e-03f, +2.263196075e-02f, +5.591264205e-04f, -3.345595810e-02f, -1.120042307e-02f, +3.553672638e-02f, +2.167350137e-02f, -2.706749712e-02f, -2.462477986e-02f, +1.402847243e-02f, +1.871398575e-02f, -4.226473266e-03f, -9.355341791e-03f, +4.367425848e-04f, +2.616713456e-03f, -2.461206998e-04f,
- /* 20, 6 */ +2.234691091e-04f, +3.036236900e-03f, -2.469443903e-03f, -1.057347601e-02f, +2.595553432e-03f, +2.240006745e-02f, +3.085080219e-03f, -3.256328476e-02f, -1.428673893e-02f, +3.384115481e-02f, +2.452951370e-02f, -2.493516141e-02f, -2.661968788e-02f, +1.212161795e-02f, +1.975009719e-02f, -3.014219819e-03f, -9.758608118e-03f, -7.368451392e-05f, +2.754492916e-03f, -1.837671888e-04f,
- /* 20, 7 */ +9.688872179e-05f, +3.013112613e-03f, -1.826068782e-03f, -1.050339555e-02f, +1.099226216e-03f, +2.198577609e-02f, +5.522941542e-03f, -3.141827834e-02f, -1.722639627e-02f, +3.187388359e-02f, +2.719713425e-02f, -2.257179274e-02f, -2.842956063e-02f, +1.005835593e-02f, +2.064933490e-02f, -1.716337171e-03f, -1.008928035e-02f, -6.235305950e-04f, +2.868852533e-03f, -1.062635081e-04f,
- /* 20, 8 */ -1.289664191e-05f, +2.956215411e-03f, -1.209105881e-03f, -1.033987080e-02f, -3.418102460e-04f, +2.139858161e-02f, +7.853344535e-03f, -3.003502508e-02f, -1.999546871e-02f, +2.965257519e-02f, +2.965257519e-02f, -1.999546871e-02f, -3.003502508e-02f, +7.853344535e-03f, +2.139858161e-02f, -3.418102460e-04f, -1.033987080e-02f, -1.209105881e-03f, +2.956215411e-03f, -1.289664191e-05f,
- /* 20, 9 */ -1.062635081e-04f, +2.868852533e-03f, -6.235305950e-04f, -1.008928035e-02f, -1.716337171e-03f, +2.064933490e-02f, +1.005835593e-02f, -2.842956063e-02f, -2.257179274e-02f, +2.719713425e-02f, +3.187388359e-02f, -1.722639627e-02f, -3.141827834e-02f, +5.522941542e-03f, +2.198577609e-02f, +1.099226216e-03f, -1.050339555e-02f, -1.826068782e-03f, +3.013112613e-03f, +9.688872179e-05f,
- /* 20,10 */ -1.837671888e-04f, +2.754492916e-03f, -7.368451392e-05f, -9.758608118e-03f, -3.014219819e-03f, +1.975009719e-02f, +1.212161795e-02f, -2.661968788e-02f, -2.493516141e-02f, +2.452951370e-02f, +3.384115481e-02f, -1.428673893e-02f, -3.256328476e-02f, +3.085080219e-03f, +2.240006745e-02f, +2.595553432e-03f, -1.057347601e-02f, -2.469443903e-03f, +3.036236900e-03f, +2.234691091e-04f,
- /* 20,11 */ -2.461206998e-04f, +2.616713456e-03f, +4.367425848e-04f, -9.355341791e-03f, -4.226473266e-03f, +1.871398575e-02f, +1.402847243e-02f, -2.462477986e-02f, -2.706749712e-02f, +2.167350137e-02f, +3.553672638e-02f, -1.120042307e-02f, -3.345595810e-02f, +5.591264205e-04f, +2.263196075e-02f, +4.134948499e-03f, -1.054443774e-02f, -3.133648777e-03f, +3.022497230e-03f, +3.670219514e-04f,
- /* 20,12 */ -2.941732022e-04f, +2.459146683e-03f, +9.047221591e-04f, -8.887369558e-03f, -5.345313722e-03f, +1.755501285e-02f, +1.576606531e-02f, -2.246557005e-02f, -2.895300188e-02f, +1.865448932e-02f, +3.694535030e-02f, -7.992925296e-03f, -3.408432658e-02f, -2.034281900e-03f, +2.267345221e-02f, +5.704278009e-03f, -1.041140495e-02f, -3.812529364e-03f, +2.969073324e-03f, +5.275063595e-04f,
- /* 20,13 */ -3.288882594e-04f, +2.285430476e-03f, +1.327887989e-03f, -8.362876507e-03f, -6.364195274e-03f, +1.628791973e-02f, +1.732343066e-02f, -2.016393226e-02f, -3.057828381e-02f, +1.549922824e-02f, +3.805434209e-02f, -4.691042688e-03f, -3.443867914e-02f, -4.673411391e-03f, +2.251815219e-02f, +7.289604703e-03f, -1.017038969e-02f, -4.499404245e-03f, +2.873469547e-03f, +7.046452899e-04f,
- /* 20,14 */ -3.513221827e-04f, +2.099160368e-03f, +1.704529263e-03f, -7.790241855e-03f, -7.277832099e-03f, +1.492800767e-02f, +1.869155385e-02f, -1.774265256e-02f, -3.193245877e-02f, +1.223556951e-02f, +3.885370480e-02f, -1.322648265e-03f, -3.451169090e-02f, -7.335624654e-03f, +2.216139438e-02f, +8.876306372e-03f, -9.818374279e-03f, -5.187117330e-03f, +2.733567376e-03f, +8.979094201e-04f,
- /* 20,15 */ +0.000000000e+00f, +1.903844954e-03f, +2.033576095e-03f, -7.177938171e-03f, -8.082206357e-03f, +1.349096787e-02f, +1.986341365e-02f, -1.522519578e-02f, -3.300722623e-02f, +8.892197588e-03f, +3.933622696e-02f, +2.083565903e-03f, -3.429852636e-02f, -9.997584470e-03f, +2.160032962e-02f, +1.044920601e-02f, -9.353385898e-03f, -5.868098774e-03f, +2.547675666e-03f, +1.499435496e-03f,
- /* 20, 0 */ -3.735125865e-04f, +2.550984103e-03f, -2.725752467e-05f, -1.024966855e-02f, +8.379667777e-04f, +2.252874535e-02f, -1.249359695e-03f, -3.448318510e-02f, +6.071698875e-04f, +3.949755319e-02f, +6.071698875e-04f, -3.448318510e-02f, -1.249359695e-03f, +2.252874535e-02f, +8.379667777e-04f, -1.024966855e-02f, -2.725752467e-05f, +2.565652055e-03f, -3.735125865e-04f, +0.000000000e+00f,
- /* 20, 1 */ -3.929324583e-04f, +2.236335973e-03f, +5.288730096e-04f, -9.916240655e-03f, -7.235223044e-04f, +2.212021870e-02f, +1.557339330e-03f, -3.412515163e-02f, -3.088657053e-03f, +3.930609269e-02f, +4.328121901e-03f, -3.450613681e-02f, -4.117983282e-03f, +2.271744325e-02f, +2.467540325e-03f, -1.048404473e-02f, -6.307983207e-04f, +2.729031078e-03f, -3.387491377e-04f, +0.000000000e+00f,
- /* 20, 2 */ +0.000000000e+00f, +1.931175707e-03f, +1.033703668e-03f, -9.493276252e-03f, -2.202626937e-03f, +2.150371837e-02f, +4.274418757e-03f, -3.344119198e-02f, -6.721842627e-03f, +3.873376177e-02f, +8.036125742e-03f, -3.418837690e-02f, -7.019484999e-03f, +2.267661502e-02f, +4.149462009e-03f, -1.061062992e-02f, -1.276919763e-03f, +2.866023275e-03f, -2.870815261e-04f, +0.000000000e+00f,
- /* 20, 3 */ +0.000000000e+00f, +1.638662038e-03f, +1.484286050e-03f, -8.990907936e-03f, -3.586602863e-03f, +2.069305390e-02f, +6.875821908e-03f, -3.244383298e-02f, -1.025584288e-02f, +3.778668841e-02f, +1.169297592e-02f, -3.352791602e-02f, -9.923776326e-03f, +2.239890298e-02f, +5.866701604e-03f, -1.062161571e-02f, -1.959867511e-03f, +2.971909246e-03f, -2.170808154e-04f, +0.000000000e+00f,
- /* 20, 4 */ +0.000000000e+00f, +1.361489293e-03f, +1.878600735e-03f, -8.419725702e-03f, -4.864357078e-03f, +1.970376789e-02f, +9.337391966e-03f, -3.114878076e-02f, -1.365548733e-02f, +3.647500669e-02f, +1.526076366e-02f, -3.252647846e-02f, -1.280005487e-02f, +2.187944695e-02f, +7.601099328e-03f, -1.051027343e-02f, -2.672992279e-03f, +3.042103091e-03f, -1.274866066e-04f, +0.000000000e+00f,
- /* 20, 5 */ +0.000000000e+00f, +1.101888322e-03f, +2.215532402e-03f, -7.790617836e-03f, -6.026519023e-03f, +1.855289977e-02f, +1.163710530e-02f, -2.957469445e-02f, -1.688736106e-02f, +3.481273909e-02f, +1.870230489e-02f, -3.118953221e-02f, -1.561714772e-02f, +2.111601531e-02f, +9.333550613e-03f, -1.027109466e-02f, -3.408794343e-03f, +3.072235528e-03f, -1.724424543e-05f, +0.000000000e+00f,
- /* 20, 6 */ +0.000000000e+00f, +8.616336525e-04f, +2.494833248e-03f, -7.114614810e-03f, -7.065487327e-03f, +1.725873795e-02f, +1.375527431e-02f, -2.774292839e-02f, -1.992016339e-02f, +3.281763375e-02f, +2.198156213e-02f, -2.952627516e-02f, -1.834386597e-02f, +2.010910684e-02f, +1.104420948e-02f, -9.899921148e-03f, -4.158982805e-03f, +3.058238443e-03f, +1.144582079e-04f, +0.000000000e+00f,
- /* 20, 7 */ +0.000000000e+00f, +6.420563626e-04f, +2.717075783e-03f, -6.402738187e-03f, -7.975452307e-03f, +1.584056403e-02f, +1.567471786e-02f, -2.567724669e-02f, -2.272503888e-02f, +3.051095862e-02f, +2.506405514e-02f, -2.754957697e-02f, -2.094936609e-02f, +1.886202143e-02f, +1.271270843e-02f, -9.394061811e-03f, -4.914549404e-03f, +2.996429606e-03f, +2.681538305e-04f, +0.000000000e+00f,
- /* 20, 8 */ +0.000000000e+00f, +4.440621234e-04f, +2.883596201e-03f, -5.665856445e-03f, -8.752394750e-03f, +1.431839236e-02f, +1.738089791e-02f, -2.340351394e-02f, -2.527587699e-02f, +2.791725525e-02f, +2.791725525e-02f, -2.527587699e-02f, -2.340351394e-02f, +1.738089791e-02f, +1.431839236e-02f, -8.752394750e-03f, -5.665856445e-03f, +2.883596201e-03f, +4.440621234e-04f, +0.000000000e+00f,
- /* 20, 9 */ +0.000000000e+00f, +2.681538305e-04f, +2.996429606e-03f, -4.914549404e-03f, -9.394061811e-03f, +1.271270843e-02f, +1.886202143e-02f, -2.094936609e-02f, -2.754957697e-02f, +2.506405514e-02f, +3.051095862e-02f, -2.272503888e-02f, -2.567724669e-02f, +1.567471786e-02f, +1.584056403e-02f, -7.975452307e-03f, -6.402738187e-03f, +2.717075783e-03f, +6.420563626e-04f, +0.000000000e+00f,
- /* 20,10 */ +0.000000000e+00f, +1.144582079e-04f, +3.058238443e-03f, -4.158982805e-03f, -9.899921148e-03f, +1.104420948e-02f, +2.010910684e-02f, -1.834386597e-02f, -2.952627516e-02f, +2.198156213e-02f, +3.281763375e-02f, -1.992016339e-02f, -2.774292839e-02f, +1.375527431e-02f, +1.725873795e-02f, -7.065487327e-03f, -7.114614810e-03f, +2.494833248e-03f, +8.616336525e-04f, +0.000000000e+00f,
- /* 20,11 */ +0.000000000e+00f, -1.724424543e-05f, +3.072235528e-03f, -3.408794343e-03f, -1.027109466e-02f, +9.333550613e-03f, +2.111601531e-02f, -1.561714772e-02f, -3.118953221e-02f, +1.870230489e-02f, +3.481273909e-02f, -1.688736106e-02f, -2.957469445e-02f, +1.163710530e-02f, +1.855289977e-02f, -6.026519023e-03f, -7.790617836e-03f, +2.215532402e-03f, +1.101888322e-03f, +0.000000000e+00f,
- /* 20,12 */ +0.000000000e+00f, -1.274866066e-04f, +3.042103091e-03f, -2.672992279e-03f, -1.051027343e-02f, +7.601099328e-03f, +2.187944695e-02f, -1.280005487e-02f, -3.252647846e-02f, +1.526076366e-02f, +3.647500669e-02f, -1.365548733e-02f, -3.114878076e-02f, +9.337391966e-03f, +1.970376789e-02f, -4.864357078e-03f, -8.419725702e-03f, +1.878600735e-03f, +1.361489293e-03f, +0.000000000e+00f,
- /* 20,13 */ +0.000000000e+00f, -2.170808154e-04f, +2.971909246e-03f, -1.959867511e-03f, -1.062161571e-02f, +5.866701604e-03f, +2.239890298e-02f, -9.923776326e-03f, -3.352791602e-02f, +1.169297592e-02f, +3.778668841e-02f, -1.025584288e-02f, -3.244383298e-02f, +6.875821908e-03f, +2.069305390e-02f, -3.586602863e-03f, -8.990907936e-03f, +1.484286050e-03f, +1.638662038e-03f, +0.000000000e+00f,
- /* 20,14 */ +0.000000000e+00f, -2.870815261e-04f, +2.866023275e-03f, -1.276919763e-03f, -1.061062992e-02f, +4.149462009e-03f, +2.267661502e-02f, -7.019484999e-03f, -3.418837690e-02f, +8.036125742e-03f, +3.873376177e-02f, -6.721842627e-03f, -3.344119198e-02f, +4.274418757e-03f, +2.150371837e-02f, -2.202626937e-03f, -9.493276252e-03f, +1.033703668e-03f, +1.931175707e-03f, +0.000000000e+00f,
- /* 20,15 */ +0.000000000e+00f, -3.387491377e-04f, +2.729031078e-03f, -6.307983207e-04f, -1.048404473e-02f, +2.467540325e-03f, +2.271744325e-02f, -4.117983282e-03f, -3.450613681e-02f, +4.328121901e-03f, +3.930609269e-02f, -3.088657053e-03f, -3.412515163e-02f, +1.557339330e-03f, +2.212021870e-02f, -7.235223044e-04f, -9.916240655e-03f, +5.288730096e-04f, +2.236335973e-03f, -3.929324583e-04f,
- /* 16, 0 */ +3.044394378e-03f, -5.755865016e-03f, -7.644875237e-03f, +1.825808857e-02f, +9.222448502e-03f, -3.286388427e-02f, -4.241838036e-03f, +3.949755319e-02f, -4.241838036e-03f, -3.286388427e-02f, +9.222448502e-03f, +1.825808857e-02f, -7.644875237e-03f, -5.755865016e-03f, +3.044394378e-03f, -1.466795211e-05f,
- /* 16, 1 */ +3.096598285e-03f, -4.938670705e-03f, -8.543525001e-03f, +1.681174815e-02f, +1.171692718e-02f, -3.156650717e-02f, -8.140229219e-03f, +3.927338559e-02f, -2.566011090e-04f, -3.380519836e-02f, +6.539747546e-03f, +1.954192550e-02f, -6.591652894e-03f, -6.554797296e-03f, +2.932700428e-03f, +1.424716020e-04f,
- /* 16, 2 */ +3.093580763e-03f, -4.116215273e-03f, -9.283856280e-03f, +1.522768985e-02f, +1.399813452e-02f, -2.993548791e-02f, -1.190603152e-02f, +3.860369285e-02f, +3.768233493e-03f, -3.437220120e-02f, +3.697060454e-03f, +2.063975168e-02f, -5.390052618e-03f, -7.321916780e-03f, +2.757987679e-03f, +3.278051009e-04f,
- /* 16, 3 */ +3.040228116e-03f, -3.300778044e-03f, -9.864516741e-03f, +1.353158972e-02f, +1.604446323e-02f, -2.799705310e-02f, -1.549559239e-02f, +3.749686691e-02f, +7.784523662e-03f, -3.455113173e-02f, +7.255039591e-04f, +2.152972014e-02f, -4.048737024e-03f, -8.043312786e-03f, +2.517583336e-03f, +5.415628140e-04f,
- /* 16, 4 */ +2.941918573e-03f, -2.503765206e-03f, -1.028645874e-02f, +1.174962597e-02f, +1.783794825e-02f, -2.578082191e-02f, -1.886790220e-02f, +3.596676747e-02f, +1.174386090e-02f, -3.433297304e-02f, -2.341279491e-03f, +2.219201396e-02f, -2.578818314e-03f, -8.704920467e-03f, +2.209778110e-03f, +1.246855370e-03f,
- /* 16, 5 */ +2.804395319e-03f, -1.735580001e-03f, -1.055281940e-02f, +9.908096520e-03f, +1.936441115e-02f, -2.331935318e-02f, -2.198510572e-02f, +3.403253365e-02f, +1.559820593e-02f, -3.371364718e-02f, -5.467520855e-03f, +2.260919785e-02f, -9.938011251e-04f, -9.292739628e-03f, +1.833922789e-03f, +1.492594630e-03f,
- /* 16, 6 */ +2.633640678e-03f, -1.005515791e-03f, -1.066877263e-02f, +8.033047542e-03f, +2.061354789e-02f, -2.064765983e-02f, -2.481296600e-02f, +3.171832409e-02f, +1.930052332e-02f, -3.269414425e-02f, -8.615762914e-03f, +2.276654580e-02f, +6.905139302e-04f, -9.793063512e-03f, +1.390511455e-03f, +1.739628231e-03f,
- /* 16, 7 */ +2.435753603e-03f, -3.216727033e-04f, -1.064135670e-02f, +6.149918447e-03f, +2.157895980e-02f, -1.780269814e-02f, -2.732127429e-02f, +2.905298940e-02f, +2.280540611e-02f, -3.128058296e-02f, -1.174733238e-02f, +2.265233903e-02f, +2.456165958e-03f, -1.019271416e-02f, +8.812491435e-04f, +1.982865330e-03f,
- /* 16, 8 */ +2.216832517e-03f, +3.091018830e-04f, -1.047928070e-02f, +4.283208005e-03f, +2.225812888e-02f, -1.482283947e-02f, -2.948420097e-02f, +2.606968157e-02f, +2.606968157e-02f, -2.948420097e-02f, -1.482283947e-02f, +2.225812888e-02f, +4.283208005e-03f, -1.047928070e-02f, +3.091018830e-04f, +2.216832517e-03f,
- /* 16, 9 */ +1.982865330e-03f, +8.812491435e-04f, -1.019271416e-02f, +2.456165958e-03f, +2.265233903e-02f, -1.174733238e-02f, -3.128058296e-02f, +2.280540611e-02f, +2.905298940e-02f, -2.732127429e-02f, -1.780269814e-02f, +2.157895980e-02f, +6.149918447e-03f, -1.064135670e-02f, -3.216727033e-04f, +2.435753603e-03f,
- /* 16,10 */ +1.739628231e-03f, +1.390511455e-03f, -9.793063512e-03f, +6.905139302e-04f, +2.276654580e-02f, -8.615762914e-03f, -3.269414425e-02f, +1.930052332e-02f, +3.171832409e-02f, -2.481296600e-02f, -2.064765983e-02f, +2.061354789e-02f, +8.033047542e-03f, -1.066877263e-02f, -1.005515791e-03f, +2.633640678e-03f,
- /* 16,11 */ +1.492594630e-03f, +1.833922789e-03f, -9.292739628e-03f, -9.938011251e-04f, +2.260919785e-02f, -5.467520855e-03f, -3.371364718e-02f, +1.559820593e-02f, +3.403253365e-02f, -2.198510572e-02f, -2.331935318e-02f, +1.936441115e-02f, +9.908096520e-03f, -1.055281940e-02f, -1.735580001e-03f, +2.804395319e-03f,
- /* 16,12 */ +1.246855370e-03f, +2.209778110e-03f, -8.704920467e-03f, -2.578818314e-03f, +2.219201396e-02f, -2.341279491e-03f, -3.433297304e-02f, +1.174386090e-02f, +3.596676747e-02f, -1.886790220e-02f, -2.578082191e-02f, +1.783794825e-02f, +1.174962597e-02f, -1.028645874e-02f, -2.503765206e-03f, +2.941918573e-03f,
- /* 16,13 */ +5.415628140e-04f, +2.517583336e-03f, -8.043312786e-03f, -4.048737024e-03f, +2.152972014e-02f, +7.255039591e-04f, -3.455113173e-02f, +7.784523662e-03f, +3.749686691e-02f, -1.549559239e-02f, -2.799705310e-02f, +1.604446323e-02f, +1.353158972e-02f, -9.864516741e-03f, -3.300778044e-03f, +3.040228116e-03f,
- /* 16,14 */ +3.278051009e-04f, +2.757987679e-03f, -7.321916780e-03f, -5.390052618e-03f, +2.063975168e-02f, +3.697060454e-03f, -3.437220120e-02f, +3.768233493e-03f, +3.860369285e-02f, -1.190603152e-02f, -2.993548791e-02f, +1.399813452e-02f, +1.522768985e-02f, -9.283856280e-03f, -4.116215273e-03f, +3.093580763e-03f,
- /* 16,15 */ +1.424716020e-04f, +2.932700428e-03f, -6.554797296e-03f, -6.591652894e-03f, +1.954192550e-02f, +6.539747546e-03f, -3.380519836e-02f, -2.566011090e-04f, +3.927338559e-02f, -8.140229219e-03f, -3.156650717e-02f, +1.171692718e-02f, +1.681174815e-02f, -8.543525001e-03f, -4.938670705e-03f, +3.096598285e-03f,
- /* 16, 0 */ +2.106112688e-03f, -1.136549770e-04f, -1.070669430e-02f, +1.017472059e-02f, +1.725397418e-02f, -2.914959442e-02f, -8.963852042e-03f, +3.949755319e-02f, -8.963852042e-03f, -2.914959442e-02f, +1.725397418e-02f, +1.017472059e-02f, -1.070669430e-02f, -1.136549770e-04f, +2.106112688e-03f, +0.000000000e+00f,
- /* 16, 1 */ +1.845338280e-03f, +5.473343456e-04f, -1.065891816e-02f, +8.155641030e-03f, +1.899089579e-02f, -2.691951328e-02f, -1.297236480e-02f, +3.923810803e-02f, -4.790894575e-03f, -3.103786392e-02f, +1.521305380e-02f, +1.215062389e-02f, -1.058864907e-02f, -8.385121370e-04f, +2.352913572e-03f, +0.000000000e+00f,
- /* 16, 2 */ +1.577651889e-03f, +1.138027416e-03f, -1.045641117e-02f, +6.125232216e-03f, +2.040939526e-02f, -2.438627738e-02f, -1.676283724e-02f, +3.846353557e-02f, -5.100475811e-04f, -3.254996068e-02f, +1.288771825e-02f, +1.405076114e-02f, -1.029592106e-02f, -1.619065127e-03f, +2.578329862e-03f, +0.000000000e+00f,
- /* 16, 3 */ +1.309641631e-03f, +1.653747621e-03f, -1.011218665e-02f, +4.114112388e-03f, +2.150028131e-02f, -2.159216402e-02f, -2.028541539e-02f, +3.718506562e-02f, +3.820010384e-03f, -3.365643786e-02f, +1.030255138e-02f, +1.584231759e-02f, -9.822158049e-03f, -2.445442331e-03f, +2.774741598e-03f, +0.000000000e+00f,
- /* 16, 4 */ +5.462770218e-04f, +2.091544281e-03f, -9.640854940e-03f, +2.151223968e-03f, +2.225957955e-02f, -1.858235038e-02f, -2.349470263e-02f, +3.542121816e-02f, +8.139354376e-03f, -3.433331277e-02f, +7.486889709e-03f, +1.749279467e-02f, -9.163764446e-03f, -3.306153325e-03f, +2.934475195e-03f, -4.634120047e-04f,
- /* 16, 5 */ +3.039101756e-04f, +2.450135010e-03f, -9.058284956e-03f, +2.634319572e-04f, +2.268843286e-02f, -1.540416082e-02f, -2.635039795e-02f, +3.319751225e-02f, +1.238771678e-02f, -3.456253827e-02f, +4.474489227e-03f, +1.897056596e-02f, -8.320109905e-03f, -4.188206830e-03f, +3.049970761e-03f, -4.400286560e-04f,
- /* 16, 6 */ +9.722433303e-05f, +2.729819110e-03f, -8.381259809e-03f, -1.524826854e-03f, +2.279292110e-02f, -1.210629477e-02f, -2.881784707e-02f, +3.054606534e-02f, +1.650540309e-02f, -3.433238619e-02f, +1.303110212e-03f, +2.024543829e-02f, -7.293693549e-03f, -5.077265419e-03f, +3.113958519e-03f, -3.921992729e-04f,
- /* 16, 7 */ -7.427658644e-05f, +2.932365266e-03f, -7.627133157e-03f, -3.191839567e-03f, +2.258380561e-02f, -8.738048497e-03f, -3.086849848e-02f, +2.750508980e-02f, +2.043420490e-02f, -3.363773532e-02f, -1.985974837e-03f, +2.128920837e-02f, -6.090258802e-03f, -5.957835775e-03f, +3.119640969e-03f, -3.169896142e-04f,
- /* 16, 8 */ -2.117631665e-04f, +3.060877176e-03f, -6.813492559e-03f, -4.718854594e-03f, +2.207620481e-02f, -5.348543574e-03f, -3.248025769e-02f, +2.411829496e-02f, +2.411829496e-02f, -3.248025769e-02f, -5.348543574e-03f, +2.207620481e-02f, -4.718854594e-03f, -6.813492559e-03f, +3.060877176e-03f, -2.117631665e-04f,
- /* 16, 9 */ -3.169896142e-04f, +3.119640969e-03f, -5.957835775e-03f, -6.090258802e-03f, +2.128920837e-02f, -1.985974837e-03f, -3.363773532e-02f, +2.043420490e-02f, +2.750508980e-02f, -3.086849848e-02f, -8.738048497e-03f, +2.258380561e-02f, -3.191839567e-03f, -7.627133157e-03f, +2.932365266e-03f, -7.427658644e-05f,
- /* 16,10 */ -3.921992729e-04f, +3.113958519e-03f, -5.077265419e-03f, -7.293693549e-03f, +2.024543829e-02f, +1.303110212e-03f, -3.433238619e-02f, +1.650540309e-02f, +3.054606534e-02f, -2.881784707e-02f, -1.210629477e-02f, +2.279292110e-02f, -1.524826854e-03f, -8.381259809e-03f, +2.729819110e-03f, +9.722433303e-05f,
- /* 16,11 */ -4.400286560e-04f, +3.049970761e-03f, -4.188206830e-03f, -8.320109905e-03f, +1.897056596e-02f, +4.474489227e-03f, -3.456253827e-02f, +1.238771678e-02f, +3.319751225e-02f, -2.635039795e-02f, -1.540416082e-02f, +2.268843286e-02f, +2.634319572e-04f, -9.058284956e-03f, +2.450135010e-03f, +3.039101756e-04f,
- /* 16,12 */ -4.634120047e-04f, +2.934475195e-03f, -3.306153325e-03f, -9.163764446e-03f, +1.749279467e-02f, +7.486889709e-03f, -3.433331277e-02f, +8.139354376e-03f, +3.542121816e-02f, -2.349470263e-02f, -1.858235038e-02f, +2.225957955e-02f, +2.151223968e-03f, -9.640854940e-03f, +2.091544281e-03f, +5.462770218e-04f,
- /* 16,13 */ +0.000000000e+00f, +2.774741598e-03f, -2.445442331e-03f, -9.822158049e-03f, +1.584231759e-02f, +1.030255138e-02f, -3.365643786e-02f, +3.820010384e-03f, +3.718506562e-02f, -2.028541539e-02f, -2.159216402e-02f, +2.150028131e-02f, +4.114112388e-03f, -1.011218665e-02f, +1.653747621e-03f, +1.309641631e-03f,
- /* 16,14 */ +0.000000000e+00f, +2.578329862e-03f, -1.619065127e-03f, -1.029592106e-02f, +1.405076114e-02f, +1.288771825e-02f, -3.254996068e-02f, -5.100475811e-04f, +3.846353557e-02f, -1.676283724e-02f, -2.438627738e-02f, +2.040939526e-02f, +6.125232216e-03f, -1.045641117e-02f, +1.138027416e-03f, +1.577651889e-03f,
- /* 16,15 */ +0.000000000e+00f, +2.352913572e-03f, -8.385121370e-04f, -1.058864907e-02f, +1.215062389e-02f, +1.521305380e-02f, -3.103786392e-02f, -4.790894575e-03f, +3.923810803e-02f, -1.297236480e-02f, -2.691951328e-02f, +1.899089579e-02f, +8.155641030e-03f, -1.065891816e-02f, +5.473343456e-04f, +1.845338280e-03f,
- /* 16, 0 */ -2.517634455e-04f, +5.956310854e-03f, -8.647029609e-03f, +1.153545125e-03f, +2.185732832e-02f, -2.369518339e-02f, -1.347728153e-02f, +3.949755319e-02f, -1.347728153e-02f, -2.369518339e-02f, +2.185732832e-02f, +1.153545125e-03f, -8.647029609e-03f, +2.914798040e-03f, -2.517634455e-04f, +0.000000000e+00f,
- /* 16, 1 */ -3.647589216e-04f, +5.559366521e-03f, -7.860683839e-03f, -8.150822761e-04f, +2.252089097e-02f, -2.063007883e-02f, -1.749200540e-02f, +3.920026256e-02f, -9.205150933e-03f, -2.647415600e-02f, +2.081322447e-02f, +3.223212212e-03f, -9.337661142e-03f, +2.677108373e-03f, -9.939782505e-05f, +0.000000000e+00f,
- /* 16, 2 */ -4.414886472e-04f, +5.113535158e-03f, -7.000222932e-03f, -2.654422569e-03f, +2.280787202e-02f, -1.733513495e-02f, -2.118899605e-02f, +3.831333038e-02f, -4.740975303e-03f, -2.891426752e-02f, +1.939126736e-02f, +5.362271050e-03f, -9.911447152e-03f, +2.349799583e-03f, +9.477253367e-05f, +0.000000000e+00f,
- /* 16, 3 */ -4.855802427e-04f, +4.633347213e-03f, -6.087250386e-03f, -4.340001532e-03f, +2.272858071e-02f, -1.386914009e-02f, -2.451395150e-02f, +3.685148678e-02f, -1.540603716e-04f, -3.096737610e-02f, +1.760097190e-02f, +7.536131493e-03f, -1.034820384e-02f, +1.931270179e-03f, +3.323676319e-04f, +0.000000000e+00f,
- /* 16, 4 */ +0.000000000e+00f, +4.132457962e-03f, -5.142935987e-03f, -5.851401101e-03f, +2.229926864e-02f, -1.029228788e-02f, -2.741946400e-02f, +3.483898696e-02f, +4.483517704e-03f, -3.259088680e-02f, +1.545873378e-02f, +9.707799030e-03f, -1.062918096e-02f, +1.421916825e-03f, +6.140535745e-04f, +0.000000000e+00f,
- /* 16, 5 */ +0.000000000e+00f, +3.623457200e-03f, -4.187611099e-03f, -7.172450485e-03f, +2.154162444e-02f, -6.665085054e-03f, -2.986575546e-02f, +3.230917458e-02f, +9.098146940e-03f, -3.374862716e-02f, +1.298775300e-02f, +1.183848413e-02f, -1.073754388e-02f, +8.242784646e-04f, +9.394126333e-04f, +0.000000000e+00f,
- /* 16, 6 */ +0.000000000e+00f, +3.117716971e-03f, -3.240404345e-03f, -8.291325326e-03f, +2.048218318e-02f, -3.047278250e-03f, -3.182126614e-02f, +2.930388237e-02f, +1.361595241e-02f, -3.441162052e-02f, +1.021782484e-02f, +1.388827332e-02f, -1.065884073e-02f, +1.431392807e-04f, +1.306826648e-03f, +0.000000000e+00f,
- /* 16, 7 */ +0.000000000e+00f, +2.625277441e-03f, -2.318923448e-03f, -9.200556695e-03f, +1.915166452e-02f, +5.031802154e-04f, -3.326308735e-02f, +2.587268140e-02f, +1.796408380e-02f, -3.455874049e-02f, +7.184998851e-03f, +1.581685040e-02f, -1.038144369e-02f, -6.144144569e-04f, +1.713377737e-03f, +0.000000000e+00f,
- /* 16, 8 */ +0.000000000e+00f, +2.154770219e-03f, -1.438987736e-03f, -9.896953513e-03f, +1.758425506e-02f, +3.931108902e-03f, -3.417723209e-02f, +2.207199352e-02f, +2.207199352e-02f, -3.417723209e-02f, +3.931108902e-03f, +1.758425506e-02f, -9.896953513e-03f, -1.438987736e-03f, +2.154770219e-03f, +0.000000000e+00f,
- /* 16, 9 */ +0.000000000e+00f, +1.713377737e-03f, -6.144144569e-04f, -1.038144369e-02f, +1.581685040e-02f, +7.184998851e-03f, -3.455874049e-02f, +1.796408380e-02f, +2.587268140e-02f, -3.326308735e-02f, +5.031802154e-04f, +1.915166452e-02f, -9.200556695e-03f, -2.318923448e-03f, +2.625277441e-03f, +0.000000000e+00f,
- /* 16,10 */ +0.000000000e+00f, +1.306826648e-03f, +1.431392807e-04f, -1.065884073e-02f, +1.388827332e-02f, +1.021782484e-02f, -3.441162052e-02f, +1.361595241e-02f, +2.930388237e-02f, -3.182126614e-02f, -3.047278250e-03f, +2.048218318e-02f, -8.291325326e-03f, -3.240404345e-03f, +3.117716971e-03f, +0.000000000e+00f,
- /* 16,11 */ +0.000000000e+00f, +9.394126333e-04f, +8.242784646e-04f, -1.073754388e-02f, +1.183848413e-02f, +1.298775300e-02f, -3.374862716e-02f, +9.098146940e-03f, +3.230917458e-02f, -2.986575546e-02f, -6.665085054e-03f, +2.154162444e-02f, -7.172450485e-03f, -4.187611099e-03f, +3.623457200e-03f, +0.000000000e+00f,
- /* 16,12 */ +0.000000000e+00f, +6.140535745e-04f, +1.421916825e-03f, -1.062918096e-02f, +9.707799030e-03f, +1.545873378e-02f, -3.259088680e-02f, +4.483517704e-03f, +3.483898696e-02f, -2.741946400e-02f, -1.029228788e-02f, +2.229926864e-02f, -5.851401101e-03f, -5.142935987e-03f, +4.132457962e-03f, +0.000000000e+00f,
- /* 16,13 */ +0.000000000e+00f, +3.323676319e-04f, +1.931270179e-03f, -1.034820384e-02f, +7.536131493e-03f, +1.760097190e-02f, -3.096737610e-02f, -1.540603716e-04f, +3.685148678e-02f, -2.451395150e-02f, -1.386914009e-02f, +2.272858071e-02f, -4.340001532e-03f, -6.087250386e-03f, +4.633347213e-03f, -4.855802427e-04f,
- /* 16,14 */ +0.000000000e+00f, +9.477253367e-05f, +2.349799583e-03f, -9.911447152e-03f, +5.362271050e-03f, +1.939126736e-02f, -2.891426752e-02f, -4.740975303e-03f, +3.831333038e-02f, -2.118899605e-02f, -1.733513495e-02f, +2.280787202e-02f, -2.654422569e-03f, -7.000222932e-03f, +5.113535158e-03f, -4.414886472e-04f,
- /* 16,15 */ +0.000000000e+00f, -9.939782505e-05f, +2.677108373e-03f, -9.337661142e-03f, +3.223212212e-03f, +2.081322447e-02f, -2.647415600e-02f, -9.205150933e-03f, +3.920026256e-02f, -1.749200540e-02f, -2.063007883e-02f, +2.252089097e-02f, -8.150822761e-04f, -7.860683839e-03f, +5.559366521e-03f, -3.647589216e-04f,
- /* 12, 0 */ -3.924537125e-03f, -6.177283790e-03f, +2.270137823e-02f, -1.696686670e-02f, -1.770529738e-02f, +3.949755319e-02f, -1.770529738e-02f, -1.696686670e-02f, +2.270137823e-02f, -6.177283790e-03f, -3.924537125e-03f, +2.689823824e-03f,
- /* 12, 1 */ -2.918444824e-03f, -7.533875928e-03f, +2.217225575e-02f, -1.325050127e-02f, -2.161377319e-02f, +3.915985190e-02f, -1.343239533e-02f, -2.049610855e-02f, +2.283609035e-02f, -4.600700986e-03f, -4.945631587e-03f, +2.897838580e-03f,
- /* 12, 2 */ -1.948111766e-03f, -8.657444743e-03f, +2.127619260e-02f, -9.420045488e-03f, -2.509275167e-02f, +3.815312062e-02f, -8.867972963e-03f, -2.376686078e-02f, +2.255583139e-02f, -2.822790564e-03f, -5.958903400e-03f, +3.051876120e-03f,
- /* 12, 3 */ -1.031879811e-03f, -9.540571177e-03f, +2.004673480e-02f, -5.548699503e-03f, -2.808617760e-02f, +3.649634673e-02f, -4.091413649e-03f, -2.671092541e-02f, +2.184766025e-02f, -8.677312765e-04f, -6.939883353e-03f, +3.140832095e-03f,
- /* 12, 4 */ -1.854082964e-04f, -1.018130776e-02f, +1.852257236e-02f, -1.708362919e-03f, -3.054799363e-02f, +3.422074403e-02f, +8.129280323e-04f, -2.926474106e-02f, +2.070682375e-02f, +1.235031889e-03f, -7.862950435e-03f, +3.154329873e-03f,
- /* 12, 5 */ +5.785109863e-04f, -1.058292035e-02f, +1.674653148e-02f, +2.031769072e-03f, -3.244290444e-02f, +3.136911490e-02f, +5.757350815e-03f, -3.137078637e-02f, +1.913716500e-02f, +3.451172065e-03f, -8.701884951e-03f, +3.083080347e-03f,
- /* 12, 6 */ +1.250056620e-03f, -1.075352499e-02f, +1.476451598e-02f, +5.606517218e-03f, -3.374690984e-02f, +2.799497691e-02f, +1.065251585e-02f, -3.297888633e-02f, +1.715135739e-02f, +5.741996578e-03f, -9.430471381e-03f, +2.919238566e-03f,
- /* 12, 7 */ +1.822400383e-03f, -1.070563332e-02f, +1.262442359e-02f, +8.955911342e-03f, -3.444759838e-02f, +2.416147295e-02f, +1.540920462e-02f, -3.404739100e-02f, +1.477095353e-02f, +8.065088216e-03f, -1.002313834e-02f, +2.656746896e-03f,
- /* 12, 8 */ +2.291654178e-03f, -1.045562141e-02f, +1.037506188e-02f, +1.202624229e-02f, -3.454419870e-02f, +1.994008861e-02f, +1.994008861e-02f, -3.454419870e-02f, +1.202624229e-02f, +1.037506188e-02f, -1.045562141e-02f, +2.291654178e-03f,
- /* 12, 9 */ +2.656746896e-03f, -1.002313834e-02f, +8.065088216e-03f, +1.477095353e-02f, -3.404739100e-02f, +1.540920462e-02f, +2.416147295e-02f, -3.444759838e-02f, +8.955911342e-03f, +1.262442359e-02f, -1.070563332e-02f, +1.822400383e-03f,
- /* 12,10 */ +2.919238566e-03f, -9.430471381e-03f, +5.741996578e-03f, +1.715135739e-02f, -3.297888633e-02f, +1.065251585e-02f, +2.799497691e-02f, -3.374690984e-02f, +5.606517218e-03f, +1.476451598e-02f, -1.075352499e-02f, +1.250056620e-03f,
- /* 12,11 */ +3.083080347e-03f, -8.701884951e-03f, +3.451172065e-03f, +1.913716500e-02f, -3.137078637e-02f, +5.757350815e-03f, +3.136911490e-02f, -3.244290444e-02f, +2.031769072e-03f, +1.674653148e-02f, -1.058292035e-02f, +5.785109863e-04f,
- /* 12,12 */ +3.154329873e-03f, -7.862950435e-03f, +1.235031889e-03f, +2.070682375e-02f, -2.926474106e-02f, +8.129280323e-04f, +3.422074403e-02f, -3.054799363e-02f, -1.708362919e-03f, +1.852257236e-02f, -1.018130776e-02f, -1.854082964e-04f,
- /* 12,13 */ +3.140832095e-03f, -6.939883353e-03f, -8.677312765e-04f, +2.184766025e-02f, -2.671092541e-02f, -4.091413649e-03f, +3.649634673e-02f, -2.808617760e-02f, -5.548699503e-03f, +2.004673480e-02f, -9.540571177e-03f, -1.031879811e-03f,
- /* 12,14 */ +3.051876120e-03f, -5.958903400e-03f, -2.822790564e-03f, +2.255583139e-02f, -2.376686078e-02f, -8.867972963e-03f, +3.815312062e-02f, -2.509275167e-02f, -9.420045488e-03f, +2.127619260e-02f, -8.657444743e-03f, -1.948111766e-03f,
- /* 12,15 */ +2.897838580e-03f, -4.945631587e-03f, -4.600700986e-03f, +2.283609035e-02f, -2.049610855e-02f, -1.343239533e-02f, +3.915985190e-02f, -2.161377319e-02f, -1.325050127e-02f, +2.217225575e-02f, -7.533875928e-03f, -2.918444824e-03f,
- /* 12, 0 */ +5.529156756e-04f, -1.017944650e-02f, +2.010395691e-02f, -9.501724583e-03f, -2.157725737e-02f, +3.949755319e-02f, -2.157725737e-02f, -9.501724583e-03f, +2.010395691e-02f, -1.017944650e-02f, +5.529156756e-04f, +9.520529918e-04f,
- /* 12, 1 */ +1.269440891e-03f, -1.060857725e-02f, +1.848426560e-02f, -5.389674050e-03f, -2.526172923e-02f, +3.911687897e-02f, -1.740939271e-02f, -1.356576871e-02f, +2.138958875e-02f, -9.480008902e-03f, -2.676127190e-04f, +1.273328470e-03f,
- /* 12, 2 */ +1.873685854e-03f, -1.077705214e-02f, +1.658179711e-02f, -1.315683663e-03f, -2.839592801e-02f, +3.798295250e-02f, -1.283645305e-02f, -1.749413418e-02f, +2.229518867e-02f, -8.506812328e-03f, -1.180051037e-03f, +1.604489886e-03f,
- /* 12, 3 */ +2.361120897e-03f, -1.070010905e-02f, +1.445171501e-02f, +2.637679549e-03f, -3.092573063e-02f, +3.611987567e-02f, -7.946589383e-03f, -2.119952675e-02f, +2.278144860e-02f, -7.263083188e-03f, -2.168530550e-03f, +1.934678236e-03f,
- /* 12, 4 */ +2.730794315e-03f, -1.039785120e-02f, +1.215160004e-02f, +6.393108320e-03f, -3.281077803e-02f, +3.356720057e-02f, -2.835931904e-03f, -2.459705675e-02f, +2.281696739e-02f, -5.759053577e-03f, -3.213563229e-03f, +2.251787566e-03f,
- /* 12, 5 */ +2.985073479e-03f, -9.894440683e-03f, +9.739988515e-03f, +9.880142532e-03f, -3.402514934e-02f, +3.037901891e-02f, +2.393471366e-03f, -2.760625942e-02f, +2.237934513e-02f, -4.012119167e-03f, -4.292316215e-03f, +2.542756696e-03f,
- /* 12, 6 */ +3.129309714e-03f, -9.217233004e-03f, +7.274949975e-03f, +1.303654969e-02f, -3.455769209e-02f, +2.662271867e-02f, +7.635875993e-03f, -3.015305887e-02f, +2.145609570e-02f, -2.046814992e-03f, -5.379003980e-03f, +2.793918230e-03f,
- /* 12, 7 */ +3.171441616e-03f, -8.395878746e-03f, +4.812738303e-03f, +1.580947051e-02f, -3.441200543e-02f, +2.237743869e-02f, +1.278417054e-02f, -3.217162603e-02f, +2.004534769e-02f, +1.053992035e-04f, -6.445394017e-03f, +2.991397563e-03f,
- /* 12, 8 */ +3.121552430e-03f, -7.461418245e-03f, +2.406547485e-03f, +1.815630830e-02f, -3.360608252e-02f, +1.773225889e-02f, +1.773225889e-02f, -3.360608252e-02f, +1.815630830e-02f, +2.406547485e-03f, -7.461418245e-03f, +3.121552430e-03f,
- /* 12, 9 */ +2.991397563e-03f, -6.445394017e-03f, +1.053992035e-04f, +2.004534769e-02f, -3.217162603e-02f, +1.278417054e-02f, +2.237743869e-02f, -3.441200543e-02f, +1.580947051e-02f, +4.812738303e-03f, -8.395878746e-03f, +3.171441616e-03f,
- /* 12,10 */ +2.793918230e-03f, -5.379003980e-03f, -2.046814992e-03f, +2.145609570e-02f, -3.015305887e-02f, +7.635875993e-03f, +2.662271867e-02f, -3.455769209e-02f, +1.303654969e-02f, +7.274949975e-03f, -9.217233004e-03f, +3.129309714e-03f,
- /* 12,11 */ +2.542756696e-03f, -4.292316215e-03f, -4.012119167e-03f, +2.237934513e-02f, -2.760625942e-02f, +2.393471366e-03f, +3.037901891e-02f, -3.402514934e-02f, +9.880142532e-03f, +9.739988515e-03f, -9.894440683e-03f, +2.985073479e-03f,
- /* 12,12 */ +2.251787566e-03f, -3.213563229e-03f, -5.759053577e-03f, +2.281696739e-02f, -2.459705675e-02f, -2.835931904e-03f, +3.356720057e-02f, -3.281077803e-02f, +6.393108320e-03f, +1.215160004e-02f, -1.039785120e-02f, +2.730794315e-03f,
- /* 12,13 */ +1.934678236e-03f, -2.168530550e-03f, -7.263083188e-03f, +2.278144860e-02f, -2.119952675e-02f, -7.946589383e-03f, +3.611987567e-02f, -3.092573063e-02f, +2.637679549e-03f, +1.445171501e-02f, -1.070010905e-02f, +2.361120897e-03f,
- /* 12,14 */ +1.604489886e-03f, -1.180051037e-03f, -8.506812328e-03f, +2.229518867e-02f, -1.749413418e-02f, -1.283645305e-02f, +3.798295250e-02f, -2.839592801e-02f, -1.315683663e-03f, +1.658179711e-02f, -1.077705214e-02f, +1.873685854e-03f,
- /* 12,15 */ +1.273328470e-03f, -2.676127190e-04f, -9.480008902e-03f, +2.138958875e-02f, -1.356576871e-02f, -1.740939271e-02f, +3.911687897e-02f, -2.526172923e-02f, -5.389674050e-03f, +1.848426560e-02f, -1.060857725e-02f, +1.269440891e-03f,
-
- /* 24, 0 */ -8.820438069e-05f, -1.519461079e-04f, -2.301651496e-04f, -3.149320871e-04f, -3.945939739e-04f, -4.554410135e-04f, -4.841532882e-04f, -4.705408991e-04f, -4.099602091e-04f, -3.048100066e-04f, -1.646897470e-04f, -5.099007530e-06f, +1.551006323e-04f, +2.969416536e-04f, +4.046294158e-04f, +4.681429482e-04f, +4.846228261e-04f, +4.583040637e-04f, +3.990939388e-04f, +3.201968846e-04f, +2.353759082e-04f, +1.564712483e-04f, +9.167483068e-05f, +4.482688286e-05f,
- /* 24, 1 */ -8.480575132e-05f, -1.474789784e-04f, -2.249812225e-04f, -3.096480504e-04f, -3.900204007e-04f, -4.524514078e-04f, -4.835165803e-04f, -4.727530367e-04f, -4.151145025e-04f, -3.125397891e-04f, -1.742016828e-04f, -1.529460870e-05f, +1.454387449e-04f, +2.889379628e-04f, +3.991236794e-04f, +4.655589110e-04f, +4.849233000e-04f, +4.610375470e-04f, +4.035168325e-04f, +3.254391996e-04f, +2.406110065e-04f, +1.610529558e-04f, +9.521673594e-05f, +4.721513201e-05f,
- /* 24, 2 */ -8.147924507e-05f, -1.430712350e-04f, -2.198265592e-04f, -3.043479843e-04f, -3.853766873e-04f, -4.493383067e-04f, -4.827146831e-04f, -4.747797448e-04f, -4.200908527e-04f, -3.201278616e-04f, -1.836320864e-04f, -2.548296987e-05f, +1.357085413e-04f, +2.808022583e-04f, +3.934446700e-04f, +4.627886263e-04f, +4.850529052e-04f, +4.636385032e-04f, +4.078592000e-04f, +3.306557574e-04f, +2.458678944e-04f, +1.656897170e-04f, +9.882966748e-05f, +4.967415993e-05f,
- /* 24, 3 */ -7.822510242e-05f, -1.387241832e-04f, -2.147035314e-04f, -2.990350629e-04f, -3.806663042e-04f, -4.461048161e-04f, -4.817496625e-04f, -4.766215175e-04f, -4.248879309e-04f, -3.275711800e-04f, -1.929766610e-04f, -3.565926997e-05f, +1.259145254e-04f, +2.725379532e-04f, +3.875941701e-04f, +4.598320457e-04f, +4.850099279e-04f, +4.661040260e-04f, +4.121175966e-04f, +3.358432542e-04f, +2.511439643e-04f, +1.703799499e-04f, +1.025131319e-04f, +5.220438912e-05f,
- /* 24, 4 */ -7.504350274e-05f, -1.344390595e-04f, -2.096144489e-04f, -2.937124231e-04f, -3.758927218e-04f, -4.427540852e-04f, -4.806236671e-04f, -4.782789577e-04f, -4.295045226e-04f, -3.348667971e-04f, -2.022311686e-04f, -4.581869630e-05f, +1.160612449e-04f, +2.641485480e-04f, +3.815740737e-04f, +4.566892339e-04f, +4.847927474e-04f, +4.684312656e-04f, +4.162885910e-04f, +3.409983591e-04f, +2.564365532e-04f, +1.751220037e-04f, +1.062665706e-04f, +5.480619333e-05f,
- /* 24, 5 */ -7.193456522e-05f, -1.302170312e-04f, -2.045615590e-04f, -2.883831622e-04f, -3.710594077e-04f, -4.392893036e-04f, -4.793389263e-04f, -4.797527765e-04f, -4.339395286e-04f, -3.420118645e-04f, -2.113914331e-04f, -5.595644787e-05f, +1.061532886e-04f, +2.556376279e-04f, +3.753863858e-04f, +4.533603695e-04f, +4.843998374e-04f, +4.706174312e-04f, +4.203687678e-04f, +3.461177167e-04f, +2.617429433e-04f, +1.799141593e-04f, +1.100893595e-04f, +5.747989630e-05f,
- /* 24, 6 */ -6.889834987e-05f, -1.260591965e-04f, -1.995470454e-04f, -2.830503358e-04f, -3.661698243e-04f, -4.357136989e-04f, -4.778977479e-04f, -4.810437916e-04f, -4.381919648e-04f, -3.490036345e-04f, -2.204533432e-04f, -6.606773875e-05f, +9.619528314e-05f, +2.470088608e-04f, +3.690332209e-04f, +4.498457452e-04f, +4.838297683e-04f, +4.726597937e-04f, +4.243547301e-04f, +3.511979487e-04f, +2.670603639e-04f, +1.847546294e-04f, +1.139808078e-04f, +6.022577049e-05f,
- /* 24, 7 */ -6.593485851e-05f, -1.219665852e-04f, -1.945730275e-04f, -2.777169567e-04f, -3.612274261e-04f, -4.320305335e-04f, -4.763025159e-04f, -4.821529264e-04f, -4.422609626e-04f, -3.558394612e-04f, -2.294128549e-04f, -7.614780136e-05f, +8.619188981e-05f, +2.382659945e-04f, +3.625168024e-04f, +4.461457687e-04f, +4.830812085e-04f, +4.745556880e-04f, +4.282431024e-04f, +3.562356572e-04f, +2.723859925e-04f, +1.896415594e-04f, +1.179401580e-04f, +6.304403582e-05f,
- /* 24, 8 */ -6.304403582e-05f, -1.179401580e-04f, -1.896415594e-04f, -2.723859925e-04f, -3.562356572e-04f, -4.282431024e-04f, -4.745556880e-04f, -4.830812085e-04f, -4.461457687e-04f, -3.625168024e-04f, -2.382659945e-04f, -8.619188981e-05f, +7.614780136e-05f, +2.294128549e-04f, +3.558394612e-04f, +4.422609626e-04f, +4.821529264e-04f, +4.763025159e-04f, +4.320305335e-04f, +3.612274261e-04f, +2.777169567e-04f, +1.945730275e-04f, +1.219665852e-04f, +6.593485851e-05f,
- /* 24, 9 */ -6.022577049e-05f, -1.139808078e-04f, -1.847546294e-04f, -2.670603639e-04f, -3.511979487e-04f, -4.243547301e-04f, -4.726597937e-04f, -4.838297683e-04f, -4.498457452e-04f, -3.690332209e-04f, -2.470088608e-04f, -9.619528314e-05f, +6.606773875e-05f, +2.204533432e-04f, +3.490036345e-04f, +4.381919648e-04f, +4.810437916e-04f, +4.778977479e-04f, +4.357136989e-04f, +3.661698243e-04f, +2.830503358e-04f, +1.995470454e-04f, +1.260591965e-04f, +6.889834987e-05f,
- /* 24,10 */ -5.747989630e-05f, -1.100893595e-04f, -1.799141593e-04f, -2.617429433e-04f, -3.461177167e-04f, -4.203687678e-04f, -4.706174312e-04f, -4.843998374e-04f, -4.533603695e-04f, -3.753863858e-04f, -2.556376279e-04f, -1.061532886e-04f, +5.595644787e-05f, +2.113914331e-04f, +3.420118645e-04f, +4.339395286e-04f, +4.797527765e-04f, +4.793389263e-04f, +4.392893036e-04f, +3.710594077e-04f, +2.883831622e-04f, +2.045615590e-04f, +1.302170312e-04f, +7.193456522e-05f,
- /* 24,11 */ -5.480619333e-05f, -1.062665706e-04f, -1.751220037e-04f, -2.564365532e-04f, -3.409983591e-04f, -4.162885910e-04f, -4.684312656e-04f, -4.847927474e-04f, -4.566892339e-04f, -3.815740737e-04f, -2.641485480e-04f, -1.160612449e-04f, +4.581869630e-05f, +2.022311686e-04f, +3.348667971e-04f, +4.295045226e-04f, +4.782789577e-04f, +4.806236671e-04f, +4.427540852e-04f, +3.758927218e-04f, +2.937124231e-04f, +2.096144489e-04f, +1.344390595e-04f, +7.504350274e-05f,
- /* 24,12 */ -5.220438912e-05f, -1.025131319e-04f, -1.703799499e-04f, -2.511439643e-04f, -3.358432542e-04f, -4.121175966e-04f, -4.661040260e-04f, -4.850099279e-04f, -4.598320457e-04f, -3.875941701e-04f, -2.725379532e-04f, -1.259145254e-04f, +3.565926997e-05f, +1.929766610e-04f, +3.275711800e-04f, +4.248879309e-04f, +4.766215175e-04f, +4.817496625e-04f, +4.461048161e-04f, +3.806663042e-04f, +2.990350629e-04f, +2.147035314e-04f, +1.387241832e-04f, +7.822510242e-05f,
- /* 24,13 */ -4.967415993e-05f, -9.882966748e-05f, -1.656897170e-04f, -2.458678944e-04f, -3.306557574e-04f, -4.078592000e-04f, -4.636385032e-04f, -4.850529052e-04f, -4.627886263e-04f, -3.934446700e-04f, -2.808022583e-04f, -1.357085413e-04f, +2.548296987e-05f, +1.836320864e-04f, +3.201278616e-04f, +4.200908527e-04f, +4.747797448e-04f, +4.827146831e-04f, +4.493383067e-04f, +3.853766873e-04f, +3.043479843e-04f, +2.198265592e-04f, +1.430712350e-04f, +8.147924507e-05f,
- /* 24,14 */ -4.721513201e-05f, -9.521673594e-05f, -1.610529558e-04f, -2.406110065e-04f, -3.254391996e-04f, -4.035168325e-04f, -4.610375470e-04f, -4.849233000e-04f, -4.655589110e-04f, -3.991236794e-04f, -2.889379628e-04f, -1.454387449e-04f, +1.529460870e-05f, +1.742016828e-04f, +3.125397891e-04f, +4.151145025e-04f, +4.727530367e-04f, +4.835165803e-04f, +4.524514078e-04f, +3.900204007e-04f, +3.096480504e-04f, +2.249812225e-04f, +1.474789784e-04f, +8.480575132e-05f,
- /* 24,15 */ -4.482688286e-05f, -9.167483068e-05f, -1.564712483e-04f, -2.353759082e-04f, -3.201968846e-04f, -3.990939388e-04f, -4.583040637e-04f, -4.846228261e-04f, -4.681429482e-04f, -4.046294158e-04f, -2.969416536e-04f, -1.551006323e-04f, +5.099007530e-06f, +1.646897470e-04f, +3.048100066e-04f, +4.099602091e-04f, +4.705408991e-04f, +4.841532882e-04f, +4.554410135e-04f, +3.945939739e-04f, +3.149320871e-04f, +2.301651496e-04f, +1.519461079e-04f, +8.820438069e-05f,
- /* 24, 0 */ +3.721332452e-05f, -8.727351622e-06f, -1.260052743e-04f, -3.262895896e-04f, -5.956603662e-04f, -8.899501259e-04f, -1.140781305e-03f, -1.272347980e-03f, -1.224469676e-03f, -9.741728935e-04f, -5.476309302e-04f, -1.718639697e-05f, +5.165697336e-04f, +9.521355524e-04f, +1.214742061e-03f, +1.275075958e-03f, +1.153251370e-03f, +9.076938752e-04f, +6.139361451e-04f, +3.414081512e-04f, +1.360881127e-04f, +1.374767685e-05f, -3.597568203e-05f, -3.836441874e-05f,
- /* 24, 1 */ +3.827272022e-05f, -3.990309212e-06f, -1.162552839e-04f, -3.114511951e-04f, -5.774902753e-04f, -8.720393210e-04f, -1.127840237e-03f, -1.268906542e-03f, -1.233389975e-03f, -9.955061195e-04f, -5.782766642e-04f, -5.154594549e-05f, +4.851159022e-04f, +9.294071718e-04f, +1.204207601e-03f, +1.277079499e-03f, +1.165232472e-03f, +9.252515980e-04f, +6.323029482e-04f, +3.567995352e-04f, +1.465038861e-04f, +1.905656402e-05f, -3.455261727e-05f, -3.906074609e-05f,
- /* 24, 2 */ +3.916105537e-05f, +4.689475139e-07f, -1.068376458e-04f, -2.968998221e-04f, -5.594401371e-04f, -8.539803004e-04f, -1.114446367e-03f, -1.264763218e-03f, -1.241503276e-03f, -1.016122900e-03f, -6.084845647e-04f, -8.586577249e-05f, +4.532926958e-04f, +9.060015608e-04f, +1.192867560e-03f, +1.278348235e-03f, +1.176706916e-03f, +9.426042142e-04f, +6.507457252e-04f, +3.724559064e-04f, +1.572522637e-04f, +2.465906089e-05f, -3.293697730e-05f, -3.967556907e-05f,
- /* 24, 3 */ +3.988551544e-05f, +4.656120273e-06f, -9.775146571e-05f, -2.826418349e-04f, -5.415238064e-04f, -8.357917522e-04f, -1.100618114e-03f, -1.259930153e-03f, -1.248810685e-03f, -1.036011659e-03f, -6.382327409e-04f, -1.201194461e-04f, +4.211237814e-04f, +8.819332498e-04f, +1.180724004e-03f, +1.278872430e-03f, +1.187657300e-03f, +9.597325558e-04f, +6.692490513e-04f, +3.883689407e-04f, +1.683324883e-04f, +3.055997058e-05f, -3.112164378e-05f, -4.020250110e-05f,
- /* 24, 4 */ +4.045327387e-05f, +8.577101915e-06f, -8.899546026e-05f, -2.686831091e-04f, -5.237547173e-04f, -8.174921923e-04f, -1.086374092e-03f, -1.254420050e-03f, -1.255314082e-03f, -1.055161588e-03f, -6.674998060e-04f, -1.542806079e-04f, +3.886332072e-04f, +8.572174771e-04f, +1.167779798e-03f, +1.278642989e-03f, +1.198066533e-03f, +9.766173891e-04f, +6.877971412e-04f, +4.045298263e-04f, +1.797433681e-04f, +3.676383839e-05f, -2.909954521e-05f, -4.063504078e-05f,
- /* 24, 5 */ +4.087148106e-05f, +1.223796294e-05f, -8.056796775e-05f, -2.550290329e-04f, -5.061458738e-04f, -7.990999447e-04f, -1.071733083e-03f, -1.248246148e-03f, -1.261016119e-03f, -1.073562648e-03f, -6.962648992e-04f, -1.883230024e-04f, +3.558453770e-04f, +8.318701747e-04f, +1.154038613e-03f, +1.277651484e-03f, +1.207917863e-03f, +9.932394374e-04f, +7.063738625e-04f, +4.209292660e-04f, +1.914832687e-04f, +4.327493877e-05f, -2.686366939e-05f, -4.096657950e-05f,
- /* 24, 6 */ +4.114725367e-05f, +1.564493806e-05f, -7.246695886e-05f, -2.416845105e-04f, -4.887098400e-04f, -7.806331214e-04f, -1.056714015e-03f, -1.241422199e-03f, -1.265920211e-03f, -1.091205584e-03f, -7.245077077e-04f, -2.222205061e-04f, +3.227850234e-04f, +8.059079530e-04f, +1.139504920e-03f, +1.275890161e-03f, +1.217194897e-03f, +1.009579403e-03f, +7.249627509e-04f, +4.375574807e-04f, +2.035501057e-04f, +5.009726244e-05f, -2.440707607e-05f, -4.119040933e-05f,
- /* 24, 7 */ +4.128766430e-05f, +1.880441272e-05f, -6.469004778e-05f, -2.286539641e-04f, -4.714587328e-04f, -7.621096041e-04f, -1.041335936e-03f, -1.233962452e-03f, -1.270030522e-03f, -1.108081926e-03f, -7.522084876e-04f, -2.559471563e-04f, +2.894771803e-04f, +7.793480846e-04f, +1.124183998e-03f, +1.273351959e-03f, +1.225881627e-03f, +1.025617992e-03f, +7.435470253e-04f, +4.544042133e-04f, +2.159413387e-04f, +5.723450367e-05f, -2.172290976e-05f, -4.129973134e-05f,
- /* 24, 8 */ +4.129973134e-05f, +2.172290976e-05f, -5.723450367e-05f, -2.159413387e-04f, -4.544042133e-04f, -7.435470253e-04f, -1.025617992e-03f, -1.225881627e-03f, -1.273351959e-03f, -1.124183998e-03f, -7.793480846e-04f, -2.894771803e-04f, +2.559471563e-04f, +7.522084876e-04f, +1.108081926e-03f, +1.270030522e-03f, +1.233962452e-03f, +1.041335936e-03f, +7.621096041e-04f, +4.714587328e-04f, +2.286539641e-04f, +6.469004778e-05f, -1.880441272e-05f, -4.128766430e-05f,
- /* 24, 9 */ +4.119040933e-05f, +2.440707607e-05f, -5.009726244e-05f, -2.035501057e-04f, -4.375574807e-04f, -7.249627509e-04f, -1.009579403e-03f, -1.217194897e-03f, -1.275890161e-03f, -1.139504920e-03f, -8.059079530e-04f, -3.227850234e-04f, +2.222205061e-04f, +7.245077077e-04f, +1.091205584e-03f, +1.265920211e-03f, +1.241422199e-03f, +1.056714015e-03f, +7.806331214e-04f, +4.887098400e-04f, +2.416845105e-04f, +7.246695886e-05f, -1.564493806e-05f, -4.114725367e-05f,
- /* 24,10 */ +4.096657950e-05f, +2.686366939e-05f, -4.327493877e-05f, -1.914832687e-04f, -4.209292660e-04f, -7.063738625e-04f, -9.932394374e-04f, -1.207917863e-03f, -1.277651484e-03f, -1.154038613e-03f, -8.318701747e-04f, -3.558453770e-04f, +1.883230024e-04f, +6.962648992e-04f, +1.073562648e-03f, +1.261016119e-03f, +1.248246148e-03f, +1.071733083e-03f, +7.990999447e-04f, +5.061458738e-04f, +2.550290329e-04f, +8.056796775e-05f, -1.223796294e-05f, -4.087148106e-05f,
- /* 24,11 */ +4.063504078e-05f, +2.909954521e-05f, -3.676383839e-05f, -1.797433681e-04f, -4.045298263e-04f, -6.877971412e-04f, -9.766173891e-04f, -1.198066533e-03f, -1.278642989e-03f, -1.167779798e-03f, -8.572174771e-04f, -3.886332072e-04f, +1.542806079e-04f, +6.674998060e-04f, +1.055161588e-03f, +1.255314082e-03f, +1.254420050e-03f, +1.086374092e-03f, +8.174921923e-04f, +5.237547173e-04f, +2.686831091e-04f, +8.899546026e-05f, -8.577101915e-06f, -4.045327387e-05f,
- /* 24,12 */ +4.020250110e-05f, +3.112164378e-05f, -3.055997058e-05f, -1.683324883e-04f, -3.883689407e-04f, -6.692490513e-04f, -9.597325558e-04f, -1.187657300e-03f, -1.278872430e-03f, -1.180724004e-03f, -8.819332498e-04f, -4.211237814e-04f, +1.201194461e-04f, +6.382327409e-04f, +1.036011659e-03f, +1.248810685e-03f, +1.259930153e-03f, +1.100618114e-03f, +8.357917522e-04f, +5.415238064e-04f, +2.826418349e-04f, +9.775146571e-05f, -4.656120273e-06f, -3.988551544e-05f,
- /* 24,13 */ +3.967556907e-05f, +3.293697730e-05f, -2.465906089e-05f, -1.572522637e-04f, -3.724559064e-04f, -6.507457252e-04f, -9.426042142e-04f, -1.176706916e-03f, -1.278348235e-03f, -1.192867560e-03f, -9.060015608e-04f, -4.532926958e-04f, +8.586577249e-05f, +6.084845647e-04f, +1.016122900e-03f, +1.241503276e-03f, +1.264763218e-03f, +1.114446367e-03f, +8.539803004e-04f, +5.594401371e-04f, +2.968998221e-04f, +1.068376458e-04f, -4.689475139e-07f, -3.916105537e-05f,
- /* 24,14 */ +3.906074609e-05f, +3.455261727e-05f, -1.905656402e-05f, -1.465038861e-04f, -3.567995352e-04f, -6.323029482e-04f, -9.252515980e-04f, -1.165232472e-03f, -1.277079499e-03f, -1.204207601e-03f, -9.294071718e-04f, -4.851159022e-04f, +5.154594549e-05f, +5.782766642e-04f, +9.955061195e-04f, +1.233389975e-03f, +1.268906542e-03f, +1.127840237e-03f, +8.720393210e-04f, +5.774902753e-04f, +3.114511951e-04f, +1.162552839e-04f, +3.990309212e-06f, -3.827272022e-05f,
- /* 24,15 */ +3.836441874e-05f, +3.597568203e-05f, -1.374767685e-05f, -1.360881127e-04f, -3.414081512e-04f, -6.139361451e-04f, -9.076938752e-04f, -1.153251370e-03f, -1.275075958e-03f, -1.214742061e-03f, -9.521355524e-04f, -5.165697336e-04f, +1.718639697e-05f, +5.476309302e-04f, +9.741728935e-04f, +1.224469676e-03f, +1.272347980e-03f, +1.140781305e-03f, +8.899501259e-04f, +5.956603662e-04f, +3.262895896e-04f, +1.260052743e-04f, +8.727351622e-06f, -3.721332452e-05f,
- /* 24, 0 */ +8.266384897e-05f, +1.864042294e-04f, +2.488885336e-04f, +1.546439211e-04f, -1.995837972e-04f, -8.300120177e-04f, -1.613160849e-03f, -2.296673715e-03f, -2.585717258e-03f, -2.273475621e-03f, -1.352242686e-03f, -4.324968723e-05f, +1.278412578e-03f, +2.232544293e-03f, +2.585064833e-03f, +2.329165788e-03f, +1.661894649e-03f, +8.765619362e-04f, +2.314166150e-04f, -1.408802900e-04f, -2.488728147e-04f, -1.925779863e-04f, -8.867605644e-05f, -1.381647235e-05f,
- /* 24, 1 */ +7.679604466e-05f, +1.800850086e-04f, +2.482891228e-04f, +1.673628145e-04f, -1.688781476e-04f, -7.841040553e-04f, -1.564053778e-03f, -2.262611362e-03f, -2.583952550e-03f, -2.311948888e-03f, -1.424504725e-03f, -1.296977982e-04f, +1.203096102e-03f, +2.189184288e-03f, +2.581965725e-03f, +2.360018674e-03f, +1.710180642e-03f, +9.237037585e-04f, +2.643640884e-04f, -1.260534627e-04f, -2.482108983e-04f, -1.985807152e-04f, -9.482163577e-05f, -1.700840565e-05f,
- /* 24, 2 */ +7.108272573e-05f, +1.736451253e-04f, +2.471057735e-04f, +1.790568131e-04f, -1.393098721e-04f, -7.388859215e-04f, -1.514647192e-03f, -2.227049028e-03f, -2.579803518e-03f, -2.347938498e-03f, -1.495119547e-03f, -2.159922036e-04f, +1.126377386e-03f, +2.143428746e-03f, +2.576393731e-03f, +2.389164999e-03f, +1.757943642e-03f, +9.713853048e-04f, +2.984113695e-04f, -1.101464409e-04f, -2.468719141e-04f, -2.043861254e-04f, -1.010885985e-04f, -2.040687624e-05f,
- /* 24, 3 */ +6.553303557e-05f, +1.671085856e-04f, +2.453697283e-04f, +1.897470664e-04f, -1.108869031e-04f, -6.944032625e-04f, -1.465013955e-03f, -2.190058265e-03f, -2.573306150e-03f, -2.381422658e-03f, -1.564010684e-03f, -3.020307159e-04f, +1.048342851e-03f, +2.095314540e-03f, +2.568326065e-03f, +2.416539054e-03f, +1.805107932e-03f, +1.019552324e-03f, +3.335412514e-04f, -9.314376077e-05f, -2.448252646e-04f, -2.099672379e-04f, -1.074639934e-04f, -2.401251277e-05f,
- /* 24, 4 */ +6.015519126e-05f, +1.604985702e-04f, +2.431122111e-04f, +1.994559526e-04f, -8.361493575e-05f, -6.506994570e-04f, -1.415225919e-03f, -2.151711738e-03f, -2.564499518e-03f, -2.412383397e-03f, -1.631104459e-03f, -3.877115714e-04f, +9.690810727e-04f, +2.044882222e-03f, +2.557743429e-03f, +2.442076932e-03f, +1.851597394e-03f, +1.068148557e-03f, +3.697341485e-04f, -7.503156587e-05f, -2.420407013e-04f, -2.152964269e-04f, -1.139339030e-04f, -2.782526914e-05f,
- /* 24, 5 */ +5.495649810e-05f, +1.538374078e-04f, +2.403643576e-04f, +2.082069988e-04f, -5.749746926e-05f, -6.078155802e-04f, -1.365353811e-03f, -2.112083086e-03f, -2.553425683e-03f, -2.440806561e-03f, -1.696330106e-03f, -4.729335981e-04f, +8.886826408e-04f, +1.992175989e-03f, +2.544630075e-03f, +2.465716661e-03f, +1.897335642e-03f, +1.117115802e-03f, +4.069680813e-04f, -5.579767803e-05f, -2.384884029e-04f, -2.203454641e-04f, -1.204834430e-04f, -3.184439496e-05f,
- /* 24, 6 */ +4.994336610e-05f, +1.471465506e-04f, +2.371571498e-04f, +2.160248014e-04f, -3.253585139e-05f, -5.657903730e-04f, -1.315467130e-03f, -2.071246779e-03f, -2.540129593e-03f, -2.466681818e-03f, -1.759619871e-03f, -5.575963834e-04f, +8.072400133e-04f, +1.937243618e-03f, +2.528973864e-03f, +2.487398336e-03f, +1.942246152e-03f, +1.166393990e-03f, +4.452186667e-04f, -3.543166589e-05f, -2.341390536e-04f, -2.250855657e-04f, -1.270967638e-04f, -3.606840695e-05f,
- /* 24, 7 */ +4.512132841e-05f, +1.404465535e-04f, +2.335213506e-04f, +2.229349451e-04f, -8.729326764e-06f, -5.246602166e-04f, -1.265634037e-03f, -2.029277978e-03f, -2.524658979e-03f, -2.490002646e-03f, -1.820909115e-03f, -6.416004392e-04f, +7.248473657e-04f, +1.880136408e-03f, +2.510766314e-03f, +2.507064240e-03f, +1.986252395e-03f, +1.215921259e-03f, +4.844591124e-04f, -1.392491133e-05f, -2.289639228e-04f, -2.294874421e-04f, -1.337570553e-04f, -4.049506149e-05f,
- /* 24, 8 */ +4.049506149e-05f, +1.337570553e-04f, +2.294874421e-04f, +2.289639228e-04f, +1.392491133e-05f, -4.844591124e-04f, -1.215921259e-03f, -1.986252395e-03f, -2.507064240e-03f, -2.510766314e-03f, -1.880136408e-03f, -7.248473657e-04f, +6.416004392e-04f, +1.820909115e-03f, +2.490002646e-03f, +2.524658979e-03f, +2.029277978e-03f, +1.265634037e-03f, +5.246602166e-04f, +8.729326764e-06f, -2.229349451e-04f, -2.335213506e-04f, -1.404465535e-04f, -4.512132841e-05f,
- /* 24, 9 */ +3.606840695e-05f, +1.270967638e-04f, +2.250855657e-04f, +2.341390536e-04f, +3.543166589e-05f, -4.452186667e-04f, -1.166393990e-03f, -1.942246152e-03f, -2.487398336e-03f, -2.528973864e-03f, -1.937243618e-03f, -8.072400133e-04f, +5.575963834e-04f, +1.759619871e-03f, +2.466681818e-03f, +2.540129593e-03f, +2.071246779e-03f, +1.315467130e-03f, +5.657903730e-04f, +3.253585139e-05f, -2.160248014e-04f, -2.371571498e-04f, -1.471465506e-04f, -4.994336610e-05f,
- /* 24,10 */ +3.184439496e-05f, +1.204834430e-04f, +2.203454641e-04f, +2.384884029e-04f, +5.579767803e-05f, -4.069680813e-04f, -1.117115802e-03f, -1.897335642e-03f, -2.465716661e-03f, -2.544630075e-03f, -1.992175989e-03f, -8.886826408e-04f, +4.729335981e-04f, +1.696330106e-03f, +2.440806561e-03f, +2.553425683e-03f, +2.112083086e-03f, +1.365353811e-03f, +6.078155802e-04f, +5.749746926e-05f, -2.082069988e-04f, -2.403643576e-04f, -1.538374078e-04f, -5.495649810e-05f,
- /* 24,11 */ +2.782526914e-05f, +1.139339030e-04f, +2.152964269e-04f, +2.420407013e-04f, +7.503156587e-05f, -3.697341485e-04f, -1.068148557e-03f, -1.851597394e-03f, -2.442076932e-03f, -2.557743429e-03f, -2.044882222e-03f, -9.690810727e-04f, +3.877115714e-04f, +1.631104459e-03f, +2.412383397e-03f, +2.564499518e-03f, +2.151711738e-03f, +1.415225919e-03f, +6.506994570e-04f, +8.361493575e-05f, -1.994559526e-04f, -2.431122111e-04f, -1.604985702e-04f, -6.015519126e-05f,
- /* 24,12 */ +2.401251277e-05f, +1.074639934e-04f, +2.099672379e-04f, +2.448252646e-04f, +9.314376077e-05f, -3.335412514e-04f, -1.019552324e-03f, -1.805107932e-03f, -2.416539054e-03f, -2.568326065e-03f, -2.095314540e-03f, -1.048342851e-03f, +3.020307159e-04f, +1.564010684e-03f, +2.381422658e-03f, +2.573306150e-03f, +2.190058265e-03f, +1.465013955e-03f, +6.944032625e-04f, +1.108869031e-04f, -1.897470664e-04f, -2.453697283e-04f, -1.671085856e-04f, -6.553303557e-05f,
- /* 24,13 */ +2.040687624e-05f, +1.010885985e-04f, +2.043861254e-04f, +2.468719141e-04f, +1.101464409e-04f, -2.984113695e-04f, -9.713853048e-04f, -1.757943642e-03f, -2.389164999e-03f, -2.576393731e-03f, -2.143428746e-03f, -1.126377386e-03f, +2.159922036e-04f, +1.495119547e-03f, +2.347938498e-03f, +2.579803518e-03f, +2.227049028e-03f, +1.514647192e-03f, +7.388859215e-04f, +1.393098721e-04f, -1.790568131e-04f, -2.471057735e-04f, -1.736451253e-04f, -7.108272573e-05f,
- /* 24,14 */ +1.700840565e-05f, +9.482163577e-05f, +1.985807152e-04f, +2.482108983e-04f, +1.260534627e-04f, -2.643640884e-04f, -9.237037585e-04f, -1.710180642e-03f, -2.360018674e-03f, -2.581965725e-03f, -2.189184288e-03f, -1.203096102e-03f, +1.296977982e-04f, +1.424504725e-03f, +2.311948888e-03f, +2.583952550e-03f, +2.262611362e-03f, +1.564053778e-03f, +7.841040553e-04f, +1.688781476e-04f, -1.673628145e-04f, -2.482891228e-04f, -1.800850086e-04f, -7.679604466e-05f,
- /* 24,15 */ +1.381647235e-05f, +8.867605644e-05f, +1.925779863e-04f, +2.488728147e-04f, +1.408802900e-04f, -2.314166150e-04f, -8.765619362e-04f, -1.661894649e-03f, -2.329165788e-03f, -2.585064833e-03f, -2.232544293e-03f, -1.278412578e-03f, +4.324968723e-05f, +1.352242686e-03f, +2.273475621e-03f, +2.585717258e-03f, +2.296673715e-03f, +1.613160849e-03f, +8.300120177e-04f, +1.995837972e-04f, -1.546439211e-04f, -2.488885336e-04f, -1.864042294e-04f, -8.266384897e-05f,
- /* 24, 0 */ -8.756118778e-05f, -1.009631262e-05f, +2.499923290e-04f, +5.877223422e-04f, +6.788717735e-04f, +1.353208099e-04f, -1.181609893e-03f, -2.907631270e-03f, -4.227440709e-03f, -4.289302846e-03f, -2.753030129e-03f, -9.027467135e-05f, +2.610460208e-03f, +4.239433597e-03f, +4.275304929e-03f, +3.011836329e-03f, +1.284225967e-03f, -7.470693818e-05f, -6.668983668e-04f, -6.049037547e-04f, -2.711811033e-04f, -7.712041122e-07f, +8.724954076e-05f, +5.404595280e-05f,
- /* 24, 1 */ -8.741655630e-05f, -2.019027119e-05f, +2.291878545e-04f, +5.696067266e-04f, +6.882827247e-04f, +1.927359117e-04f, -1.080756061e-03f, -2.801858302e-03f, -4.174485032e-03f, -4.332641998e-03f, -2.890980043e-03f, -2.706680808e-04f, +2.463494124e-03f, +4.183052585e-03f, +4.317905196e-03f, +3.114235078e-03f, +1.388440877e-03f, -1.091717027e-05f, -6.522789212e-04f, -6.210469572e-04f, -2.926973166e-04f, -1.241413728e-05f, +8.645224618e-05f, +5.751117153e-05f,
- /* 24, 2 */ -8.684540791e-05f, -2.951540942e-05f, +2.088206066e-04f, +5.506594457e-04f, +6.952187414e-04f, +2.469379129e-04f, -9.818199274e-04f, -2.694754852e-03f, -4.116618896e-03f, -4.369446535e-03f, -3.024096686e-03f, -4.505940556e-04f, +2.312365817e-03f, +4.120192033e-03f, +4.355078033e-03f, +3.214588722e-03f, +1.494083528e-03f, +5.601692583e-05f, -6.349341530e-04f, -6.360467505e-04f, -3.144802134e-04f, -2.483132916e-05f, +8.514047439e-05f, +6.091502927e-05f,
- /* 24, 3 */ -8.587775422e-05f, -3.807920270e-05f, +1.889395528e-04f, +5.309813040e-04f, +6.997709178e-04f, +2.979208532e-04f, -8.849487633e-04f, -2.586556795e-03f, -4.054031257e-03f, -4.399725659e-03f, -3.152177828e-03f, -6.297421881e-04f, +2.157318805e-03f, +4.050898074e-03f, +4.386669491e-03f, +3.312658663e-03f, +1.600975431e-03f, +1.260549593e-04f, -6.147894349e-04f, -6.497970322e-04f, -3.364651980e-04f, -3.801847602e-05f, +8.328608571e-05f, +6.423360450e-05f,
- /* 24, 4 */ -8.454371894e-05f, -4.589171696e-05f, +1.695896910e-04f, +5.106711213e-04f, +7.020335552e-04f, +3.456869501e-04f, -7.902814402e-04f, -2.477497901e-03f, -3.986918477e-03f, -4.423502152e-03f, -3.275032702e-03f, -8.078038906e-04f, +1.998605647e-03f, +3.975230752e-03f, +4.412535626e-03f, +3.408207107e-03f, +1.708931018e-03f, +1.991476106e-04f, -5.917751493e-04f, -6.621910968e-04f, -3.585839047e-04f, -5.196800512e-05f, +8.086178430e-05f, +6.744196867e-05f,
- /* 24, 5 */ -8.287340509e-05f, -5.296545744e-05f, +1.508120534e-04f, +4.898254962e-04f, +7.021037953e-04f, +3.902463858e-04f, -6.979482496e-04f, -2.367809282e-03f, -3.915483754e-03f, -4.440812209e-03f, -3.392482395e-03f, -9.844731162e-04f, +1.836487379e-03f, +3.893263974e-03f, +4.432542967e-03f, +3.500997660e-03f, +1.817757983e-03f, +2.752365501e-04f, -5.658270331e-04f, -6.731219472e-04f, -3.807642824e-04f, -6.666895953e-05f, +7.784127492e-05f, +7.051425394e-05f,
- /* 24, 6 */ -8.089676755e-05f, -5.931521393e-05f, +1.326437227e-04f, +4.685385820e-04f, +7.000812546e-04f, +4.316170765e-04f, -6.080707472e-04f, -2.257718867e-03f, -3.839936544e-03f, -4.451705229e-03f, -3.504360214e-03f, -1.159447072e-03f, +1.671232927e-03f, +3.805085432e-03f, +4.446568950e-03f, +3.590795947e-03f, +1.927257648e-03f, +3.542543807e-04f, -5.368865161e-04f, -6.824826149e-04f, -4.029306956e-04f, -8.210689127e-05f, +7.419942176e-05f, +7.342372810e-05f,
- /* 24, 7 */ -7.864349144e-05f, -6.495790319e-05f, +1.151178633e-04f, +4.469018792e-04f, +6.960676605e-04f, +4.698244236e-04f, -5.207616239e-04f, -2.147450881e-03f, -3.760491970e-03f, -4.456243581e-03f, -3.610512013e-03f, -1.332426925e-03f, +1.503118492e-03f, +3.710796487e-03f, +4.454502333e-03f, +3.677370219e-03f, +2.037225356e-03f, +4.361246060e-04f, -5.049010493e-04f, -6.901664903e-04f, -4.250040411e-04f, -9.826376366e-05f, +6.991240915e-05f, +7.614287656e-05f,
- /* 24, 8 */ -7.614287656e-05f, -6.991240915e-05f, +9.826376366e-05f, +4.250040411e-04f, +6.901664903e-04f, +5.049010493e-04f, -4.361246060e-04f, -2.037225356e-03f, -3.677370219e-03f, -4.454502333e-03f, -3.710796487e-03f, -1.503118492e-03f, +1.332426925e-03f, +3.610512013e-03f, +4.456243581e-03f, +3.760491970e-03f, +2.147450881e-03f, +5.207616239e-04f, -4.698244236e-04f, -6.960676605e-04f, -4.469018792e-04f, -1.151178633e-04f, +6.495790319e-05f, +7.864349144e-05f,
- /* 24, 9 */ -7.342372810e-05f, -7.419942176e-05f, +8.210689127e-05f, +4.029306956e-04f, +6.824826149e-04f, +5.368865161e-04f, -3.542543807e-04f, -1.927257648e-03f, -3.590795947e-03f, -4.446568950e-03f, -3.805085432e-03f, -1.671232927e-03f, +1.159447072e-03f, +3.504360214e-03f, +4.451705229e-03f, +3.839936544e-03f, +2.257718867e-03f, +6.080707472e-04f, -4.316170765e-04f, -7.000812546e-04f, -4.685385820e-04f, -1.326437227e-04f, +5.931521393e-05f, +8.089676755e-05f,
- /* 24,10 */ -7.051425394e-05f, -7.784127492e-05f, +6.666895953e-05f, +3.807642824e-04f, +6.731219472e-04f, +5.658270331e-04f, -2.752365501e-04f, -1.817757983e-03f, -3.500997660e-03f, -4.432542967e-03f, -3.893263974e-03f, -1.836487379e-03f, +9.844731162e-04f, +3.392482395e-03f, +4.440812209e-03f, +3.915483754e-03f, +2.367809282e-03f, +6.979482496e-04f, -3.902463858e-04f, -7.021037953e-04f, -4.898254962e-04f, -1.508120534e-04f, +5.296545744e-05f, +8.287340509e-05f,
- /* 24,11 */ -6.744196867e-05f, -8.086178430e-05f, +5.196800512e-05f, +3.585839047e-04f, +6.621910968e-04f, +5.917751493e-04f, -1.991476106e-04f, -1.708931018e-03f, -3.408207107e-03f, -4.412535626e-03f, -3.975230752e-03f, -1.998605647e-03f, +8.078038906e-04f, +3.275032702e-03f, +4.423502152e-03f, +3.986918477e-03f, +2.477497901e-03f, +7.902814402e-04f, -3.456869501e-04f, -7.020335552e-04f, -5.106711213e-04f, -1.695896910e-04f, +4.589171696e-05f, +8.454371894e-05f,
- /* 24,12 */ -6.423360450e-05f, -8.328608571e-05f, +3.801847602e-05f, +3.364651980e-04f, +6.497970322e-04f, +6.147894349e-04f, -1.260549593e-04f, -1.600975431e-03f, -3.312658663e-03f, -4.386669491e-03f, -4.050898074e-03f, -2.157318805e-03f, +6.297421881e-04f, +3.152177828e-03f, +4.399725659e-03f, +4.054031257e-03f, +2.586556795e-03f, +8.849487633e-04f, -2.979208532e-04f, -6.997709178e-04f, -5.309813040e-04f, -1.889395528e-04f, +3.807920270e-05f, +8.587775422e-05f,
- /* 24,13 */ -6.091502927e-05f, -8.514047439e-05f, +2.483132916e-05f, +3.144802134e-04f, +6.360467505e-04f, +6.349341530e-04f, -5.601692583e-05f, -1.494083528e-03f, -3.214588722e-03f, -4.355078033e-03f, -4.120192033e-03f, -2.312365817e-03f, +4.505940556e-04f, +3.024096686e-03f, +4.369446535e-03f, +4.116618896e-03f, +2.694754852e-03f, +9.818199274e-04f, -2.469379129e-04f, -6.952187414e-04f, -5.506594457e-04f, -2.088206066e-04f, +2.951540942e-05f, +8.684540791e-05f,
- /* 24,14 */ -5.751117153e-05f, -8.645224618e-05f, +1.241413728e-05f, +2.926973166e-04f, +6.210469572e-04f, +6.522789212e-04f, +1.091717027e-05f, -1.388440877e-03f, -3.114235078e-03f, -4.317905196e-03f, -4.183052585e-03f, -2.463494124e-03f, +2.706680808e-04f, +2.890980043e-03f, +4.332641998e-03f, +4.174485032e-03f, +2.801858302e-03f, +1.080756061e-03f, -1.927359117e-04f, -6.882827247e-04f, -5.696067266e-04f, -2.291878545e-04f, +2.019027119e-05f, +8.741655630e-05f,
- /* 24,15 */ -5.404595280e-05f, -8.724954076e-05f, +7.712041122e-07f, +2.711811033e-04f, +6.049037547e-04f, +6.668983668e-04f, +7.470693818e-05f, -1.284225967e-03f, -3.011836329e-03f, -4.275304929e-03f, -4.239433597e-03f, -2.610460208e-03f, +9.027467135e-05f, +2.753030129e-03f, +4.289302846e-03f, +4.227440709e-03f, +2.907631270e-03f, +1.181609893e-03f, -1.353208099e-04f, -6.788717735e-04f, -5.877223422e-04f, -2.499923290e-04f, +1.009631262e-05f, +8.756118778e-05f,
- /* 24, 0 */ -4.836862817e-05f, -2.381906908e-04f, -2.861422699e-04f, +1.419765781e-04f, +9.779307384e-04f, +1.431118485e-03f, +4.239072727e-04f, -2.320049614e-03f, -5.516524807e-03f, -6.885468951e-03f, -4.882970050e-03f, -1.652445539e-04f, +4.647640808e-03f, +6.864975932e-03f, +5.679465803e-03f, +2.528057977e-03f, -2.982544427e-04f, -1.420326139e-03f, -1.029081461e-03f, -1.868092348e-04f, +2.758007186e-04f, +2.491702023e-04f, +5.836581816e-05f, -3.491105347e-05f,
- /* 24, 1 */ -3.887878147e-05f, -2.267040256e-04f, -2.944876029e-04f, +9.900949096e-05f, +9.254138922e-04f, +1.435932770e-03f, +5.422031866e-04f, -2.114193296e-03f, -5.346195092e-03f, -6.891993065e-03f, -5.106971374e-03f, -4.953359135e-04f, +4.401480442e-03f, +6.830374341e-03f, +5.834433801e-03f, +2.737690485e-03f, -1.653667139e-04f, -1.403322383e-03f, -1.078579553e-03f, -2.333982604e-04f, +2.633988510e-04f, +2.595470071e-04f, +6.884149383e-05f, -3.317859772e-05f,
- /* 24, 2 */ -2.992041863e-05f, -2.148033017e-04f, -3.009073041e-04f, +5.800387728e-05f, +8.718108917e-04f, +1.435015360e-03f, +6.530479478e-04f, -1.910998057e-03f, -5.169072824e-03f, -6.884726614e-03f, -5.319183002e-03f, -8.242352929e-04f, +4.145019341e-03f, +6.781564023e-03f, +5.980858542e-03f, +2.948401826e-03f, -2.539414214e-05f, -1.379888189e-03f, -1.126132932e-03f, -2.816211011e-04f, +2.488796810e-04f, +2.692234993e-04f, +7.976200316e-05f, -3.095924021e-05f,
- /* 24, 3 */ -2.151306397e-05f, -2.025787804e-04f, -3.054778181e-04f, +1.904245883e-05f, +8.173942695e-04f, +1.428624316e-03f, +7.563747429e-04f, -1.710952703e-03f, -4.985763915e-03f, -6.863885651e-03f, -5.519179462e-03f, -1.151152247e-03f, +3.878819947e-03f, +6.718485032e-03f, +6.118185890e-03f, +3.159630822e-03f, +1.214850236e-04f, -1.349820125e-03f, -1.171444944e-03f, -3.313418525e-04f, +2.321939470e-04f, +2.781004545e-04f, +9.108884721e-05f, -2.823129406e-05f,
- /* 24, 4 */ -1.367174826e-05f, -1.901175448e-04f, -3.082808136e-04f, -1.780505549e-05f, +7.624282793e-04f, +1.417028061e-03f, +8.521437270e-04f, -1.514524553e-03f, -4.796881865e-03f, -6.829722854e-03f, -5.706572744e-03f, -1.475302628e-03f, +3.603475092e-03f, +6.641118197e-03f, +6.245879909e-03f, +3.370802059e-03f, +2.750642929e-04f, -1.312931609e-03f, -1.214215433e-03f, -3.824113238e-04f, +2.133007109e-04f, +2.860774924e-04f, +1.027786538e-04f, -2.497524656e-05f,
- /* 24, 5 */ -6.407151783e-06f, -1.775031866e-04f, -3.094025487e-04f, -5.248174754e-05f, +7.071681142e-04f, +1.400504044e-03f, +9.403414758e-04f, -1.322158275e-03f, -4.603045619e-03f, -6.782526316e-03f, -5.881013326e-03f, -1.795911068e-03f, +3.319606230e-03f, +6.549485546e-03f, +6.363424898e-03f, +3.581327596e-03f, +4.351089927e-04f, -1.269054120e-03f, -1.254141844e-03f, -4.346671648e-04f, +1.921679399e-04f, +2.930535649e-04f, +1.147831783e-04f, -2.117401174e-05f,
- /* 24, 6 */ +2.742338831e-07f, -1.648155254e-04f, -3.089332390e-04f, -8.494321776e-05f, +6.518591895e-04f, +1.379337399e-03f, +1.020980349e-03f, -1.134274832e-03f, -4.404877423e-03f, -6.722618231e-03f, -6.042191052e-03f, -2.112213435e-03f, +3.027861551e-03f, +6.443650588e-03f, +6.470327373e-03f, +3.790608755e-03f, +6.013564365e-04f, -1.218038367e-03f, -1.290920380e-03f, -4.879340571e-04f, +1.687730668e-04f, +2.989274696e-04f, +1.270493337e-04f, -1.681317980e-05f,
- /* 24, 7 */ +6.369927035e-06f, -1.521303593e-04f, -3.069664313e-04f, -1.151572658e-04f, +5.967364879e-04f, +1.353819611e-03f, +1.094097769e-03f, -9.512705360e-04f, -4.203000702e-03f, -6.650353458e-03f, -6.189835876e-03f, -2.423459243e-03f, +2.728914008e-03f, +6.323718452e-03f, +6.566118000e-03f, +3.998037969e-03f, +7.735162047e-04f, -1.159755419e-03f, -1.324247193e-03f, -5.420239710e-04f, +1.431035268e-04f, +3.035983857e-04f, +1.395192491e-04f, -1.188126168e-05f,
- /* 24, 8 */ +1.188126168e-05f, -1.395192491e-04f, -3.035983857e-04f, -1.431035268e-04f, +5.420239710e-04f, +1.324247193e-03f, +1.159755419e-03f, -7.735162047e-04f, -3.998037969e-03f, -6.566118000e-03f, -6.323718452e-03f, -2.728914008e-03f, +2.423459243e-03f, +6.189835876e-03f, +6.650353458e-03f, +4.203000702e-03f, +9.512705360e-04f, -1.094097769e-03f, -1.353819611e-03f, -5.967364879e-04f, +1.151572658e-04f, +3.069664313e-04f, +1.521303593e-04f, -6.369927035e-06f,
- /* 24, 9 */ +1.681317980e-05f, -1.270493337e-04f, -2.989274696e-04f, -1.687730668e-04f, +4.879340571e-04f, +1.290920380e-03f, +1.218038367e-03f, -6.013564365e-04f, -3.790608755e-03f, -6.470327373e-03f, -6.443650588e-03f, -3.027861551e-03f, +2.112213435e-03f, +6.042191052e-03f, +6.722618231e-03f, +4.404877423e-03f, +1.134274832e-03f, -1.020980349e-03f, -1.379337399e-03f, -6.518591895e-04f, +8.494321776e-05f, +3.089332390e-04f, +1.648155254e-04f, -2.742338831e-07f,
- /* 24,10 */ +2.117401174e-05f, -1.147831783e-04f, -2.930535649e-04f, -1.921679399e-04f, +4.346671648e-04f, +1.254141844e-03f, +1.269054120e-03f, -4.351089927e-04f, -3.581327596e-03f, -6.363424898e-03f, -6.549485546e-03f, -3.319606230e-03f, +1.795911068e-03f, +5.881013326e-03f, +6.782526316e-03f, +4.603045619e-03f, +1.322158275e-03f, -9.403414758e-04f, -1.400504044e-03f, -7.071681142e-04f, +5.248174754e-05f, +3.094025487e-04f, +1.775031866e-04f, +6.407151783e-06f,
- /* 24,11 */ +2.497524656e-05f, -1.027786538e-04f, -2.860774924e-04f, -2.133007109e-04f, +3.824113238e-04f, +1.214215433e-03f, +1.312931609e-03f, -2.750642929e-04f, -3.370802059e-03f, -6.245879909e-03f, -6.641118197e-03f, -3.603475092e-03f, +1.475302628e-03f, +5.706572744e-03f, +6.829722854e-03f, +4.796881865e-03f, +1.514524553e-03f, -8.521437270e-04f, -1.417028061e-03f, -7.624282793e-04f, +1.780505549e-05f, +3.082808136e-04f, +1.901175448e-04f, +1.367174826e-05f,
- /* 24,12 */ +2.823129406e-05f, -9.108884721e-05f, -2.781004545e-04f, -2.321939470e-04f, +3.313418525e-04f, +1.171444944e-03f, +1.349820125e-03f, -1.214850236e-04f, -3.159630822e-03f, -6.118185890e-03f, -6.718485032e-03f, -3.878819947e-03f, +1.151152247e-03f, +5.519179462e-03f, +6.863885651e-03f, +4.985763915e-03f, +1.710952703e-03f, -7.563747429e-04f, -1.428624316e-03f, -8.173942695e-04f, -1.904245883e-05f, +3.054778181e-04f, +2.025787804e-04f, +2.151306397e-05f,
- /* 24,13 */ +3.095924021e-05f, -7.976200316e-05f, -2.692234993e-04f, -2.488796810e-04f, +2.816211011e-04f, +1.126132932e-03f, +1.379888189e-03f, +2.539414214e-05f, -2.948401826e-03f, -5.980858542e-03f, -6.781564023e-03f, -4.145019341e-03f, +8.242352929e-04f, +5.319183002e-03f, +6.884726614e-03f, +5.169072824e-03f, +1.910998057e-03f, -6.530479478e-04f, -1.435015360e-03f, -8.718108917e-04f, -5.800387728e-05f, +3.009073041e-04f, +2.148033017e-04f, +2.992041863e-05f,
- /* 24,14 */ +3.317859772e-05f, -6.884149383e-05f, -2.595470071e-04f, -2.633988510e-04f, +2.333982604e-04f, +1.078579553e-03f, +1.403322383e-03f, +1.653667139e-04f, -2.737690485e-03f, -5.834433801e-03f, -6.830374341e-03f, -4.401480442e-03f, +4.953359135e-04f, +5.106971374e-03f, +6.891993065e-03f, +5.346195092e-03f, +2.114193296e-03f, -5.422031866e-04f, -1.435932770e-03f, -9.254138922e-04f, -9.900949096e-05f, +2.944876029e-04f, +2.267040256e-04f, +3.887878147e-05f,
- /* 24,15 */ +3.491105347e-05f, -5.836581816e-05f, -2.491702023e-04f, -2.758007186e-04f, +1.868092348e-04f, +1.029081461e-03f, +1.420326139e-03f, +2.982544427e-04f, -2.528057977e-03f, -5.679465803e-03f, -6.864975932e-03f, -4.647640808e-03f, +1.652445539e-04f, +4.882970050e-03f, +6.885468951e-03f, +5.516524807e-03f, +2.320049614e-03f, -4.239072727e-04f, -1.431118485e-03f, -9.779307384e-04f, -1.419765781e-04f, +2.861422699e-04f, +2.381906908e-04f, +4.836862817e-05f,
- /* 24, 0 */ +1.364396009e-04f, +7.446376994e-05f, -3.699603221e-04f, -7.278325124e-04f, -5.051635567e-05f, +1.645033952e-03f, +2.378022613e-03f, -2.243714932e-04f, -5.680096534e-03f, -9.704626250e-03f, -7.823014841e-03f, -2.751390883e-04f, +7.480820734e-03f, +9.788905453e-03f, +6.030582333e-03f, +5.101196376e-04f, -2.328731157e-03f, -1.748114996e-03f, -3.640531891e-05f, +7.242350145e-04f, +4.042879967e-04f, -5.742334247e-05f, -1.414906982e-04f, -2.710774794e-05f,
- /* 24, 1 */ +1.307026563e-04f, +8.975162518e-05f, -3.355241044e-04f, -7.270603554e-04f, -1.326866063e-04f, +1.538422151e-03f, +2.413247311e-03f, +4.875121157e-05f, -5.324161431e-03f, -9.595517291e-03f, -8.141086512e-03f, -8.245287223e-04f, +7.115425083e-03f, +9.847646625e-03f, +6.374200107e-03f, +8.077901021e-04f, -2.264974711e-03f, -1.846937004e-03f, -1.278166248e-04f, +7.160485626e-04f, +4.382702758e-04f, -3.863673145e-05f, -1.457592711e-04f, -3.374854096e-05f,
- /* 24, 2 */ +1.243758393e-04f, +1.032931784e-04f, -3.012044148e-04f, -7.221532843e-04f, -2.098818030e-04f, +1.428995714e-03f, +2.434853697e-03f, +3.086181402e-04f, -4.964188024e-03f, -9.462372525e-03f, -8.434212217e-03f, -1.371256439e-03f, +6.727842835e-03f, +9.880231223e-03f, +6.709529590e-03f, +1.116608515e-03f, -2.186408722e-03f, -1.940762958e-03f, -2.234175210e-04f, +7.030713845e-04f, +4.716595396e-04f, -1.812362539e-05f, -1.491486840e-04f, -4.073257728e-05f,
- /* 24, 3 */ +1.175537217e-04f, +1.151066589e-04f, -2.672136493e-04f, -7.133593846e-04f, -2.819161814e-04f, +1.317455363e-03f, +2.443336794e-03f, +5.546728855e-04f, -4.601573558e-03f, -9.306067159e-03f, -8.701668636e-03f, -1.913559980e-03f, +6.319179241e-03f, +9.886134123e-03f, +7.035155238e-03f, +1.435731166e-03f, -2.092745601e-03f, -2.028850662e-03f, -3.228698520e-04f, +6.851212972e-04f, +5.041985339e-04f, +4.082412249e-06f, -1.515631236e-04f, -4.801831197e-05f,
- /* 24, 4 */ +1.103288160e-04f, +1.252215041e-04f, -2.337507561e-04f, -7.009379926e-04f, -3.486413414e-04f, +1.204483360e-03f, +2.439234434e-03f, +7.864337317e-04f, -4.237695644e-03f, -9.127552920e-03f, -8.942835031e-03f, -2.449695551e-03f, +5.890625670e-03f, +9.864926907e-03f, +7.349672574e-03f, +1.764247300e-03f, -1.983757790e-03f, -2.110456450e-03f, -4.257977068e-04f, +6.620377298e-04f, +5.356216172e-04f, +2.793344097e-05f, -1.529084143e-04f, -5.555842361e-05f,
- /* 24, 5 */ +1.027909684e-04f, +1.336775649e-04f, -2.010005851e-04f, -6.851576168e-04f, -4.099455518e-04f, +1.090740633e-03f, +2.423123355e-03f, +1.003494037e-03f, -3.873906570e-03f, -8.927853008e-03f, -9.157195135e-03f, -2.977945083e-03f, +5.443455012e-03f, +9.816280735e-03f, +7.651694576e-03f, +2.101181791e-03f, -1.859280606e-03f, -2.184839011e-03f, -5.317880090e-04f, +6.336836952e-04f, +5.656561208e-04f, +5.336672075e-05f, -1.530928622e-04f, -6.329988035e-05f,
- /* 24, 6 */ +9.502680145e-05f, +1.405242734e-04f, -1.691333585e-04f, -6.662938873e-04f, -4.657528710e-04f, +9.768641187e-04f, +2.395615219e-03f, +1.205522243e-03f, -3.511527821e-03f, -8.708056786e-03f, -9.344338564e-03f, -3.496623369e-03f, +4.979016698e-03f, +9.739968779e-03f, +7.939858067e-03f, +2.445498177e-03f, -1.719214825e-03f, -2.251263312e-03f, -6.403913399e-04f, +5.999476948e-04f, +5.940238143e-04f, +8.030437567e-05f, -1.520281231e-04f, -7.118405837e-05f,
- /* 24, 7 */ +8.711921055e-05f, +1.458197836e-04f, -1.383042613e-04f, -6.446275435e-04f, -5.160220948e-04f, +8.634643034e-04f, +2.357352548e-03f, +1.392261511e-03f, -3.151844842e-03f, -8.469314215e-03f, -9.503961719e-03f, -4.004085039e-03f, +4.498731341e-03f, +9.635868210e-03f, +8.212830089e-03f, +2.796102059e-03f, -1.563529005e-03f, -2.309004616e-03f, -7.511229995e-04f, +5.607455425e-04f, +6.204424737e-04f, +1.086531499e-04f, -1.496300883e-04f, -7.914691395e-05f,
- /* 24, 8 */ +7.914691395e-05f, +1.496300883e-04f, -1.086531499e-04f, -6.204424737e-04f, -5.607455425e-04f, +7.511229995e-04f, +2.309004616e-03f, +1.563529005e-03f, -2.796102059e-03f, -8.212830089e-03f, -9.635868210e-03f, -4.498731341e-03f, +4.004085039e-03f, +9.503961719e-03f, +8.469314215e-03f, +3.151844842e-03f, -1.392261511e-03f, -2.357352548e-03f, -8.634643034e-04f, +5.160220948e-04f, +6.446275435e-04f, +1.383042613e-04f, -1.458197836e-04f, -8.711921055e-05f,
- /* 24, 9 */ +7.118405837e-05f, +1.520281231e-04f, -8.030437567e-05f, -5.940238143e-04f, -5.999476948e-04f, +6.403913399e-04f, +2.251263312e-03f, +1.719214825e-03f, -2.445498177e-03f, -7.939858067e-03f, -9.739968779e-03f, -4.979016698e-03f, +3.496623369e-03f, +9.344338564e-03f, +8.708056786e-03f, +3.511527821e-03f, -1.205522243e-03f, -2.395615219e-03f, -9.768641187e-04f, +4.657528710e-04f, +6.662938873e-04f, +1.691333585e-04f, -1.405242734e-04f, -9.502680145e-05f,
- /* 24,10 */ +6.329988035e-05f, +1.530928622e-04f, -5.336672075e-05f, -5.656561208e-04f, -6.336836952e-04f, +5.317880090e-04f, +2.184839011e-03f, +1.859280606e-03f, -2.101181791e-03f, -7.651694576e-03f, -9.816280735e-03f, -5.443455012e-03f, +2.977945083e-03f, +9.157195135e-03f, +8.927853008e-03f, +3.873906570e-03f, -1.003494037e-03f, -2.423123355e-03f, -1.090740633e-03f, +4.099455518e-04f, +6.851576168e-04f, +2.010005851e-04f, -1.336775649e-04f, -1.027909684e-04f,
- /* 24,11 */ +5.555842361e-05f, +1.529084143e-04f, -2.793344097e-05f, -5.356216172e-04f, -6.620377298e-04f, +4.257977068e-04f, +2.110456450e-03f, +1.983757790e-03f, -1.764247300e-03f, -7.349672574e-03f, -9.864926907e-03f, -5.890625670e-03f, +2.449695551e-03f, +8.942835031e-03f, +9.127552920e-03f, +4.237695644e-03f, -7.864337317e-04f, -2.439234434e-03f, -1.204483360e-03f, +3.486413414e-04f, +7.009379926e-04f, +2.337507561e-04f, -1.252215041e-04f, -1.103288160e-04f,
- /* 24,12 */ +4.801831197e-05f, +1.515631236e-04f, -4.082412249e-06f, -5.041985339e-04f, -6.851212972e-04f, +3.228698520e-04f, +2.028850662e-03f, +2.092745601e-03f, -1.435731166e-03f, -7.035155238e-03f, -9.886134123e-03f, -6.319179241e-03f, +1.913559980e-03f, +8.701668636e-03f, +9.306067159e-03f, +4.601573558e-03f, -5.546728855e-04f, -2.443336794e-03f, -1.317455363e-03f, +2.819161814e-04f, +7.133593846e-04f, +2.672136493e-04f, -1.151066589e-04f, -1.175537217e-04f,
- /* 24,13 */ +4.073257728e-05f, +1.491486840e-04f, +1.812362539e-05f, -4.716595396e-04f, -7.030713845e-04f, +2.234175210e-04f, +1.940762958e-03f, +2.186408722e-03f, -1.116608515e-03f, -6.709529590e-03f, -9.880231223e-03f, -6.727842835e-03f, +1.371256439e-03f, +8.434212217e-03f, +9.462372525e-03f, +4.964188024e-03f, -3.086181402e-04f, -2.434853697e-03f, -1.428995714e-03f, +2.098818030e-04f, +7.221532843e-04f, +3.012044148e-04f, -1.032931784e-04f, -1.243758393e-04f,
- /* 24,14 */ +3.374854096e-05f, +1.457592711e-04f, +3.863673145e-05f, -4.382702758e-04f, -7.160485626e-04f, +1.278166248e-04f, +1.846937004e-03f, +2.264974711e-03f, -8.077901021e-04f, -6.374200107e-03f, -9.847646625e-03f, -7.115425083e-03f, +8.245287223e-04f, +8.141086512e-03f, +9.595517291e-03f, +5.324161431e-03f, -4.875121157e-05f, -2.413247311e-03f, -1.538422151e-03f, +1.326866063e-04f, +7.270603554e-04f, +3.355241044e-04f, -8.975162518e-05f, -1.307026563e-04f,
- /* 24,15 */ +2.710774794e-05f, +1.414906982e-04f, +5.742334247e-05f, -4.042879967e-04f, -7.242350145e-04f, +3.640531891e-05f, +1.748114996e-03f, +2.328731157e-03f, -5.101196376e-04f, -6.030582333e-03f, -9.788905453e-03f, -7.480820734e-03f, +2.751390883e-04f, +7.823014841e-03f, +9.704626250e-03f, +5.680096534e-03f, +2.243714932e-04f, -2.378022613e-03f, -1.645033952e-03f, +5.051635567e-05f, +7.278325124e-04f, +3.699603221e-04f, -7.446376994e-05f, -1.364396009e-04f,
- /* 20, 0 */ +1.366654441e-04f, -5.248309364e-04f, -9.559425272e-04f, +4.495080153e-04f, +2.846407623e-03f, +1.989454068e-03f, -4.491151594e-03f, -1.156100448e-02f, -1.065698581e-02f, -3.895768346e-04f, +1.023895907e-02f, +1.180960294e-02f, +5.007407400e-03f, -1.738511442e-03f, -2.938517986e-03f, -6.019203323e-04f, +9.329195550e-04f, +5.763302237e-04f, -1.134902041e-04f, -1.824770389e-04f,
- /* 20, 1 */ +1.568890194e-04f, -4.728495798e-04f, -9.708996289e-04f, +3.024354413e-04f, +2.741035078e-03f, +2.215509786e-03f, -3.978754642e-03f, -1.127853170e-02f, -1.103432131e-02f, -1.167153605e-03f, +9.781544627e-03f, +1.202253469e-02f, +5.525210549e-03f, -1.462933465e-03f, -3.016077094e-03f, -7.588827792e-04f, +9.015285321e-04f, +6.268920900e-04f, -8.735502929e-05f, -1.921860197e-04f,
- /* 20, 2 */ +1.741940978e-04f, -4.208194393e-04f, -9.781360984e-04f, +1.614183836e-04f, +2.623714429e-03f, +2.416571115e-03f, -3.472449249e-03f, -1.096411041e-02f, -1.136986548e-02f, -1.940007910e-03f, +9.286243980e-03f, +1.219815240e-02f, +6.042182027e-03f, -1.163118517e-03f, -3.077830056e-03f, -9.195341683e-04f, +8.615147935e-04f, +6.760417132e-04f, -5.827810709e-05f, -2.008073985e-04f,
- /* 20, 3 */ +1.886370492e-04f, -3.691494362e-04f, -9.780356474e-04f, +2.709710175e-05f, +2.495775707e-03f, +2.592671089e-03f, -2.974378699e-03f, -1.061978749e-02f, -1.166272581e-02f, -2.705018824e-03f, +8.754750074e-03f, +1.233496472e-02f, +6.555887236e-03f, -8.396136973e-04f, -3.122565398e-03f, -1.082944596e-03f, +8.126754773e-04f, +7.232876858e-04f, -2.630548656e-05f, -2.081598890e-04f,
- /* 20, 4 */ +2.002956356e-04f, -3.182221327e-04f, -9.710157868e-04f, -9.996474913e-05f, +2.358556029e-03f, +2.743978910e-03f, -2.486586970e-03f, -1.024771819e-02f, -1.191222039e-02f, -3.459106327e-03f, +8.188939591e-03f, +1.243164652e-02f, +7.063848473e-03f, -4.931158341e-04f, -3.149124311e-03f, -1.248118895e-03f, +7.548636055e-04f, +7.681251779e-04f, +8.487693398e-06f, -2.140618814e-04f,
- /* 20, 5 */ +2.092671085e-04f, -2.683920446e-04f, -9.575231021e-04f, -2.192806382e-04f, +2.213390969e-03f, +2.870794883e-03f, -2.011009640e-03f, -9.850152742e-03f, -1.211787969e-02f, -4.199247312e-03f, +7.590864160e-03f, +1.248704815e-02f, +7.563557889e-03f, -1.244715801e-04f, -3.156409832e-03f, -1.414000676e-03f, +6.879919170e-04f, +8.100393630e-04f, +4.599617124e-05f, -2.183332212e-04f,
- /* 20, 6 */ +2.156662323e-04f, -2.199842607e-04f, -9.380285157e-04f, -3.304411223e-04f, +2.061606212e-03f, +2.973544666e-03f, -1.549465619e-03f, -9.429422833e-03f, -1.227944713e-02f, -4.922491262e-03f, +6.962740532e-03f, +1.250020393e-02f, +8.052490864e-03f, +2.653234199e-04f, -3.143395899e-03f, -1.579476941e-03f, +6.120364145e-04f, +8.485090918e-04f, +8.608374363e-05f, -2.207970734e-04f,
- /* 20, 7 */ +2.196232573e-04f, -1.732933680e-04f, -9.130225739e-04f, -4.331132727e-04f, +1.904509553e-03f, +3.052772891e-03f, -1.103649750e-03f, -8.987927630e-03f, -1.239687839e-02f, -5.625975475e-03f, +6.306939763e-03f, +1.247033951e-02f, +8.528119711e-03f, +6.751263085e-04f, -3.109136222e-03f, -1.743383273e-03f, +5.270395872e-04f, +8.830107920e-04f, +1.285826773e-04f, -2.212818602e-04f,
- /* 20, 8 */ +2.212818602e-04f, -1.285826773e-04f, -8.830107920e-04f, -5.270395872e-04f, +1.743383273e-03f, +3.109136222e-03f, -6.751263085e-04f, -8.528119711e-03f, -1.247033951e-02f, -6.306939763e-03f, +5.625975475e-03f, +1.239687839e-02f, +8.987927630e-03f, +1.103649750e-03f, -3.052772891e-03f, -1.904509553e-03f, +4.331132727e-04f, +9.130225739e-04f, +1.732933680e-04f, -2.196232573e-04f,
- /* 20, 9 */ +2.207970734e-04f, -8.608374363e-05f, -8.485090918e-04f, -6.120364145e-04f, +1.579476941e-03f, +3.143395899e-03f, -2.653234199e-04f, -8.052490864e-03f, -1.250020393e-02f, -6.962740532e-03f, +4.922491262e-03f, +1.227944713e-02f, +9.429422833e-03f, +1.549465619e-03f, -2.973544666e-03f, -2.061606212e-03f, +3.304411223e-04f, +9.380285157e-04f, +2.199842607e-04f, -2.156662323e-04f,
- /* 20,10 */ +2.183332212e-04f, -4.599617124e-05f, -8.100393630e-04f, -6.879919170e-04f, +1.414000676e-03f, +3.156409832e-03f, +1.244715801e-04f, -7.563557889e-03f, -1.248704815e-02f, -7.590864160e-03f, +4.199247312e-03f, +1.211787969e-02f, +9.850152742e-03f, +2.011009640e-03f, -2.870794883e-03f, -2.213390969e-03f, +2.192806382e-04f, +9.575231021e-04f, +2.683920446e-04f, -2.092671085e-04f,
- /* 20,11 */ +2.140618814e-04f, -8.487693398e-06f, -7.681251779e-04f, -7.548636055e-04f, +1.248118895e-03f, +3.149124311e-03f, +4.931158341e-04f, -7.063848473e-03f, -1.243164652e-02f, -8.188939591e-03f, +3.459106327e-03f, +1.191222039e-02f, +1.024771819e-02f, +2.486586970e-03f, -2.743978910e-03f, -2.358556029e-03f, +9.996474913e-05f, +9.710157868e-04f, +3.182221327e-04f, -2.002956356e-04f,
- /* 20,12 */ +2.081598890e-04f, +2.630548656e-05f, -7.232876858e-04f, -8.126754773e-04f, +1.082944596e-03f, +3.122565398e-03f, +8.396136973e-04f, -6.555887236e-03f, -1.233496472e-02f, -8.754750074e-03f, +2.705018824e-03f, +1.166272581e-02f, +1.061978749e-02f, +2.974378699e-03f, -2.592671089e-03f, -2.495775707e-03f, -2.709710175e-05f, +9.780356474e-04f, +3.691494362e-04f, -1.886370492e-04f,
- /* 20,13 */ +2.008073985e-04f, +5.827810709e-05f, -6.760417132e-04f, -8.615147935e-04f, +9.195341683e-04f, +3.077830056e-03f, +1.163118517e-03f, -6.042182027e-03f, -1.219815240e-02f, -9.286243980e-03f, +1.940007910e-03f, +1.136986548e-02f, +1.096411041e-02f, +3.472449249e-03f, -2.416571115e-03f, -2.623714429e-03f, -1.614183836e-04f, +9.781360984e-04f, +4.208194393e-04f, -1.741940978e-04f,
- /* 20,14 */ +1.921860197e-04f, +8.735502929e-05f, -6.268920900e-04f, -9.015285321e-04f, +7.588827792e-04f, +3.016077094e-03f, +1.462933465e-03f, -5.525210549e-03f, -1.202253469e-02f, -9.781544627e-03f, +1.167153605e-03f, +1.103432131e-02f, +1.127853170e-02f, +3.978754642e-03f, -2.215509786e-03f, -2.741035078e-03f, -3.024354413e-04f, +9.708996289e-04f, +4.728495798e-04f, -1.568890194e-04f,
- /* 20,15 */ +1.824770389e-04f, +1.134902041e-04f, -5.763302237e-04f, -9.329195550e-04f, +6.019203323e-04f, +2.938517986e-03f, +1.738511442e-03f, -5.007407400e-03f, -1.180960294e-02f, -1.023895907e-02f, +3.895768346e-04f, +1.065698581e-02f, +1.156100448e-02f, +4.491151594e-03f, -1.989454068e-03f, -2.846407623e-03f, -4.495080153e-04f, +9.559425272e-04f, +5.248309364e-04f, -1.366654441e-04f,
- /* 20, 0 */ +2.228492143e-04f, +8.155042897e-05f, -9.008994790e-04f, -8.358434283e-04f, +2.057950411e-03f, +3.687980724e-03f, -2.439509438e-03f, -1.276984908e-02f, -1.372824692e-02f, -5.233437973e-04f, +1.325794606e-02f, +1.324423486e-02f, +3.079014715e-03f, -3.569583683e-03f, -2.275574997e-03f, +7.329307333e-04f, +9.595727172e-04f, -3.951670647e-05f, -2.357435643e-04f, +0.000000000e+00f,
- /* 20, 1 */ +2.085936177e-04f, +1.192685572e-04f, -8.383784628e-04f, -9.252931617e-04f, +1.836793834e-03f, +3.772148819e-03f, -1.820843931e-03f, -1.225552529e-02f, -1.413563751e-02f, -1.567452511e-03f, +1.272631251e-02f, +1.367510758e-02f, +3.736377939e-03f, -3.415952420e-03f, -2.487640644e-03f, +6.166326985e-04f, +1.013551226e-03f, +6.721135679e-06f, -2.469830254e-04f, +3.513221827e-04f,
- /* 20, 2 */ +1.932641301e-04f, +1.526114972e-04f, -7.728409668e-04f, -1.001322392e-03f, +1.614057279e-03f, +3.823286477e-03f, -1.225775962e-03f, -1.170500117e-02f, -1.447891891e-02f, -2.603840968e-03f, +1.213529571e-02f, +1.405908160e-02f, +4.408408028e-03f, -3.226289363e-03f, -2.692058620e-03f, +4.871526668e-04f, +1.061979909e-03f, +5.699759108e-05f, -2.562708188e-04f, -2.243392330e-05f,
- /* 20, 3 */ +1.771389305e-04f, +1.815689683e-04f, -7.050956564e-04f, -1.064087220e-03f, +1.391605775e-03f, +3.842769943e-03f, -6.568264230e-04f, -1.112214974e-02f, -1.475727496e-02f, -3.627416831e-03f, +1.148720750e-02f, +1.439298630e-02f, +5.091721334e-03f, -3.000017933e-03f, -2.886692602e-03f, +3.448244648e-04f, +1.104003505e-03f, +1.110914327e-04f, -2.633104157e-04f, -3.471505729e-05f,
- /* 20, 4 */ +1.604844080e-04f, +2.061770649e-04f, -6.359221544e-04f, -1.113850250e-03f, +1.171206475e-03f, +3.832136817e-03f, -1.162685315e-04f, -1.051095143e-02f, -1.497027375e-02f, -4.633169088e-03f, +1.078471010e-02f, +1.467389068e-02f, +5.782760145e-03f, -2.736794515e-03f, -3.069373786e-03f, +1.901162062e-04f, +1.138774993e-03f, +1.687245284e-04f, -2.678091338e-04f, -4.805250238e-05f,
- /* 20, 5 */ +1.435528424e-04f, +2.265149998e-04f, -5.660652366e-04f, -1.150972836e-03f, +9.545189950e-04f, +3.793068954e-03f, +3.938808876e-04f, -9.875465824e-03f, -1.511786634e-02f, -5.616199746e-03f, +1.003080152e-02f, +1.489912656e-02f, +6.477812874e-03f, -2.436518983e-03f, -3.237916857e-03f, +2.363306300e-05f, +1.165464351e-03f, +2.295611999e-04f, -2.694819135e-04f, -6.235351094e-05f,
- /* 20, 6 */ +1.265803873e-04f, +2.427015763e-04f, -4.962296614e-04f, -1.175906803e-03f, +7.430870045e-04f, +3.727374795e-03f, +8.718680321e-04f, -9.219803451e-03f, -1.520038286e-02f, -6.571754682e-03f, +9.228798617e-03f, +1.506631023e-02f, +7.173035830e-03f, -2.099343642e-03f, -3.390136682e-03f, -1.538810619e-04f, +1.183267602e-03f, +2.932081598e-04f, -2.680552395e-04f, -7.750368078e-05f,
- /* 20, 7 */ +1.097853637e-04f, +2.548914413e-04f, -4.270756535e-04f, -1.189185758e-03f, +5.383311068e-04f, +3.636971298e-03f, +1.316206650e-03f, -8.548097577e-03f, -1.521852609e-02f, -7.495253444e-03f, +8.382317770e-03f, +1.517336238e-02f, +7.864476409e-03f, -1.725680482e-03f, -3.523865616e-03f, -3.415430197e-04f, +1.191416067e-03f, +3.592150564e-04f, -2.632711715e-04f, -9.336686615e-05f,
- /* 20, 8 */ +9.336686615e-05f, +2.632711715e-04f, -3.592150564e-04f, -1.191416067e-03f, +3.415430197e-04f, +3.523865616e-03f, +1.725680482e-03f, -7.864476409e-03f, -1.517336238e-02f, -8.382317770e-03f, +7.495253444e-03f, +1.521852609e-02f, +8.548097577e-03f, -1.316206650e-03f, -3.636971298e-03f, -5.383311068e-04f, +1.189185758e-03f, +4.270756535e-04f, -2.548914413e-04f, -1.097853637e-04f,
- /* 20, 9 */ +7.750368078e-05f, +2.680552395e-04f, -2.932081598e-04f, -1.183267602e-03f, +1.538810619e-04f, +3.390136682e-03f, +2.099343642e-03f, -7.173035830e-03f, -1.506631023e-02f, -9.228798617e-03f, +6.571754682e-03f, +1.520038286e-02f, +9.219803451e-03f, -8.718680321e-04f, -3.727374795e-03f, -7.430870045e-04f, +1.175906803e-03f, +4.962296614e-04f, -2.427015763e-04f, -1.265803873e-04f,
- /* 20,10 */ +6.235351094e-05f, +2.694819135e-04f, -2.295611999e-04f, -1.165464351e-03f, -2.363306300e-05f, +3.237916857e-03f, +2.436518983e-03f, -6.477812874e-03f, -1.489912656e-02f, -1.003080152e-02f, +5.616199746e-03f, +1.511786634e-02f, +9.875465824e-03f, -3.938808876e-04f, -3.793068954e-03f, -9.545189950e-04f, +1.150972836e-03f, +5.660652366e-04f, -2.265149998e-04f, -1.435528424e-04f,
- /* 20,11 */ +4.805250238e-05f, +2.678091338e-04f, -1.687245284e-04f, -1.138774993e-03f, -1.901162062e-04f, +3.069373786e-03f, +2.736794515e-03f, -5.782760145e-03f, -1.467389068e-02f, -1.078471010e-02f, +4.633169088e-03f, +1.497027375e-02f, +1.051095143e-02f, +1.162685315e-04f, -3.832136817e-03f, -1.171206475e-03f, +1.113850250e-03f, +6.359221544e-04f, -2.061770649e-04f, -1.604844080e-04f,
- /* 20,12 */ +3.471505729e-05f, +2.633104157e-04f, -1.110914327e-04f, -1.104003505e-03f, -3.448244648e-04f, +2.886692602e-03f, +3.000017933e-03f, -5.091721334e-03f, -1.439298630e-02f, -1.148720750e-02f, +3.627416831e-03f, +1.475727496e-02f, +1.112214974e-02f, +6.568264230e-04f, -3.842769943e-03f, -1.391605775e-03f, +1.064087220e-03f, +7.050956564e-04f, -1.815689683e-04f, -1.771389305e-04f,
- /* 20,13 */ +2.243392330e-05f, +2.562708188e-04f, -5.699759108e-05f, -1.061979909e-03f, -4.871526668e-04f, +2.692058620e-03f, +3.226289363e-03f, -4.408408028e-03f, -1.405908160e-02f, -1.213529571e-02f, +2.603840968e-03f, +1.447891891e-02f, +1.170500117e-02f, +1.225775962e-03f, -3.823286477e-03f, -1.614057279e-03f, +1.001322392e-03f, +7.728409668e-04f, -1.526114972e-04f, -1.932641301e-04f,
- /* 20,14 */ -3.513221827e-04f, +2.469830254e-04f, -6.721135679e-06f, -1.013551226e-03f, -6.166326985e-04f, +2.487640644e-03f, +3.415952420e-03f, -3.736377939e-03f, -1.367510758e-02f, -1.272631251e-02f, +1.567452511e-03f, +1.413563751e-02f, +1.225552529e-02f, +1.820843931e-03f, -3.772148819e-03f, -1.836793834e-03f, +9.252931617e-04f, +8.383784628e-04f, -1.192685572e-04f, -2.085936177e-04f,
- /* 20,15 */ +0.000000000e+00f, +2.357435643e-04f, +3.951670647e-05f, -9.595727172e-04f, -7.329307333e-04f, +2.275574997e-03f, +3.569583683e-03f, -3.079014715e-03f, -1.324423486e-02f, -1.325794606e-02f, +5.233437973e-04f, +1.372824692e-02f, +1.276984908e-02f, +2.439509438e-03f, -3.687980724e-03f, -2.057950411e-03f, +8.358434283e-04f, +9.008994790e-04f, -8.155042897e-05f, -2.228492143e-04f,
- /* 20, 0 */ +1.941987182e-05f, +3.146481294e-04f, -2.345645569e-04f, -1.414667200e-03f, +5.144442975e-04f, +4.454307224e-03f, +1.983750799e-04f, -1.327145644e-02f, -1.714303646e-02f, -6.846700315e-04f, +1.665178821e-02f, +1.403392762e-02f, +4.892879248e-04f, -4.540173148e-03f, -7.773192529e-04f, +1.425286503e-03f, +3.160682424e-04f, -3.205185770e-04f, -3.476344875e-05f, +0.000000000e+00f,
- /* 20, 1 */ -3.929324583e-04f, +3.051602666e-04f, -1.573970191e-04f, -1.390281543e-03f, +2.638941923e-04f, +4.333213577e-03f, +8.411158857e-04f, -1.246868983e-02f, -1.754185168e-02f, -2.049974665e-03f, +1.606968443e-02f, +1.474987505e-02f, +1.218921159e-03f, -4.587812221e-03f, -1.050600845e-03f, +1.421006956e-03f, +4.012475422e-04f, -3.223256966e-04f, -5.166761157e-05f, +0.000000000e+00f,
- /* 20, 2 */ +0.000000000e+00f, +2.925136688e-04f, -8.512788201e-05f, -1.353337804e-03f, +2.735561011e-05f, +4.180044295e-03f, +1.436437300e-03f, -1.163198941e-02f, -1.784731333e-02f, -3.403203680e-03f, +1.539895444e-02f, +1.541325656e-02f, +1.987128326e-03f, -4.594412557e-03f, -1.332146559e-03f, +1.400789491e-03f, +4.893452569e-04f, -3.196436833e-04f, -7.000071077e-05f, +0.000000000e+00f,
- /* 20, 3 */ +0.000000000e+00f, +2.771727451e-04f, -1.822077520e-05f, -1.305102482e-03f, -1.937209193e-04f, +3.998069961e-03f, +1.982303068e-03f, -1.076779718e-02f, -1.805915757e-02f, -4.736408619e-03f, +1.464246859e-02f, +1.601826823e-02f, +2.790083541e-03f, -4.557383277e-03f, -1.619599483e-03f, +1.363706016e-03f, +5.795104543e-04f, -3.120743969e-04f, -8.959420873e-05f, +0.000000000e+00f,
- /* 20, 4 */ +0.000000000e+00f, +2.596009711e-04f, +4.295843246e-05f, -1.246883037e-03f, -3.981230344e-04f, +3.790645354e-03f, +2.477139789e-03f, -9.882582946e-03f, -1.817777152e-02f, -6.041793017e-03f, +1.380372215e-02f, +1.655939544e-02f, +3.623550339e-03f, -4.474387395e-03f, -1.910400883e-03f, +1.308956662e-03f, +6.708027600e-04f, -2.992550459e-04f, -1.102423612e-04f, +0.000000000e+00f,
- /* 20, 5 */ +0.000000000e+00f, +2.402546692e-04f, +9.813963752e-05f, -1.180011107e-03f, -5.848760724e-04f, +3.561175652e-03f, +2.919834686e-03f, -8.982792490e-03f, -1.820418220e-02f, -7.311771311e-03f, +1.288681385e-02f, +1.703146227e-02f, +4.482904855e-03f, -4.343373467e-03f, -2.201805423e-03f, +1.235886510e-03f, +7.621980241e-04f, -2.808658988e-04f, -1.317024534e-04f, +0.000000000e+00f,
- /* 20, 6 */ +0.000000000e+00f, +2.195772899e-04f, +1.471454599e-04f, -1.105826337e-03f, -7.532402115e-04f, +3.313083439e-03f, +3.309729355e-03f, -8.074797022e-03f, -1.814004021e-02f, -8.539025902e-03f, +1.189641917e-02f, +1.742967891e-02f, +5.363163073e-03f, -4.162605659e-03f, -2.490898970e-03f, +1.144001586e-03f, +8.525953702e-04f, -2.566379213e-04f, -1.536956226e-04f, +0.000000000e+00f,
- /* 20, 7 */ +0.000000000e+00f, +1.979942392e-04f, +1.898872476e-04f, -1.025661016e-03f, -9.027053553e-04f, +3.049776817e-03f, +3.646609643e-03f, -7.164844319e-03f, -1.798759853e-02f, -9.716561844e-03f, +1.083775871e-02f, +1.774968640e-02f, +6.259011965e-03f, -3.930691879e-03f, -2.774618906e-03f, +1.032983905e-03f, +9.408256132e-04f, -2.263602294e-04f, -1.759082929e-04f, +0.000000000e+00f,
- /* 20, 8 */ +0.000000000e+00f, +1.759082929e-04f, +2.263602294e-04f, -9.408256132e-04f, -1.032983905e-03f, +2.774618906e-03f, +3.930691879e-03f, -6.259011965e-03f, -1.774968640e-02f, -1.083775871e-02f, +9.716561844e-03f, +1.798759853e-02f, +7.164844319e-03f, -3.646609643e-03f, -3.049776817e-03f, +9.027053553e-04f, +1.025661016e-03f, -1.898872476e-04f, -1.979942392e-04f, +0.000000000e+00f,
- /* 20, 9 */ +0.000000000e+00f, +1.536956226e-04f, +2.566379213e-04f, -8.525953702e-04f, -1.144001586e-03f, +2.490898970e-03f, +4.162605659e-03f, -5.363163073e-03f, -1.742967891e-02f, -1.189641917e-02f, +8.539025902e-03f, +1.814004021e-02f, +8.074797022e-03f, -3.309729355e-03f, -3.313083439e-03f, +7.532402115e-04f, +1.105826337e-03f, -1.471454599e-04f, -2.195772899e-04f, +0.000000000e+00f,
- /* 20,10 */ +0.000000000e+00f, +1.317024534e-04f, +2.808658988e-04f, -7.621980241e-04f, -1.235886510e-03f, +2.201805423e-03f, +4.343373467e-03f, -4.482904855e-03f, -1.703146227e-02f, -1.288681385e-02f, +7.311771311e-03f, +1.820418220e-02f, +8.982792490e-03f, -2.919834686e-03f, -3.561175652e-03f, +5.848760724e-04f, +1.180011107e-03f, -9.813963752e-05f, -2.402546692e-04f, +0.000000000e+00f,
- /* 20,11 */ +0.000000000e+00f, +1.102423612e-04f, +2.992550459e-04f, -6.708027600e-04f, -1.308956662e-03f, +1.910400883e-03f, +4.474387395e-03f, -3.623550339e-03f, -1.655939544e-02f, -1.380372215e-02f, +6.041793017e-03f, +1.817777152e-02f, +9.882582946e-03f, -2.477139789e-03f, -3.790645354e-03f, +3.981230344e-04f, +1.246883037e-03f, -4.295843246e-05f, -2.596009711e-04f, +0.000000000e+00f,
- /* 20,12 */ +0.000000000e+00f, +8.959420873e-05f, +3.120743969e-04f, -5.795104543e-04f, -1.363706016e-03f, +1.619599483e-03f, +4.557383277e-03f, -2.790083541e-03f, -1.601826823e-02f, -1.464246859e-02f, +4.736408619e-03f, +1.805915757e-02f, +1.076779718e-02f, -1.982303068e-03f, -3.998069961e-03f, +1.937209193e-04f, +1.305102482e-03f, +1.822077520e-05f, -2.771727451e-04f, +0.000000000e+00f,
- /* 20,13 */ +0.000000000e+00f, +7.000071077e-05f, +3.196436833e-04f, -4.893452569e-04f, -1.400789491e-03f, +1.332146559e-03f, +4.594412557e-03f, -1.987128326e-03f, -1.541325656e-02f, -1.539895444e-02f, +3.403203680e-03f, +1.784731333e-02f, +1.163198941e-02f, -1.436437300e-03f, -4.180044295e-03f, -2.735561011e-05f, +1.353337804e-03f, +8.512788201e-05f, -2.925136688e-04f, +0.000000000e+00f,
- /* 20,14 */ +0.000000000e+00f, +5.166761157e-05f, +3.223256966e-04f, -4.012475422e-04f, -1.421006956e-03f, +1.050600845e-03f, +4.587812221e-03f, -1.218921159e-03f, -1.474987505e-02f, -1.606968443e-02f, +2.049974665e-03f, +1.754185168e-02f, +1.246868983e-02f, -8.411158857e-04f, -4.333213577e-03f, -2.638941923e-04f, +1.390281543e-03f, +1.573970191e-04f, -3.051602666e-04f, +3.929324583e-04f,
- /* 20,15 */ +0.000000000e+00f, +3.476344875e-05f, +3.205185770e-04f, -3.160682424e-04f, -1.425286503e-03f, +7.773192529e-04f, +4.540173148e-03f, -4.892879248e-04f, -1.403392762e-02f, -1.665178821e-02f, +6.846700315e-04f, +1.714303646e-02f, +1.327145644e-02f, -1.983750799e-04f, -4.454307224e-03f, -5.144442975e-04f, +1.414667200e-03f, +2.345645569e-04f, -3.146481294e-04f, -1.941987182e-05f,
- /* 16, 0 */ +3.215659774e-04f, -1.081239301e-03f, -1.047044785e-03f, +4.045780572e-03f, +3.005074105e-03f, -1.291342297e-02f, -2.083886340e-02f, -8.761305366e-04f, +2.037274022e-02f, +1.401097590e-02f, -2.379335663e-03f, -4.351475252e-03f, +8.522542940e-04f, +1.190910327e-03f, -2.874725537e-04f, -1.571395541e-04f,
- /* 16, 1 */ +3.474336395e-04f, -9.673171402e-04f, -1.215210440e-03f, +3.716713245e-03f, +3.558195313e-03f, -1.178473019e-02f, -2.117503726e-02f, -2.622305580e-03f, +1.977768827e-02f, +1.506763496e-02f, -1.682580557e-03f, -4.628640452e-03f, +6.313208395e-04f, +1.294421768e-03f, -2.448738999e-04f, -1.853334990e-04f,
- /* 16, 2 */ +3.654544998e-04f, -8.509694882e-04f, -1.356620316e-03f, +3.369379821e-03f, +4.037840451e-03f, -1.063463040e-02f, -2.138131359e-02f, -4.350277043e-03f, +1.905580462e-02f, +1.607371744e-02f, -9.171630004e-04f, -4.872124601e-03f, +3.850930357e-04f, +1.389803701e-03f, -1.936024914e-04f, -2.137577131e-04f,
- /* 16, 3 */ +3.760939096e-04f, -7.339202470e-04f, -1.471475134e-03f, +3.008783957e-03f, +4.443873126e-03f, -9.472744965e-03f, -2.145880202e-02f, -6.048090342e-03f, +1.821025632e-02f, +1.701970579e-02f, -8.619500088e-05f, -5.076839304e-03f, +1.147982409e-04f, +1.475048300e-03f, -1.336143134e-04f, -2.418805517e-04f,
- /* 16, 4 */ +3.798900997e-04f, -6.177751723e-04f, -1.560284979e-03f, +2.639777229e-03f, +4.776853126e-03f, -8.308496634e-03f, -2.140964525e-02f, -7.704060609e-03f, +1.724526338e-02f, +1.789634168e-02f, +8.064574864e-04f, -5.237819035e-03f, -1.779495980e-04f, +1.548135431e-03f, -6.499930382e-05f, -2.691226085e-04f,
- /* 16, 5 */ +3.774404835e-04f, -5.040080805e-04f, -1.623844377e-03f, +2.267013831e-03f, +5.038003695e-03f, -7.151026424e-03f, -2.123698452e-02f, -9.306876654e-03f, +1.616607109e-02f, +1.869471933e-02f, +1.756186609e-03f, -5.350281937e-03f, -4.911465534e-04f, +1.607060019e-03f, +1.200956190e-05f, -2.948629835e-04f,
- /* 16, 6 */ +3.693879948e-04f, -3.939497146e-04f, -1.663205192e-03f, +1.894909522e-03f, +5.229172900e-03f, -6.009115326e-03f, -2.094491570e-02f, -1.084570103e-02f, +1.497891218e-02f, +1.940637710e-02f, +2.757662946e-03f, -5.409691072e-03f, -8.224000281e-04f, +1.649860923e-03f, +9.702877105e-05f, -3.184467584e-04f,
- /* 16, 7 */ +3.564076658e-04f, -2.887792732e-04f, -1.679647798e-03f, +1.527605146e-03f, +5.352789702e-03f, -4.891111570e-03f, -2.053843663e-02f, -1.231026521e-02f, +1.369095882e-02f, +2.002338639e-02f, +3.804864118e-03f, -5.411815390e-03f, -1.168934972e-03f, +1.674650966e-03f, +1.895185724e-04f, -3.391936346e-04f,
- /* 16, 8 */ +3.391936346e-04f, -1.895185724e-04f, -1.674650966e-03f, +1.168934972e-03f, +5.411815390e-03f, -3.804864118e-03f, -2.002338639e-02f, -1.369095882e-02f, +1.231026521e-02f, +2.053843663e-02f, +4.891111570e-03f, -5.352789702e-03f, -1.527605146e-03f, +1.679647798e-03f, +2.887792732e-04f, -3.564076658e-04f,
- /* 16, 9 */ +3.184467584e-04f, -9.702877105e-05f, -1.649860923e-03f, +8.224000281e-04f, +5.409691072e-03f, -2.757662946e-03f, -1.940637710e-02f, -1.497891218e-02f, +1.084570103e-02f, +2.094491570e-02f, +6.009115326e-03f, -5.229172900e-03f, -1.894909522e-03f, +1.663205192e-03f, +3.939497146e-04f, -3.693879948e-04f,
- /* 16,10 */ +2.948629835e-04f, -1.200956190e-05f, -1.607060019e-03f, +4.911465534e-04f, +5.350281937e-03f, -1.756186609e-03f, -1.869471933e-02f, -1.616607109e-02f, +9.306876654e-03f, +2.123698452e-02f, +7.151026424e-03f, -5.038003695e-03f, -2.267013831e-03f, +1.623844377e-03f, +5.040080805e-04f, -3.774404835e-04f,
- /* 16,11 */ +2.691226085e-04f, +6.499930382e-05f, -1.548135431e-03f, +1.779495980e-04f, +5.237819035e-03f, -8.064574864e-04f, -1.789634168e-02f, -1.724526338e-02f, +7.704060609e-03f, +2.140964525e-02f, +8.308496634e-03f, -4.776853126e-03f, -2.639777229e-03f, +1.560284979e-03f, +6.177751723e-04f, -3.798900997e-04f,
- /* 16,12 */ +2.418805517e-04f, +1.336143134e-04f, -1.475048300e-03f, -1.147982409e-04f, +5.076839304e-03f, +8.619500088e-05f, -1.701970579e-02f, -1.821025632e-02f, +6.048090342e-03f, +2.145880202e-02f, +9.472744965e-03f, -4.443873126e-03f, -3.008783957e-03f, +1.471475134e-03f, +7.339202470e-04f, -3.760939096e-04f,
- /* 16,13 */ +2.137577131e-04f, +1.936024914e-04f, -1.389803701e-03f, -3.850930357e-04f, +4.872124601e-03f, +9.171630004e-04f, -1.607371744e-02f, -1.905580462e-02f, +4.350277043e-03f, +2.138131359e-02f, +1.063463040e-02f, -4.037840451e-03f, -3.369379821e-03f, +1.356620316e-03f, +8.509694882e-04f, -3.654544998e-04f,
- /* 16,14 */ +1.853334990e-04f, +2.448738999e-04f, -1.294421768e-03f, -6.313208395e-04f, +4.628640452e-03f, +1.682580557e-03f, -1.506763496e-02f, -1.977768827e-02f, +2.622305580e-03f, +2.117503726e-02f, +1.178473019e-02f, -3.558195313e-03f, -3.716713245e-03f, +1.215210440e-03f, +9.673171402e-04f, -3.474336395e-04f,
- /* 16,15 */ +1.571395541e-04f, +2.874725537e-04f, -1.190910327e-03f, -8.522542940e-04f, +4.351475252e-03f, +2.379335663e-03f, -1.401097590e-02f, -2.037274022e-02f, +8.761305366e-04f, +2.083886340e-02f, +1.291342297e-02f, -3.005074105e-03f, -4.045780572e-03f, +1.047044785e-03f, +1.081239301e-03f, -3.215659774e-04f,
- /* 16, 0 */ +3.737698842e-04f, -2.640449894e-04f, -1.945694549e-03f, +2.599440145e-03f, +5.499552783e-03f, -1.161604587e-02f, -2.473725459e-02f, -1.100298137e-03f, +2.435797715e-02f, +1.306966182e-02f, -5.062036618e-03f, -3.067638325e-03f, +1.905476637e-03f, +3.919780470e-04f, -3.991665042e-04f, +0.000000000e+00f,
- /* 16, 1 */ +3.444161169e-04f, -1.448617079e-04f, -1.955541719e-03f, +2.132654952e-03f, +5.839402648e-03f, -1.015371093e-02f, -2.494083956e-02f, -3.291998323e-03f, +2.380252288e-02f, +1.450063212e-02f, -4.525267650e-03f, -3.530814272e-03f, +1.832921116e-03f, +5.273022833e-04f, -4.195866486e-04f, +0.000000000e+00f,
- /* 16, 2 */ +3.121018536e-04f, -3.553225965e-05f, -1.937280777e-03f, +1.673279684e-03f, +6.084169165e-03f, -8.696195593e-03f, -2.497087446e-02f, -5.457102987e-03f, +2.307209479e-02f, +1.589478690e-02f, -3.888719495e-03f, -3.982156136e-03f, +1.726408630e-03f, +6.684076945e-04f, -4.340068349e-04f, +0.000000000e+00f,
- /* 16, 3 */ +2.777843660e-04f, +6.309259068e-05f, -1.893417136e-03f, +1.226820211e-03f, +6.237358144e-03f, -7.256513778e-03f, -2.483111182e-02f, -7.578189778e-03f, +2.216959356e-02f, +1.723786448e-02f, -3.152978451e-03f, -4.414545490e-03f, +1.584716951e-03f, +8.134406195e-04f, -4.414195390e-04f, +4.634120047e-04f,
- /* 16, 4 */ +2.423668462e-04f, +1.504100330e-04f, -1.826645633e-03f, +7.982477790e-04f, +6.303316031e-03f, -5.847027899e-03f, -2.452684878e-02f, -9.638294429e-03f, +2.109960841e-02f, +1.851566754e-02f, -2.319783877e-03f, -4.820635148e-03f, +1.407067591e-03f, +9.603162700e-04f, -4.408546251e-04f, -2.338334874e-05f,
- /* 16, 5 */ +2.066858426e-04f, +2.260561294e-04f, -1.739797615e-03f, +3.919648528e-04f, +6.287140435e-03f, -4.479333074e-03f, -2.406484480e-02f, -1.162108621e-02f, +1.986838848e-02f, +1.971422226e-02f, -1.392055451e-03f, -5.192933984e-03f, +1.193168502e-03f, +1.106736135e-03f, -4.314017719e-04f, -4.782938304e-05f,
- /* 16, 6 */ +1.715009195e-04f, +2.898933732e-04f, -1.635789255e-03f, +1.178042715e-05f, +6.194584811e-03f, -3.164153635e-03f, -2.345322399e-02f, -1.351103572e-02f, +1.848379497e-02f, +2.081993840e-02f, -3.739065234e-04f, -5.523897843e-03f, +9.432519997e-04f, +1.250210274e-03f, -4.122335402e-04f, -7.520965874e-05f,
- /* 16, 7 */ +1.374865801e-04f, +3.419953130e-04f, -1.517571800e-03f, -3.391052954e-04f, +6.031958779e-03f, -1.911252903e-03f, -2.270136331e-02f, -1.529357304e-02f, +1.695523429e-02f, +2.181976838e-02f, +7.293570292e-04f, -5.806025538e-03f, +6.581070752e-04f, +1.388084428e-03f, -3.826286881e-04f, -1.052264476e-04f,
- /* 16, 8 */ +1.052264476e-04f, +3.826286881e-04f, -1.388084428e-03f, -6.581070752e-04f, +5.806025538e-03f, -7.293570292e-04f, -2.181976838e-02f, -1.695523429e-02f, +1.529357304e-02f, +2.270136331e-02f, +1.911252903e-03f, -6.031958779e-03f, +3.391052954e-04f, +1.517571800e-03f, -3.419953130e-04f, -1.374865801e-04f,
- /* 16, 9 */ +7.520965874e-05f, +4.122335402e-04f, -1.250210274e-03f, -9.432519997e-04f, +5.523897843e-03f, +3.739065234e-04f, -2.081993840e-02f, -1.848379497e-02f, +1.351103572e-02f, +2.345322399e-02f, +3.164153635e-03f, -6.194584811e-03f, -1.178042715e-05f, +1.635789255e-03f, -2.898933732e-04f, -1.715009195e-04f,
- /* 16,10 */ +4.782938304e-05f, +4.314017719e-04f, -1.106736135e-03f, -1.193168502e-03f, +5.192933984e-03f, +1.392055451e-03f, -1.971422226e-02f, -1.986838848e-02f, +1.162108621e-02f, +2.406484480e-02f, +4.479333074e-03f, -6.287140435e-03f, -3.919648528e-04f, +1.739797615e-03f, -2.260561294e-04f, -2.066858426e-04f,
- /* 16,11 */ +2.338334874e-05f, +4.408546251e-04f, -9.603162700e-04f, -1.407067591e-03f, +4.820635148e-03f, +2.319783877e-03f, -1.851566754e-02f, -2.109960841e-02f, +9.638294429e-03f, +2.452684878e-02f, +5.847027899e-03f, -6.303316031e-03f, -7.982477790e-04f, +1.826645633e-03f, -1.504100330e-04f, -2.423668462e-04f,
- /* 16,12 */ -4.634120047e-04f, +4.414195390e-04f, -8.134406195e-04f, -1.584716951e-03f, +4.414545490e-03f, +3.152978451e-03f, -1.723786448e-02f, -2.216959356e-02f, +7.578189778e-03f, +2.483111182e-02f, +7.256513778e-03f, -6.237358144e-03f, -1.226820211e-03f, +1.893417136e-03f, -6.309259068e-05f, -2.777843660e-04f,
- /* 16,13 */ +0.000000000e+00f, +4.340068349e-04f, -6.684076945e-04f, -1.726408630e-03f, +3.982156136e-03f, +3.888719495e-03f, -1.589478690e-02f, -2.307209479e-02f, +5.457102987e-03f, +2.497087446e-02f, +8.696195593e-03f, -6.084169165e-03f, -1.673279684e-03f, +1.937280777e-03f, +3.553225965e-05f, -3.121018536e-04f,
- /* 16,14 */ +0.000000000e+00f, +4.195866486e-04f, -5.273022833e-04f, -1.832921116e-03f, +3.530814272e-03f, +4.525267650e-03f, -1.450063212e-02f, -2.380252288e-02f, +3.291998323e-03f, +2.494083956e-02f, +1.015371093e-02f, -5.839402648e-03f, -2.132654952e-03f, +1.955541719e-03f, +1.448617079e-04f, -3.444161169e-04f,
- /* 16,15 */ +0.000000000e+00f, +3.991665042e-04f, -3.919780470e-04f, -1.905476637e-03f, +3.067638325e-03f, +5.062036618e-03f, -1.306966182e-02f, -2.435797715e-02f, +1.100298137e-03f, +2.473725459e-02f, +1.161604587e-02f, -5.499552783e-03f, -2.599440145e-03f, +1.945694549e-03f, +2.640449894e-04f, -3.737698842e-04f,
- /* 16, 0 */ +1.129954761e-04f, +3.969443331e-04f, -1.897918409e-03f, +5.803605804e-04f, +7.236474393e-03f, -9.385964725e-03f, -2.874576735e-02f, -1.359743295e-03f, +2.853093461e-02f, +1.118139232e-02f, -7.102956997e-03f, -1.091735034e-03f, +2.023521864e-03f, -3.328791130e-04f, -1.523656204e-04f, +0.000000000e+00f,
- /* 16, 1 */ +7.672972562e-05f, +4.458313625e-04f, -1.753034729e-03f, +1.022461377e-04f, +7.257902118e-03f, -7.620475041e-03f, -2.873131200e-02f, -4.066570788e-03f, +2.808336987e-02f, +1.298853535e-02f, -6.850603202e-03f, -1.630677017e-03f, +2.125649126e-03f, -2.532507071e-04f, -1.941703587e-04f, +0.000000000e+00f,
- /* 16, 2 */ +4.409159553e-05f, +4.801879450e-04f, -1.593056257e-03f, -3.378401438e-04f, +7.175055211e-03f, -5.902082228e-03f, -2.849345261e-02f, -6.735572940e-03f, +2.740215275e-02f, +1.478830973e-02f, -6.473886365e-03f, -2.190599691e-03f, +2.200171639e-03f, -1.579695096e-04f, -2.375950982e-04f, +0.000000000e+00f,
- /* 16, 3 */ -4.855802427e-04f, +5.008892512e-04f, -1.422085430e-03f, -7.360682089e-04f, +6.996656391e-03f, -4.246700138e-03f, -2.804039906e-02f, -9.342037235e-03f, +2.648893755e-02f, +1.656098957e-02f, -5.968640123e-03f, -2.764068406e-03f, +2.243110553e-03f, -4.727037370e-05f, -2.816859426e-04f, +0.000000000e+00f,
- /* 16, 4 */ +0.000000000e+00f, +5.090007623e-04f, -1.244075649e-03f, -1.089544232e-03f, +6.732169339e-03f, -2.668838337e-03f, -2.738254409e-02f, -1.186200034e-02f, +2.534797081e-02f, +1.828644204e-02f, -5.332184360e-03f, -3.342863857e-03f, +2.250722132e-03f, +7.826276448e-05f, -3.253590588e-04f, +0.000000000e+00f,
- /* 16, 5 */ +0.000000000e+00f, +5.057402285e-04f, -1.062772468e-03f, -1.396293958e-03f, +6.391628670e-03f, -1.181467029e-03f, -2.653229393e-02f, -1.427253312e-02f, +2.398607480e-02f, +1.994437434e-02f, -4.563434465e-03f, -3.918061651e-03f, +2.219584858e-03f, +2.176775461e-04f, -3.674140144e-04f, +0.000000000e+00f,
- /* 16, 6 */ +0.000000000e+00f, +4.924395299e-04f, -8.816626027e-04f, -1.655232286e-03f, +5.985469320e-03f, +2.040926394e-04f, -2.550387540e-02f, -1.655201127e-02f, +2.241259678e-02f, +2.151458926e-02f, -3.662991573e-03f, -4.480127768e-03f, +2.146686747e-03f, +3.696399185e-04f, -4.065510896e-04f, +0.000000000e+00f,
- /* 16, 7 */ +0.000000000e+00f, +4.705072223e-04f, -7.039312026e-04f, -1.866120323e-03f, +5.524357980e-03f, +1.478252020e-03f, -2.431312252e-02f, -1.868036788e-02f, +2.063932435e-02f, +2.297724601e-02f, -2.633211707e-03f, -5.019029099e-03f, +2.029511283e-03f, +5.324276437e-04f, -4.413924818e-04f, +0.000000000e+00f,
- /* 16, 8 */ +0.000000000e+00f, +4.413924818e-04f, -5.324276437e-04f, -2.029511283e-03f, +5.019029099e-03f, +2.633211707e-03f, -2.297724601e-02f, -2.063932435e-02f, +1.868036788e-02f, +2.431312252e-02f, -1.478252020e-03f, -5.524357980e-03f, +1.866120323e-03f, +7.039312026e-04f, -4.705072223e-04f, +0.000000000e+00f,
- /* 16, 9 */ +0.000000000e+00f, +4.065510896e-04f, -3.696399185e-04f, -2.146686747e-03f, +4.480127768e-03f, +3.662991573e-03f, -2.151458926e-02f, -2.241259678e-02f, +1.655201127e-02f, +2.550387540e-02f, -2.040926394e-04f, -5.985469320e-03f, +1.655232286e-03f, +8.816626027e-04f, -4.924395299e-04f, +0.000000000e+00f,
- /* 16,10 */ +0.000000000e+00f, +3.674140144e-04f, -2.176775461e-04f, -2.219584858e-03f, +3.918061651e-03f, +4.563434465e-03f, -1.994437434e-02f, -2.398607480e-02f, +1.427253312e-02f, +2.653229393e-02f, +1.181467029e-03f, -6.391628670e-03f, +1.396293958e-03f, +1.062772468e-03f, -5.057402285e-04f, +0.000000000e+00f,
- /* 16,11 */ +0.000000000e+00f, +3.253590588e-04f, -7.826276448e-05f, -2.250722132e-03f, +3.342863857e-03f, +5.332184360e-03f, -1.828644204e-02f, -2.534797081e-02f, +1.186200034e-02f, +2.738254409e-02f, +2.668838337e-03f, -6.732169339e-03f, +1.089544232e-03f, +1.244075649e-03f, -5.090007623e-04f, +0.000000000e+00f,
- /* 16,12 */ +0.000000000e+00f, +2.816859426e-04f, +4.727037370e-05f, -2.243110553e-03f, +2.764068406e-03f, +5.968640123e-03f, -1.656098957e-02f, -2.648893755e-02f, +9.342037235e-03f, +2.804039906e-02f, +4.246700138e-03f, -6.996656391e-03f, +7.360682089e-04f, +1.422085430e-03f, -5.008892512e-04f, +4.855802427e-04f,
- /* 16,13 */ +0.000000000e+00f, +2.375950982e-04f, +1.579695096e-04f, -2.200171639e-03f, +2.190599691e-03f, +6.473886365e-03f, -1.478830973e-02f, -2.740215275e-02f, +6.735572940e-03f, +2.849345261e-02f, +5.902082228e-03f, -7.175055211e-03f, +3.378401438e-04f, +1.593056257e-03f, -4.801879450e-04f, -4.409159553e-05f,
- /* 16,14 */ +0.000000000e+00f, +1.941703587e-04f, +2.532507071e-04f, -2.125649126e-03f, +1.630677017e-03f, +6.850603202e-03f, -1.298853535e-02f, -2.808336987e-02f, +4.066570788e-03f, +2.873131200e-02f, +7.620475041e-03f, -7.257902118e-03f, -1.022461377e-04f, +1.753034729e-03f, -4.458313625e-04f, -7.672972562e-05f,
- /* 16,15 */ +0.000000000e+00f, +1.523656204e-04f, +3.328791130e-04f, -2.023521864e-03f, +1.091735034e-03f, +7.102956997e-03f, -1.118139232e-02f, -2.853093461e-02f, +1.359743295e-03f, +2.874576735e-02f, +9.385964725e-03f, -7.236474393e-03f, -5.803605804e-04f, +1.897918409e-03f, -3.969443331e-04f, -1.129954761e-04f,
- /* 12, 0 */ -1.111572639e-03f, -1.388266820e-03f, +7.900037037e-03f, -6.320860170e-03f, -3.276049121e-02f, -1.657033928e-03f, +3.280306521e-02f, +8.402419704e-03f, -8.147060845e-03f, +9.779320530e-04f, +1.332890330e-03f, -5.705687800e-04f,
- /* 12, 1 */ -8.925738220e-04f, -1.737094155e-03f, +7.544883174e-03f, -4.325531156e-03f, -3.242830266e-02f, -4.953502968e-03f, +3.254754550e-02f, +1.054842384e-02f, -8.272560314e-03f, +5.083818205e-04f, +1.551863117e-03f, -5.805594968e-04f,
- /* 12, 2 */ -6.800837112e-04f, -2.023419107e-03f, +7.095763901e-03f, -2.436087367e-03f, -3.181840805e-02f, -8.197416535e-03f, +3.198906769e-02f, +1.273520115e-02f, -8.264181830e-03f, -1.673924732e-05f, +1.763414955e-03f, -5.764989135e-04f,
- /* 12, 3 */ -4.777710304e-04f, -2.247467778e-03f, +6.567344318e-03f, -6.698479312e-04f, -3.094591156e-02f, -1.135453705e-02f, +3.112651563e-02f, +1.493747887e-02f, -8.110878239e-03f, -5.924008684e-04f, +1.962133432e-03f, -5.566237283e-04f,
- /* 12, 4 */ -2.887507612e-04f, -2.410593616e-03f, +5.974525144e-03f, +9.583644900e-04f, -2.982883555e-02f, -1.439181272e-02f, +2.996260004e-02f, +1.712870168e-02f, -7.803165138e-03f, -1.212178752e-03f, +2.142359210e-03f, -5.193755958e-04f,
- /* 12, 5 */ -1.155657138e-04f, -2.515168800e-03f, +5.332187403e-03f, +2.436339775e-03f, -2.848780461e-02f, -1.727782533e-02f, +2.850388027e-02f, +1.928138098e-02f, -7.333362623e-03f, -1.868272468e-03f, +2.298288008e-03f, -4.634616378e-04f,
- /* 12, 6 */ +3.981829456e-05f, -2.564463655e-03f, +4.654950666e-03f, +3.754551105e-03f, -2.694569661e-02f, -1.998321224e-02f, +2.676072816e-02f, +2.136746929e-02f, -6.695817566e-03f, -2.551550686e-03f, +2.424083786e-03f, -3.879138191e-04f,
- /* 12, 7 */ +1.760045094e-04f, -2.562517141e-03f, +3.956948521e-03f, +4.906180706e-03f, -2.522726725e-02f, -2.248105576e-02f, +2.474723407e-02f, +2.335875442e-02f, -5.887101657e-03f, -3.251624436e-03f, +2.514001460e-03f, -2.921456350e-04f,
- /* 12, 8 */ +2.921456350e-04f, -2.514001460e-03f, +3.251624436e-03f, +5.887101657e-03f, -2.335875442e-02f, -2.474723407e-02f, +2.248105576e-02f, +2.522726725e-02f, -4.906180706e-03f, -3.956948521e-03f, +2.562517141e-03f, -1.760045094e-04f,
- /* 12, 9 */ +3.879138191e-04f, -2.424083786e-03f, +2.551550686e-03f, +6.695817566e-03f, -2.136746929e-02f, -2.676072816e-02f, +1.998321224e-02f, +2.694569661e-02f, -3.754551105e-03f, -4.654950666e-03f, +2.564463655e-03f, -3.981829456e-05f,
- /* 12,10 */ +4.634616378e-04f, -2.298288008e-03f, +1.868272468e-03f, +7.333362623e-03f, -1.928138098e-02f, -2.850388027e-02f, +1.727782533e-02f, +2.848780461e-02f, -2.436339775e-03f, -5.332187403e-03f, +2.515168800e-03f, +1.155657138e-04f,
- /* 12,11 */ +5.193755958e-04f, -2.142359210e-03f, +1.212178752e-03f, +7.803165138e-03f, -1.712870168e-02f, -2.996260004e-02f, +1.439181272e-02f, +2.982883555e-02f, -9.583644900e-04f, -5.974525144e-03f, +2.410593616e-03f, +2.887507612e-04f,
- /* 12,12 */ +5.566237283e-04f, -1.962133432e-03f, +5.924008684e-04f, +8.110878239e-03f, -1.493747887e-02f, -3.112651563e-02f, +1.135453705e-02f, +3.094591156e-02f, +6.698479312e-04f, -6.567344318e-03f, +2.247467778e-03f, +4.777710304e-04f,
- /* 12,13 */ +5.764989135e-04f, -1.763414955e-03f, +1.673924732e-05f, +8.264181830e-03f, -1.273520115e-02f, -3.198906769e-02f, +8.197416535e-03f, +3.181840805e-02f, +2.436087367e-03f, -7.095763901e-03f, +2.023419107e-03f, +6.800837112e-04f,
- /* 12,14 */ +5.805594968e-04f, -1.551863117e-03f, -5.083818205e-04f, +8.272560314e-03f, -1.054842384e-02f, -3.254754550e-02f, +4.953502968e-03f, +3.242830266e-02f, +4.325531156e-03f, -7.544883174e-03f, +1.737094155e-03f, +8.925738220e-04f,
- /* 12,15 */ +5.705687800e-04f, -1.332890330e-03f, -9.779320530e-04f, +8.147060845e-03f, -8.402419704e-03f, -3.280306521e-02f, +1.657033928e-03f, +3.276049121e-02f, +6.320860170e-03f, -7.900037037e-03f, +1.388266820e-03f, +1.111572639e-03f,
- /* 12, 0 */ -1.054803383e-04f, -2.744858958e-03f, +7.370914553e-03f, -2.604494739e-03f, -3.666896703e-02f, -1.994735221e-03f, +3.707596726e-02f, +4.873177855e-03f, -8.012348726e-03f, +2.554514858e-03f, +3.117958677e-04f, -3.625540242e-04f,
- /* 12, 1 */ +7.775923585e-05f, -2.860662969e-03f, +6.648820026e-03f, -4.950753709e-04f, -3.590728113e-02f, -5.960234251e-03f, +3.711196787e-02f, +7.277671607e-03f, -8.552819277e-03f, +2.286292242e-03f, +5.385913036e-04f, -4.265219564e-04f,
- /* 12, 2 */ +2.361482435e-04f, -2.906545541e-03f, +5.866306097e-03f, +1.435258618e-03f, -3.481183398e-02f, -9.854190425e-03f, +3.676562700e-02f, +9.791136525e-03f, -8.972352970e-03f, +1.938320040e-03f, +7.824350015e-04f, -4.875429386e-04f,
- /* 12, 3 */ +3.687004846e-04f, -2.888204359e-03f, +5.043181884e-03f, +3.170488652e-03f, -3.340772759e-02f, -1.363013975e-02f, +3.603085731e-02f, +1.238366322e-02f, -9.251714734e-03f, +1.510362297e-03f, +1.039066351e-03f, -5.431259501e-04f,
- /* 12, 4 */ +4.751685216e-04f, -2.812206203e-03f, +4.198484259e-03f, +4.698496481e-03f, -3.172374637e-02f, -1.724344185e-02f, +3.490702283e-02f, +1.502265637e-02f, -9.372823891e-03f, +1.003961424e-03f, +1.303424694e-03f, -5.906251216e-04f,
- /* 12, 5 */ +5.559799195e-04f, -2.685773447e-03f, +3.350171906e-03f, +6.011087921e-03f, -2.979181001e-02f, -2.065196332e-02f, +3.339904530e-02f, +1.767328103e-02f, -9.319170237e-03f, +4.225520445e-04f, +1.569701578e-03f, -6.273034189e-04f,
- /* 12, 6 */ +6.121620582e-04f, -2.516571985e-03f, +2.514858275e-03f, +7.103945228e-03f, -2.764638515e-02f, -2.381671619e-02f, +3.151741694e-02f, +2.029896461e-02f, -9.076221424e-03f, -2.284590483e-04f, +1.831416829e-03f, -6.504054889e-04f,
- /* 12, 7 */ +6.452583046e-04f, -2.312505227e-03f, +1.707586806e-03f, +7.976511649e-03f, -2.532386758e-02f, -2.670244010e-02f, +2.927811806e-02f, +2.286194672e-02f, -8.631812899e-03f, -9.416507761e-04f, +2.081518390e-03f, -6.572383529e-04f,
- /* 12, 8 */ +6.572383529e-04f, -2.081518390e-03f, +9.416507761e-04f, +8.631812899e-03f, -2.286194672e-02f, -2.927811806e-02f, +2.670244010e-02f, +2.532386758e-02f, -7.976511649e-03f, -1.707586806e-03f, +2.312505227e-03f, -6.452583046e-04f,
- /* 12, 9 */ +6.504054889e-04f, -1.831416829e-03f, +2.284590483e-04f, +9.076221424e-03f, -2.029896461e-02f, -3.151741694e-02f, +2.381671619e-02f, +2.764638515e-02f, -7.103945228e-03f, -2.514858275e-03f, +2.516571985e-03f, -6.121620582e-04f,
- /* 12,10 */ +6.273034189e-04f, -1.569701578e-03f, -4.225520445e-04f, +9.319170237e-03f, -1.767328103e-02f, -3.339904530e-02f, +2.065196332e-02f, +2.979181001e-02f, -6.011087921e-03f, -3.350171906e-03f, +2.685773447e-03f, -5.559799195e-04f,
- /* 12,11 */ +5.906251216e-04f, -1.303424694e-03f, -1.003961424e-03f, +9.372823891e-03f, -1.502265637e-02f, -3.490702283e-02f, +1.724344185e-02f, +3.172374637e-02f, -4.698496481e-03f, -4.198484259e-03f, +2.812206203e-03f, -4.751685216e-04f,
- /* 12,12 */ +5.431259501e-04f, -1.039066351e-03f, -1.510362297e-03f, +9.251714734e-03f, -1.238366322e-02f, -3.603085731e-02f, +1.363013975e-02f, +3.340772759e-02f, -3.170488652e-03f, -5.043181884e-03f, +2.888204359e-03f, -3.687004846e-04f,
- /* 12,13 */ +4.875429386e-04f, -7.824350015e-04f, -1.938320040e-03f, +8.972352970e-03f, -9.791136525e-03f, -3.676562700e-02f, +9.854190425e-03f, +3.481183398e-02f, -1.435258618e-03f, -5.866306097e-03f, +2.906545541e-03f, -2.361482435e-04f,
- /* 12,14 */ +4.265219564e-04f, -5.385913036e-04f, -2.286292242e-03f, +8.552819277e-03f, -7.277671607e-03f, -3.711196787e-02f, +5.960234251e-03f, +3.590728113e-02f, +4.950753709e-04f, -6.648820026e-03f, +2.860662969e-03f, -7.775923585e-05f,
- /* 12,15 */ +3.625540242e-04f, -3.117958677e-04f, -2.554514858e-03f, +8.012348726e-03f, -4.873177855e-03f, -3.707596726e-02f, +1.994735221e-03f, +3.666896703e-02f, +2.604494739e-03f, -7.370914553e-03f, +2.744858958e-03f, +1.054803383e-04f,
- /* 12, 0 */ +6.110448771e-04f, -3.173989705e-03f, +5.751223243e-03f, +1.507555794e-03f, -4.035343888e-02f, -2.375409442e-03f, +4.124383193e-02f, +8.091337269e-04f, -6.726716888e-03f, +3.253952459e-03f, -5.087325269e-04f, -4.127854608e-05f,
- /* 12, 1 */ +6.820041984e-04f, -3.029137857e-03f, +4.746351538e-03f, +3.578915017e-03f, -3.904147991e-02f, -7.094160720e-03f, +4.168490752e-02f, +3.349306133e-03f, -7.647219355e-03f, +3.259488816e-03f, -3.738470149e-04f, -9.536054020e-05f,
- /* 12, 2 */ +7.235832870e-04f, -2.829602454e-03f, +3.736224000e-03f, +5.388621830e-03f, -3.734163661e-02f, -1.171726725e-02f, +4.165549067e-02f, +6.085743956e-03f, -8.486093037e-03f, +3.182049180e-03f, -2.060445111e-04f, -1.573545891e-04f,
- /* 12, 3 */ +7.383739029e-04f, -2.585946508e-03f, +2.743066911e-03f, +6.925917423e-03f, -3.529277498e-02f, -1.618281485e-02f, +4.114151479e-02f, +8.986133221e-03f, -9.216195947e-03f, +3.014391908e-03f, -5.966328360e-06f, -2.260166200e-04f,
- /* 12, 4 */ +7.294476853e-04f, -2.308795686e-03f, +1.786872733e-03f, +8.185530694e-03f, -3.293811768e-02f, -2.043162352e-02f, +4.013642610e-02f, +1.201345370e-02f, -9.810446156e-03f, +2.750895834e-03f, +2.246717082e-04f, -2.996559917e-04f,
- /* 12, 5 */ +7.002161546e-04f, -2.008565767e-03f, +8.851333656e-04f, +9.167495079e-03f, -3.032435275e-02f, -2.440826356e-02f, +3.864144993e-02f, +1.512648157e-02f, -1.024241966e-02f, +2.387856219e-03f, +4.830138128e-04f, -3.761418846e-04f,
- /* 12, 6 */ +6.542939604e-04f, -1.695217727e-03f, +5.264660367e-05f, +9.876866054e-03f, -2.750069849e-02f, -2.806199617e-02f, +3.666571148e-02f, +1.828039745e-02f, -1.048696943e-02f, +1.923755148e-03f, +7.650267923e-04f, -4.529261561e-04f,
- /* 12, 7 */ +5.953691186e-04f, -1.378044726e-03f, -6.986040124e-04f, +1.032334944e-02f, -2.451794467e-02f, -3.134761990e-02f, +3.422620641e-02f, +2.142749023e-02f, -1.052085229e-02f, +1.359497506e-03f, +1.065494162e-03f, -5.270834853e-04f,
- /* 12, 8 */ +5.270834853e-04f, -1.065494162e-03f, -1.359497506e-03f, +1.052085229e-02f, -2.142749023e-02f, -3.422620641e-02f, +3.134761990e-02f, +2.451794467e-02f, -1.032334944e-02f, +6.986040124e-04f, +1.378044726e-03f, -5.953691186e-04f,
- /* 12, 9 */ +4.529261561e-04f, -7.650267923e-04f, -1.923755148e-03f, +1.048696943e-02f, -1.828039745e-02f, -3.666571148e-02f, +2.806199617e-02f, +2.750069849e-02f, -9.876866054e-03f, -5.264660367e-05f, +1.695217727e-03f, -6.542939604e-04f,
- /* 12,10 */ +3.761418846e-04f, -4.830138128e-04f, -2.387856219e-03f, +1.024241966e-02f, -1.512648157e-02f, -3.864144993e-02f, +2.440826356e-02f, +3.032435275e-02f, -9.167495079e-03f, -8.851333656e-04f, +2.008565767e-03f, -7.002161546e-04f,
- /* 12,11 */ +2.996559917e-04f, -2.246717082e-04f, -2.750895834e-03f, +9.810446156e-03f, -1.201345370e-02f, -4.013642610e-02f, +2.043162352e-02f, +3.293811768e-02f, -8.185530694e-03f, -1.786872733e-03f, +2.308795686e-03f, -7.294476853e-04f,
- /* 12,12 */ +2.260166200e-04f, +5.966328360e-06f, -3.014391908e-03f, +9.216195947e-03f, -8.986133221e-03f, -4.114151479e-02f, +1.618281485e-02f, +3.529277498e-02f, -6.925917423e-03f, -2.743066911e-03f, +2.585946508e-03f, -7.383739029e-04f,
- /* 12,13 */ +1.573545891e-04f, +2.060445111e-04f, -3.182049180e-03f, +8.486093037e-03f, -6.085743956e-03f, -4.165549067e-02f, +1.171726725e-02f, +3.734163661e-02f, -5.388621830e-03f, -3.736224000e-03f, +2.829602454e-03f, -7.235832870e-04f,
- /* 12,14 */ +9.536054020e-05f, +3.738470149e-04f, -3.259488816e-03f, +7.647219355e-03f, -3.349306133e-03f, -4.168490752e-02f, +7.094160720e-03f, +3.904147991e-02f, -3.578915017e-03f, -4.746351538e-03f, +3.029137857e-03f, -6.820041984e-04f,
- /* 12,15 */ +4.127854608e-05f, +5.087325269e-04f, -3.253952459e-03f, +6.726716888e-03f, -8.091337269e-04f, -4.124383193e-02f, +2.375409442e-03f, +4.035343888e-02f, -1.507555794e-03f, -5.751223243e-03f, +3.173989705e-03f, -6.110448771e-04f,
-
- /* 24, 0 */ -8.820438069e-05f, -1.519461079e-04f, -2.301651496e-04f, -3.149320871e-04f, -3.945939739e-04f, -4.554410135e-04f, -4.841532882e-04f, -4.705408991e-04f, -4.099602091e-04f, -3.048100066e-04f, -1.646897470e-04f, -5.099007530e-06f, +1.551006323e-04f, +2.969416536e-04f, +4.046294158e-04f, +4.681429482e-04f, +4.846228261e-04f, +4.583040637e-04f, +3.990939388e-04f, +3.201968846e-04f, +2.353759082e-04f, +1.564712483e-04f, +9.167483068e-05f, +4.482688286e-05f,
- /* 24, 1 */ -8.480575132e-05f, -1.474789784e-04f, -2.249812225e-04f, -3.096480504e-04f, -3.900204007e-04f, -4.524514078e-04f, -4.835165803e-04f, -4.727530367e-04f, -4.151145025e-04f, -3.125397891e-04f, -1.742016828e-04f, -1.529460870e-05f, +1.454387449e-04f, +2.889379628e-04f, +3.991236794e-04f, +4.655589110e-04f, +4.849233000e-04f, +4.610375470e-04f, +4.035168325e-04f, +3.254391996e-04f, +2.406110065e-04f, +1.610529558e-04f, +9.521673594e-05f, +4.721513201e-05f,
- /* 24, 2 */ -8.147924507e-05f, -1.430712350e-04f, -2.198265592e-04f, -3.043479843e-04f, -3.853766873e-04f, -4.493383067e-04f, -4.827146831e-04f, -4.747797448e-04f, -4.200908527e-04f, -3.201278616e-04f, -1.836320864e-04f, -2.548296987e-05f, +1.357085413e-04f, +2.808022583e-04f, +3.934446700e-04f, +4.627886263e-04f, +4.850529052e-04f, +4.636385032e-04f, +4.078592000e-04f, +3.306557574e-04f, +2.458678944e-04f, +1.656897170e-04f, +9.882966748e-05f, +4.967415993e-05f,
- /* 24, 3 */ -7.822510242e-05f, -1.387241832e-04f, -2.147035314e-04f, -2.990350629e-04f, -3.806663042e-04f, -4.461048161e-04f, -4.817496625e-04f, -4.766215175e-04f, -4.248879309e-04f, -3.275711800e-04f, -1.929766610e-04f, -3.565926997e-05f, +1.259145254e-04f, +2.725379532e-04f, +3.875941701e-04f, +4.598320457e-04f, +4.850099279e-04f, +4.661040260e-04f, +4.121175966e-04f, +3.358432542e-04f, +2.511439643e-04f, +1.703799499e-04f, +1.025131319e-04f, +5.220438912e-05f,
- /* 24, 4 */ -7.504350274e-05f, -1.344390595e-04f, -2.096144489e-04f, -2.937124231e-04f, -3.758927218e-04f, -4.427540852e-04f, -4.806236671e-04f, -4.782789577e-04f, -4.295045226e-04f, -3.348667971e-04f, -2.022311686e-04f, -4.581869630e-05f, +1.160612449e-04f, +2.641485480e-04f, +3.815740737e-04f, +4.566892339e-04f, +4.847927474e-04f, +4.684312656e-04f, +4.162885910e-04f, +3.409983591e-04f, +2.564365532e-04f, +1.751220037e-04f, +1.062665706e-04f, +5.480619333e-05f,
- /* 24, 5 */ -7.193456522e-05f, -1.302170312e-04f, -2.045615590e-04f, -2.883831622e-04f, -3.710594077e-04f, -4.392893036e-04f, -4.793389263e-04f, -4.797527765e-04f, -4.339395286e-04f, -3.420118645e-04f, -2.113914331e-04f, -5.595644787e-05f, +1.061532886e-04f, +2.556376279e-04f, +3.753863858e-04f, +4.533603695e-04f, +4.843998374e-04f, +4.706174312e-04f, +4.203687678e-04f, +3.461177167e-04f, +2.617429433e-04f, +1.799141593e-04f, +1.100893595e-04f, +5.747989630e-05f,
- /* 24, 6 */ -6.889834987e-05f, -1.260591965e-04f, -1.995470454e-04f, -2.830503358e-04f, -3.661698243e-04f, -4.357136989e-04f, -4.778977479e-04f, -4.810437916e-04f, -4.381919648e-04f, -3.490036345e-04f, -2.204533432e-04f, -6.606773875e-05f, +9.619528314e-05f, +2.470088608e-04f, +3.690332209e-04f, +4.498457452e-04f, +4.838297683e-04f, +4.726597937e-04f, +4.243547301e-04f, +3.511979487e-04f, +2.670603639e-04f, +1.847546294e-04f, +1.139808078e-04f, +6.022577049e-05f,
- /* 24, 7 */ -6.593485851e-05f, -1.219665852e-04f, -1.945730275e-04f, -2.777169567e-04f, -3.612274261e-04f, -4.320305335e-04f, -4.763025159e-04f, -4.821529264e-04f, -4.422609626e-04f, -3.558394612e-04f, -2.294128549e-04f, -7.614780136e-05f, +8.619188981e-05f, +2.382659945e-04f, +3.625168024e-04f, +4.461457687e-04f, +4.830812085e-04f, +4.745556880e-04f, +4.282431024e-04f, +3.562356572e-04f, +2.723859925e-04f, +1.896415594e-04f, +1.179401580e-04f, +6.304403582e-05f,
- /* 24, 8 */ -6.304403582e-05f, -1.179401580e-04f, -1.896415594e-04f, -2.723859925e-04f, -3.562356572e-04f, -4.282431024e-04f, -4.745556880e-04f, -4.830812085e-04f, -4.461457687e-04f, -3.625168024e-04f, -2.382659945e-04f, -8.619188981e-05f, +7.614780136e-05f, +2.294128549e-04f, +3.558394612e-04f, +4.422609626e-04f, +4.821529264e-04f, +4.763025159e-04f, +4.320305335e-04f, +3.612274261e-04f, +2.777169567e-04f, +1.945730275e-04f, +1.219665852e-04f, +6.593485851e-05f,
- /* 24, 9 */ -6.022577049e-05f, -1.139808078e-04f, -1.847546294e-04f, -2.670603639e-04f, -3.511979487e-04f, -4.243547301e-04f, -4.726597937e-04f, -4.838297683e-04f, -4.498457452e-04f, -3.690332209e-04f, -2.470088608e-04f, -9.619528314e-05f, +6.606773875e-05f, +2.204533432e-04f, +3.490036345e-04f, +4.381919648e-04f, +4.810437916e-04f, +4.778977479e-04f, +4.357136989e-04f, +3.661698243e-04f, +2.830503358e-04f, +1.995470454e-04f, +1.260591965e-04f, +6.889834987e-05f,
- /* 24,10 */ -5.747989630e-05f, -1.100893595e-04f, -1.799141593e-04f, -2.617429433e-04f, -3.461177167e-04f, -4.203687678e-04f, -4.706174312e-04f, -4.843998374e-04f, -4.533603695e-04f, -3.753863858e-04f, -2.556376279e-04f, -1.061532886e-04f, +5.595644787e-05f, +2.113914331e-04f, +3.420118645e-04f, +4.339395286e-04f, +4.797527765e-04f, +4.793389263e-04f, +4.392893036e-04f, +3.710594077e-04f, +2.883831622e-04f, +2.045615590e-04f, +1.302170312e-04f, +7.193456522e-05f,
- /* 24,11 */ -5.480619333e-05f, -1.062665706e-04f, -1.751220037e-04f, -2.564365532e-04f, -3.409983591e-04f, -4.162885910e-04f, -4.684312656e-04f, -4.847927474e-04f, -4.566892339e-04f, -3.815740737e-04f, -2.641485480e-04f, -1.160612449e-04f, +4.581869630e-05f, +2.022311686e-04f, +3.348667971e-04f, +4.295045226e-04f, +4.782789577e-04f, +4.806236671e-04f, +4.427540852e-04f, +3.758927218e-04f, +2.937124231e-04f, +2.096144489e-04f, +1.344390595e-04f, +7.504350274e-05f,
- /* 24,12 */ -5.220438912e-05f, -1.025131319e-04f, -1.703799499e-04f, -2.511439643e-04f, -3.358432542e-04f, -4.121175966e-04f, -4.661040260e-04f, -4.850099279e-04f, -4.598320457e-04f, -3.875941701e-04f, -2.725379532e-04f, -1.259145254e-04f, +3.565926997e-05f, +1.929766610e-04f, +3.275711800e-04f, +4.248879309e-04f, +4.766215175e-04f, +4.817496625e-04f, +4.461048161e-04f, +3.806663042e-04f, +2.990350629e-04f, +2.147035314e-04f, +1.387241832e-04f, +7.822510242e-05f,
- /* 24,13 */ -4.967415993e-05f, -9.882966748e-05f, -1.656897170e-04f, -2.458678944e-04f, -3.306557574e-04f, -4.078592000e-04f, -4.636385032e-04f, -4.850529052e-04f, -4.627886263e-04f, -3.934446700e-04f, -2.808022583e-04f, -1.357085413e-04f, +2.548296987e-05f, +1.836320864e-04f, +3.201278616e-04f, +4.200908527e-04f, +4.747797448e-04f, +4.827146831e-04f, +4.493383067e-04f, +3.853766873e-04f, +3.043479843e-04f, +2.198265592e-04f, +1.430712350e-04f, +8.147924507e-05f,
- /* 24,14 */ -4.721513201e-05f, -9.521673594e-05f, -1.610529558e-04f, -2.406110065e-04f, -3.254391996e-04f, -4.035168325e-04f, -4.610375470e-04f, -4.849233000e-04f, -4.655589110e-04f, -3.991236794e-04f, -2.889379628e-04f, -1.454387449e-04f, +1.529460870e-05f, +1.742016828e-04f, +3.125397891e-04f, +4.151145025e-04f, +4.727530367e-04f, +4.835165803e-04f, +4.524514078e-04f, +3.900204007e-04f, +3.096480504e-04f, +2.249812225e-04f, +1.474789784e-04f, +8.480575132e-05f,
- /* 24,15 */ -4.482688286e-05f, -9.167483068e-05f, -1.564712483e-04f, -2.353759082e-04f, -3.201968846e-04f, -3.990939388e-04f, -4.583040637e-04f, -4.846228261e-04f, -4.681429482e-04f, -4.046294158e-04f, -2.969416536e-04f, -1.551006323e-04f, +5.099007530e-06f, +1.646897470e-04f, +3.048100066e-04f, +4.099602091e-04f, +4.705408991e-04f, +4.841532882e-04f, +4.554410135e-04f, +3.945939739e-04f, +3.149320871e-04f, +2.301651496e-04f, +1.519461079e-04f, +8.820438069e-05f,
- /* 24, 0 */ +1.254177052e-04f, +1.432187562e-04f, +1.041598752e-04f, -1.135750248e-05f, -2.010663923e-04f, -4.345091125e-04f, -6.566280172e-04f, -8.018070806e-04f, -8.145094672e-04f, -6.693628869e-04f, -3.829411831e-04f, -1.208738944e-05f, +3.614691013e-04f, +6.551938988e-04f, +8.101126455e-04f, +8.069330100e-04f, +6.686285441e-04f, +4.493898115e-04f, +2.148422063e-04f, +2.121126661e-05f, -9.928779545e-05f, -1.427235715e-04f, -1.276505127e-04f, -8.319130160e-05f,
- /* 24, 1 */ +1.230784715e-04f, +1.434886692e-04f, +1.087259386e-04f, -1.803144714e-06f, -1.874698746e-04f, -4.195879132e-04f, -6.443236569e-04f, -7.961535056e-04f, -8.182754723e-04f, -6.829663304e-04f, -4.040749814e-04f, -3.625133679e-05f, +3.396771574e-04f, +6.404692089e-04f, +8.050839212e-04f, +8.115205881e-04f, +6.803091718e-04f, +4.642140510e-04f, +2.287861157e-04f, +3.136033560e-05f, -9.410712043e-05f, -1.419963918e-04f, -1.297693532e-04f, -8.627587811e-05f,
- /* 24, 2 */ +1.206403004e-04f, +1.435401825e-04f, +1.129889134e-04f, +7.448162127e-06f, -1.740634498e-04f, -4.046419937e-04f, -6.317316839e-04f, -7.899834729e-04f, -8.214124236e-04f, -6.959950382e-04f, -4.248524782e-04f, -6.038280262e-05f, +3.175841545e-04f, +6.251993025e-04f, +7.994228899e-04f, +8.155596091e-04f, +6.916540113e-04f, +4.789657110e-04f, +2.428865252e-04f, +4.180014906e-05f, -8.861563067e-05f, -1.410306561e-04f, -1.317666448e-04f, -8.934972901e-05f,
- /* 24, 3 */ +1.181106179e-04f, +1.433803035e-04f, +1.169520657e-04f, +1.639322797e-05f, -1.608575022e-04f, -3.896869361e-04f, -6.188684520e-04f, -7.833086355e-04f, -8.239227539e-04f, -7.084404793e-04f, -4.452560799e-04f, -8.446017611e-05f, +2.952092559e-04f, +6.093952965e-04f, +7.931298338e-04f, +8.190403838e-04f, +7.026473724e-04f, +4.936285297e-04f, +2.571314547e-04f, +5.252568657e-05f, -8.281147599e-05f, -1.398199793e-04f, -1.336347757e-04f, -9.240689021e-05f,
- /* 24, 4 */ +1.154967766e-04f, +1.430161614e-04f, +1.206189886e-04f, +2.502931407e-05f, -1.478619956e-04f, -3.747381071e-04f, -6.057504254e-04f, -7.761410928e-04f, -8.258095592e-04f, -7.202947906e-04f, -4.652686374e-04f, -1.084619116e-04f, +2.725719623e-04f, +5.930689291e-04f, +7.862057246e-04f, +8.219537553e-04f, +7.132737861e-04f, +5.081861235e-04f, +2.715085502e-04f, +6.353146713e-05f, -7.669318508e-05f, -1.383581653e-04f, -1.353661159e-04f, -9.544123411e-05f,
- /* 24, 5 */ +1.128060463e-04f, +1.424549941e-04f, +1.239935912e-04f, +3.335412922e-05f, -1.350864661e-04f, -3.598106411e-04f, -5.923941571e-04f, -7.684933716e-04f, -8.270765907e-04f, -7.315507834e-04f, -4.848734661e-04f, -1.323665545e-04f, +2.496920884e-04f, +5.762325468e-04f, +7.786522269e-04f, +8.242911148e-04f, +7.235180256e-04f, +5.226220062e-04f, +2.860050947e-04f, +7.481154929e-05f, -7.025967465e-05f, -1.366392205e-04f, -1.369530289e-04f, -9.844647580e-05f,
- /* 24, 6 */ +1.100456035e-04f, +1.417041346e-04f, +1.270800866e-04f, +4.136582536e-05f, -1.225400157e-04f, -3.449194225e-04f, -5.788162671e-04f, -7.603784078e-04f, -8.277282458e-04f, -7.422019493e-04f, -5.040543645e-04f, -1.561527673e-04f, +2.265897402e-04f, +5.588990922e-04f, +7.704716994e-04f, +8.260444163e-04f, +7.333651287e-04f, +5.369196097e-04f, +3.006080208e-04f, +8.635953200e-05f, -6.351025813e-05f, -1.346573670e-04f, -1.383878839e-04f, -1.014161798e-04f,
- /* 24, 7 */ +1.072225228e-04f, +1.407709979e-04f, +1.298829797e-04f, +4.906299265e-05f, -1.102313067e-04f, -3.300790706e-04f, -5.650334202e-04f, -7.518095256e-04f, -8.277695590e-04f, -7.522424649e-04f, -5.227956327e-04f, -1.797993550e-04f, +2.032852905e-04f, +5.410820901e-04f, +7.616671958e-04f, +8.272061905e-04f, +7.428004186e-04f, +5.510623045e-04f, +3.153039229e-04f, +9.816855611e-05f, -5.644465382e-05f, -1.324070557e-04f, -1.396630677e-04f, -1.043437672e-04f,
- /* 24, 8 */ +1.043437672e-04f, +1.396630677e-04f, +1.324070557e-04f, +5.644465382e-05f, -9.816855611e-05f, -3.153039229e-04f, -5.510623045e-04f, -7.428004186e-04f, -8.272061905e-04f, -7.616671958e-04f, -5.410820901e-04f, -2.032852905e-04f, +1.797993550e-04f, +5.227956327e-04f, +7.522424649e-04f, +8.277695590e-04f, +7.518095256e-04f, +5.650334202e-04f, +3.300790706e-04f, +1.102313067e-04f, -4.906299265e-05f, -1.298829797e-04f, -1.407709979e-04f, -1.072225228e-04f,
- /* 24, 9 */ +1.014161798e-04f, +1.383878839e-04f, +1.346573670e-04f, +6.351025813e-05f, -8.635953200e-05f, -3.006080208e-04f, -5.369196097e-04f, -7.333651287e-04f, -8.260444163e-04f, -7.704716994e-04f, -5.588990922e-04f, -2.265897402e-04f, +1.561527673e-04f, +5.040543645e-04f, +7.422019493e-04f, +8.277282458e-04f, +7.603784078e-04f, +5.788162671e-04f, +3.449194225e-04f, +1.225400157e-04f, -4.136582536e-05f, -1.270800866e-04f, -1.417041346e-04f, -1.100456035e-04f,
- /* 24,10 */ +9.844647580e-05f, +1.369530289e-04f, +1.366392205e-04f, +7.025967465e-05f, -7.481154929e-05f, -2.860050947e-04f, -5.226220062e-04f, -7.235180256e-04f, -8.242911148e-04f, -7.786522269e-04f, -5.762325468e-04f, -2.496920884e-04f, +1.323665545e-04f, +4.848734661e-04f, +7.315507834e-04f, +8.270765907e-04f, +7.684933716e-04f, +5.923941571e-04f, +3.598106411e-04f, +1.350864661e-04f, -3.335412922e-05f, -1.239935912e-04f, -1.424549941e-04f, -1.128060463e-04f,
- /* 24,11 */ +9.544123411e-05f, +1.353661159e-04f, +1.383581653e-04f, +7.669318508e-05f, -6.353146713e-05f, -2.715085502e-04f, -5.081861235e-04f, -7.132737861e-04f, -8.219537553e-04f, -7.862057246e-04f, -5.930689291e-04f, -2.725719623e-04f, +1.084619116e-04f, +4.652686374e-04f, +7.202947906e-04f, +8.258095592e-04f, +7.761410928e-04f, +6.057504254e-04f, +3.747381071e-04f, +1.478619956e-04f, -2.502931407e-05f, -1.206189886e-04f, -1.430161614e-04f, -1.154967766e-04f,
- /* 24,12 */ +9.240689021e-05f, +1.336347757e-04f, +1.398199793e-04f, +8.281147599e-05f, -5.252568657e-05f, -2.571314547e-04f, -4.936285297e-04f, -7.026473724e-04f, -8.190403838e-04f, -7.931298338e-04f, -6.093952965e-04f, -2.952092559e-04f, +8.446017611e-05f, +4.452560799e-04f, +7.084404793e-04f, +8.239227539e-04f, +7.833086355e-04f, +6.188684520e-04f, +3.896869361e-04f, +1.608575022e-04f, -1.639322797e-05f, -1.169520657e-04f, -1.433803035e-04f, -1.181106179e-04f,
- /* 24,13 */ +8.934972901e-05f, +1.317666448e-04f, +1.410306561e-04f, +8.861563067e-05f, -4.180014906e-05f, -2.428865252e-04f, -4.789657110e-04f, -6.916540113e-04f, -8.155596091e-04f, -7.994228899e-04f, -6.251993025e-04f, -3.175841545e-04f, +6.038280262e-05f, +4.248524782e-04f, +6.959950382e-04f, +8.214124236e-04f, +7.899834729e-04f, +6.317316839e-04f, +4.046419937e-04f, +1.740634498e-04f, -7.448162127e-06f, -1.129889134e-04f, -1.435401825e-04f, -1.206403004e-04f,
- /* 24,14 */ +8.627587811e-05f, +1.297693532e-04f, +1.419963918e-04f, +9.410712043e-05f, -3.136033560e-05f, -2.287861157e-04f, -4.642140510e-04f, -6.803091718e-04f, -8.115205881e-04f, -8.050839212e-04f, -6.404692089e-04f, -3.396771574e-04f, +3.625133679e-05f, +4.040749814e-04f, +6.829663304e-04f, +8.182754723e-04f, +7.961535056e-04f, +6.443236569e-04f, +4.195879132e-04f, +1.874698746e-04f, +1.803144714e-06f, -1.087259386e-04f, -1.434886692e-04f, -1.230784715e-04f,
- /* 24,15 */ +8.319130160e-05f, +1.276505127e-04f, +1.427235715e-04f, +9.928779545e-05f, -2.121126661e-05f, -2.148422063e-04f, -4.493898115e-04f, -6.686285441e-04f, -8.069330100e-04f, -8.101126455e-04f, -6.551938988e-04f, -3.614691013e-04f, +1.208738944e-05f, +3.829411831e-04f, +6.693628869e-04f, +8.145094672e-04f, +8.018070806e-04f, +6.566280172e-04f, +4.345091125e-04f, +2.010663923e-04f, +1.135750248e-05f, -1.041598752e-04f, -1.432187562e-04f, -1.254177052e-04f,
- /* 24, 0 */ +4.545052445e-05f, +1.951315810e-04f, +3.748938080e-04f, +4.809335107e-04f, +3.960765690e-04f, +5.993810822e-05f, -4.723795438e-04f, -1.024325735e-03f, -1.361247582e-03f, -1.299302728e-03f, -8.046117557e-04f, -2.606329026e-05f, +7.618428442e-04f, +1.280408741e-03f, +1.370322771e-03f, +1.054089829e-03f, +5.086432784e-04f, -3.113193898e-05f, -3.825195300e-04f, -4.822884412e-04f, -3.849609275e-04f, -2.063256631e-04f, -5.270037440e-05f, +2.454794639e-05f,
- /* 24, 1 */ +3.852332445e-05f, +1.840753178e-04f, +3.645444067e-04f, +4.788140096e-04f, +4.086121277e-04f, +8.793526572e-05f, -4.362135407e-04f, -9.937048198e-04f, -1.350562575e-03f, -1.316442769e-03f, -8.462280606e-04f, -7.815185270e-05f, +7.179801999e-04f, +1.259777116e-03f, +1.377758125e-03f, +1.082939175e-03f, +5.449481703e-04f, -1.547839432e-06f, -3.679388598e-04f, -4.828529979e-04f, -3.947147844e-04f, -2.176372792e-04f, -6.026901850e-05f, +2.205234045e-05f,
- /* 24, 2 */ +3.192167036e-05f, +1.731761778e-04f, +3.539434193e-04f, +4.759566352e-04f, +4.201302650e-04f, +1.150943789e-04f, -4.002008253e-04f, -9.622858103e-04f, -1.338300241e-03f, -1.331815598e-03f, -8.866349827e-04f, -1.301264311e-04f, +6.730846905e-04f, +1.237427186e-03f, +1.383526171e-03f, +1.110816763e-03f, +5.812367254e-04f, +2.878109064e-05f, -3.523343557e-04f, -4.826023474e-04f, -4.041241778e-04f, -2.290451863e-04f, -6.815162122e-05f, +1.926869283e-05f,
- /* 24, 3 */ +2.564752013e-05f, +1.624524653e-04f, +3.431211940e-04f, +4.723889014e-04f, +4.306369033e-04f, +1.413884897e-04f, -3.643958409e-04f, -9.301281119e-04f, -1.324495465e-03f, -1.345410999e-03f, -9.257779427e-04f, -1.819112698e-04f, +6.272190697e-04f, +1.213381290e-03f, +1.387602061e-03f, +1.137666624e-03f, +6.174506312e-04f, +5.981976836e-05f, -3.357077999e-04f, -4.815127015e-04f, -4.131577529e-04f, -2.405272085e-04f, -7.634234963e-05f, +1.618998833e-05f,
- /* 24, 4 */ +1.970191739e-05f, +1.519214683e-04f, +3.321076713e-04f, +4.681390617e-04f, +4.401397816e-04f, +1.667927354e-04f, -3.288518263e-04f, -8.972916878e-04f, -1.309185436e-03f, -1.357221809e-03f, -9.636046528e-04f, -2.334309635e-04f, +5.804478655e-04f, +1.187664745e-03f, +1.389963631e-03f, +1.163433942e-03f, +6.535308606e-04f, +9.153116784e-05f, -3.180629927e-04f, -4.795613921e-04f, -4.217840695e-04f, -2.520602653e-04f, -8.483435780e-05f, +1.280977164e-05f,
- /* 24, 5 */ +1.408501704e-05f, +1.415994448e-04f, +3.209323254e-04f, +4.632360317e-04f, +4.486484045e-04f, +1.912843645e-04f, -2.936207276e-04f, -8.638369381e-04f, -1.292409564e-03f, -1.367243913e-03f, -1.000065207e-03f, -2.846105957e-04f, +5.328372638e-04f, +1.160305814e-03f, +1.390591463e-03f, +1.188065177e-03f, +6.894177793e-04f, +1.238763650e-04f, -2.994057812e-04f, -4.767269440e-04f, -4.299716716e-04f, -2.636204028e-04f, -9.361977359e-05f, +9.122184539e-06f,
- /* 24, 6 */ +8.796112429e-06f, +1.315016126e-04f, +3.096241086e-04f, +4.577093118e-04f, +4.561739887e-04f, +2.148427485e-04f, -2.587531149e-04f, -8.298245798e-04f, -1.274209383e-03f, -1.375476234e-03f, -1.035112163e-03f, -3.353758773e-04f, +4.844549899e-04f, +1.131335665e-03f, +1.389468944e-03f, +1.211508174e-03f, +7.250512548e-04f, +1.568145870e-04f, -2.797440842e-04f, -4.729891466e-04f, -4.376891593e-04f, -2.751828281e-04f, -1.026896878e-04f, +5.122002376e-06f,
- /* 24, 7 */ +3.833664119e-06f, +1.216421408e-04f, +2.982113984e-04f, +4.515889092e-04f, +4.627294060e-04f, +2.374493875e-04f, -2.242981012e-04f, -7.953155261e-04f, -1.254628457e-03f, -1.381920720e-03f, -1.068700627e-03f, -3.856532828e-04f, +4.353701854e-04f, +1.100788324e-03f, +1.386582316e-03f, +1.233712281e-03f, +7.603707678e-04f, +1.903032668e-04f, -2.590879129e-04f, -4.683291247e-04f, -4.449052614e-04f, -2.867219458e-04f, -1.120341455e-04f, +8.046698450e-07f,
- /* 24, 8 */ -8.046698450e-07f, +1.120341455e-04f, +2.867219458e-04f, +4.449052614e-04f, +4.683291247e-04f, +2.590879129e-04f, -1.903032668e-04f, -7.603707678e-04f, -1.233712281e-03f, -1.386582316e-03f, -1.100788324e-03f, -4.353701854e-04f, +3.856532828e-04f, +1.068700627e-03f, +1.381920720e-03f, +1.254628457e-03f, +7.953155261e-04f, +2.242981012e-04f, -2.374493875e-04f, -4.627294060e-04f, -4.515889092e-04f, -2.982113984e-04f, -1.216421408e-04f, -3.833664119e-06f,
- /* 24, 9 */ -5.122002376e-06f, +1.026896878e-04f, +2.751828281e-04f, +4.376891593e-04f, +4.729891466e-04f, +2.797440842e-04f, -1.568145870e-04f, -7.250512548e-04f, -1.211508174e-03f, -1.389468944e-03f, -1.131335665e-03f, -4.844549899e-04f, +3.353758773e-04f, +1.035112163e-03f, +1.375476234e-03f, +1.274209383e-03f, +8.298245798e-04f, +2.587531149e-04f, -2.148427485e-04f, -4.561739887e-04f, -4.577093118e-04f, -3.096241086e-04f, -1.315016126e-04f, -8.796112429e-06f,
- /* 24,10 */ -9.122184539e-06f, +9.361977359e-05f, +2.636204028e-04f, +4.299716716e-04f, +4.767269440e-04f, +2.994057812e-04f, -1.238763650e-04f, -6.894177793e-04f, -1.188065177e-03f, -1.390591463e-03f, -1.160305814e-03f, -5.328372638e-04f, +2.846105957e-04f, +1.000065207e-03f, +1.367243913e-03f, +1.292409564e-03f, +8.638369381e-04f, +2.936207276e-04f, -1.912843645e-04f, -4.486484045e-04f, -4.632360317e-04f, -3.209323254e-04f, -1.415994448e-04f, -1.408501704e-05f,
- /* 24,11 */ -1.280977164e-05f, +8.483435780e-05f, +2.520602653e-04f, +4.217840695e-04f, +4.795613921e-04f, +3.180629927e-04f, -9.153116784e-05f, -6.535308606e-04f, -1.163433942e-03f, -1.389963631e-03f, -1.187664745e-03f, -5.804478655e-04f, +2.334309635e-04f, +9.636046528e-04f, +1.357221809e-03f, +1.309185436e-03f, +8.972916878e-04f, +3.288518263e-04f, -1.667927354e-04f, -4.401397816e-04f, -4.681390617e-04f, -3.321076713e-04f, -1.519214683e-04f, -1.970191739e-05f,
- /* 24,12 */ -1.618998833e-05f, +7.634234963e-05f, +2.405272085e-04f, +4.131577529e-04f, +4.815127015e-04f, +3.357077999e-04f, -5.981976836e-05f, -6.174506312e-04f, -1.137666624e-03f, -1.387602061e-03f, -1.213381290e-03f, -6.272190697e-04f, +1.819112698e-04f, +9.257779427e-04f, +1.345410999e-03f, +1.324495465e-03f, +9.301281119e-04f, +3.643958409e-04f, -1.413884897e-04f, -4.306369033e-04f, -4.723889014e-04f, -3.431211940e-04f, -1.624524653e-04f, -2.564752013e-05f,
- /* 24,13 */ -1.926869283e-05f, +6.815162122e-05f, +2.290451863e-04f, +4.041241778e-04f, +4.826023474e-04f, +3.523343557e-04f, -2.878109064e-05f, -5.812367254e-04f, -1.110816763e-03f, -1.383526171e-03f, -1.237427186e-03f, -6.730846905e-04f, +1.301264311e-04f, +8.866349827e-04f, +1.331815598e-03f, +1.338300241e-03f, +9.622858103e-04f, +4.002008253e-04f, -1.150943789e-04f, -4.201302650e-04f, -4.759566352e-04f, -3.539434193e-04f, -1.731761778e-04f, -3.192167036e-05f,
- /* 24,14 */ -2.205234045e-05f, +6.026901850e-05f, +2.176372792e-04f, +3.947147844e-04f, +4.828529979e-04f, +3.679388598e-04f, +1.547839432e-06f, -5.449481703e-04f, -1.082939175e-03f, -1.377758125e-03f, -1.259777116e-03f, -7.179801999e-04f, +7.815185270e-05f, +8.462280606e-04f, +1.316442769e-03f, +1.350562575e-03f, +9.937048198e-04f, +4.362135407e-04f, -8.793526572e-05f, -4.086121277e-04f, -4.788140096e-04f, -3.645444067e-04f, -1.840753178e-04f, -3.852332445e-05f,
- /* 24,15 */ -2.454794639e-05f, +5.270037440e-05f, +2.063256631e-04f, +3.849609275e-04f, +4.822884412e-04f, +3.825195300e-04f, +3.113193898e-05f, -5.086432784e-04f, -1.054089829e-03f, -1.370322771e-03f, -1.280408741e-03f, -7.618428442e-04f, +2.606329026e-05f, +8.046117557e-04f, +1.299302728e-03f, +1.361247582e-03f, +1.024325735e-03f, +4.723795438e-04f, -5.993810822e-05f, -3.960765690e-04f, -4.809335107e-04f, -3.748938080e-04f, -1.951315810e-04f, -4.545052445e-05f,
- /* 24, 0 */ -1.702250368e-04f, -1.965005420e-04f, +1.103795304e-06f, +4.330784212e-04f, +8.784555707e-04f, +9.653328276e-04f, +4.315509563e-04f, -6.109575553e-04f, -1.641723450e-03f, -2.015827225e-03f, -1.400787443e-03f, -4.702498413e-05f, +1.332047630e-03f, +2.006889303e-03f, +1.690240096e-03f, +6.826705419e-04f, -3.776686811e-04f, -9.512688743e-04f, -8.983149818e-04f, -4.640234647e-04f, -2.230828855e-05f, +1.918067822e-04f, +1.759255972e-04f, +6.786242515e-05f,
- /* 24, 1 */ -1.642126010e-04f, -2.002752798e-04f, -1.910126829e-05f, +4.022439121e-04f, +8.571608722e-04f, +9.768399670e-04f, +4.832977173e-04f, -5.392469404e-04f, -1.590532482e-03f, -2.020693110e-03f, -1.466475318e-03f, -1.409702826e-04f, +1.260398022e-03f, +1.993868298e-03f, +1.735939471e-03f, +7.542164043e-04f, -3.217397652e-04f, -9.346209288e-04f, -9.166430096e-04f, -4.949934945e-04f, -4.448641826e-05f, +1.861665779e-04f, +1.812738819e-04f, +7.451957718e-05f,
- /* 24, 2 */ -1.579281336e-04f, -2.031605347e-04f, -3.828516688e-05f, +3.716026326e-04f, +8.345286135e-04f, +9.858238344e-04f, +5.328272649e-04f, -4.677058239e-04f, -1.536815378e-03f, -2.021508037e-03f, -1.528977139e-03f, -2.346018520e-04f, +1.185988431e-03f, +1.976763286e-03f, +1.778684302e-03f, +8.254237228e-04f, -2.638601140e-04f, -9.153683790e-04f, -9.333455225e-04f, -5.259003096e-04f, -6.760829922e-05f, +1.795547962e-04f, +1.862290729e-04f, +8.132190552e-05f,
- /* 24, 3 */ -1.514107898e-04f, -2.051877883e-04f, -5.643017558e-05f, +3.412342375e-04f, +8.106578209e-04f, +9.923241157e-04f, +5.800651921e-04f, -3.964985305e-04f, -1.480725107e-03f, -2.018303000e-03f, -1.588167145e-03f, -3.277114722e-04f, +1.108975953e-03f, +1.955583535e-03f, +1.818343426e-03f, +8.961196099e-04f, -2.041325004e-04f, -8.934973649e-04f, -9.483306864e-04f, -5.566532714e-04f, -9.163993343e-05f, +1.719487619e-04f, +1.907500791e-04f, +8.824611727e-05f,
- /* 24, 4 */ -1.446989102e-04f, -2.063902871e-04f, -7.352252002e-05f, +3.112151687e-04f, +7.856484910e-04f, +9.963864071e-04f, +6.249444785e-04f, -3.257861630e-04f, -1.422418959e-03f, -2.011118755e-03f, -1.643928243e-03f, -4.200923193e-04f, +1.029524574e-03f, +1.930348530e-03f, +1.854792197e-03f, +9.661301752e-04f, -1.426663759e-04f, -8.690009463e-04f, -9.615092978e-04f, -5.871595310e-04f, -1.165432034e-04f, +1.633284218e-04f, +1.947956873e-04f, +9.526723781e-05f,
- /* 24, 5 */ -1.378299032e-04f, -2.068028652e-04f, -8.955230425e-05f, +2.816184974e-04f, +7.596012646e-04f, +9.980619660e-04f, +6.674055614e-04f, -2.557261963e-04f, -1.362058071e-03f, -2.000005648e-03f, -1.696152289e-03f, -5.115395181e-04f, +9.478047386e-04f, +1.901087985e-03f, +1.887912892e-03f, +1.035280999e-03f, -7.957765930e-05f, -8.418792522e-04f, -9.727951144e-04f, -6.173242692e-04f, -1.422758795e-04f, +1.536765045e-04f, +1.983247179e-04f, +1.023586489e-04f,
- /* 24, 6 */ -1.308401336e-04f, -2.064617646e-04f, -1.045134271e-04f, +2.525137807e-04f, +7.326171060e-04f, +9.974074494e-04f, +7.073963828e-04f, -1.864720875e-04f, -1.299806951e-03f, -1.985023411e-03f, -1.744740344e-03f, -6.018506887e-04f, +8.639929140e-04f, +1.867841815e-03f, +1.917595086e-03f, +1.103397612e-03f, -1.498850339e-05f, -8.121396097e-04f, -9.821051828e-04f, -6.470509490e-04f, -1.687916421e-04f, +1.429786744e-04f, +2.012961856e-04f, +1.094921351e-04f,
- /* 24, 7 */ -1.237648199e-04f, -2.054044567e-04f, -1.184034872e-04f, +2.239669341e-04f, +7.047969872e-04f, +9.944846402e-04f, +7.448724134e-04f, -1.181729029e-04f, -1.235832990e-03f, -1.966240936e-03f, -1.789602898e-03f, -6.908264855e-04f, +7.782711267e-04f, +1.830660078e-03f, +1.943736019e-03f, +1.170305979e-03f, +5.097296116e-05f, -7.797966533e-04f, -9.893601617e-04f, -6.762415789e-04f, -1.960401183e-04f, +1.312236785e-04f, +2.036694644e-04f, +1.166379381e-04f,
- /* 24, 8 */ -1.166379381e-04f, -2.036694644e-04f, -1.312236785e-04f, +1.960401183e-04f, +6.762415789e-04f, +9.893601617e-04f, +7.797966533e-04f, -5.097296116e-05f, -1.170305979e-03f, -1.943736019e-03f, -1.830660078e-03f, -7.782711267e-04f, +6.908264855e-04f, +1.789602898e-03f, +1.966240936e-03f, +1.235832990e-03f, +1.181729029e-04f, -7.448724134e-04f, -9.944846402e-04f, -7.047969872e-04f, -2.239669341e-04f, +1.184034872e-04f, +2.054044567e-04f, +1.237648199e-04f,
- /* 24, 9 */ -1.094921351e-04f, -2.012961856e-04f, -1.429786744e-04f, +1.687916421e-04f, +6.470509490e-04f, +9.821051828e-04f, +8.121396097e-04f, +1.498850339e-05f, -1.103397612e-03f, -1.917595086e-03f, -1.867841815e-03f, -8.639929140e-04f, +6.018506887e-04f, +1.744740344e-03f, +1.985023411e-03f, +1.299806951e-03f, +1.864720875e-04f, -7.073963828e-04f, -9.974074494e-04f, -7.326171060e-04f, -2.525137807e-04f, +1.045134271e-04f, +2.064617646e-04f, +1.308401336e-04f,
- /* 24,10 */ -1.023586489e-04f, -1.983247179e-04f, -1.536765045e-04f, +1.422758795e-04f, +6.173242692e-04f, +9.727951144e-04f, +8.418792522e-04f, +7.957765930e-05f, -1.035280999e-03f, -1.887912892e-03f, -1.901087985e-03f, -9.478047386e-04f, +5.115395181e-04f, +1.696152289e-03f, +2.000005648e-03f, +1.362058071e-03f, +2.557261963e-04f, -6.674055614e-04f, -9.980619660e-04f, -7.596012646e-04f, -2.816184974e-04f, +8.955230425e-05f, +2.068028652e-04f, +1.378299032e-04f,
- /* 24,11 */ -9.526723781e-05f, -1.947956873e-04f, -1.633284218e-04f, +1.165432034e-04f, +5.871595310e-04f, +9.615092978e-04f, +8.690009463e-04f, +1.426663759e-04f, -9.661301752e-04f, -1.854792197e-03f, -1.930348530e-03f, -1.029524574e-03f, +4.200923193e-04f, +1.643928243e-03f, +2.011118755e-03f, +1.422418959e-03f, +3.257861630e-04f, -6.249444785e-04f, -9.963864071e-04f, -7.856484910e-04f, -3.112151687e-04f, +7.352252002e-05f, +2.063902871e-04f, +1.446989102e-04f,
- /* 24,12 */ -8.824611727e-05f, -1.907500791e-04f, -1.719487619e-04f, +9.163993343e-05f, +5.566532714e-04f, +9.483306864e-04f, +8.934973649e-04f, +2.041325004e-04f, -8.961196099e-04f, -1.818343426e-03f, -1.955583535e-03f, -1.108975953e-03f, +3.277114722e-04f, +1.588167145e-03f, +2.018303000e-03f, +1.480725107e-03f, +3.964985305e-04f, -5.800651921e-04f, -9.923241157e-04f, -8.106578209e-04f, -3.412342375e-04f, +5.643017558e-05f, +2.051877883e-04f, +1.514107898e-04f,
- /* 24,13 */ -8.132190552e-05f, -1.862290729e-04f, -1.795547962e-04f, +6.760829922e-05f, +5.259003096e-04f, +9.333455225e-04f, +9.153683790e-04f, +2.638601140e-04f, -8.254237228e-04f, -1.778684302e-03f, -1.976763286e-03f, -1.185988431e-03f, +2.346018520e-04f, +1.528977139e-03f, +2.021508037e-03f, +1.536815378e-03f, +4.677058239e-04f, -5.328272649e-04f, -9.858238344e-04f, -8.345286135e-04f, -3.716026326e-04f, +3.828516688e-05f, +2.031605347e-04f, +1.579281336e-04f,
- /* 24,14 */ -7.451957718e-05f, -1.812738819e-04f, -1.861665779e-04f, +4.448641826e-05f, +4.949934945e-04f, +9.166430096e-04f, +9.346209288e-04f, +3.217397652e-04f, -7.542164043e-04f, -1.735939471e-03f, -1.993868298e-03f, -1.260398022e-03f, +1.409702826e-04f, +1.466475318e-03f, +2.020693110e-03f, +1.590532482e-03f, +5.392469404e-04f, -4.832977173e-04f, -9.768399670e-04f, -8.571608722e-04f, -4.022439121e-04f, +1.910126829e-05f, +2.002752798e-04f, +1.642126010e-04f,
- /* 24,15 */ -6.786242515e-05f, -1.759255972e-04f, -1.918067822e-04f, +2.230828855e-05f, +4.640234647e-04f, +8.983149818e-04f, +9.512688743e-04f, +3.776686811e-04f, -6.826705419e-04f, -1.690240096e-03f, -2.006889303e-03f, -1.332047630e-03f, +4.702498413e-05f, +1.400787443e-03f, +2.015827225e-03f, +1.641723450e-03f, +6.109575553e-04f, -4.315509563e-04f, -9.653328276e-04f, -8.784555707e-04f, -4.330784212e-04f, -1.103795304e-06f, +1.965005420e-04f, +1.702250368e-04f,
- /* 24, 0 */ +3.919255962e-05f, -2.280943782e-04f, -5.361345988e-04f, -4.457457641e-04f, +2.990589649e-04f, +1.295797675e-03f, +1.605517166e-03f, +5.875816565e-04f, -1.289084098e-03f, -2.596166105e-03f, -2.129939921e-03f, -7.496988250e-05f, +2.037180601e-03f, +2.625542335e-03f, +1.404160874e-03f, -4.837783526e-04f, -1.582480410e-03f, -1.345619201e-03f, -3.621830939e-04f, +4.180945199e-04f, +5.469818219e-04f, +2.499414065e-04f, -2.888372260e-05f, -8.895700627e-05f,
- /* 24, 1 */ +4.853777483e-05f, -2.065137544e-04f, -5.236754574e-04f, -4.705972357e-04f, +2.371311675e-04f, +1.243196859e-03f, +1.622959247e-03f, +6.876650067e-04f, -1.171710060e-03f, -2.559351067e-03f, -2.215991331e-03f, -2.246678327e-04f, +1.937986318e-03f, +2.647321756e-03f, +1.516528605e-03f, -3.765445934e-04f, -1.553807591e-03f, -1.392405213e-03f, -4.263006320e-04f, +3.876486968e-04f, +5.560961676e-04f, +2.719611444e-04f, -1.761075235e-05f, -9.068976925e-05f,
- /* 24, 2 */ +5.692498928e-05f, -1.852878923e-04f, -5.097279107e-04f, -4.926555685e-04f, +1.765921503e-04f, +1.188077447e-03f, +1.634867875e-03f, +7.837567953e-04f, -1.052453928e-03f, -2.515280079e-03f, -2.295086316e-03f, -3.736412373e-04f, +1.832653524e-03f, +2.661371990e-03f, +1.625780509e-03f, -2.661868955e-04f, -1.519477670e-03f, -1.435905115e-03f, -4.911987788e-04f, +3.544256494e-04f, +5.633598944e-04f, +2.940548284e-04f, -5.378471232e-06f, -9.187426948e-05f,
- /* 24, 3 */ +6.436469025e-05f, -1.644995777e-04f, -4.944173708e-04f, -5.119388451e-04f, +1.176233517e-04f, +1.130703462e-03f, +1.641323506e-03f, +8.756040923e-04f, -9.317326579e-04f, -2.464159993e-03f, -2.367001633e-03f, -5.214100591e-04f, +1.721501142e-03f, +2.667586958e-03f, +1.731516399e-03f, -1.530278412e-04f, -1.479490407e-03f, -1.475875084e-03f, -5.566555092e-04f, +3.184551797e-04f, +5.686591450e-04f, +3.161189305e-04f, +7.802761507e-06f, -9.246489856e-05f,
- /* 24, 4 */ +7.087197068e-05f, -1.442258278e-04f, -4.778705046e-04f, -5.284761768e-04f, +6.039472401e-05f, +1.071341110e-03f, +1.642425167e-03f, +9.629733481e-04f, -8.099633882e-04f, -2.406220702e-03f, -2.431540042e-03f, -6.674987371e-04f, +1.604869446e-03f, +2.665887444e-03f, +1.833344283e-03f, -3.740504807e-05f, -1.433866725e-03f, -1.512079220e-03f, -6.224402836e-04f, +2.797797731e-04f, +5.718846156e-04f, +3.380454975e-04f, +2.191686946e-05f, -9.241721523e-05f,
- /* 24, 5 */ +7.646625331e-05f, -1.245377292e-04f, -4.602146020e-04f, -5.423072437e-04f, +5.064318866e-06f, +1.010257658e-03f, +1.638289725e-03f, +1.045651008e-03f, -6.875618648e-04f, -2.341714107e-03f, -2.488530931e-03f, -8.114379517e-04f, +1.483118851e-03f, +2.656221571e-03f, +1.930881931e-03f, +8.032993590e-05f, -1.382648990e-03f, -1.544290670e-03f, -6.883148110e-04f, +2.384547825e-04f, +5.729322223e-04f, +3.597225244e-04f, +3.694190340e-05f, -9.168826568e-05f,
- /* 24, 6 */ +8.117100143e-05f, -1.055003114e-04f, -4.415769617e-04f, -5.534817998e-04f, -4.822206513e-05f, +9.477203224e-04f, +1.629051096e-03f, +1.123444034e-03f, -5.649408783e-04f, -2.270913001e-03f, -2.537830838e-03f, -9.527663633e-04f, +1.356628624e-03f, +2.638565156e-03f, +2.023758423e-03f, +1.998128074e-04f, -1.325901212e-03f, -1.572292748e-03f, -7.540338642e-04f, +1.945485578e-04f, +5.717037624e-04f, +3.810343609e-04f, +5.284991195e-05f, -9.023690790e-05f,
- /* 24, 7 */ +8.501341847e-05f, -8.717245610e-05f, -4.220842946e-04f, -5.620591450e-04f, -9.933117260e-05f, +8.839951872e-04f, +1.614859393e-03f, +1.196180345e-03f, -4.425087329e-04f, -2.194109877e-03f, -2.579323863e-03f, -1.091032318e-03f, +1.225795515e-03f, +2.612921966e-03f, +2.111615667e-03f, +3.206677492e-04f, -1.263709151e-03f, -1.595880025e-03f, -8.193461436e-04f, +1.481425192e-04f, +5.681075679e-04f, +4.018621494e-04f, +6.960683992e-05f, -8.802413824e-05f,
- /* 24, 8 */ +8.802413824e-05f, -6.960683992e-05f, -4.018621494e-04f, -5.681075679e-04f, -1.481425192e-04f, +8.193461436e-04f, +1.595880025e-03f, +1.263709151e-03f, -3.206677492e-04f, -2.111615667e-03f, -2.612921966e-03f, -1.225795515e-03f, +1.091032318e-03f, +2.579323863e-03f, +2.194109877e-03f, +4.425087329e-04f, -1.196180345e-03f, -1.614859393e-03f, -8.839951872e-04f, +9.933117260e-05f, +5.620591450e-04f, +4.220842946e-04f, +8.717245610e-05f, -8.501341847e-05f,
- /* 24, 9 */ +9.023690790e-05f, -5.284991195e-05f, -3.810343609e-04f, -5.717037624e-04f, -1.945485578e-04f, +7.540338642e-04f, +1.572292748e-03f, +1.325901212e-03f, -1.998128074e-04f, -2.023758423e-03f, -2.638565156e-03f, -1.356628624e-03f, +9.527663633e-04f, +2.537830838e-03f, +2.270913001e-03f, +5.649408783e-04f, -1.123444034e-03f, -1.629051096e-03f, -9.477203224e-04f, +4.822206513e-05f, +5.534817998e-04f, +4.415769617e-04f, +1.055003114e-04f, -8.117100143e-05f,
- /* 24,10 */ +9.168826568e-05f, -3.694190340e-05f, -3.597225244e-04f, -5.729322223e-04f, -2.384547825e-04f, +6.883148110e-04f, +1.544290670e-03f, +1.382648990e-03f, -8.032993590e-05f, -1.930881931e-03f, -2.656221571e-03f, -1.483118851e-03f, +8.114379517e-04f, +2.488530931e-03f, +2.341714107e-03f, +6.875618648e-04f, -1.045651008e-03f, -1.638289725e-03f, -1.010257658e-03f, -5.064318866e-06f, +5.423072437e-04f, +4.602146020e-04f, +1.245377292e-04f, -7.646625331e-05f,
- /* 24,11 */ +9.241721523e-05f, -2.191686946e-05f, -3.380454975e-04f, -5.718846156e-04f, -2.797797731e-04f, +6.224402836e-04f, +1.512079220e-03f, +1.433866725e-03f, +3.740504807e-05f, -1.833344283e-03f, -2.665887444e-03f, -1.604869446e-03f, +6.674987371e-04f, +2.431540042e-03f, +2.406220702e-03f, +8.099633882e-04f, -9.629733481e-04f, -1.642425167e-03f, -1.071341110e-03f, -6.039472401e-05f, +5.284761768e-04f, +4.778705046e-04f, +1.442258278e-04f, -7.087197068e-05f,
- /* 24,12 */ +9.246489856e-05f, -7.802761507e-06f, -3.161189305e-04f, -5.686591450e-04f, -3.184551797e-04f, +5.566555092e-04f, +1.475875084e-03f, +1.479490407e-03f, +1.530278412e-04f, -1.731516399e-03f, -2.667586958e-03f, -1.721501142e-03f, +5.214100591e-04f, +2.367001633e-03f, +2.464159993e-03f, +9.317326579e-04f, -8.756040923e-04f, -1.641323506e-03f, -1.130703462e-03f, -1.176233517e-04f, +5.119388451e-04f, +4.944173708e-04f, +1.644995777e-04f, -6.436469025e-05f,
- /* 24,13 */ +9.187426948e-05f, +5.378471232e-06f, -2.940548284e-04f, -5.633598944e-04f, -3.544256494e-04f, +4.911987788e-04f, +1.435905115e-03f, +1.519477670e-03f, +2.661868955e-04f, -1.625780509e-03f, -2.661371990e-03f, -1.832653524e-03f, +3.736412373e-04f, +2.295086316e-03f, +2.515280079e-03f, +1.052453928e-03f, -7.837567953e-04f, -1.634867875e-03f, -1.188077447e-03f, -1.765921503e-04f, +4.926555685e-04f, +5.097279107e-04f, +1.852878923e-04f, -5.692498928e-05f,
- /* 24,14 */ +9.068976925e-05f, +1.761075235e-05f, -2.719611444e-04f, -5.560961676e-04f, -3.876486968e-04f, +4.263006320e-04f, +1.392405213e-03f, +1.553807591e-03f, +3.765445934e-04f, -1.516528605e-03f, -2.647321756e-03f, -1.937986318e-03f, +2.246678327e-04f, +2.215991331e-03f, +2.559351067e-03f, +1.171710060e-03f, -6.876650067e-04f, -1.622959247e-03f, -1.243196859e-03f, -2.371311675e-04f, +4.705972357e-04f, +5.236754574e-04f, +2.065137544e-04f, -4.853777483e-05f,
- /* 24,15 */ +8.895700627e-05f, +2.888372260e-05f, -2.499414065e-04f, -5.469818219e-04f, -4.180945199e-04f, +3.621830939e-04f, +1.345619201e-03f, +1.582480410e-03f, +4.837783526e-04f, -1.404160874e-03f, -2.625542335e-03f, -2.037180601e-03f, +7.496988250e-05f, +2.129939921e-03f, +2.596166105e-03f, +1.289084098e-03f, -5.875816565e-04f, -1.605517166e-03f, -1.295797675e-03f, -2.990589649e-04f, +4.457457641e-04f, +5.361345988e-04f, +2.280943782e-04f, -3.919255962e-05f,
- /* 24, 0 */ +1.848082291e-04f, +3.126544607e-04f, -8.381805218e-05f, -8.698090905e-04f, -1.028447094e-03f, +2.139154673e-04f, +1.954115341e-03f, +2.095678120e-03f, -1.635717275e-04f, -2.819157299e-03f, -2.940044791e-03f, -1.098945345e-04f, +2.833179926e-03f, +2.923929522e-03f, +3.511165299e-04f, -2.017938339e-03f, -2.030476715e-03f, -3.277888569e-04f, +9.926761418e-04f, +9.110442493e-04f, +1.284872781e-04f, -3.065935448e-04f, -1.998565163e-04f, +7.803305534e-06f,
- /* 24, 1 */ +1.695814378e-04f, +3.164556508e-04f, -4.103650150e-05f, -8.260698464e-04f, -1.058100498e-03f, +1.024893805e-04f, +1.871044125e-03f, +2.162944507e-03f, +2.203366063e-05f, -2.703524226e-03f, -3.034115138e-03f, -3.291928088e-04f, +2.713944640e-03f, +3.017272284e-03f, +5.397663057e-04f, -1.929900383e-03f, -2.099607997e-03f, -4.436146208e-04f, +9.507629285e-04f, +9.494468230e-04f, +1.748714247e-04f, -2.981837386e-04f, -2.146007649e-04f, -5.699432396e-07f,
- /* 24, 2 */ +1.542962580e-04f, +3.180964801e-04f, -2.971107404e-07f, -7.801571616e-04f, -1.081692695e-03f, -6.019646704e-06f, +1.781805749e-03f, +2.219616197e-03f, +2.048848004e-04f, -2.577645910e-03f, -3.115029215e-03f, -5.470211463e-04f, +2.582823494e-03f, +3.098667200e-03f, +7.286710477e-04f, -1.831793311e-03f, -2.161014579e-03f, -5.608747689e-04f, +9.027154107e-04f, +9.846924856e-04f, +2.227798586e-04f, -2.873471247e-04f, -2.289106872e-04f, -9.773337074e-06f,
- /* 24, 3 */ +1.390667857e-04f, +3.176854393e-04f, +3.826416878e-05f, -7.324018434e-04f, -1.099310451e-03f, -1.111689527e-04f, +1.686962051e-03f, +2.265625589e-03f, +3.841903571e-04f, -2.442181508e-03f, -3.182489175e-03f, -7.624077328e-04f, +2.440359294e-03f, +3.167649091e-03f, +9.169693475e-04f, -1.723899657e-03f, -2.214230624e-03f, -6.790305367e-04f, +8.485750922e-04f, +1.016463150e-03f, +2.720045869e-04f, -2.740180422e-04f, -2.426519708e-04f, -1.978701792e-05f,
- /* 24, 4 */ +1.240005643e-04f, +3.153390489e-04f, +7.453005747e-05f, -6.831329371e-04f, -1.111069621e-03f, -2.125447010e-04f, +1.587090707e-03f, +2.300958285e-03f, +5.591862212e-04f, -2.297830066e-03f, -3.236262287e-03f, -9.743929228e-04f, +2.287150577e-03f, +3.223808711e-03f, +1.103792665e-03f, -1.606554759e-03f, -2.258822083e-03f, -7.975248409e-04f, +7.884177261e-04f, +1.044449054e-03f, +3.223209063e-04f, -2.581440514e-04f, -2.556870681e-04f, -3.058317705e-05f,
- /* 24, 5 */ +1.091981202e-04f, +3.111807515e-04f, +1.084019636e-04f, -6.326758693e-04f, -1.117113666e-03f, -3.097634105e-04f, +1.482781879e-03f, +2.325652312e-03f, +7.291390495e-04f, -2.145326692e-03f, -3.276181809e-03f, -1.182034015e-03f, +2.123848782e-03f, +3.266795190e-03f, +1.288269679e-03f, -1.480145805e-03f, -2.294389599e-03f, -9.157848908e-04f, +7.223538352e-04f, +1.068350860e-03f, +3.734881809e-04f, -2.396868442e-04f, -2.678760406e-04f, -4.212586861e-05f,
- /* 24, 6 */ +9.475256757e-05f, +3.053397988e-04f, +1.397998805e-04f, -5.813506695e-04f, -1.117612060e-03f, -4.024732802e-04f, +1.374634870e-03f, +2.339797075e-03f, +8.933496022e-04f, -1.985438555e-03f, -3.302147511e-03f, -1.384409934e-03f, +1.951155148e-03f, +3.296318191e-03f, +1.469530695e-03f, -1.345110577e-03f, -2.320571262e-03f, -1.033224945e-03f, +6.505290403e-04f, +1.087881752e-03f, +4.252507475e-04f, -2.186230940e-04f, -2.790774568e-04f, -5.437087857e-05f,
- /* 24, 7 */ +8.074928352e-05f, +2.979501429e-04f, +1.686621699e-04f, -5.294702777e-04f, -1.112758583e-03f, -4.903553074e-04f, +1.263254779e-03f, +2.343532047e-03f, +1.051155860e-03f, -1.818960757e-03f, -3.314125843e-03f, -1.580625796e-03f, +1.769817333e-03f, +3.312149758e-03f, +1.646712089e-03f, -1.201935910e-03f, -2.337045209e-03f, -1.149249197e-03f, +5.731241934e-04f, +1.102769514e-03f, +4.773389469e-04f, -1.949452358e-04f, -2.891493374e-04f, -6.726565227e-05f,
- /* 24, 8 */ +6.726565227e-05f, +2.891493374e-04f, +1.949452358e-04f, -4.773389469e-04f, -1.102769514e-03f, -5.731241934e-04f, +1.149249197e-03f, +2.337045209e-03f, +1.201935910e-03f, -1.646712089e-03f, -3.312149758e-03f, -1.769817333e-03f, +1.580625796e-03f, +3.314125843e-03f, +1.818960757e-03f, -1.051155860e-03f, -2.343532047e-03f, -1.263254779e-03f, +4.903553074e-04f, +1.112758583e-03f, +5.294702777e-04f, -1.686621699e-04f, -2.979501429e-04f, -8.074928352e-05f,
- /* 24, 9 */ +5.437087857e-05f, +2.790774568e-04f, +2.186230940e-04f, -4.252507475e-04f, -1.087881752e-03f, -6.505290403e-04f, +1.033224945e-03f, +2.320571262e-03f, +1.345110577e-03f, -1.469530695e-03f, -3.296318191e-03f, -1.951155148e-03f, +1.384409934e-03f, +3.302147511e-03f, +1.985438555e-03f, -8.933496022e-04f, -2.339797075e-03f, -1.374634870e-03f, +4.024732802e-04f, +1.117612060e-03f, +5.813506695e-04f, -1.397998805e-04f, -3.053397988e-04f, -9.475256757e-05f,
- /* 24,10 */ +4.212586861e-05f, +2.678760406e-04f, +2.396868442e-04f, -3.734881809e-04f, -1.068350860e-03f, -7.223538352e-04f, +9.157848908e-04f, +2.294389599e-03f, +1.480145805e-03f, -1.288269679e-03f, -3.266795190e-03f, -2.123848782e-03f, +1.182034015e-03f, +3.276181809e-03f, +2.145326692e-03f, -7.291390495e-04f, -2.325652312e-03f, -1.482781879e-03f, +3.097634105e-04f, +1.117113666e-03f, +6.326758693e-04f, -1.084019636e-04f, -3.111807515e-04f, -1.091981202e-04f,
- /* 24,11 */ +3.058317705e-05f, +2.556870681e-04f, +2.581440514e-04f, -3.223209063e-04f, -1.044449054e-03f, -7.884177261e-04f, +7.975248409e-04f, +2.258822083e-03f, +1.606554759e-03f, -1.103792665e-03f, -3.223808711e-03f, -2.287150577e-03f, +9.743929228e-04f, +3.236262287e-03f, +2.297830066e-03f, -5.591862212e-04f, -2.300958285e-03f, -1.587090707e-03f, +2.125447010e-04f, +1.111069621e-03f, +6.831329371e-04f, -7.453005747e-05f, -3.153390489e-04f, -1.240005643e-04f,
- /* 24,12 */ +1.978701792e-05f, +2.426519708e-04f, +2.740180422e-04f, -2.720045869e-04f, -1.016463150e-03f, -8.485750922e-04f, +6.790305367e-04f, +2.214230624e-03f, +1.723899657e-03f, -9.169693475e-04f, -3.167649091e-03f, -2.440359294e-03f, +7.624077328e-04f, +3.182489175e-03f, +2.442181508e-03f, -3.841903571e-04f, -2.265625589e-03f, -1.686962051e-03f, +1.111689527e-04f, +1.099310451e-03f, +7.324018434e-04f, -3.826416878e-05f, -3.176854393e-04f, -1.390667857e-04f,
- /* 24,13 */ +9.773337074e-06f, +2.289106872e-04f, +2.873471247e-04f, -2.227798586e-04f, -9.846924856e-04f, -9.027154107e-04f, +5.608747689e-04f, +2.161014579e-03f, +1.831793311e-03f, -7.286710477e-04f, -3.098667200e-03f, -2.582823494e-03f, +5.470211463e-04f, +3.115029215e-03f, +2.577645910e-03f, -2.048848004e-04f, -2.219616197e-03f, -1.781805749e-03f, +6.019646704e-06f, +1.081692695e-03f, +7.801571616e-04f, +2.971107404e-07f, -3.180964801e-04f, -1.542962580e-04f,
- /* 24,14 */ +5.699432396e-07f, +2.146007649e-04f, +2.981837386e-04f, -1.748714247e-04f, -9.494468230e-04f, -9.507629285e-04f, +4.436146208e-04f, +2.099607997e-03f, +1.929900383e-03f, -5.397663057e-04f, -3.017272284e-03f, -2.713944640e-03f, +3.291928088e-04f, +3.034115138e-03f, +2.703524226e-03f, -2.203366063e-05f, -2.162944507e-03f, -1.871044125e-03f, -1.024893805e-04f, +1.058100498e-03f, +8.260698464e-04f, +4.103650150e-05f, -3.164556508e-04f, -1.695814378e-04f,
- /* 24,15 */ -7.803305534e-06f, +1.998565163e-04f, +3.065935448e-04f, -1.284872781e-04f, -9.110442493e-04f, -9.926761418e-04f, +3.277888569e-04f, +2.030476715e-03f, +2.017938339e-03f, -3.511165299e-04f, -2.923929522e-03f, -2.833179926e-03f, +1.098945345e-04f, +2.940044791e-03f, +2.819157299e-03f, +1.635717275e-04f, -2.095678120e-03f, -1.954115341e-03f, -2.139154673e-04f, +1.028447094e-03f, +8.698090905e-04f, +8.381805218e-05f, -3.126544607e-04f, -1.848082291e-04f,
- /* 24, 0 */ -1.364396009e-04f, -7.446376994e-05f, +5.066257662e-04f, +2.030015760e-04f, -9.054261715e-04f, -1.195525937e-03f, +4.683850093e-04f, +2.213825561e-03f, +1.188944940e-03f, -1.856378227e-03f, -2.833970964e-03f, -1.144377463e-04f, +2.758138339e-03f, +2.020697482e-03f, -1.023174933e-03f, -2.248631080e-03f, -6.097868283e-04f, +1.146194663e-03f, +9.693248739e-04f, -1.479047908e-04f, -5.177782008e-04f, -1.250536964e-04f, +1.414906982e-04f, +2.710774794e-05f,
- /* 24, 1 */ -1.307026563e-04f, -8.975162518e-05f, +4.924131238e-04f, +2.542107757e-04f, -8.382130226e-04f, -1.235986710e-03f, +3.277877666e-04f, +2.166758574e-03f, +1.345406789e-03f, -1.683014413e-03f, -2.893234801e-03f, -3.426248829e-04f, +2.666119545e-03f, +2.174888063e-03f, -8.489895579e-04f, -2.270723567e-03f, -7.511023835e-04f, +1.088054225e-03f, +1.029345157e-03f, -8.915647260e-05f, -5.256253050e-04f, -1.535492882e-04f, +1.457592711e-04f, +3.374854096e-05f,
- /* 24, 2 */ -1.243758393e-04f, -1.032931784e-04f, +4.753985127e-04f, +3.013338450e-04f, -7.682542954e-04f, -1.267577330e-03f, +1.888607322e-04f, +2.107952975e-03f, +1.491738775e-03f, -1.501737881e-03f, -2.935653267e-03f, -5.687514710e-04f, +2.558401145e-03f, +2.317921172e-03f, -6.673475630e-04f, -2.279727032e-03f, -8.914213340e-04f, +1.021228789e-03f, +1.084932315e-03f, -2.702967135e-05f, -5.299376467e-04f, -1.826837732e-04f, +1.491486840e-04f, +4.073257728e-05f,
- /* 24, 3 */ -1.175537217e-04f, -1.151066589e-04f, +4.558506985e-04f, +3.442099484e-04f, -6.961194660e-04f, -1.290358261e-03f, +5.243891240e-05f, +2.037998203e-03f, +1.627194859e-03f, -1.313720334e-03f, -2.961057174e-03f, -7.914588446e-04f, +2.435570833e-03f, +2.448830599e-03f, -4.792680017e-04f, -2.275344863e-03f, -1.029819797e-03f, +9.459060659e-04f, +1.135545329e-03f, +3.816638860e-05f, -5.305040204e-04f, -2.122423012e-04f, +1.515631236e-04f, +4.801831197e-05f,
- /* 24, 4 */ -1.103288160e-04f, -1.252215041e-04f, +4.340463917e-04f, +3.827158599e-04f, -6.223744454e-04f, -1.304448109e-03f, -8.067840470e-05f, +1.957545178e-03f, +1.751108674e-03f, -1.120165265e-03f, -2.969385358e-03f, -1.009410776e-03f, +2.298313921e-03f, +2.566719612e-03f, -2.858241016e-04f, -2.257363134e-03f, -1.165366520e-03f, +8.623375551e-04f, +1.180661312e-03f, +1.060874480e-04f, -5.271339238e-04f, -2.419953224e-04f, +1.529084143e-04f, +5.555842361e-05f,
- /* 24, 5 */ -1.027909684e-04f, -1.336775649e-04f, +4.102676936e-04f, +4.167655723e-04f, -5.475775503e-04f, -1.310021272e-03f, -2.097323863e-04f, +1.867300846e-03f, +1.862896930e-03f, -9.222997333e-04f, -2.960684559e-03f, -1.221302229e-03f, +2.147409148e-03f, +2.670767418e-03f, -8.813668768e-05f, -2.225653372e-03f, -1.297129225e-03f, +7.708383352e-04f, +1.219779926e-03f, +1.763556677e-04f, -5.196599496e-04f, -2.716999419e-04f, +1.530928622e-04f, +6.329988035e-05f,
- /* 24, 6 */ -9.502680145e-05f, -1.405242734e-04f, +3.847995909e-04f, +4.463096266e-04f, -4.722756447e-04f, -1.307305241e-03f, -3.340090076e-04f, +1.768022423e-03f, +1.962062202e-03f, -7.213660470e-04f, -2.935108571e-03f, -1.425867893e-03f, +1.983723834e-03f, +2.760235146e-03f, +1.126327965e-04f, -2.180174758e-03f, -1.424181074e-03f, +6.717863708e-04f, +1.252427754e-03f, +2.485613970e-04f, -5.079400707e-04f, -3.011014490e-04f, +1.520281231e-04f, +7.118405837e-05f,
- /* 24, 7 */ -8.711921055e-05f, -1.458197836e-04f, +3.579275186e-04f, +4.713341756e-04f, -3.970004792e-04f, -1.296577576e-03f, -4.528429958e-04f, +1.660511380e-03f, +2.048195092e-03f, -5.186134147e-04f, -2.892916666e-03f, -1.621890436e-03f, +1.808208423e-03f, +2.834471303e-03f, +3.152896222e-04f, -2.120975750e-03f, -1.545607217e-03f, +5.656213428e-04f, +1.278162587e-03f, +3.222652495e-04f, -4.918597964e-04f, -3.299350101e-04f, +1.496300883e-04f, +7.914691395e-05f,
- /* 24, 8 */ -7.914691395e-05f, -1.496300883e-04f, +3.299350101e-04f, +4.918597964e-04f, -3.222652495e-04f, -1.278162587e-03f, -5.656213428e-04f, +1.545607217e-03f, +2.120975750e-03f, -3.152896222e-04f, -2.834471303e-03f, -1.808208423e-03f, +1.621890436e-03f, +2.892916666e-03f, +5.186134147e-04f, -2.048195092e-03f, -1.660511380e-03f, +4.528429958e-04f, +1.296577576e-03f, +3.970004792e-04f, -4.713341756e-04f, -3.579275186e-04f, +1.458197836e-04f, +8.711921055e-05f,
- /* 24, 9 */ -7.118405837e-05f, -1.520281231e-04f, +3.011014490e-04f, +5.079400707e-04f, -2.485613970e-04f, -1.252427754e-03f, -6.717863708e-04f, +1.424181074e-03f, +2.180174758e-03f, -1.126327965e-04f, -2.760235146e-03f, -1.983723834e-03f, +1.425867893e-03f, +2.935108571e-03f, +7.213660470e-04f, -1.962062202e-03f, -1.768022423e-03f, +3.340090076e-04f, +1.307305241e-03f, +4.722756447e-04f, -4.463096266e-04f, -3.847995909e-04f, +1.405242734e-04f, +9.502680145e-05f,
- /* 24,10 */ -6.329988035e-05f, -1.530928622e-04f, +2.716999419e-04f, +5.196599496e-04f, -1.763556677e-04f, -1.219779926e-03f, -7.708383352e-04f, +1.297129225e-03f, +2.225653372e-03f, +8.813668768e-05f, -2.670767418e-03f, -2.147409148e-03f, +1.221302229e-03f, +2.960684559e-03f, +9.222997333e-04f, -1.862896930e-03f, -1.867300846e-03f, +2.097323863e-04f, +1.310021272e-03f, +5.475775503e-04f, -4.167655723e-04f, -4.102676936e-04f, +1.336775649e-04f, +1.027909684e-04f,
- /* 24,11 */ -5.555842361e-05f, -1.529084143e-04f, +2.419953224e-04f, +5.271339238e-04f, -1.060874480e-04f, -1.180661312e-03f, -8.623375551e-04f, +1.165366520e-03f, +2.257363134e-03f, +2.858241016e-04f, -2.566719612e-03f, -2.298313921e-03f, +1.009410776e-03f, +2.969385358e-03f, +1.120165265e-03f, -1.751108674e-03f, -1.957545178e-03f, +8.067840470e-05f, +1.304448109e-03f, +6.223744454e-04f, -3.827158599e-04f, -4.340463917e-04f, +1.252215041e-04f, +1.103288160e-04f,
- /* 24,12 */ -4.801831197e-05f, -1.515631236e-04f, +2.122423012e-04f, +5.305040204e-04f, -3.816638860e-05f, -1.135545329e-03f, -9.459060659e-04f, +1.029819797e-03f, +2.275344863e-03f, +4.792680017e-04f, -2.448830599e-03f, -2.435570833e-03f, +7.914588446e-04f, +2.961057174e-03f, +1.313720334e-03f, -1.627194859e-03f, -2.037998203e-03f, -5.243891240e-05f, +1.290358261e-03f, +6.961194660e-04f, -3.442099484e-04f, -4.558506985e-04f, +1.151066589e-04f, +1.175537217e-04f,
- /* 24,13 */ -4.073257728e-05f, -1.491486840e-04f, +1.826837732e-04f, +5.299376467e-04f, +2.702967135e-05f, -1.084932315e-03f, -1.021228789e-03f, +8.914213340e-04f, +2.279727032e-03f, +6.673475630e-04f, -2.317921172e-03f, -2.558401145e-03f, +5.687514710e-04f, +2.935653267e-03f, +1.501737881e-03f, -1.491738775e-03f, -2.107952975e-03f, -1.888607322e-04f, +1.267577330e-03f, +7.682542954e-04f, -3.013338450e-04f, -4.753985127e-04f, +1.032931784e-04f, +1.243758393e-04f,
- /* 24,14 */ -3.374854096e-05f, -1.457592711e-04f, +1.535492882e-04f, +5.256253050e-04f, +8.915647260e-05f, -1.029345157e-03f, -1.088054225e-03f, +7.511023835e-04f, +2.270723567e-03f, +8.489895579e-04f, -2.174888063e-03f, -2.666119545e-03f, +3.426248829e-04f, +2.893234801e-03f, +1.683014413e-03f, -1.345406789e-03f, -2.166758574e-03f, -3.277877666e-04f, +1.235986710e-03f, +8.382130226e-04f, -2.542107757e-04f, -4.924131238e-04f, +8.975162518e-05f, +1.307026563e-04f,
- /* 24,15 */ -2.710774794e-05f, -1.414906982e-04f, +1.250536964e-04f, +5.177782008e-04f, +1.479047908e-04f, -9.693248739e-04f, -1.146194663e-03f, +6.097868283e-04f, +2.248631080e-03f, +1.023174933e-03f, -2.020697482e-03f, -2.758138339e-03f, +1.144377463e-04f, +2.833970964e-03f, +1.856378227e-03f, -1.188944940e-03f, -2.213825561e-03f, -4.683850093e-04f, +1.195525937e-03f, +9.054261715e-04f, -2.030015760e-04f, -5.066257662e-04f, +7.446376994e-05f, +1.364396009e-04f,
- /* 20, 0 */ +8.618377023e-05f, +6.063813654e-04f, +5.504304823e-05f, -1.285351444e-03f, -7.884572117e-04f, +1.698526656e-03f, +2.051642156e-03f, -1.208844608e-03f, -3.071261118e-03f, -1.337669627e-04f, +3.018986987e-03f, +1.434631920e-03f, -1.928392685e-03f, -1.831072241e-03f, +6.629429882e-04f, +1.334851066e-03f, +2.665316224e-05f, -6.158469302e-04f, -1.222533602e-04f, +1.824770389e-04f,
- /* 20, 1 */ +5.170459821e-05f, +5.921181369e-04f, +1.325211661e-04f, -1.227728603e-03f, -9.042412445e-04f, +1.556639033e-03f, +2.157910711e-03f, -9.769935819e-04f, -3.101316201e-03f, -4.002989059e-04f, +2.944767882e-03f, +1.652572896e-03f, -1.788832610e-03f, -1.953018956e-03f, +5.284364506e-04f, +1.375515478e-03f, +1.120226944e-04f, -6.201709543e-04f, -1.596279961e-04f, +5.435082024e-04f,
- /* 20, 2 */ +1.907003227e-05f, +5.734309365e-04f, +2.052951315e-04f, -1.162740775e-03f, -1.009657150e-03f, +1.406715362e-03f, +2.246673287e-03f, -7.408907618e-04f, -3.109053425e-03f, -6.638330580e-04f, +2.849051730e-03f, +1.860929207e-03f, -1.633773999e-03f, -2.063170847e-03f, +3.857714352e-04f, +1.406686835e-03f, +2.004651158e-04f, -6.190441221e-04f, -1.979927117e-04f, +1.783734753e-04f,
- /* 20, 3 */ -1.149811868e-05f, +5.507184044e-04f, +2.729399910e-04f, -1.091184321e-03f, -1.104169932e-03f, +1.250098855e-03f, +2.317552276e-03f, -5.023622502e-04f, -3.094549152e-03f, -9.223980063e-04f, +2.732457430e-03f, +2.058021578e-03f, -1.464165902e-03f, -2.160404235e-03f, +2.358727957e-04f, +1.427769061e-03f, +2.913280278e-04f, -6.121962531e-04f, -2.370049292e-04f, +1.734448317e-04f,
- /* 20, 4 */ -3.981122763e-05f, +5.243991976e-04f, +3.350936324e-04f, -1.013885501e-03f, -1.187349554e-03f, +1.088157908e-03f, +2.370318438e-03f, -2.632332411e-04f, -3.058053364e-03f, -1.174062761e-03f, +2.595770512e-03f, +2.242244162e-03f, -1.281088328e-03f, -2.243678681e-03f, +7.975052491e-05f, +1.438235101e-03f, +3.839113875e-04f, -5.994006494e-04f, -2.762968272e-04f, +1.660093790e-04f,
- /* 20, 5 */ -6.571426612e-05f, +4.949070444e-04f, +3.914578654e-04f, -9.316921975e-04f, -1.258871974e-03f, +9.222740706e-04f, +2.404890527e-03f, -2.531308203e-05f, -2.999986642e-03f, -1.416952434e-03f, +2.439937364e-03f, +2.412078410e-03f, -1.085745014e-03f, -2.312047403e-03f, -8.150702581e-05f, +1.437633739e-03f, +4.774724341e-04f, -5.804781630e-04f, -3.154780847e-04f, +1.559797103e-04f,
- /* 20, 6 */ -8.908584503e-05f, +4.626858369e-04f, +4.417988543e-04f, -8.454656803e-04f, -1.318519207e-03f, +7.538301290e-04f, +2.421333651e-03f, +2.096193816e-04f, -2.920935727e-03f, -1.649263420e-03f, +2.266058084e-03f, +2.566106310e-03f, -8.794550343e-04f, -2.364667062e-03f, -2.467407834e-04f, +1.425595879e-03f, +5.712311871e-04f, -5.553009320e-04f, -3.541389831e-04f, +1.432933926e-04f,
- /* 20, 7 */ -1.098378936e-04f, +4.281848093e-04f, +4.859469205e-04f, -7.560724855e-04f, -1.366178446e-03f, +5.841984075e-04f, +2.419856400e-03f, +4.398300532e-04f, -2.821647705e-03f, -1.869277969e-03f, +2.075378006e-03f, +2.703022864e-03f, -6.636433018e-04f, -2.400806791e-03f, -4.147293943e-04f, +1.401840253e-03f, +6.643764801e-04f, -5.237957356e-04f, -3.918538488e-04f, +1.279149940e-04f,
- /* 20, 8 */ -1.279149940e-04f, +3.918538488e-04f, +5.237957356e-04f, -6.643764801e-04f, -1.401840253e-03f, +4.147293943e-04f, +2.400806791e-03f, +6.636433018e-04f, -2.703022864e-03f, -2.075378006e-03f, +1.869277969e-03f, +2.821647705e-03f, -4.398300532e-04f, -2.419856400e-03f, -5.841984075e-04f, +1.366178446e-03f, +7.560724855e-04f, -4.859469205e-04f, -4.281848093e-04f, +1.098378936e-04f,
- /* 20, 9 */ -1.432933926e-04f, +3.541389831e-04f, +5.553009320e-04f, -5.712311871e-04f, -1.425595879e-03f, +2.467407834e-04f, +2.364667062e-03f, +8.794550343e-04f, -2.566106310e-03f, -2.266058084e-03f, +1.649263420e-03f, +2.920935727e-03f, -2.096193816e-04f, -2.421333651e-03f, -7.538301290e-04f, +1.318519207e-03f, +8.454656803e-04f, -4.417988543e-04f, -4.626858369e-04f, +8.908584503e-05f,
- /* 20,10 */ -1.559797103e-04f, +3.154780847e-04f, +5.804781630e-04f, -4.774724341e-04f, -1.437633739e-03f, +8.150702581e-05f, +2.312047403e-03f, +1.085745014e-03f, -2.412078410e-03f, -2.439937364e-03f, +1.416952434e-03f, +2.999986642e-03f, +2.531308203e-05f, -2.404890527e-03f, -9.222740706e-04f, +1.258871974e-03f, +9.316921975e-04f, -3.914578654e-04f, -4.949070444e-04f, +6.571426612e-05f,
- /* 20,11 */ -1.660093790e-04f, +2.762968272e-04f, +5.994006494e-04f, -3.839113875e-04f, -1.438235101e-03f, -7.975052491e-05f, +2.243678681e-03f, +1.281088328e-03f, -2.242244162e-03f, -2.595770512e-03f, +1.174062761e-03f, +3.058053364e-03f, +2.632332411e-04f, -2.370318438e-03f, -1.088157908e-03f, +1.187349554e-03f, +1.013885501e-03f, -3.350936324e-04f, -5.243991976e-04f, +3.981122763e-05f,
- /* 20,12 */ -1.734448317e-04f, +2.370049292e-04f, +6.121962531e-04f, -2.913280278e-04f, -1.427769061e-03f, -2.358727957e-04f, +2.160404235e-03f, +1.464165902e-03f, -2.058021578e-03f, -2.732457430e-03f, +9.223980063e-04f, +3.094549152e-03f, +5.023622502e-04f, -2.317552276e-03f, -1.250098855e-03f, +1.104169932e-03f, +1.091184321e-03f, -2.729399910e-04f, -5.507184044e-04f, +1.149811868e-05f,
- /* 20,13 */ -1.783734753e-04f, +1.979927117e-04f, +6.190441221e-04f, -2.004651158e-04f, -1.406686835e-03f, -3.857714352e-04f, +2.063170847e-03f, +1.633773999e-03f, -1.860929207e-03f, -2.849051730e-03f, +6.638330580e-04f, +3.109053425e-03f, +7.408907618e-04f, -2.246673287e-03f, -1.406715362e-03f, +1.009657150e-03f, +1.162740775e-03f, -2.052951315e-04f, -5.734309365e-04f, -1.907003227e-05f,
- /* 20,14 */ -5.435082024e-04f, +1.596279961e-04f, +6.201709543e-04f, -1.120226944e-04f, -1.375515478e-03f, -5.284364506e-04f, +1.953018956e-03f, +1.788832610e-03f, -1.652572896e-03f, -2.944767882e-03f, +4.002989059e-04f, +3.101316201e-03f, +9.769935819e-04f, -2.157910711e-03f, -1.556639033e-03f, +9.042412445e-04f, +1.227728603e-03f, -1.325211661e-04f, -5.921181369e-04f, -5.170459821e-05f,
- /* 20,15 */ -1.824770389e-04f, +1.222533602e-04f, +6.158469302e-04f, -2.665316224e-05f, -1.334851066e-03f, -6.629429882e-04f, +1.831072241e-03f, +1.928392685e-03f, -1.434631920e-03f, -3.018986987e-03f, +1.337669627e-04f, +3.071261118e-03f, +1.208844608e-03f, -2.051642156e-03f, -1.698526656e-03f, +7.884572117e-04f, +1.285351444e-03f, -5.504304823e-05f, -6.063813654e-04f, -8.618377023e-05f,
- /* 20, 0 */ -2.034293425e-04f, +2.330977005e-04f, +6.663349221e-04f, -5.788237715e-04f, -1.543506114e-03f, +7.663264997e-04f, +2.637884518e-03f, -5.016073607e-04f, -3.414789539e-03f, -1.613262342e-04f, +3.393842146e-03f, +7.896927597e-04f, -2.589726790e-03f, -9.705894653e-04f, +1.498255744e-03f, +6.923557695e-04f, -6.435044748e-04f, -2.810018705e-04f, +2.009801156e-04f, +0.000000000e+00f,
- /* 20, 1 */ -6.015260759e-04f, +1.858917095e-04f, +6.809814437e-04f, -4.649883812e-04f, -1.572899641e-03f, +5.610647582e-04f, +2.661959816e-03f, -2.131645492e-04f, -3.406214168e-03f, -4.825221542e-04f, +3.343371924e-03f, +1.074767465e-03f, -2.517456780e-03f, -1.171859801e-03f, +1.437039798e-03f, +8.043742580e-04f, -6.123036842e-04f, -3.290468323e-04f, +1.953154138e-04f, -3.513221827e-04f,
- /* 20, 2 */ -1.932641301e-04f, +1.399021716e-04f, +6.877130848e-04f, -3.520154127e-04f, -1.586701669e-03f, +3.567578182e-04f, +2.662213263e-03f, +7.301175991e-05f, -3.368394423e-03f, -7.993627115e-04f, +3.263658730e-03f, +1.354174959e-03f, -2.421279702e-03f, -1.368123194e-03f, +1.359912061e-03f, +9.136368247e-04f, -5.726346524e-04f, -3.766412744e-04f, +1.862701081e-04f, +2.243392330e-05f,
- /* 20, 3 */ -1.771389305e-04f, +9.560377684e-05f, +6.868748812e-04f, -2.410152618e-04f, -1.585326694e-03f, +1.553000173e-04f, +2.639129491e-03f, +3.543525656e-04f, -3.301882608e-03f, -1.108991788e-03f, +3.155261081e-03f, +1.625281932e-03f, -2.301637793e-03f, -1.557365345e-03f, +1.267093119e-03f, +1.018881552e-03f, -5.244930508e-04f, -4.231658296e-04f, +1.737162070e-04f, +3.471505729e-05f,
- /* 20, 4 */ -1.604844080e-04f, +5.342390613e-05f, +6.788805869e-04f, -1.330327870e-04f, -1.569329509e-03f, -4.149146373e-05f, +2.593408320e-03f, +6.283684809e-04f, -3.207497769e-03f, -1.408623929e-03f, +3.019012048e-03f, +1.885504757e-03f, -2.159209806e-03f, -1.737592880e-03f, +1.158972903e-03f, +1.118840456e-03f, -4.679722330e-04f, -4.679795743e-04f, +1.575667726e-04f, +4.805250238e-05f,
- /* 20, 5 */ -1.435528424e-04f, +1.373966937e-05f, +6.642048742e-04f, -2.903827106e-05f, -1.539395067e-03f, -2.318933016e-04f, +2.525953799e-03f, +8.926733333e-04f, -3.086315860e-03f, -1.695571566e-03f, +2.856012327e-03f, +2.132335710e-03f, -1.994908019e-03f, -1.906854484e-03f, +1.036111434e-03f, +1.212253447e-03f, -4.032663270e-04f, -5.104270987e-04f, +1.377794601e-04f, +6.235351094e-05f,
- /* 20, 6 */ -1.265803873e-04f, -2.312428639e-05f, +6.433751213e-04f, +7.008046528e-05f, -1.496327216e-03f, -4.142913555e-04f, +2.437861323e-03f, +1.145006429e-03f, -2.939657349e-03f, -1.967271220e-03f, +2.667620552e-03f, +2.363368676e-03f, -1.809872756e-03f, -2.063262017e-03f, +8.992377119e-04f, +1.297882648e-03f, -3.306722314e-04f, -5.498460811e-04f, +1.143596169e-04f, +7.750368078e-05f,
- /* 20, 7 */ -1.097853637e-04f, -5.689720211e-05f, +6.169629011e-04f, +1.635247423e-04f, -1.441036462e-03f, -5.871944806e-04f, +2.330402993e-03f, +1.383253258e-03f, -2.769072436e-03f, -2.221308400e-03f, +2.455440941e-03f, +2.576324026e-03f, -1.605464444e-03f, -2.205011397e-03f, +7.492467105e-04f, +1.374526925e-03f, -2.505904541e-04f, -5.855752858e-04f, +8.736287854e-05f, +9.336686615e-05f,
- /* 20, 8 */ -9.336686615e-05f, -8.736287854e-05f, +5.855752858e-04f, +2.505904541e-04f, -1.374526925e-03f, -7.492467105e-04f, +2.205011397e-03f, +1.605464444e-03f, -2.576324026e-03f, -2.455440941e-03f, +2.221308400e-03f, +2.769072436e-03f, -1.383253258e-03f, -2.330402993e-03f, +5.871944806e-04f, +1.441036462e-03f, -1.635247423e-04f, -6.169629011e-04f, +5.689720211e-05f, +1.097853637e-04f,
- /* 20, 9 */ -7.750368078e-05f, -1.143596169e-04f, +5.498460811e-04f, +3.306722314e-04f, -1.297882648e-03f, -8.992377119e-04f, +2.063262017e-03f, +1.809872756e-03f, -2.363368676e-03f, -2.667620552e-03f, +1.967271220e-03f, +2.939657349e-03f, -1.145006429e-03f, -2.437861323e-03f, +4.142913555e-04f, +1.496327216e-03f, -7.008046528e-05f, -6.433751213e-04f, +2.312428639e-05f, +1.265803873e-04f,
- /* 20,10 */ -6.235351094e-05f, -1.377794601e-04f, +5.104270987e-04f, +4.032663270e-04f, -1.212253447e-03f, -1.036111434e-03f, +1.906854484e-03f, +1.994908019e-03f, -2.132335710e-03f, -2.856012327e-03f, +1.695571566e-03f, +3.086315860e-03f, -8.926733333e-04f, -2.525953799e-03f, +2.318933016e-04f, +1.539395067e-03f, +2.903827106e-05f, -6.642048742e-04f, -1.373966937e-05f, +1.435528424e-04f,
- /* 20,11 */ -4.805250238e-05f, -1.575667726e-04f, +4.679795743e-04f, +4.679722330e-04f, -1.118840456e-03f, -1.158972903e-03f, +1.737592880e-03f, +2.159209806e-03f, -1.885504757e-03f, -3.019012048e-03f, +1.408623929e-03f, +3.207497769e-03f, -6.283684809e-04f, -2.593408320e-03f, +4.149146373e-05f, +1.569329509e-03f, +1.330327870e-04f, -6.788805869e-04f, -5.342390613e-05f, +1.604844080e-04f,
- /* 20,12 */ -3.471505729e-05f, -1.737162070e-04f, +4.231658296e-04f, +5.244930508e-04f, -1.018881552e-03f, -1.267093119e-03f, +1.557365345e-03f, +2.301637793e-03f, -1.625281932e-03f, -3.155261081e-03f, +1.108991788e-03f, +3.301882608e-03f, -3.543525656e-04f, -2.639129491e-03f, -1.553000173e-04f, +1.585326694e-03f, +2.410152618e-04f, -6.868748812e-04f, -9.560377684e-05f, +1.771389305e-04f,
- /* 20,13 */ -2.243392330e-05f, -1.862701081e-04f, +3.766412744e-04f, +5.726346524e-04f, -9.136368247e-04f, -1.359912061e-03f, +1.368123194e-03f, +2.421279702e-03f, -1.354174959e-03f, -3.263658730e-03f, +7.993627115e-04f, +3.368394423e-03f, -7.301175991e-05f, -2.662213263e-03f, -3.567578182e-04f, +1.586701669e-03f, +3.520154127e-04f, -6.877130848e-04f, -1.399021716e-04f, +1.932641301e-04f,
- /* 20,14 */ +3.513221827e-04f, -1.953154138e-04f, +3.290468323e-04f, +6.123036842e-04f, -8.043742580e-04f, -1.437039798e-03f, +1.171859801e-03f, +2.517456780e-03f, -1.074767465e-03f, -3.343371924e-03f, +4.825221542e-04f, +3.406214168e-03f, +2.131645492e-04f, -2.661959816e-03f, -5.610647582e-04f, +1.572899641e-03f, +4.649883812e-04f, -6.809814437e-04f, -1.858917095e-04f, +6.015260759e-04f,
- /* 20,15 */ +0.000000000e+00f, -2.009801156e-04f, +2.810018705e-04f, +6.435044748e-04f, -6.923557695e-04f, -1.498255744e-03f, +9.705894653e-04f, +2.589726790e-03f, -7.896927597e-04f, -3.393842146e-03f, +1.613262342e-04f, +3.414789539e-03f, +5.016073607e-04f, -2.637884518e-03f, -7.663264997e-04f, +1.543506114e-03f, +5.788237715e-04f, -6.663349221e-04f, -2.330977005e-04f, +2.034293425e-04f,
- /* 20, 0 */ -1.941987182e-05f, -3.146481294e-04f, +5.561305343e-04f, +3.334278991e-04f, -1.561489082e-03f, -4.085266513e-04f, +2.806699025e-03f, +3.580334706e-04f, -3.695826941e-03f, -1.914605051e-04f, +3.720952014e-03f, -2.295171057e-05f, -2.868623587e-03f, +1.886978960e-04f, +1.629573547e-03f, -2.343761763e-04f, -6.035407960e-04f, +1.633790229e-04f, +3.476344875e-05f, +0.000000000e+00f,
- /* 20, 1 */ +3.929324583e-04f, -3.051602666e-04f, +5.048306585e-04f, +4.229644027e-04f, -1.479104632e-03f, -6.165003319e-04f, +2.717079427e-03f, +6.839596419e-04f, -3.633185574e-03f, -5.723309145e-04f, +3.708003841e-03f, +3.177599071e-04f, -2.901501717e-03f, -4.082823094e-05f, +1.681921685e-03f, -1.265851889e-04f, -6.461214422e-04f, +1.369921977e-04f, +5.166761157e-05f, +0.000000000e+00f,
- /* 20, 2 */ +0.000000000e+00f, -2.925136688e-04f, +4.505823818e-04f, +5.023683161e-04f, -1.383975926e-03f, -8.106644739e-04f, +2.601403151e-03f, +9.973590062e-04f, -3.534000256e-03f, -9.470733637e-04f, +3.656850180e-03f, +6.604608766e-04f, -2.904291326e-03f, -2.777120434e-04f, +1.717239595e-03f, -1.098579054e-05f, -6.829477483e-04f, +1.058859702e-04f, +7.000071077e-05f, +0.000000000e+00f,
- /* 20, 3 */ +0.000000000e+00f, -2.771727451e-04f, +3.943146848e-04f, +5.711822345e-04f, -1.277754215e-03f, -9.892860040e-04f, +2.461570058e-03f, +1.295052213e-03f, -3.399644449e-03f, -1.311681723e-03f, +3.567787737e-03f, +1.001437562e-03f, -2.876278542e-03f, -5.194560271e-04f, +1.734397724e-03f, +1.113422841e-04f, -7.131247677e-04f, +7.019384523e-05f, +8.959420873e-05f, +0.000000000e+00f,
- /* 20, 4 */ +0.000000000e+00f, -2.596009711e-04f, +3.369316672e-04f, +6.291078651e-04f, -1.162161945e-03f, -1.150868125e-03f, +2.299713337e-03f, +1.574086312e-03f, -3.231873732e-03f, -1.662267592e-03f, +3.441541225e-03f, +1.336946247e-03f, -2.817092852e-03f, -7.634316403e-04f, +1.732451285e-03f, +2.391787684e-04f, -7.358020638e-04f, +3.013243736e-05f, +1.102423612e-04f, +0.000000000e+00f,
- /* 20, 5 */ +0.000000000e+00f, -2.402546692e-04f, +2.793008459e-04f, +6.760030262e-04f, -1.038968304e-03f, -1.294161821e-03f, +2.118169008e-03f, +1.831766066e-03f, -3.032802328e-03f, -1.995105343e-03f, +3.279257242e-03f, +1.663257052e-03f, -2.726718246e-03f, -1.006908470e-03f, +1.710658870e-03f, +3.711735089e-04f, -7.501884622e-04f, -1.399708473e-05f, +1.317024534e-04f, +0.000000000e+00f,
- /* 20, 6 */ +0.000000000e+00f, -2.195772899e-04f, +2.222425350e-04f, +7.118766228e-04f, -9.099649801e-04f, -1.418173917e-03f, +1.919443545e-03f, +2.065681697e-03f, -2.804875489e-03f, -2.306675131e-03f, +3.082493013e-03f, +1.976698190e-03f, -2.605500127e-03f, -1.247085413e-03f, +1.668498942e-03f, +5.058593370e-04f, -7.555665992e-04f, -6.180883712e-05f, +1.536956226e-04f, +0.000000000e+00f,
- /* 20, 7 */ +0.000000000e+00f, -1.979942392e-04f, +1.665204182e-04f, +7.368817426e-04f, -7.769424426e-04f, -1.522171671e-03f, +1.706180058e-03f, +2.273732749e-03f, -2.550838108e-03f, -2.593703365e-03f, +2.853200114e-03f, +2.273699984e-03f, -2.454147846e-03f, -1.481123511e-03f, +1.605683934e-03f, +6.416670612e-04f, -7.513070408e-04f, -1.128334053e-04f, +1.759082929e-04f, +0.000000000e+00f,
- /* 20, 8 */ +0.000000000e+00f, -1.759082929e-04f, +1.128334053e-04f, +7.513070408e-04f, -6.416670612e-04f, -1.605683934e-03f, +1.481123511e-03f, +2.454147846e-03f, -2.273699984e-03f, -2.853200114e-03f, +2.593703365e-03f, +2.550838108e-03f, -2.273732749e-03f, -1.706180058e-03f, +1.522171671e-03f, +7.769424426e-04f, -7.368817426e-04f, -1.665204182e-04f, +1.979942392e-04f, +0.000000000e+00f,
- /* 20, 9 */ +0.000000000e+00f, -1.536956226e-04f, +6.180883712e-05f, +7.555665992e-04f, -5.058593370e-04f, -1.668498942e-03f, +1.247085413e-03f, +2.605500127e-03f, -1.976698190e-03f, -3.082493013e-03f, +2.306675131e-03f, +2.804875489e-03f, -2.065681697e-03f, -1.919443545e-03f, +1.418173917e-03f, +9.099649801e-04f, -7.118766228e-04f, -2.222425350e-04f, +2.195772899e-04f, +0.000000000e+00f,
- /* 20,10 */ +0.000000000e+00f, -1.317024534e-04f, +1.399708473e-05f, +7.501884622e-04f, -3.711735089e-04f, -1.710658870e-03f, +1.006908470e-03f, +2.726718246e-03f, -1.663257052e-03f, -3.279257242e-03f, +1.995105343e-03f, +3.032802328e-03f, -1.831766066e-03f, -2.118169008e-03f, +1.294161821e-03f, +1.038968304e-03f, -6.760030262e-04f, -2.793008459e-04f, +2.402546692e-04f, +0.000000000e+00f,
- /* 20,11 */ +0.000000000e+00f, -1.102423612e-04f, -3.013243736e-05f, +7.358020638e-04f, -2.391787684e-04f, -1.732451285e-03f, +7.634316403e-04f, +2.817092852e-03f, -1.336946247e-03f, -3.441541225e-03f, +1.662267592e-03f, +3.231873732e-03f, -1.574086312e-03f, -2.299713337e-03f, +1.150868125e-03f, +1.162161945e-03f, -6.291078651e-04f, -3.369316672e-04f, +2.596009711e-04f, +0.000000000e+00f,
- /* 20,12 */ +0.000000000e+00f, -8.959420873e-05f, -7.019384523e-05f, +7.131247677e-04f, -1.113422841e-04f, -1.734397724e-03f, +5.194560271e-04f, +2.876278542e-03f, -1.001437562e-03f, -3.567787737e-03f, +1.311681723e-03f, +3.399644449e-03f, -1.295052213e-03f, -2.461570058e-03f, +9.892860040e-04f, +1.277754215e-03f, -5.711822345e-04f, -3.943146848e-04f, +2.771727451e-04f, +0.000000000e+00f,
- /* 20,13 */ +0.000000000e+00f, -7.000071077e-05f, -1.058859702e-04f, +6.829477483e-04f, +1.098579054e-05f, -1.717239595e-03f, +2.777120434e-04f, +2.904291326e-03f, -6.604608766e-04f, -3.656850180e-03f, +9.470733637e-04f, +3.534000256e-03f, -9.973590062e-04f, -2.601403151e-03f, +8.106644739e-04f, +1.383975926e-03f, -5.023683161e-04f, -4.505823818e-04f, +2.925136688e-04f, +0.000000000e+00f,
- /* 20,14 */ +0.000000000e+00f, -5.166761157e-05f, -1.369921977e-04f, +6.461214422e-04f, +1.265851889e-04f, -1.681921685e-03f, +4.082823094e-05f, +2.901501717e-03f, -3.177599071e-04f, -3.708003841e-03f, +5.723309145e-04f, +3.633185574e-03f, -6.839596419e-04f, -2.717079427e-03f, +6.165003319e-04f, +1.479104632e-03f, -4.229644027e-04f, -5.048306585e-04f, +3.051602666e-04f, -3.929324583e-04f,
- /* 20,15 */ +0.000000000e+00f, -3.476344875e-05f, -1.633790229e-04f, +6.035407960e-04f, +2.343761763e-04f, -1.629573547e-03f, -1.886978960e-04f, +2.868623587e-03f, +2.295171057e-05f, -3.720952014e-03f, +1.914605051e-04f, +3.695826941e-03f, -3.580334706e-04f, -2.806699025e-03f, +4.085266513e-04f, +1.561489082e-03f, -3.334278991e-04f, -5.561305343e-04f, +3.146481294e-04f, +1.941987182e-05f,
- /* 16, 0 */ +5.220390682e-05f, +8.171943113e-04f, -8.986497643e-04f, -1.446340428e-03f, +2.494478678e-03f, +1.297377101e-03f, -3.898391184e-03f, -2.241676001e-04f, +3.985236927e-03f, -9.413140896e-04f, -2.682700956e-03f, +1.283836927e-03f, +1.053222343e-03f, -7.989322796e-04f, -1.116939505e-04f, +1.571395541e-04f,
- /* 16, 1 */ -3.017522584e-06f, +8.224554322e-04f, -7.403312787e-04f, -1.584058293e-03f, +2.281207335e-03f, +1.631019258e-03f, -3.765802305e-03f, -6.696927435e-04f, +4.024834602e-03f, -5.670028406e-04f, -2.842687093e-03f, +1.097826180e-03f, +1.201600277e-03f, -7.671194843e-04f, -1.747127487e-04f, +1.853334990e-04f,
- /* 16, 2 */ -5.335264618e-05f, +8.154372286e-04f, -5.806604605e-04f, -1.696100138e-03f, +2.046328714e-03f, +1.938434809e-03f, -3.589560871e-03f, -1.106825943e-03f, +4.016290169e-03f, -1.789305351e-04f, -2.971556495e-03f, +8.899684644e-04f, +1.341315594e-03f, -7.213960065e-04f, -2.404043435e-04f, +2.137577131e-04f,
- /* 16, 3 */ -9.830954357e-05f, +7.970128377e-04f, -4.219420013e-04f, -1.781963746e-03f, +1.793485018e-03f, +2.216231187e-03f, -3.372309802e-03f, -1.530099436e-03f, +3.959337237e-03f, +2.181586899e-04f, -3.066783450e-03f, +6.622938144e-04f, +1.469918710e-03f, -6.616076810e-04f, -3.078052257e-04f, +7.052925564e-04f,
- /* 16, 4 */ -1.375232535e-04f, +7.681852053e-04f, -2.663606532e-04f, -1.841529450e-03f, +1.526462906e-03f, +2.461468734e-03f, -3.117203525e-03f, -1.934233820e-03f, +3.854345030e-03f, +6.193258599e-04f, -3.126241364e-03f, +4.171838871e-04f, +1.585017189e-03f, -5.878191605e-04f, -3.758553213e-04f, +2.457392598e-04f,
- /* 16, 5 */ -1.707546409e-04f, +7.300642099e-04f, -1.159532388e-04f, -1.875048978e-03f, +1.249136740e-03f, +2.671693350e-03f, -2.827860277e-03f, -2.314209556e-03f, +3.702317390e-03f, +1.019502933e-03f, -3.148242059e-03f, +1.573479538e-04f, +1.684315055e-03f, -5.003238841e-04f, -4.434113338e-04f, +2.470336005e-04f,
- /* 16, 6 */ -1.978870754e-04f, +6.838430878e-04f, +2.741593655e-05f, -1.883129095e-03f, +9.654119112e-04f, +2.844961691e-03f, -2.508308289e-03f, -2.665334690e-03f, +3.504882792e-03f, +1.413561295e-03f, -3.131569469e-03f, -1.142067707e-04f, +1.765652028e-03f, -3.996506493e-04f, -5.092623113e-04f, +2.432370997e-04f,
- /* 16, 7 */ -2.189210857e-04f, +6.307745862e-04f, +1.620759979e-04f, -1.866710442e-03f, +6.791690772e-04f, +2.979858667e-03f, -2.162926680e-03f, -2.983307830e-03f, +3.264275462e-03f, +1.796381989e-03f, -3.075507089e-03f, -3.942101476e-04f, +1.827042047e-03f, -2.865665382e-04f, -5.721472605e-04f, +2.339671870e-04f,
- /* 16, 8 */ -2.339671870e-04f, +5.721472605e-04f, +2.865665382e-04f, -1.827042047e-03f, +3.942101476e-04f, +3.075507089e-03f, -1.796381989e-03f, -3.264275462e-03f, +2.983307830e-03f, +2.162926680e-03f, -2.979858667e-03f, -6.791690772e-04f, +1.866710442e-03f, -1.620759979e-04f, -6.307745862e-04f, +2.189210857e-04f,
- /* 16, 9 */ -2.432370997e-04f, +5.092623113e-04f, +3.996506493e-04f, -1.765652028e-03f, +1.142067707e-04f, +3.131569469e-03f, -1.413561295e-03f, -3.504882792e-03f, +2.665334690e-03f, +2.508308289e-03f, -2.844961691e-03f, -9.654119112e-04f, +1.883129095e-03f, -2.741593655e-05f, -6.838430878e-04f, +1.978870754e-04f,
- /* 16,10 */ -2.470336005e-04f, +4.434113338e-04f, +5.003238841e-04f, -1.684315055e-03f, -1.573479538e-04f, +3.148242059e-03f, -1.019502933e-03f, -3.702317390e-03f, +2.314209556e-03f, +2.827860277e-03f, -2.671693350e-03f, -1.249136740e-03f, +1.875048978e-03f, +1.159532388e-04f, -7.300642099e-04f, +1.707546409e-04f,
- /* 16,11 */ -2.457392598e-04f, +3.758553213e-04f, +5.878191605e-04f, -1.585017189e-03f, -4.171838871e-04f, +3.126241364e-03f, -6.193258599e-04f, -3.854345030e-03f, +1.934233820e-03f, +3.117203525e-03f, -2.461468734e-03f, -1.526462906e-03f, +1.841529450e-03f, +2.663606532e-04f, -7.681852053e-04f, +1.375232535e-04f,
- /* 16,12 */ -7.052925564e-04f, +3.078052257e-04f, +6.616076810e-04f, -1.469918710e-03f, -6.622938144e-04f, +3.066783450e-03f, -2.181586899e-04f, -3.959337237e-03f, +1.530099436e-03f, +3.372309802e-03f, -2.216231187e-03f, -1.793485018e-03f, +1.781963746e-03f, +4.219420013e-04f, -7.970128377e-04f, +9.830954357e-05f,
- /* 16,13 */ -2.137577131e-04f, +2.404043435e-04f, +7.213960065e-04f, -1.341315594e-03f, -8.899684644e-04f, +2.971556495e-03f, +1.789305351e-04f, -4.016290169e-03f, +1.106825943e-03f, +3.589560871e-03f, -1.938434809e-03f, -2.046328714e-03f, +1.696100138e-03f, +5.806604605e-04f, -8.154372286e-04f, +5.335264618e-05f,
- /* 16,14 */ -1.853334990e-04f, +1.747127487e-04f, +7.671194843e-04f, -1.201600277e-03f, -1.097826180e-03f, +2.842687093e-03f, +5.670028406e-04f, -4.024834602e-03f, +6.696927435e-04f, +3.765802305e-03f, -1.631019258e-03f, -2.281207335e-03f, +1.584058293e-03f, +7.403312787e-04f, -8.224554322e-04f, +3.017522584e-06f,
- /* 16,15 */ -1.571395541e-04f, +1.116939505e-04f, +7.989322796e-04f, -1.053222343e-03f, -1.283836927e-03f, +2.682700956e-03f, +9.413140896e-04f, -3.985236927e-03f, +2.241676001e-04f, +3.898391184e-03f, -1.297377101e-03f, -2.494478678e-03f, +1.446340428e-03f, +8.986497643e-04f, -8.171943113e-04f, -5.220390682e-05f,
- /* 16, 0 */ -2.607744081e-04f, +6.609893225e-04f, +4.777614003e-05f, -2.019079564e-03f, +1.736921610e-03f, +2.230081148e-03f, -4.008512761e-03f, -2.594451583e-04f, +4.172957467e-03f, -1.888269495e-03f, -2.040920379e-03f, +1.975903291e-03f, +1.180452271e-04f, -7.248571600e-04f, +2.468008838e-04f, +0.000000000e+00f,
- /* 16, 1 */ -2.676863913e-04f, +5.906930705e-04f, +2.025069901e-04f, -2.030408814e-03f, +1.418499470e-03f, +2.533235894e-03f, -3.790472440e-03f, -7.745724648e-04f, +4.280846994e-03f, -1.512096765e-03f, -2.325335551e-03f, +1.900137256e-03f, +2.927280105e-04f, -7.805529904e-04f, +2.254162899e-04f, +0.000000000e+00f,
- /* 16, 2 */ -2.680102581e-04f, +5.157202047e-04f, +3.442245196e-04f, -2.011119828e-03f, +1.090886046e-03f, +2.794113365e-03f, -3.522578151e-03f, -1.278469954e-03f, +4.330057965e-03f, -1.106477171e-03f, -2.585166870e-03f, +1.791556445e-03f, +4.737630093e-04f, -8.263772041e-04f, +1.964117366e-04f, +0.000000000e+00f,
- /* 16, 3 */ -7.633646088e-04f, +4.377966605e-04f, +4.713317060e-04f, -1.962888420e-03f, +7.592982470e-04f, +3.009813640e-03f, -3.209287239e-03f, -1.763847458e-03f, +4.319343992e-03f, -6.768749158e-04f, -2.815661672e-03f, +1.650477084e-03f, +6.583936022e-04f, -8.607109932e-04f, +1.597335965e-04f, -4.634120047e-04f,
- /* 16, 4 */ -2.423668462e-04f, +3.585907293e-04f, +5.825699836e-04f, -1.887792011e-03f, +4.288533077e-04f, +3.178189562e-03f, -2.855695312e-03f, -2.223705909e-03f, +4.248362401e-03f, -2.292254995e-04f, -3.012400483e-03f, +1.477771292e-03f, +8.436545409e-04f, -8.820535056e-04f, +1.154955663e-04f, +2.338334874e-05f,
- /* 16, 5 */ -2.066858426e-04f, +2.796840991e-04f, +6.770251471e-04f, -1.788258811e-03f, +1.044882353e-04f, +3.297866045e-03f, -2.467449129e-03f, -2.651446905e-03f, +4.117686315e-03f, +2.301520823e-04f, -3.171379014e-03f, +1.274872332e-03f, +1.026416356e-03f, -8.890585891e-04f, +6.398775754e-05f, +4.782938304e-05f,
- /* 16, 6 */ -1.715009195e-04f, +2.025461567e-04f, +7.541266524e-04f, -1.667012713e-03f, -2.091154912e-04f, +3.368246274e-03f, -2.050651409e-03f, -3.040975547e-03f, +3.928801804e-03f, +6.946508648e-04f, -3.289085050e-03f, +1.043770075e-03f, +1.203434747e-03f, -8.805703554e-04f, +5.682450650e-06f, +7.520965874e-05f,
- /* 16, 7 */ -1.374865801e-04f, +1.285119093e-04f, +8.136405975e-04f, -1.527015027e-03f, -5.076007987e-04f, +3.389504923e-03f, -1.611759203e-03f, -3.386794836e-03f, +3.684090065e-03f, +1.157477637e-03f, -3.362568736e-03f, +7.869964389e-04f, +1.371404208e-03f, -8.556567843e-04f, -5.876379361e-05f, +1.052264476e-04f,
- /* 16, 8 */ -1.052264476e-04f, +5.876379361e-05f, +8.556567843e-04f, -1.371404208e-03f, -7.869964389e-04f, +3.362568736e-03f, -1.157477637e-03f, -3.684090065e-03f, +3.386794836e-03f, +1.611759203e-03f, -3.389504923e-03f, +5.076007987e-04f, +1.527015027e-03f, -8.136405975e-04f, -1.285119093e-04f, +1.374865801e-04f,
- /* 16, 9 */ -7.520965874e-05f, -5.682450650e-06f, +8.805703554e-04f, -1.203434747e-03f, -1.043770075e-03f, +3.289085050e-03f, -6.946508648e-04f, -3.928801804e-03f, +3.040975547e-03f, +2.050651409e-03f, -3.368246274e-03f, +2.091154912e-04f, +1.667012713e-03f, -7.541266524e-04f, -2.025461567e-04f, +1.715009195e-04f,
- /* 16,10 */ -4.782938304e-05f, -6.398775754e-05f, +8.890585891e-04f, -1.026416356e-03f, -1.274872332e-03f, +3.171379014e-03f, -2.301520823e-04f, -4.117686315e-03f, +2.651446905e-03f, +2.467449129e-03f, -3.297866045e-03f, -1.044882353e-04f, +1.788258811e-03f, -6.770251471e-04f, -2.796840991e-04f, +2.066858426e-04f,
- /* 16,11 */ -2.338334874e-05f, -1.154955663e-04f, +8.820535056e-04f, -8.436545409e-04f, -1.477771292e-03f, +3.012400483e-03f, +2.292254995e-04f, -4.248362401e-03f, +2.223705909e-03f, +2.855695312e-03f, -3.178189562e-03f, -4.288533077e-04f, +1.887792011e-03f, -5.825699836e-04f, -3.585907293e-04f, +2.423668462e-04f,
- /* 16,12 */ +4.634120047e-04f, -1.597335965e-04f, +8.607109932e-04f, -6.583936022e-04f, -1.650477084e-03f, +2.815661672e-03f, +6.768749158e-04f, -4.319343992e-03f, +1.763847458e-03f, +3.209287239e-03f, -3.009813640e-03f, -7.592982470e-04f, +1.962888420e-03f, -4.713317060e-04f, -4.377966605e-04f, +7.633646088e-04f,
- /* 16,13 */ +0.000000000e+00f, -1.964117366e-04f, +8.263772041e-04f, -4.737630093e-04f, -1.791556445e-03f, +2.585166870e-03f, +1.106477171e-03f, -4.330057965e-03f, +1.278469954e-03f, +3.522578151e-03f, -2.794113365e-03f, -1.090886046e-03f, +2.011119828e-03f, -3.442245196e-04f, -5.157202047e-04f, +2.680102581e-04f,
- /* 16,14 */ +0.000000000e+00f, -2.254162899e-04f, +7.805529904e-04f, -2.927280105e-04f, -1.900137256e-03f, +2.325335551e-03f, +1.512096765e-03f, -4.280846994e-03f, +7.745724648e-04f, +3.790472440e-03f, -2.533235894e-03f, -1.418499470e-03f, +2.030408814e-03f, -2.025069901e-04f, -5.906930705e-04f, +2.676863913e-04f,
- /* 16,15 */ +0.000000000e+00f, -2.468008838e-04f, +7.248571600e-04f, -1.180452271e-04f, -1.975903291e-03f, +2.040920379e-03f, +1.888269495e-03f, -4.172957467e-03f, +2.594451583e-04f, +4.008512761e-03f, -2.230081148e-03f, -1.736921610e-03f, +2.019079564e-03f, -4.777614003e-05f, -6.609893225e-04f, +2.607744081e-04f,
- /* 16, 0 */ -1.129954761e-04f, -3.969443331e-04f, +7.863457700e-04f, -1.968627401e-03f, +6.635626436e-04f, +3.065104554e-03f, -4.014723865e-03f, -2.972906332e-04f, +4.272130602e-03f, -2.778972616e-03f, -1.044103847e-03f, +2.069667087e-03f, -6.906315332e-04f, -2.376896670e-04f, +1.523656204e-04f, +0.000000000e+00f,
- /* 16, 1 */ -7.672972562e-05f, -4.458313625e-04f, +8.604609066e-04f, -1.839340292e-03f, +2.869810557e-04f, +3.294943885e-03f, -3.696990655e-03f, -8.869321804e-04f, +4.464175630e-03f, -2.440111513e-03f, -1.421957113e-03f, +2.139058837e-03f, -5.737860098e-04f, -3.273087897e-04f, +1.941703587e-04f, +0.000000000e+00f,
- /* 16, 2 */ -4.409159553e-05f, -4.801879450e-04f, +9.129725459e-04f, -1.685578963e-03f, -7.929130936e-05f, +3.465994861e-03f, -3.324955442e-03f, -1.461843594e-03f, +4.586914931e-03f, -2.053108579e-03f, -1.790295465e-03f, +2.173860444e-03f, -4.367566844e-04f, -4.185294039e-04f, +2.375950982e-04f, +0.000000000e+00f,
- /* 16, 3 */ +4.855802427e-04f, -5.008892512e-04f, +9.443143993e-04f, -1.511399569e-03f, -4.293120730e-04f, +3.576852207e-03f, -2.905512498e-03f, -2.012499819e-03f, +4.637578076e-03f, -1.623510702e-03f, -2.142238116e-03f, +2.171667537e-03f, -2.809771210e-04f, -5.093533546e-04f, +2.816859426e-04f, +0.000000000e+00f,
- /* 16, 4 */ +0.000000000e+00f, -5.090007623e-04f, +9.553248878e-04f, -1.321049384e-03f, -7.576441950e-04f, +3.627202827e-03f, -2.446291464e-03f, -2.529812382e-03f, +4.614629236e-03f, -1.157740361e-03f, -2.470980778e-03f, +2.130685105e-03f, -1.083629217e-04f, -5.976383603e-04f, +3.253590588e-04f, +0.000000000e+00f,
- /* 16, 5 */ +0.000000000e+00f, -5.057402285e-04f, +9.472067544e-04f, -1.118874842e-03f, -1.059441268e-03f, +3.617806804e-03f, -1.955510679e-03f, -3.005292216e-03f, +4.517805471e-03f, -6.629933593e-04f, -2.769928158e-03f, +2.049789183e-03f, +7.870314989e-05f, -6.811391839e-04f, +3.674140144e-04f, +0.000000000e+00f,
- /* 16, 6 */ +0.000000000e+00f, -4.924395299e-04f, +9.214808972e-04f, -9.092313688e-04f, -1.330518654e-03f, +3.550458465e-03f, -1.441821213e-03f, -3.431200966e-03f, +4.348131386e-03f, -1.471199733e-04f, -3.032825993e-03f, +1.928577081e-03f, +2.773970394e-04f, -7.575537377e-04f, +4.065510896e-04f, +0.000000000e+00f,
- /* 16, 7 */ +0.000000000e+00f, -4.705072223e-04f, +8.799357120e-04f, -6.963968181e-04f, -1.567409460e-03f, +3.427928686e-03f, -9.141447359e-04f, -3.800687882e-03f, +4.107909720e-03f, +3.815084058e-04f, -3.253889950e-03f, +1.767404663e-03f, +4.844901765e-04f, -8.245732787e-04f, +4.413924818e-04f, +0.000000000e+00f,
- /* 16, 8 */ +0.000000000e+00f, -4.413924818e-04f, +8.245732787e-04f, -4.844901765e-04f, -1.767404663e-03f, +3.253889950e-03f, -3.815084058e-04f, -4.107909720e-03f, +3.800687882e-03f, +9.141447359e-04f, -3.427928686e-03f, +1.567409460e-03f, +6.963968181e-04f, -8.799357120e-04f, +4.705072223e-04f, +0.000000000e+00f,
- /* 16, 9 */ +0.000000000e+00f, -4.065510896e-04f, +7.575537377e-04f, -2.773970394e-04f, -1.928577081e-03f, +3.032825993e-03f, +1.471199733e-04f, -4.348131386e-03f, +3.431200966e-03f, +1.441821213e-03f, -3.550458465e-03f, +1.330518654e-03f, +9.092313688e-04f, -9.214808972e-04f, +4.924395299e-04f, +0.000000000e+00f,
- /* 16,10 */ +0.000000000e+00f, -3.674140144e-04f, +6.811391839e-04f, -7.870314989e-05f, -2.049789183e-03f, +2.769928158e-03f, +6.629933593e-04f, -4.517805471e-03f, +3.005292216e-03f, +1.955510679e-03f, -3.617806804e-03f, +1.059441268e-03f, +1.118874842e-03f, -9.472067544e-04f, +5.057402285e-04f, +0.000000000e+00f,
- /* 16,11 */ +0.000000000e+00f, -3.253590588e-04f, +5.976383603e-04f, +1.083629217e-04f, -2.130685105e-03f, +2.470980778e-03f, +1.157740361e-03f, -4.614629236e-03f, +2.529812382e-03f, +2.446291464e-03f, -3.627202827e-03f, +7.576441950e-04f, +1.321049384e-03f, -9.553248878e-04f, +5.090007623e-04f, +0.000000000e+00f,
- /* 16,12 */ +0.000000000e+00f, -2.816859426e-04f, +5.093533546e-04f, +2.809771210e-04f, -2.171667537e-03f, +2.142238116e-03f, +1.623510702e-03f, -4.637578076e-03f, +2.012499819e-03f, +2.905512498e-03f, -3.576852207e-03f, +4.293120730e-04f, +1.511399569e-03f, -9.443143993e-04f, +5.008892512e-04f, -4.855802427e-04f,
- /* 16,13 */ +0.000000000e+00f, -2.375950982e-04f, +4.185294039e-04f, +4.367566844e-04f, -2.173860444e-03f, +1.790295465e-03f, +2.053108579e-03f, -4.586914931e-03f, +1.461843594e-03f, +3.324955442e-03f, -3.465994861e-03f, +7.929130936e-05f, +1.685578963e-03f, -9.129725459e-04f, +4.801879450e-04f, +4.409159553e-05f,
- /* 16,14 */ +0.000000000e+00f, -1.941703587e-04f, +3.273087897e-04f, +5.737860098e-04f, -2.139058837e-03f, +1.421957113e-03f, +2.440111513e-03f, -4.464175630e-03f, +8.869321804e-04f, +3.696990655e-03f, -3.294943885e-03f, -2.869810557e-04f, +1.839340292e-03f, -8.604609066e-04f, +4.458313625e-04f, +7.672972562e-05f,
- /* 16,15 */ +0.000000000e+00f, -1.523656204e-04f, +2.376896670e-04f, +6.906315332e-04f, -2.069667087e-03f, +1.044103847e-03f, +2.778972616e-03f, -4.272130602e-03f, +2.972906332e-04f, +4.014723865e-03f, -3.065104554e-03f, -6.635626436e-04f, +1.968627401e-03f, -7.863457700e-04f, +3.969443331e-04f, +1.129954761e-04f,
- /* 12, 0 */ +1.006092301e-03f, -1.356592138e-03f, -5.291224839e-04f, +3.716365432e-03f, -3.908475818e-03f, -3.377012930e-04f, +4.272902045e-03f, -3.529241849e-03f, +1.347121185e-04f, +1.576582805e-03f, -1.021094463e-03f, +2.080147558e-04f,
- /* 12, 1 */ +9.703330579e-04f, -1.123568815e-03f, -8.960631472e-04f, +3.830455785e-03f, -3.478978472e-03f, -1.006731283e-03f, +4.564422369e-03f, -3.270752231e-03f, -2.802589631e-04f, +1.777910422e-03f, -1.013271813e-03f, +1.540375404e-04f,
- /* 12, 2 */ +9.162319547e-04f, -8.831264337e-04f, -1.229457804e-03f, +3.871345986e-03f, -2.993425932e-03f, -1.656773890e-03f, +4.776559314e-03f, -2.944064628e-03f, -7.081711396e-04f, +1.955059288e-03f, -9.809799530e-04f, +8.895597490e-05f,
- /* 12, 3 */ +8.464715149e-04f, -6.407365814e-04f, -1.524162434e-03f, +3.840336583e-03f, -2.461816027e-03f, -2.275602698e-03f, +4.904341682e-03f, -2.553815646e-03f, -1.140836495e-03f, +2.102763165e-03f, -9.230670815e-04f, +1.349777819e-05f,
- /* 12, 4 */ +7.639192828e-04f, -4.016125871e-04f, -1.776040886e-03f, +3.740131991e-03f, -1.894910812e-03f, -2.851629129e-03f, +4.944422783e-03f, -2.106045312e-03f, -1.569658753e-03f, +2.216140176e-03f, -8.389345160e-04f, -7.124952580e-05f,
- /* 12, 5 */ +6.715456333e-04f, -1.706046467e-04f, -1.982015497e-03f, +3.574748146e-03f, -1.304005398e-03f, -3.374137989e-03f, +4.895165032e-03f, -1.608099956e-03f, -1.985807614e-03f, +2.290824513e-03f, -7.285864297e-04f, -1.638417811e-04f,
- /* 12, 6 */ +5.723437636e-04f, +4.789167018e-05f, -2.140092391e-03f, +3.349394124e-03f, -7.006885404e-04f, -3.833503957e-03f, +4.756688774e-03f, -1.068504673e-03f, -2.380403858e-03f, +2.323091638e-03f, -5.926669574e-04f, -2.624916697e-04f,
- /* 12, 7 */ +4.692537952e-04f, +2.500119139e-04f, -2.249361715e-03f, +3.070330944e-03f, -9.660032268e-05f, -4.221384345e-03f, +4.530883988e-03f, -4.968076992e-04f, -2.744711242e-03f, +2.309973659e-03f, -4.324830696e-04f, -3.650927179e-04f,
- /* 12, 8 */ +3.650927179e-04f, +4.324830696e-04f, -2.309973659e-03f, +2.744711242e-03f, +4.968076992e-04f, -4.530883988e-03f, +4.221384345e-03f, +9.660032268e-05f, -3.070330944e-03f, +2.249361715e-03f, -2.500119139e-04f, -4.692537952e-04f,
- /* 12, 9 */ +2.624916697e-04f, +5.926669574e-04f, -2.323091638e-03f, +2.380403858e-03f, +1.068504673e-03f, -4.756688774e-03f, +3.833503957e-03f, +7.006885404e-04f, -3.349394124e-03f, +2.140092391e-03f, -4.789167018e-05f, -5.723437636e-04f,
- /* 12,10 */ +1.638417811e-04f, +7.285864297e-04f, -2.290824513e-03f, +1.985807614e-03f, +1.608099956e-03f, -4.895165032e-03f, +3.374137989e-03f, +1.304005398e-03f, -3.574748146e-03f, +1.982015497e-03f, +1.706046467e-04f, -6.715456333e-04f,
- /* 12,11 */ +7.124952580e-05f, +8.389345160e-04f, -2.216140176e-03f, +1.569658753e-03f, +2.106045312e-03f, -4.944422783e-03f, +2.851629129e-03f, +1.894910812e-03f, -3.740131991e-03f, +1.776040886e-03f, +4.016125871e-04f, -7.639192828e-04f,
- /* 12,12 */ -1.349777819e-05f, +9.230670815e-04f, -2.102763165e-03f, +1.140836495e-03f, +2.553815646e-03f, -4.904341682e-03f, +2.275602698e-03f, +2.461816027e-03f, -3.840336583e-03f, +1.524162434e-03f, +6.407365814e-04f, -8.464715149e-04f,
- /* 12,13 */ -8.895597490e-05f, +9.809799530e-04f, -1.955059288e-03f, +7.081711396e-04f, +2.944064628e-03f, -4.776559314e-03f, +1.656773890e-03f, +2.993425932e-03f, -3.871345986e-03f, +1.229457804e-03f, +8.831264337e-04f, -9.162319547e-04f,
- /* 12,14 */ -1.540375404e-04f, +1.013271813e-03f, -1.777910422e-03f, +2.802589631e-04f, +3.270752231e-03f, -4.564422369e-03f, +1.006731283e-03f, +3.478978472e-03f, -3.830455785e-03f, +8.960631472e-04f, +1.123568815e-03f, -9.703330579e-04f,
- /* 12,15 */ -2.080147558e-04f, +1.021094463e-03f, -1.576582805e-03f, -1.347121185e-04f, +3.529241849e-03f, -4.272902045e-03f, +3.377012930e-04f, +3.908475818e-03f, -3.716365432e-03f, +5.291224839e-04f, +1.356592138e-03f, -1.006092301e-03f,
- /* 12, 0 */ +7.165252154e-04f, -4.291307465e-04f, -1.619691310e-03f, +4.112050532e-03f, -3.684471854e-03f, -3.806742210e-04f, +4.167864669e-03f, -4.064044128e-03f, +1.285631838e-03f, +6.994376016e-04f, -8.205283947e-04f, +3.212754781e-04f,
- /* 12, 1 */ +6.042449626e-04f, -1.684748882e-04f, -1.902468489e-03f, +4.073990388e-03f, -3.134198780e-03f, -1.133926469e-03f, +4.572939653e-03f, -3.928365474e-03f, +9.055999228e-04f, +9.731965741e-04f, -9.124383184e-04f, +3.311614162e-04f,
- /* 12, 2 */ +4.874350434e-04f, +7.694308689e-05f, -2.130082097e-03f, +3.953363211e-03f, -2.529802622e-03f, -1.863076830e-03f, +4.889863669e-03f, -3.705392569e-03f, +4.862599326e-04f, +1.243729140e-03f, -9.884795125e-04f, +3.301883495e-04f,
- /* 12, 3 */ +3.696734183e-04f, +3.022578517e-04f, -2.300114973e-03f, +3.755428771e-03f, -1.885047396e-03f, -2.552675098e-03f, +5.110657479e-03f, -3.397530000e-03f, +3.551878686e-05f, +1.504029611e-03f, -1.045032679e-03f, +3.171093301e-04f,
- /* 12, 4 */ +2.542791637e-04f, +5.034105172e-04f, -2.411611526e-03f, +3.487034212e-03f, -1.214371318e-03f, -3.188181667e-03f, +5.229403271e-03f, -3.009202669e-03f, -4.376222644e-04f, +1.746934410e-03f, -1.078752986e-03f, +2.909691299e-04f,
- /* 12, 5 */ +1.442362351e-04f, +6.772076791e-04f, -2.465038541e-03f, +3.156407157e-03f, -5.325427440e-04f, -3.756300237e-03f, +5.242404627e-03f, -2.546799451e-03f, -9.232494237e-04f, +1.965304174e-03f, -1.086687765e-03f, +2.511615343e-04f,
- /* 12, 6 */ +4.213190220e-05f, +8.213542577e-04f, -2.462211671e-03f, +2.772920825e-03f, +1.456866600e-04f, -4.245279979e-03f, +5.148294544e-03f, -2.018567160e-03f, -1.410748009e-03f, +2.152214196e-03f, -1.066390037e-03f, +1.974793328e-04f,
- /* 12, 7 */ -4.988918599e-05f, +9.344605010e-04f, -2.406190818e-03f, +2.346837790e-03f, +8.059229054e-04f, -4.645179801e-03f, +4.948088353e-03f, -1.434456490e-03f, -1.889039390e-03f, +2.301148282e-03f, -1.016024228e-03f, +1.301548676e-04f,
- /* 12, 8 */ -1.301548676e-04f, +1.016024228e-03f, -2.301148282e-03f, +1.889039390e-03f, +1.434456490e-03f, -4.948088353e-03f, +4.645179801e-03f, -8.059229054e-04f, -2.346837790e-03f, +2.406190818e-03f, -9.344605010e-04f, +4.988918599e-05f,
- /* 12, 9 */ -1.974793328e-04f, +1.066390037e-03f, -2.152214196e-03f, +1.410748009e-03f, +2.018567160e-03f, -5.148294544e-03f, +4.245279979e-03f, -1.456866600e-04f, -2.772920825e-03f, +2.462211671e-03f, -8.213542577e-04f, -4.213190220e-05f,
- /* 12,10 */ -2.511615343e-04f, +1.086687765e-03f, -1.965304174e-03f, +9.232494237e-04f, +2.546799451e-03f, -5.242404627e-03f, +3.756300237e-03f, +5.325427440e-04f, -3.156407157e-03f, +2.465038541e-03f, -6.772076791e-04f, -1.442362351e-04f,
- /* 12,11 */ -2.909691299e-04f, +1.078752986e-03f, -1.746934410e-03f, +4.376222644e-04f, +3.009202669e-03f, -5.229403271e-03f, +3.188181667e-03f, +1.214371318e-03f, -3.487034212e-03f, +2.411611526e-03f, -5.034105172e-04f, -2.542791637e-04f,
- /* 12,12 */ -3.171093301e-04f, +1.045032679e-03f, -1.504029611e-03f, -3.551878686e-05f, +3.397530000e-03f, -5.110657479e-03f, +2.552675098e-03f, +1.885047396e-03f, -3.755428771e-03f, +2.300114973e-03f, -3.022578517e-04f, -3.696734183e-04f,
- /* 12,13 */ -3.301883495e-04f, +9.884795125e-04f, -1.243729140e-03f, -4.862599326e-04f, +3.705392569e-03f, -4.889863669e-03f, +1.863076830e-03f, +2.529802622e-03f, -3.953363211e-03f, +2.130082097e-03f, -7.694308689e-05f, -4.874350434e-04f,
- /* 12,14 */ -3.311614162e-04f, +9.124383184e-04f, -9.731965741e-04f, -9.055999228e-04f, +3.928365474e-03f, -4.572939653e-03f, +1.133926469e-03f, +3.134198780e-03f, -4.073990388e-03f, +1.902468489e-03f, +1.684748882e-04f, -6.042449626e-04f,
- /* 12,15 */ -3.212754781e-04f, +8.205283947e-04f, -6.994376016e-04f, -1.285631838e-03f, +4.064044128e-03f, -4.167864669e-03f, +3.806742210e-04f, +3.684471854e-03f, -4.112050532e-03f, +1.619691310e-03f, +4.291307465e-04f, -7.165252154e-04f
-};
diff --git a/Alc/compat.h b/Alc/compat.h
index f54ef9ce..495bfdf2 100644
--- a/Alc/compat.h
+++ b/Alc/compat.h
@@ -1,6 +1,12 @@
#ifndef AL_COMPAT_H
#define AL_COMPAT_H
+#include "alstring.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
@@ -23,10 +29,29 @@ FILE *al_fopen(const char *fname, const char *mode);
#endif
+struct FileMapping {
+#ifdef _WIN32
+ HANDLE file;
+ HANDLE fmap;
+#else
+ int fd;
+#endif
+ void *ptr;
+ size_t len;
+};
+struct FileMapping MapFileToMem(const char *fname);
+void UnmapFileMem(const struct FileMapping *mapping);
+
+void GetProcBinary(al_string *path, al_string *fname);
+
#ifdef HAVE_DYNLOAD
void *LoadLib(const char *name);
void CloseLib(void *handle);
void *GetSymbol(void *handle, const char *name);
#endif
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
#endif /* AL_COMPAT_H */
diff --git a/Alc/converter.c b/Alc/converter.c
new file mode 100644
index 00000000..ef2eb9af
--- /dev/null
+++ b/Alc/converter.c
@@ -0,0 +1,468 @@
+
+#include "config.h"
+
+#include "converter.h"
+
+#include "fpu_modes.h"
+#include "mixer/defs.h"
+
+
+SampleConverter *CreateSampleConverter(enum DevFmtType srcType, enum DevFmtType dstType, ALsizei numchans, ALsizei srcRate, ALsizei dstRate)
+{
+ SampleConverter *converter;
+ ALsizei step;
+
+ if(numchans <= 0 || srcRate <= 0 || dstRate <= 0)
+ return NULL;
+
+ converter = al_calloc(16, FAM_SIZE(SampleConverter, Chan, numchans));
+ converter->mSrcType = srcType;
+ converter->mDstType = dstType;
+ converter->mNumChannels = numchans;
+ converter->mSrcTypeSize = BytesFromDevFmt(srcType);
+ converter->mDstTypeSize = BytesFromDevFmt(dstType);
+
+ converter->mSrcPrepCount = 0;
+ converter->mFracOffset = 0;
+
+ /* Have to set the mixer FPU mode since that's what the resampler code expects. */
+ START_MIXER_MODE();
+ step = (ALsizei)mind(((ALdouble)srcRate/dstRate*FRACTIONONE) + 0.5,
+ MAX_PITCH * FRACTIONONE);
+ converter->mIncrement = maxi(step, 1);
+ if(converter->mIncrement == FRACTIONONE)
+ converter->mResample = Resample_copy_C;
+ else
+ {
+ /* TODO: Allow other resamplers. */
+ BsincPrepare(converter->mIncrement, &converter->mState.bsinc, &bsinc12);
+ converter->mResample = SelectResampler(BSinc12Resampler);
+ }
+ END_MIXER_MODE();
+
+ return converter;
+}
+
+void DestroySampleConverter(SampleConverter **converter)
+{
+ if(converter)
+ {
+ al_free(*converter);
+ *converter = NULL;
+ }
+}
+
+
+static inline ALfloat Sample_ALbyte(ALbyte val)
+{ return val * (1.0f/128.0f); }
+static inline ALfloat Sample_ALubyte(ALubyte val)
+{ return Sample_ALbyte((ALint)val - 128); }
+
+static inline ALfloat Sample_ALshort(ALshort val)
+{ return val * (1.0f/32768.0f); }
+static inline ALfloat Sample_ALushort(ALushort val)
+{ return Sample_ALshort((ALint)val - 32768); }
+
+static inline ALfloat Sample_ALint(ALint val)
+{ return (val>>7) * (1.0f/16777216.0f); }
+static inline ALfloat Sample_ALuint(ALuint val)
+{ return Sample_ALint(val - INT_MAX - 1); }
+
+static inline ALfloat Sample_ALfloat(ALfloat val)
+{ return val; }
+
+#define DECL_TEMPLATE(T) \
+static inline void Load_##T(ALfloat *restrict dst, const T *restrict src, \
+ ALint srcstep, ALsizei samples) \
+{ \
+ ALsizei i; \
+ for(i = 0;i < samples;i++) \
+ dst[i] = Sample_##T(src[i*srcstep]); \
+}
+
+DECL_TEMPLATE(ALbyte)
+DECL_TEMPLATE(ALubyte)
+DECL_TEMPLATE(ALshort)
+DECL_TEMPLATE(ALushort)
+DECL_TEMPLATE(ALint)
+DECL_TEMPLATE(ALuint)
+DECL_TEMPLATE(ALfloat)
+
+#undef DECL_TEMPLATE
+
+static void LoadSamples(ALfloat *dst, const ALvoid *src, ALint srcstep, enum DevFmtType srctype, ALsizei samples)
+{
+ switch(srctype)
+ {
+ case DevFmtByte:
+ Load_ALbyte(dst, src, srcstep, samples);
+ break;
+ case DevFmtUByte:
+ Load_ALubyte(dst, src, srcstep, samples);
+ break;
+ case DevFmtShort:
+ Load_ALshort(dst, src, srcstep, samples);
+ break;
+ case DevFmtUShort:
+ Load_ALushort(dst, src, srcstep, samples);
+ break;
+ case DevFmtInt:
+ Load_ALint(dst, src, srcstep, samples);
+ break;
+ case DevFmtUInt:
+ Load_ALuint(dst, src, srcstep, samples);
+ break;
+ case DevFmtFloat:
+ Load_ALfloat(dst, src, srcstep, samples);
+ break;
+ }
+}
+
+
+static inline ALbyte ALbyte_Sample(ALfloat val)
+{ return fastf2i(clampf(val*128.0f, -128.0f, 127.0f)); }
+static inline ALubyte ALubyte_Sample(ALfloat val)
+{ return ALbyte_Sample(val)+128; }
+
+static inline ALshort ALshort_Sample(ALfloat val)
+{ return fastf2i(clampf(val*32768.0f, -32768.0f, 32767.0f)); }
+static inline ALushort ALushort_Sample(ALfloat val)
+{ return ALshort_Sample(val)+32768; }
+
+static inline ALint ALint_Sample(ALfloat val)
+{ return fastf2i(clampf(val*16777216.0f, -16777216.0f, 16777215.0f)) << 7; }
+static inline ALuint ALuint_Sample(ALfloat val)
+{ return ALint_Sample(val)+INT_MAX+1; }
+
+static inline ALfloat ALfloat_Sample(ALfloat val)
+{ return val; }
+
+#define DECL_TEMPLATE(T) \
+static inline void Store_##T(T *restrict dst, const ALfloat *restrict src, \
+ ALint dststep, ALsizei samples) \
+{ \
+ ALsizei i; \
+ for(i = 0;i < samples;i++) \
+ dst[i*dststep] = T##_Sample(src[i]); \
+}
+
+DECL_TEMPLATE(ALbyte)
+DECL_TEMPLATE(ALubyte)
+DECL_TEMPLATE(ALshort)
+DECL_TEMPLATE(ALushort)
+DECL_TEMPLATE(ALint)
+DECL_TEMPLATE(ALuint)
+DECL_TEMPLATE(ALfloat)
+
+#undef DECL_TEMPLATE
+
+static void StoreSamples(ALvoid *dst, const ALfloat *src, ALint dststep, enum DevFmtType dsttype, ALsizei samples)
+{
+ switch(dsttype)
+ {
+ case DevFmtByte:
+ Store_ALbyte(dst, src, dststep, samples);
+ break;
+ case DevFmtUByte:
+ Store_ALubyte(dst, src, dststep, samples);
+ break;
+ case DevFmtShort:
+ Store_ALshort(dst, src, dststep, samples);
+ break;
+ case DevFmtUShort:
+ Store_ALushort(dst, src, dststep, samples);
+ break;
+ case DevFmtInt:
+ Store_ALint(dst, src, dststep, samples);
+ break;
+ case DevFmtUInt:
+ Store_ALuint(dst, src, dststep, samples);
+ break;
+ case DevFmtFloat:
+ Store_ALfloat(dst, src, dststep, samples);
+ break;
+ }
+}
+
+
+ALsizei SampleConverterAvailableOut(SampleConverter *converter, ALsizei srcframes)
+{
+ ALint prepcount = converter->mSrcPrepCount;
+ ALsizei increment = converter->mIncrement;
+ ALsizei DataPosFrac = converter->mFracOffset;
+ ALuint64 DataSize64;
+
+ if(prepcount < 0)
+ {
+ /* Negative prepcount means we need to skip that many input samples. */
+ if(-prepcount >= srcframes)
+ return 0;
+ srcframes += prepcount;
+ prepcount = 0;
+ }
+
+ if(srcframes < 1)
+ {
+ /* No output samples if there's no input samples. */
+ return 0;
+ }
+
+ if(prepcount < MAX_RESAMPLE_PADDING*2 &&
+ MAX_RESAMPLE_PADDING*2 - prepcount >= srcframes)
+ {
+ /* Not enough input samples to generate an output sample. */
+ return 0;
+ }
+
+ DataSize64 = prepcount;
+ DataSize64 += srcframes;
+ DataSize64 -= MAX_RESAMPLE_PADDING*2;
+ DataSize64 <<= FRACTIONBITS;
+ DataSize64 -= DataPosFrac;
+
+ /* If we have a full prep, we can generate at least one sample. */
+ return (ALsizei)clampu64((DataSize64 + increment-1)/increment, 1, BUFFERSIZE);
+}
+
+
+ALsizei SampleConverterInput(SampleConverter *converter, const ALvoid **src, ALsizei *srcframes, ALvoid *dst, ALsizei dstframes)
+{
+ const ALsizei SrcFrameSize = converter->mNumChannels * converter->mSrcTypeSize;
+ const ALsizei DstFrameSize = converter->mNumChannels * converter->mDstTypeSize;
+ const ALsizei increment = converter->mIncrement;
+ ALsizei pos = 0;
+
+ START_MIXER_MODE();
+ while(pos < dstframes && *srcframes > 0)
+ {
+ ALfloat *restrict SrcData = ASSUME_ALIGNED(converter->mSrcSamples, 16);
+ ALfloat *restrict DstData = ASSUME_ALIGNED(converter->mDstSamples, 16);
+ ALint prepcount = converter->mSrcPrepCount;
+ ALsizei DataPosFrac = converter->mFracOffset;
+ ALuint64 DataSize64;
+ ALsizei DstSize;
+ ALint toread;
+ ALsizei chan;
+
+ if(prepcount < 0)
+ {
+ /* Negative prepcount means we need to skip that many input samples. */
+ if(-prepcount >= *srcframes)
+ {
+ converter->mSrcPrepCount = prepcount + *srcframes;
+ *srcframes = 0;
+ break;
+ }
+ *src = (const ALbyte*)*src + SrcFrameSize*-prepcount;
+ *srcframes += prepcount;
+ converter->mSrcPrepCount = 0;
+ continue;
+ }
+ toread = mini(*srcframes, BUFFERSIZE - MAX_RESAMPLE_PADDING*2);
+
+ if(prepcount < MAX_RESAMPLE_PADDING*2 &&
+ MAX_RESAMPLE_PADDING*2 - prepcount >= toread)
+ {
+ /* Not enough input samples to generate an output sample. Store
+ * what we're given for later.
+ */
+ for(chan = 0;chan < converter->mNumChannels;chan++)
+ LoadSamples(&converter->Chan[chan].mPrevSamples[prepcount],
+ (const ALbyte*)*src + converter->mSrcTypeSize*chan,
+ converter->mNumChannels, converter->mSrcType, toread
+ );
+
+ converter->mSrcPrepCount = prepcount + toread;
+ *srcframes = 0;
+ break;
+ }
+
+ DataSize64 = prepcount;
+ DataSize64 += toread;
+ DataSize64 -= MAX_RESAMPLE_PADDING*2;
+ DataSize64 <<= FRACTIONBITS;
+ DataSize64 -= DataPosFrac;
+
+ /* If we have a full prep, we can generate at least one sample. */
+ DstSize = (ALsizei)clampu64((DataSize64 + increment-1)/increment, 1, BUFFERSIZE);
+ DstSize = mini(DstSize, dstframes-pos);
+
+ for(chan = 0;chan < converter->mNumChannels;chan++)
+ {
+ const ALbyte *SrcSamples = (const ALbyte*)*src + converter->mSrcTypeSize*chan;
+ ALbyte *DstSamples = (ALbyte*)dst + converter->mDstTypeSize*chan;
+ const ALfloat *ResampledData;
+ ALsizei SrcDataEnd;
+
+ /* Load the previous samples into the source data first, then the
+ * new samples from the input buffer.
+ */
+ memcpy(SrcData, converter->Chan[chan].mPrevSamples,
+ prepcount*sizeof(ALfloat));
+ LoadSamples(SrcData + prepcount, SrcSamples,
+ converter->mNumChannels, converter->mSrcType, toread
+ );
+
+ /* Store as many prep samples for next time as possible, given the
+ * number of output samples being generated.
+ */
+ SrcDataEnd = (DataPosFrac + increment*DstSize)>>FRACTIONBITS;
+ if(SrcDataEnd >= prepcount+toread)
+ memset(converter->Chan[chan].mPrevSamples, 0,
+ sizeof(converter->Chan[chan].mPrevSamples));
+ else
+ {
+ size_t len = mini(MAX_RESAMPLE_PADDING*2, prepcount+toread-SrcDataEnd);
+ memcpy(converter->Chan[chan].mPrevSamples, &SrcData[SrcDataEnd],
+ len*sizeof(ALfloat));
+ memset(converter->Chan[chan].mPrevSamples+len, 0,
+ sizeof(converter->Chan[chan].mPrevSamples) - len*sizeof(ALfloat));
+ }
+
+ /* Now resample, and store the result in the output buffer. */
+ ResampledData = converter->mResample(&converter->mState,
+ SrcData+MAX_RESAMPLE_PADDING, DataPosFrac, increment,
+ DstData, DstSize
+ );
+
+ StoreSamples(DstSamples, ResampledData, converter->mNumChannels,
+ converter->mDstType, DstSize);
+ }
+
+ /* Update the number of prep samples still available, as well as the
+ * fractional offset.
+ */
+ DataPosFrac += increment*DstSize;
+ converter->mSrcPrepCount = mini(prepcount + toread - (DataPosFrac>>FRACTIONBITS),
+ MAX_RESAMPLE_PADDING*2);
+ converter->mFracOffset = DataPosFrac & FRACTIONMASK;
+
+ /* Update the src and dst pointers in case there's still more to do. */
+ *src = (const ALbyte*)*src + SrcFrameSize*(DataPosFrac>>FRACTIONBITS);
+ *srcframes -= mini(*srcframes, (DataPosFrac>>FRACTIONBITS));
+
+ dst = (ALbyte*)dst + DstFrameSize*DstSize;
+ pos += DstSize;
+ }
+ END_MIXER_MODE();
+
+ return pos;
+}
+
+
+ChannelConverter *CreateChannelConverter(enum DevFmtType srcType, enum DevFmtChannels srcChans, enum DevFmtChannels dstChans)
+{
+ ChannelConverter *converter;
+
+ if(srcChans != dstChans && !((srcChans == DevFmtMono && dstChans == DevFmtStereo) ||
+ (srcChans == DevFmtStereo && dstChans == DevFmtMono)))
+ return NULL;
+
+ converter = al_calloc(DEF_ALIGN, sizeof(*converter));
+ converter->mSrcType = srcType;
+ converter->mSrcChans = srcChans;
+ converter->mDstChans = dstChans;
+
+ return converter;
+}
+
+void DestroyChannelConverter(ChannelConverter **converter)
+{
+ if(converter)
+ {
+ al_free(*converter);
+ *converter = NULL;
+ }
+}
+
+
+#define DECL_TEMPLATE(T) \
+static void Mono2Stereo##T(ALfloat *restrict dst, const T *src, ALsizei frames)\
+{ \
+ ALsizei i; \
+ for(i = 0;i < frames;i++) \
+ dst[i*2 + 1] = dst[i*2 + 0] = Sample_##T(src[i]) * 0.707106781187f; \
+} \
+ \
+static void Stereo2Mono##T(ALfloat *restrict dst, const T *src, ALsizei frames)\
+{ \
+ ALsizei i; \
+ for(i = 0;i < frames;i++) \
+ dst[i] = (Sample_##T(src[i*2 + 0])+Sample_##T(src[i*2 + 1])) * \
+ 0.707106781187f; \
+}
+
+DECL_TEMPLATE(ALbyte)
+DECL_TEMPLATE(ALubyte)
+DECL_TEMPLATE(ALshort)
+DECL_TEMPLATE(ALushort)
+DECL_TEMPLATE(ALint)
+DECL_TEMPLATE(ALuint)
+DECL_TEMPLATE(ALfloat)
+
+#undef DECL_TEMPLATE
+
+void ChannelConverterInput(ChannelConverter *converter, const ALvoid *src, ALfloat *dst, ALsizei frames)
+{
+ if(converter->mSrcChans == converter->mDstChans)
+ {
+ LoadSamples(dst, src, 1, converter->mSrcType,
+ frames*ChannelsFromDevFmt(converter->mSrcChans, 0));
+ return;
+ }
+
+ if(converter->mSrcChans == DevFmtStereo && converter->mDstChans == DevFmtMono)
+ {
+ switch(converter->mSrcType)
+ {
+ case DevFmtByte:
+ Stereo2MonoALbyte(dst, src, frames);
+ break;
+ case DevFmtUByte:
+ Stereo2MonoALubyte(dst, src, frames);
+ break;
+ case DevFmtShort:
+ Stereo2MonoALshort(dst, src, frames);
+ break;
+ case DevFmtUShort:
+ Stereo2MonoALushort(dst, src, frames);
+ break;
+ case DevFmtInt:
+ Stereo2MonoALint(dst, src, frames);
+ break;
+ case DevFmtUInt:
+ Stereo2MonoALuint(dst, src, frames);
+ break;
+ case DevFmtFloat:
+ Stereo2MonoALfloat(dst, src, frames);
+ break;
+ }
+ }
+ else /*if(converter->mSrcChans == DevFmtMono && converter->mDstChans == DevFmtStereo)*/
+ {
+ switch(converter->mSrcType)
+ {
+ case DevFmtByte:
+ Mono2StereoALbyte(dst, src, frames);
+ break;
+ case DevFmtUByte:
+ Mono2StereoALubyte(dst, src, frames);
+ break;
+ case DevFmtShort:
+ Mono2StereoALshort(dst, src, frames);
+ break;
+ case DevFmtUShort:
+ Mono2StereoALushort(dst, src, frames);
+ break;
+ case DevFmtInt:
+ Mono2StereoALint(dst, src, frames);
+ break;
+ case DevFmtUInt:
+ Mono2StereoALuint(dst, src, frames);
+ break;
+ case DevFmtFloat:
+ Mono2StereoALfloat(dst, src, frames);
+ break;
+ }
+ }
+}
diff --git a/Alc/converter.h b/Alc/converter.h
new file mode 100644
index 00000000..b58fd831
--- /dev/null
+++ b/Alc/converter.h
@@ -0,0 +1,55 @@
+#ifndef CONVERTER_H
+#define CONVERTER_H
+
+#include "alMain.h"
+#include "alu.h"
+
+#ifdef __cpluspluc
+extern "C" {
+#endif
+
+typedef struct SampleConverter {
+ enum DevFmtType mSrcType;
+ enum DevFmtType mDstType;
+ ALsizei mNumChannels;
+ ALsizei mSrcTypeSize;
+ ALsizei mDstTypeSize;
+
+ ALint mSrcPrepCount;
+
+ ALsizei mFracOffset;
+ ALsizei mIncrement;
+ InterpState mState;
+ ResamplerFunc mResample;
+
+ alignas(16) ALfloat mSrcSamples[BUFFERSIZE];
+ alignas(16) ALfloat mDstSamples[BUFFERSIZE];
+
+ struct {
+ alignas(16) ALfloat mPrevSamples[MAX_RESAMPLE_PADDING*2];
+ } Chan[];
+} SampleConverter;
+
+SampleConverter *CreateSampleConverter(enum DevFmtType srcType, enum DevFmtType dstType, ALsizei numchans, ALsizei srcRate, ALsizei dstRate);
+void DestroySampleConverter(SampleConverter **converter);
+
+ALsizei SampleConverterInput(SampleConverter *converter, const ALvoid **src, ALsizei *srcframes, ALvoid *dst, ALsizei dstframes);
+ALsizei SampleConverterAvailableOut(SampleConverter *converter, ALsizei srcframes);
+
+
+typedef struct ChannelConverter {
+ enum DevFmtType mSrcType;
+ enum DevFmtChannels mSrcChans;
+ enum DevFmtChannels mDstChans;
+} ChannelConverter;
+
+ChannelConverter *CreateChannelConverter(enum DevFmtType srcType, enum DevFmtChannels srcChans, enum DevFmtChannels dstChans);
+void DestroyChannelConverter(ChannelConverter **converter);
+
+void ChannelConverterInput(ChannelConverter *converter, const ALvoid *src, ALfloat *dst, ALsizei frames);
+
+#ifdef __cpluspluc
+}
+#endif
+
+#endif /* CONVERTER_H */
diff --git a/Alc/cpu_caps.h b/Alc/cpu_caps.h
new file mode 100644
index 00000000..328d470e
--- /dev/null
+++ b/Alc/cpu_caps.h
@@ -0,0 +1,15 @@
+#ifndef CPU_CAPS_H
+#define CPU_CAPS_H
+
+extern int CPUCapFlags;
+enum {
+ CPU_CAP_SSE = 1<<0,
+ CPU_CAP_SSE2 = 1<<1,
+ CPU_CAP_SSE3 = 1<<2,
+ CPU_CAP_SSE4_1 = 1<<3,
+ CPU_CAP_NEON = 1<<4,
+};
+
+void FillCPUCaps(int capfilter);
+
+#endif /* CPU_CAPS_H */
diff --git a/Alc/effects/autowah.c b/Alc/effects/autowah.c
index 6770f719..ba1180ef 100644
--- a/Alc/effects/autowah.c
+++ b/Alc/effects/autowah.c
@@ -1,6 +1,6 @@
/**
* OpenAL cross platform audio library
- * Copyright (C) 2013 by Anis A. Hireche, Nasca Octavian Paul
+ * Copyright (C) 2018 by Raul Herraiz.
* 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
@@ -18,181 +18,215 @@
* Or go to http://www.gnu.org/copyleft/lgpl.html
*/
+#include "config.h"
+
+#include <math.h>
#include <stdlib.h>
-#include "config.h"
-#include "alu.h"
-#include "alFilter.h"
-#include "alError.h"
#include "alMain.h"
#include "alAuxEffectSlot.h"
+#include "alError.h"
+#include "alu.h"
+#include "filters/defs.h"
-
-/* Auto-wah is simply a low-pass filter with a cutoff frequency that shifts up
- * or down depending on the input signal, and a resonant peak at the cutoff.
- *
- * Currently, we assume a cutoff frequency range of 20hz (no amplitude) to
- * 20khz (peak gain). Peak gain is assumed to be in normalized scale.
- */
+#define MIN_FREQ 20.0f
+#define MAX_FREQ 2500.0f
+#define Q_FACTOR 5.0f
typedef struct ALautowahState {
DERIVE_FROM_TYPE(ALeffectState);
- /* Effect gains for each channel */
- ALfloat Gain[MAX_OUTPUT_CHANNELS];
-
/* Effect parameters */
ALfloat AttackRate;
ALfloat ReleaseRate;
- ALfloat Resonance;
+ ALfloat ResonanceGain;
ALfloat PeakGain;
- ALfloat GainCtrl;
- ALfloat Frequency;
-
- /* Samples processing */
- ALfilterState LowPass;
+ ALfloat FreqMinNorm;
+ ALfloat BandwidthNorm;
+ ALfloat env_delay;
+
+ /* Filter components derived from the envelope. */
+ struct {
+ ALfloat cos_w0;
+ ALfloat alpha;
+ } Env[BUFFERSIZE];
+
+ struct {
+ /* Effect filters' history. */
+ struct {
+ ALfloat z1, z2;
+ } Filter;
+
+ /* Effect gains for each output channel */
+ ALfloat CurrentGains[MAX_OUTPUT_CHANNELS];
+ ALfloat TargetGains[MAX_OUTPUT_CHANNELS];
+ } Chans[MAX_EFFECT_CHANNELS];
+
+ /* Effects buffers */
+ alignas(16) ALfloat BufferOut[BUFFERSIZE];
} ALautowahState;
-static ALvoid ALautowahState_Destruct(ALautowahState *UNUSED(state))
+static ALvoid ALautowahState_Destruct(ALautowahState *state);
+static ALboolean ALautowahState_deviceUpdate(ALautowahState *state, ALCdevice *device);
+static ALvoid ALautowahState_update(ALautowahState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props);
+static ALvoid ALautowahState_process(ALautowahState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels);
+DECLARE_DEFAULT_ALLOCATORS(ALautowahState)
+
+DEFINE_ALEFFECTSTATE_VTABLE(ALautowahState);
+
+static void ALautowahState_Construct(ALautowahState *state)
{
+ ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
+ SET_VTABLE2(ALautowahState, ALeffectState, state);
}
-static ALboolean ALautowahState_deviceUpdate(ALautowahState *state, ALCdevice *device)
+static ALvoid ALautowahState_Destruct(ALautowahState *state)
{
- state->Frequency = (ALfloat)device->Frequency;
- return AL_TRUE;
+ ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
}
-static ALvoid ALautowahState_update(ALautowahState *state, ALCdevice *device, const ALeffectslot *slot)
+static ALboolean ALautowahState_deviceUpdate(ALautowahState *state, ALCdevice *UNUSED(device))
{
- ALfloat attackTime, releaseTime;
+ /* (Re-)initializing parameters and clear the buffers. */
+ ALsizei i, j;
- attackTime = slot->EffectProps.Autowah.AttackTime * state->Frequency;
- releaseTime = slot->EffectProps.Autowah.ReleaseTime * state->Frequency;
+ state->AttackRate = 1.0f;
+ state->ReleaseRate = 1.0f;
+ state->ResonanceGain = 10.0f;
+ state->PeakGain = 4.5f;
+ state->FreqMinNorm = 4.5e-4f;
+ state->BandwidthNorm = 0.05f;
+ state->env_delay = 0.0f;
- state->AttackRate = powf(1.0f/GAIN_SILENCE_THRESHOLD, 1.0f/attackTime);
- state->ReleaseRate = powf(GAIN_SILENCE_THRESHOLD/1.0f, 1.0f/releaseTime);
- state->PeakGain = slot->EffectProps.Autowah.PeakGain;
- state->Resonance = slot->EffectProps.Autowah.Resonance;
+ memset(state->Env, 0, sizeof(state->Env));
+
+ for(i = 0;i < MAX_EFFECT_CHANNELS;i++)
+ {
+ for(j = 0;j < MAX_OUTPUT_CHANNELS;j++)
+ state->Chans[i].CurrentGains[j] = 0.0f;
+ state->Chans[i].Filter.z1 = 0.0f;
+ state->Chans[i].Filter.z2 = 0.0f;
+ }
- ComputeAmbientGains(device, slot->Gain, state->Gain);
+ return AL_TRUE;
}
-static ALvoid ALautowahState_process(ALautowahState *state, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[BUFFERSIZE], ALuint NumChannels)
+static ALvoid ALautowahState_update(ALautowahState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props)
{
- ALuint it, kt;
- ALuint base;
+ const ALCdevice *device = context->Device;
+ ALfloat ReleaseTime;
+ ALsizei i;
+
+ ReleaseTime = clampf(props->Autowah.ReleaseTime, 0.001f, 1.0f);
+
+ state->AttackRate = expf(-1.0f / (props->Autowah.AttackTime*device->Frequency));
+ state->ReleaseRate = expf(-1.0f / (ReleaseTime*device->Frequency));
+ /* 0-20dB Resonance Peak gain */
+ state->ResonanceGain = sqrtf(log10f(props->Autowah.Resonance)*10.0f / 3.0f);
+ state->PeakGain = 1.0f - log10f(props->Autowah.PeakGain/AL_AUTOWAH_MAX_PEAK_GAIN);
+ state->FreqMinNorm = MIN_FREQ / device->Frequency;
+ state->BandwidthNorm = (MAX_FREQ-MIN_FREQ) / device->Frequency;
+
+ STATIC_CAST(ALeffectState,state)->OutBuffer = device->FOAOut.Buffer;
+ STATIC_CAST(ALeffectState,state)->OutChannels = device->FOAOut.NumChannels;
+ for(i = 0;i < MAX_EFFECT_CHANNELS;i++)
+ ComputePanGains(&device->FOAOut, IdentityMatrixf.m[i], slot->Params.Gain,
+ state->Chans[i].TargetGains);
+}
- for(base = 0;base < SamplesToDo;)
+static ALvoid ALautowahState_process(ALautowahState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels)
+{
+ const ALfloat attack_rate = state->AttackRate;
+ const ALfloat release_rate = state->ReleaseRate;
+ const ALfloat res_gain = state->ResonanceGain;
+ const ALfloat peak_gain = state->PeakGain;
+ const ALfloat freq_min = state->FreqMinNorm;
+ const ALfloat bandwidth = state->BandwidthNorm;
+ ALfloat env_delay;
+ ALsizei c, i;
+
+ env_delay = state->env_delay;
+ for(i = 0;i < SamplesToDo;i++)
{
- ALfloat temps[256];
- ALuint td = minu(256, SamplesToDo-base);
- ALfloat gain = state->GainCtrl;
-
- for(it = 0;it < td;it++)
- {
- ALfloat smp = SamplesIn[it+base];
- ALfloat alpha, w0;
- ALfloat amplitude;
- ALfloat cutoff;
-
- /* Similar to compressor, we get the current amplitude of the
- * incoming signal, and attack or release to reach it. */
- amplitude = fabsf(smp);
- if(amplitude > gain)
- gain = minf(gain*state->AttackRate, amplitude);
- else if(amplitude < gain)
- gain = maxf(gain*state->ReleaseRate, amplitude);
- gain = maxf(gain, GAIN_SILENCE_THRESHOLD);
-
- /* FIXME: What range does the filter cover? */
- cutoff = lerp(20.0f, 20000.0f, minf(gain/state->PeakGain, 1.0f));
-
- /* The code below is like calling ALfilterState_setParams with
- * ALfilterType_LowPass. However, instead of passing a bandwidth,
- * we use the resonance property for Q. This also inlines the call.
- */
- w0 = F_TAU * cutoff / state->Frequency;
-
- /* FIXME: Resonance controls the resonant peak, or Q. How? Not sure
- * that Q = resonance*0.1. */
- alpha = sinf(w0) / (2.0f * state->Resonance*0.1f);
- state->LowPass.b[0] = (1.0f - cosf(w0)) / 2.0f;
- state->LowPass.b[1] = 1.0f - cosf(w0);
- state->LowPass.b[2] = (1.0f - cosf(w0)) / 2.0f;
- state->LowPass.a[0] = 1.0f + alpha;
- state->LowPass.a[1] = -2.0f * cosf(w0);
- state->LowPass.a[2] = 1.0f - alpha;
-
- state->LowPass.b[2] /= state->LowPass.a[0];
- state->LowPass.b[1] /= state->LowPass.a[0];
- state->LowPass.b[0] /= state->LowPass.a[0];
- state->LowPass.a[2] /= state->LowPass.a[0];
- state->LowPass.a[1] /= state->LowPass.a[0];
- state->LowPass.a[0] /= state->LowPass.a[0];
-
- temps[it] = ALfilterState_processSingle(&state->LowPass, smp);
- }
- state->GainCtrl = gain;
+ ALfloat w0, sample, a;
+
+ /* Envelope follower described on the book: Audio Effects, Theory,
+ * Implementation and Application.
+ */
+ sample = peak_gain * fabsf(SamplesIn[0][i]);
+ a = (sample > env_delay) ? attack_rate : release_rate;
+ env_delay = lerp(sample, env_delay, a);
+
+ /* Calculate the cos and alpha components for this sample's filter. */
+ w0 = minf((bandwidth*env_delay + freq_min), 0.46f) * F_TAU;
+ state->Env[i].cos_w0 = cosf(w0);
+ state->Env[i].alpha = sinf(w0)/(2.0f * Q_FACTOR);
+ }
+ state->env_delay = env_delay;
- for(kt = 0;kt < NumChannels;kt++)
+ for(c = 0;c < MAX_EFFECT_CHANNELS; c++)
+ {
+ /* This effectively inlines BiquadFilter_setParams for a peaking
+ * filter and BiquadFilter_processC. The alpha and cosine components
+ * for the filter coefficients were previously calculated with the
+ * envelope. Because the filter changes for each sample, the
+ * coefficients are transient and don't need to be held.
+ */
+ ALfloat z1 = state->Chans[c].Filter.z1;
+ ALfloat z2 = state->Chans[c].Filter.z2;
+
+ for(i = 0;i < SamplesToDo;i++)
{
- ALfloat gain = state->Gain[kt];
- if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
- continue;
-
- for(it = 0;it < td;it++)
- SamplesOut[kt][base+it] += gain * temps[it];
+ const ALfloat alpha = state->Env[i].alpha;
+ const ALfloat cos_w0 = state->Env[i].cos_w0;
+ ALfloat input, output;
+ ALfloat a[3], b[3];
+
+ b[0] = 1.0f + alpha*res_gain;
+ b[1] = -2.0f * cos_w0;
+ b[2] = 1.0f - alpha*res_gain;
+ a[0] = 1.0f + alpha/res_gain;
+ a[1] = -2.0f * cos_w0;
+ a[2] = 1.0f - alpha/res_gain;
+
+ input = SamplesIn[c][i];
+ output = input*(b[0]/a[0]) + z1;
+ z1 = input*(b[1]/a[0]) - output*(a[1]/a[0]) + z2;
+ z2 = input*(b[2]/a[0]) - output*(a[2]/a[0]);
+ state->BufferOut[i] = output;
}
+ state->Chans[c].Filter.z1 = z1;
+ state->Chans[c].Filter.z2 = z2;
- base += td;
+ /* Now, mix the processed sound data to the output. */
+ MixSamples(state->BufferOut, NumChannels, SamplesOut, state->Chans[c].CurrentGains,
+ state->Chans[c].TargetGains, SamplesToDo, 0, SamplesToDo);
}
}
-DECLARE_DEFAULT_ALLOCATORS(ALautowahState)
-
-DEFINE_ALEFFECTSTATE_VTABLE(ALautowahState);
-
+typedef struct AutowahStateFactory {
+ DERIVE_FROM_TYPE(EffectStateFactory);
+} AutowahStateFactory;
-typedef struct ALautowahStateFactory {
- DERIVE_FROM_TYPE(ALeffectStateFactory);
-} ALautowahStateFactory;
-
-static ALeffectState *ALautowahStateFactory_create(ALautowahStateFactory *UNUSED(factory))
+static ALeffectState *AutowahStateFactory_create(AutowahStateFactory *UNUSED(factory))
{
ALautowahState *state;
- state = ALautowahState_New(sizeof(*state));
+ NEW_OBJ0(state, ALautowahState)();
if(!state) return NULL;
- SET_VTABLE2(ALautowahState, ALeffectState, state);
-
- state->AttackRate = 1.0f;
- state->ReleaseRate = 1.0f;
- state->Resonance = 2.0f;
- state->PeakGain = 1.0f;
- state->GainCtrl = 1.0f;
-
- ALfilterState_clear(&state->LowPass);
return STATIC_CAST(ALeffectState, state);
}
-DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALautowahStateFactory);
+DEFINE_EFFECTSTATEFACTORY_VTABLE(AutowahStateFactory);
-ALeffectStateFactory *ALautowahStateFactory_getFactory(void)
+EffectStateFactory *AutowahStateFactory_getFactory(void)
{
- static ALautowahStateFactory AutowahFactory = { { GET_VTABLE2(ALautowahStateFactory, ALeffectStateFactory) } };
+ static AutowahStateFactory AutowahFactory = { { GET_VTABLE2(AutowahStateFactory, EffectStateFactory) } };
- return STATIC_CAST(ALeffectStateFactory, &AutowahFactory);
+ return STATIC_CAST(EffectStateFactory, &AutowahFactory);
}
-
-void ALautowah_setParami(ALeffect *UNUSED(effect), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-void ALautowah_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
-{
- ALautowah_setParami(effect, context, param, vals[0]);
-}
void ALautowah_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val)
{
ALeffectProps *props = &effect->Props;
@@ -200,45 +234,60 @@ void ALautowah_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, AL
{
case AL_AUTOWAH_ATTACK_TIME:
if(!(val >= AL_AUTOWAH_MIN_ATTACK_TIME && val <= AL_AUTOWAH_MAX_ATTACK_TIME))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,,"Autowah attack time out of range");
props->Autowah.AttackTime = val;
break;
case AL_AUTOWAH_RELEASE_TIME:
if(!(val >= AL_AUTOWAH_MIN_RELEASE_TIME && val <= AL_AUTOWAH_MAX_RELEASE_TIME))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,,"Autowah release time out of range");
props->Autowah.ReleaseTime = val;
break;
case AL_AUTOWAH_RESONANCE:
if(!(val >= AL_AUTOWAH_MIN_RESONANCE && val <= AL_AUTOWAH_MAX_RESONANCE))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,,"Autowah resonance out of range");
props->Autowah.Resonance = val;
break;
case AL_AUTOWAH_PEAK_GAIN:
if(!(val >= AL_AUTOWAH_MIN_PEAK_GAIN && val <= AL_AUTOWAH_MAX_PEAK_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,,"Autowah peak gain out of range");
props->Autowah.PeakGain = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid autowah float property 0x%04x", param);
}
}
+
void ALautowah_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
{
ALautowah_setParamf(effect, context, param, vals[0]);
}
-void ALautowah_getParami(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-void ALautowah_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
+void ALautowah_setParami(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint UNUSED(val))
+{
+ alSetError(context, AL_INVALID_ENUM, "Invalid autowah integer property 0x%04x", param);
+}
+
+void ALautowah_setParamiv(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, const ALint *UNUSED(vals))
+{
+ alSetError(context, AL_INVALID_ENUM, "Invalid autowah integer vector property 0x%04x", param);
+}
+
+void ALautowah_getParami(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint *UNUSED(val))
{
- ALautowah_getParami(effect, context, param, vals);
+ alSetError(context, AL_INVALID_ENUM, "Invalid autowah integer property 0x%04x", param);
}
+void ALautowah_getParamiv(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint *UNUSED(vals))
+{
+ alSetError(context, AL_INVALID_ENUM, "Invalid autowah integer vector property 0x%04x", param);
+}
+
void ALautowah_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
{
+
const ALeffectProps *props = &effect->Props;
switch(param)
{
@@ -259,9 +308,11 @@ void ALautowah_getParamf(const ALeffect *effect, ALCcontext *context, ALenum par
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid autowah float property 0x%04x", param);
}
+
}
+
void ALautowah_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
{
ALautowah_getParamf(effect, context, param, vals);
diff --git a/Alc/effects/chorus.c b/Alc/effects/chorus.c
index 7aa5898b..f2861cf5 100644
--- a/Alc/effects/chorus.c
+++ b/Alc/effects/chorus.c
@@ -24,261 +24,289 @@
#include <stdlib.h>
#include "alMain.h"
-#include "alFilter.h"
#include "alAuxEffectSlot.h"
#include "alError.h"
#include "alu.h"
+#include "filters/defs.h"
-enum ChorusWaveForm {
- CWF_Triangle = AL_CHORUS_WAVEFORM_TRIANGLE,
- CWF_Sinusoid = AL_CHORUS_WAVEFORM_SINUSOID
+static_assert(AL_CHORUS_WAVEFORM_SINUSOID == AL_FLANGER_WAVEFORM_SINUSOID, "Chorus/Flanger waveform value mismatch");
+static_assert(AL_CHORUS_WAVEFORM_TRIANGLE == AL_FLANGER_WAVEFORM_TRIANGLE, "Chorus/Flanger waveform value mismatch");
+
+enum WaveForm {
+ WF_Sinusoid,
+ WF_Triangle
};
typedef struct ALchorusState {
DERIVE_FROM_TYPE(ALeffectState);
- ALfloat *SampleBuffer[2];
- ALuint BufferLength;
- ALuint offset;
- ALuint lfo_range;
+ ALfloat *SampleBuffer;
+ ALsizei BufferLength;
+ ALsizei offset;
+
+ ALsizei lfo_offset;
+ ALsizei lfo_range;
ALfloat lfo_scale;
ALint lfo_disp;
/* Gains for left and right sides */
- ALfloat Gain[2][MAX_OUTPUT_CHANNELS];
+ struct {
+ ALfloat Current[MAX_OUTPUT_CHANNELS];
+ ALfloat Target[MAX_OUTPUT_CHANNELS];
+ } Gains[2];
/* effect parameters */
- enum ChorusWaveForm waveform;
+ enum WaveForm waveform;
ALint delay;
ALfloat depth;
ALfloat feedback;
} ALchorusState;
+static ALvoid ALchorusState_Destruct(ALchorusState *state);
+static ALboolean ALchorusState_deviceUpdate(ALchorusState *state, ALCdevice *Device);
+static ALvoid ALchorusState_update(ALchorusState *state, const ALCcontext *Context, const ALeffectslot *Slot, const ALeffectProps *props);
+static ALvoid ALchorusState_process(ALchorusState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels);
+DECLARE_DEFAULT_ALLOCATORS(ALchorusState)
+
+DEFINE_ALEFFECTSTATE_VTABLE(ALchorusState);
+
+
+static void ALchorusState_Construct(ALchorusState *state)
+{
+ ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
+ SET_VTABLE2(ALchorusState, ALeffectState, state);
+
+ state->BufferLength = 0;
+ state->SampleBuffer = NULL;
+ state->offset = 0;
+ state->lfo_offset = 0;
+ state->lfo_range = 1;
+ state->waveform = WF_Triangle;
+}
+
static ALvoid ALchorusState_Destruct(ALchorusState *state)
{
- free(state->SampleBuffer[0]);
- state->SampleBuffer[0] = NULL;
- state->SampleBuffer[1] = NULL;
+ al_free(state->SampleBuffer);
+ state->SampleBuffer = NULL;
+
+ ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
}
static ALboolean ALchorusState_deviceUpdate(ALchorusState *state, ALCdevice *Device)
{
- ALuint maxlen;
- ALuint it;
+ const ALfloat max_delay = maxf(AL_CHORUS_MAX_DELAY, AL_FLANGER_MAX_DELAY);
+ ALsizei maxlen;
- maxlen = fastf2u(AL_CHORUS_MAX_DELAY * 3.0f * Device->Frequency) + 1;
- maxlen = NextPowerOf2(maxlen);
+ maxlen = NextPowerOf2(float2int(max_delay*2.0f*Device->Frequency) + 1u);
+ if(maxlen <= 0) return AL_FALSE;
if(maxlen != state->BufferLength)
{
- void *temp;
-
- temp = realloc(state->SampleBuffer[0], maxlen * sizeof(ALfloat) * 2);
+ void *temp = al_calloc(16, maxlen * sizeof(ALfloat));
if(!temp) return AL_FALSE;
- state->SampleBuffer[0] = temp;
- state->SampleBuffer[1] = state->SampleBuffer[0] + maxlen;
+
+ al_free(state->SampleBuffer);
+ state->SampleBuffer = temp;
state->BufferLength = maxlen;
}
- for(it = 0;it < state->BufferLength;it++)
- {
- state->SampleBuffer[0][it] = 0.0f;
- state->SampleBuffer[1][it] = 0.0f;
- }
+ memset(state->SampleBuffer, 0, state->BufferLength*sizeof(ALfloat));
+ memset(state->Gains, 0, sizeof(state->Gains));
return AL_TRUE;
}
-static ALvoid ALchorusState_update(ALchorusState *state, ALCdevice *Device, const ALeffectslot *Slot)
+static ALvoid ALchorusState_update(ALchorusState *state, const ALCcontext *Context, const ALeffectslot *Slot, const ALeffectProps *props)
{
- static const ALfloat left_dir[3] = { -1.0f, 0.0f, 0.0f };
- static const ALfloat right_dir[3] = { 1.0f, 0.0f, 0.0f };
- ALfloat frequency = (ALfloat)Device->Frequency;
+ const ALsizei mindelay = MAX_RESAMPLE_PADDING << FRACTIONBITS;
+ const ALCdevice *device = Context->Device;
+ ALfloat frequency = (ALfloat)device->Frequency;
+ ALfloat coeffs[MAX_AMBI_COEFFS];
ALfloat rate;
ALint phase;
- switch(Slot->EffectProps.Chorus.Waveform)
+ switch(props->Chorus.Waveform)
{
case AL_CHORUS_WAVEFORM_TRIANGLE:
- state->waveform = CWF_Triangle;
+ state->waveform = WF_Triangle;
break;
case AL_CHORUS_WAVEFORM_SINUSOID:
- state->waveform = CWF_Sinusoid;
+ state->waveform = WF_Sinusoid;
break;
}
- state->depth = Slot->EffectProps.Chorus.Depth;
- state->feedback = Slot->EffectProps.Chorus.Feedback;
- state->delay = fastf2i(Slot->EffectProps.Chorus.Delay * frequency);
+
+ /* The LFO depth is scaled to be relative to the sample delay. Clamp the
+ * delay and depth to allow enough padding for resampling.
+ */
+ state->delay = maxi(float2int(props->Chorus.Delay*frequency*FRACTIONONE + 0.5f),
+ mindelay);
+ state->depth = minf(props->Chorus.Depth * state->delay,
+ (ALfloat)(state->delay - mindelay));
+
+ state->feedback = props->Chorus.Feedback;
/* Gains for left and right sides */
- ComputeDirectionalGains(Device, left_dir, Slot->Gain, state->Gain[0]);
- ComputeDirectionalGains(Device, right_dir, Slot->Gain, state->Gain[1]);
+ CalcAngleCoeffs(-F_PI_2, 0.0f, 0.0f, coeffs);
+ ComputePanGains(&device->Dry, coeffs, Slot->Params.Gain, state->Gains[0].Target);
+ CalcAngleCoeffs( F_PI_2, 0.0f, 0.0f, coeffs);
+ ComputePanGains(&device->Dry, coeffs, Slot->Params.Gain, state->Gains[1].Target);
- phase = Slot->EffectProps.Chorus.Phase;
- rate = Slot->EffectProps.Chorus.Rate;
+ phase = props->Chorus.Phase;
+ rate = props->Chorus.Rate;
if(!(rate > 0.0f))
{
- state->lfo_scale = 0.0f;
+ state->lfo_offset = 0;
state->lfo_range = 1;
+ state->lfo_scale = 0.0f;
state->lfo_disp = 0;
}
else
{
- /* Calculate LFO coefficient */
- state->lfo_range = fastf2u(frequency/rate + 0.5f);
+ /* Calculate LFO coefficient (number of samples per cycle). Limit the
+ * max range to avoid overflow when calculating the displacement.
+ */
+ ALsizei lfo_range = float2int(minf(frequency/rate + 0.5f, (ALfloat)(INT_MAX/360 - 180)));
+
+ state->lfo_offset = float2int((ALfloat)state->lfo_offset/state->lfo_range*
+ lfo_range + 0.5f) % lfo_range;
+ state->lfo_range = lfo_range;
switch(state->waveform)
{
- case CWF_Triangle:
+ case WF_Triangle:
state->lfo_scale = 4.0f / state->lfo_range;
break;
- case CWF_Sinusoid:
+ case WF_Sinusoid:
state->lfo_scale = F_TAU / state->lfo_range;
break;
}
/* Calculate lfo phase displacement */
- state->lfo_disp = fastf2i(state->lfo_range * (phase/360.0f));
+ if(phase < 0) phase = 360 + phase;
+ state->lfo_disp = (state->lfo_range*phase + 180) / 360;
}
}
-static inline void Triangle(ALint *delay_left, ALint *delay_right, ALuint offset, const ALchorusState *state)
+static void GetTriangleDelays(ALint *restrict delays, ALsizei offset, const ALsizei lfo_range,
+ const ALfloat lfo_scale, const ALfloat depth, const ALsizei delay,
+ const ALsizei todo)
{
- ALfloat lfo_value;
-
- lfo_value = 2.0f - fabsf(2.0f - state->lfo_scale*(offset%state->lfo_range));
- lfo_value *= state->depth * state->delay;
- *delay_left = fastf2i(lfo_value) + state->delay;
-
- offset += state->lfo_disp;
- lfo_value = 2.0f - fabsf(2.0f - state->lfo_scale*(offset%state->lfo_range));
- lfo_value *= state->depth * state->delay;
- *delay_right = fastf2i(lfo_value) + state->delay;
+ ALsizei i;
+ for(i = 0;i < todo;i++)
+ {
+ delays[i] = fastf2i((1.0f - fabsf(2.0f - lfo_scale*offset)) * depth) + delay;
+ offset = (offset+1)%lfo_range;
+ }
}
-static inline void Sinusoid(ALint *delay_left, ALint *delay_right, ALuint offset, const ALchorusState *state)
+static void GetSinusoidDelays(ALint *restrict delays, ALsizei offset, const ALsizei lfo_range,
+ const ALfloat lfo_scale, const ALfloat depth, const ALsizei delay,
+ const ALsizei todo)
{
- ALfloat lfo_value;
-
- lfo_value = 1.0f + sinf(state->lfo_scale*(offset%state->lfo_range));
- lfo_value *= state->depth * state->delay;
- *delay_left = fastf2i(lfo_value) + state->delay;
-
- offset += state->lfo_disp;
- lfo_value = 1.0f + sinf(state->lfo_scale*(offset%state->lfo_range));
- lfo_value *= state->depth * state->delay;
- *delay_right = fastf2i(lfo_value) + state->delay;
-}
-
-#define DECL_TEMPLATE(Func) \
-static void Process##Func(ALchorusState *state, const ALuint SamplesToDo, \
- const ALfloat *restrict SamplesIn, ALfloat (*restrict out)[2]) \
-{ \
- const ALuint bufmask = state->BufferLength-1; \
- ALfloat *restrict leftbuf = state->SampleBuffer[0]; \
- ALfloat *restrict rightbuf = state->SampleBuffer[1]; \
- ALuint offset = state->offset; \
- const ALfloat feedback = state->feedback; \
- ALuint it; \
- \
- for(it = 0;it < SamplesToDo;it++) \
- { \
- ALint delay_left, delay_right; \
- Func(&delay_left, &delay_right, offset, state); \
- \
- out[it][0] = leftbuf[(offset-delay_left)&bufmask]; \
- leftbuf[offset&bufmask] = (out[it][0]+SamplesIn[it]) * feedback; \
- \
- out[it][1] = rightbuf[(offset-delay_right)&bufmask]; \
- rightbuf[offset&bufmask] = (out[it][1]+SamplesIn[it]) * feedback; \
- \
- offset++; \
- } \
- state->offset = offset; \
+ ALsizei i;
+ for(i = 0;i < todo;i++)
+ {
+ delays[i] = fastf2i(sinf(lfo_scale*offset) * depth) + delay;
+ offset = (offset+1)%lfo_range;
+ }
}
-DECL_TEMPLATE(Triangle)
-DECL_TEMPLATE(Sinusoid)
-#undef DECL_TEMPLATE
-
-static ALvoid ALchorusState_process(ALchorusState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)
+static ALvoid ALchorusState_process(ALchorusState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels)
{
- ALuint it, kt;
- ALuint base;
+ const ALsizei bufmask = state->BufferLength-1;
+ const ALfloat feedback = state->feedback;
+ const ALsizei avgdelay = (state->delay + (FRACTIONONE>>1)) >> FRACTIONBITS;
+ ALfloat *restrict delaybuf = state->SampleBuffer;
+ ALsizei offset = state->offset;
+ ALsizei i, c;
+ ALsizei base;
for(base = 0;base < SamplesToDo;)
{
- ALfloat temps[128][2];
- ALuint td = minu(128, SamplesToDo-base);
+ const ALsizei todo = mini(256, SamplesToDo-base);
+ ALint moddelays[2][256];
+ alignas(16) ALfloat temps[2][256];
- switch(state->waveform)
+ if(state->waveform == WF_Sinusoid)
{
- case CWF_Triangle:
- ProcessTriangle(state, td, SamplesIn+base, temps);
- break;
- case CWF_Sinusoid:
- ProcessSinusoid(state, td, SamplesIn+base, temps);
- break;
+ GetSinusoidDelays(moddelays[0], state->lfo_offset, state->lfo_range, state->lfo_scale,
+ state->depth, state->delay, todo);
+ GetSinusoidDelays(moddelays[1], (state->lfo_offset+state->lfo_disp)%state->lfo_range,
+ state->lfo_range, state->lfo_scale, state->depth, state->delay,
+ todo);
}
+ else /*if(state->waveform == WF_Triangle)*/
+ {
+ GetTriangleDelays(moddelays[0], state->lfo_offset, state->lfo_range, state->lfo_scale,
+ state->depth, state->delay, todo);
+ GetTriangleDelays(moddelays[1], (state->lfo_offset+state->lfo_disp)%state->lfo_range,
+ state->lfo_range, state->lfo_scale, state->depth, state->delay,
+ todo);
+ }
+ state->lfo_offset = (state->lfo_offset+todo) % state->lfo_range;
- for(kt = 0;kt < NumChannels;kt++)
+ for(i = 0;i < todo;i++)
{
- ALfloat gain = state->Gain[0][kt];
- if(fabsf(gain) > GAIN_SILENCE_THRESHOLD)
- {
- for(it = 0;it < td;it++)
- SamplesOut[kt][it+base] += temps[it][0] * gain;
- }
-
- gain = state->Gain[1][kt];
- if(fabsf(gain) > GAIN_SILENCE_THRESHOLD)
- {
- for(it = 0;it < td;it++)
- SamplesOut[kt][it+base] += temps[it][1] * gain;
- }
+ ALint delay;
+ ALfloat mu;
+
+ // Feed the buffer's input first (necessary for delays < 1).
+ delaybuf[offset&bufmask] = SamplesIn[0][base+i];
+
+ // Tap for the left output.
+ delay = offset - (moddelays[0][i]>>FRACTIONBITS);
+ mu = (moddelays[0][i]&FRACTIONMASK) * (1.0f/FRACTIONONE);
+ temps[0][i] = cubic(delaybuf[(delay+1) & bufmask], delaybuf[(delay ) & bufmask],
+ delaybuf[(delay-1) & bufmask], delaybuf[(delay-2) & bufmask],
+ mu);
+
+ // Tap for the right output.
+ delay = offset - (moddelays[1][i]>>FRACTIONBITS);
+ mu = (moddelays[1][i]&FRACTIONMASK) * (1.0f/FRACTIONONE);
+ temps[1][i] = cubic(delaybuf[(delay+1) & bufmask], delaybuf[(delay ) & bufmask],
+ delaybuf[(delay-1) & bufmask], delaybuf[(delay-2) & bufmask],
+ mu);
+
+ // Accumulate feedback from the average delay of the taps.
+ delaybuf[offset&bufmask] += delaybuf[(offset-avgdelay) & bufmask] * feedback;
+ offset++;
}
- base += td;
- }
-}
+ for(c = 0;c < 2;c++)
+ MixSamples(temps[c], NumChannels, SamplesOut, state->Gains[c].Current,
+ state->Gains[c].Target, SamplesToDo-base, base, todo);
-DECLARE_DEFAULT_ALLOCATORS(ALchorusState)
+ base += todo;
+ }
-DEFINE_ALEFFECTSTATE_VTABLE(ALchorusState);
+ state->offset = offset;
+}
-typedef struct ALchorusStateFactory {
- DERIVE_FROM_TYPE(ALeffectStateFactory);
-} ALchorusStateFactory;
+typedef struct ChorusStateFactory {
+ DERIVE_FROM_TYPE(EffectStateFactory);
+} ChorusStateFactory;
-static ALeffectState *ALchorusStateFactory_create(ALchorusStateFactory *UNUSED(factory))
+static ALeffectState *ChorusStateFactory_create(ChorusStateFactory *UNUSED(factory))
{
ALchorusState *state;
- state = ALchorusState_New(sizeof(*state));
+ NEW_OBJ0(state, ALchorusState)();
if(!state) return NULL;
- SET_VTABLE2(ALchorusState, ALeffectState, state);
-
- state->BufferLength = 0;
- state->SampleBuffer[0] = NULL;
- state->SampleBuffer[1] = NULL;
- state->offset = 0;
- state->lfo_range = 1;
- state->waveform = CWF_Triangle;
return STATIC_CAST(ALeffectState, state);
}
-DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALchorusStateFactory);
+DEFINE_EFFECTSTATEFACTORY_VTABLE(ChorusStateFactory);
-ALeffectStateFactory *ALchorusStateFactory_getFactory(void)
+EffectStateFactory *ChorusStateFactory_getFactory(void)
{
- static ALchorusStateFactory ChorusFactory = { { GET_VTABLE2(ALchorusStateFactory, ALeffectStateFactory) } };
+ static ChorusStateFactory ChorusFactory = { { GET_VTABLE2(ChorusStateFactory, EffectStateFactory) } };
- return STATIC_CAST(ALeffectStateFactory, &ChorusFactory);
+ return STATIC_CAST(EffectStateFactory, &ChorusFactory);
}
@@ -289,24 +317,22 @@ void ALchorus_setParami(ALeffect *effect, ALCcontext *context, ALenum param, ALi
{
case AL_CHORUS_WAVEFORM:
if(!(val >= AL_CHORUS_MIN_WAVEFORM && val <= AL_CHORUS_MAX_WAVEFORM))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid chorus waveform");
props->Chorus.Waveform = val;
break;
case AL_CHORUS_PHASE:
if(!(val >= AL_CHORUS_MIN_PHASE && val <= AL_CHORUS_MAX_PHASE))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Chorus phase out of range");
props->Chorus.Phase = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid chorus integer property 0x%04x", param);
}
}
void ALchorus_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
-{
- ALchorus_setParami(effect, context, param, vals[0]);
-}
+{ ALchorus_setParami(effect, context, param, vals[0]); }
void ALchorus_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val)
{
ALeffectProps *props = &effect->Props;
@@ -314,36 +340,34 @@ void ALchorus_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALf
{
case AL_CHORUS_RATE:
if(!(val >= AL_CHORUS_MIN_RATE && val <= AL_CHORUS_MAX_RATE))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Chorus rate out of range");
props->Chorus.Rate = val;
break;
case AL_CHORUS_DEPTH:
if(!(val >= AL_CHORUS_MIN_DEPTH && val <= AL_CHORUS_MAX_DEPTH))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Chorus depth out of range");
props->Chorus.Depth = val;
break;
case AL_CHORUS_FEEDBACK:
if(!(val >= AL_CHORUS_MIN_FEEDBACK && val <= AL_CHORUS_MAX_FEEDBACK))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Chorus feedback out of range");
props->Chorus.Feedback = val;
break;
case AL_CHORUS_DELAY:
if(!(val >= AL_CHORUS_MIN_DELAY && val <= AL_CHORUS_MAX_DELAY))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Chorus delay out of range");
props->Chorus.Delay = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid chorus float property 0x%04x", param);
}
}
void ALchorus_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
-{
- ALchorus_setParamf(effect, context, param, vals[0]);
-}
+{ ALchorus_setParamf(effect, context, param, vals[0]); }
void ALchorus_getParami(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *val)
{
@@ -359,13 +383,11 @@ void ALchorus_getParami(const ALeffect *effect, ALCcontext *context, ALenum para
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid chorus integer property 0x%04x", param);
}
}
void ALchorus_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
-{
- ALchorus_getParami(effect, context, param, vals);
-}
+{ ALchorus_getParami(effect, context, param, vals); }
void ALchorus_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
{
const ALeffectProps *props = &effect->Props;
@@ -388,12 +410,146 @@ void ALchorus_getParamf(const ALeffect *effect, ALCcontext *context, ALenum para
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid chorus float property 0x%04x", param);
}
}
void ALchorus_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
+{ ALchorus_getParamf(effect, context, param, vals); }
+
+DEFINE_ALEFFECT_VTABLE(ALchorus);
+
+
+/* Flanger is basically a chorus with a really short delay. They can both use
+ * the same processing functions, so piggyback flanger on the chorus functions.
+ */
+typedef struct FlangerStateFactory {
+ DERIVE_FROM_TYPE(EffectStateFactory);
+} FlangerStateFactory;
+
+ALeffectState *FlangerStateFactory_create(FlangerStateFactory *UNUSED(factory))
{
- ALchorus_getParamf(effect, context, param, vals);
+ ALchorusState *state;
+
+ NEW_OBJ0(state, ALchorusState)();
+ if(!state) return NULL;
+
+ return STATIC_CAST(ALeffectState, state);
}
-DEFINE_ALEFFECT_VTABLE(ALchorus);
+DEFINE_EFFECTSTATEFACTORY_VTABLE(FlangerStateFactory);
+
+EffectStateFactory *FlangerStateFactory_getFactory(void)
+{
+ static FlangerStateFactory FlangerFactory = { { GET_VTABLE2(FlangerStateFactory, EffectStateFactory) } };
+
+ return STATIC_CAST(EffectStateFactory, &FlangerFactory);
+}
+
+
+void ALflanger_setParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val)
+{
+ ALeffectProps *props = &effect->Props;
+ switch(param)
+ {
+ case AL_FLANGER_WAVEFORM:
+ if(!(val >= AL_FLANGER_MIN_WAVEFORM && val <= AL_FLANGER_MAX_WAVEFORM))
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid flanger waveform");
+ props->Chorus.Waveform = val;
+ break;
+
+ case AL_FLANGER_PHASE:
+ if(!(val >= AL_FLANGER_MIN_PHASE && val <= AL_FLANGER_MAX_PHASE))
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Flanger phase out of range");
+ props->Chorus.Phase = val;
+ break;
+
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid flanger integer property 0x%04x", param);
+ }
+}
+void ALflanger_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
+{ ALflanger_setParami(effect, context, param, vals[0]); }
+void ALflanger_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val)
+{
+ ALeffectProps *props = &effect->Props;
+ switch(param)
+ {
+ case AL_FLANGER_RATE:
+ if(!(val >= AL_FLANGER_MIN_RATE && val <= AL_FLANGER_MAX_RATE))
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Flanger rate out of range");
+ props->Chorus.Rate = val;
+ break;
+
+ case AL_FLANGER_DEPTH:
+ if(!(val >= AL_FLANGER_MIN_DEPTH && val <= AL_FLANGER_MAX_DEPTH))
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Flanger depth out of range");
+ props->Chorus.Depth = val;
+ break;
+
+ case AL_FLANGER_FEEDBACK:
+ if(!(val >= AL_FLANGER_MIN_FEEDBACK && val <= AL_FLANGER_MAX_FEEDBACK))
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Flanger feedback out of range");
+ props->Chorus.Feedback = val;
+ break;
+
+ case AL_FLANGER_DELAY:
+ if(!(val >= AL_FLANGER_MIN_DELAY && val <= AL_FLANGER_MAX_DELAY))
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Flanger delay out of range");
+ props->Chorus.Delay = val;
+ break;
+
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid flanger float property 0x%04x", param);
+ }
+}
+void ALflanger_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
+{ ALflanger_setParamf(effect, context, param, vals[0]); }
+
+void ALflanger_getParami(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *val)
+{
+ const ALeffectProps *props = &effect->Props;
+ switch(param)
+ {
+ case AL_FLANGER_WAVEFORM:
+ *val = props->Chorus.Waveform;
+ break;
+
+ case AL_FLANGER_PHASE:
+ *val = props->Chorus.Phase;
+ break;
+
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid flanger integer property 0x%04x", param);
+ }
+}
+void ALflanger_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
+{ ALflanger_getParami(effect, context, param, vals); }
+void ALflanger_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
+{
+ const ALeffectProps *props = &effect->Props;
+ switch(param)
+ {
+ case AL_FLANGER_RATE:
+ *val = props->Chorus.Rate;
+ break;
+
+ case AL_FLANGER_DEPTH:
+ *val = props->Chorus.Depth;
+ break;
+
+ case AL_FLANGER_FEEDBACK:
+ *val = props->Chorus.Feedback;
+ break;
+
+ case AL_FLANGER_DELAY:
+ *val = props->Chorus.Delay;
+ break;
+
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid flanger float property 0x%04x", param);
+ }
+}
+void ALflanger_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
+{ ALflanger_getParamf(effect, context, param, vals); }
+
+DEFINE_ALEFFECT_VTABLE(ALflanger);
diff --git a/Alc/effects/compressor.c b/Alc/effects/compressor.c
index 9859a085..2b4a76b0 100644
--- a/Alc/effects/compressor.c
+++ b/Alc/effects/compressor.c
@@ -27,141 +27,172 @@
#include "alu.h"
+#define AMP_ENVELOPE_MIN 0.5f
+#define AMP_ENVELOPE_MAX 2.0f
+
+#define ATTACK_TIME 0.1f /* 100ms to rise from min to max */
+#define RELEASE_TIME 0.2f /* 200ms to drop from max to min */
+
+
typedef struct ALcompressorState {
DERIVE_FROM_TYPE(ALeffectState);
/* Effect gains for each channel */
- ALfloat Gain[MAX_OUTPUT_CHANNELS];
+ ALfloat Gain[MAX_EFFECT_CHANNELS][MAX_OUTPUT_CHANNELS];
/* Effect parameters */
ALboolean Enabled;
- ALfloat AttackRate;
- ALfloat ReleaseRate;
- ALfloat GainCtrl;
+ ALfloat AttackMult;
+ ALfloat ReleaseMult;
+ ALfloat EnvFollower;
} ALcompressorState;
-static ALvoid ALcompressorState_Destruct(ALcompressorState *UNUSED(state))
+static ALvoid ALcompressorState_Destruct(ALcompressorState *state);
+static ALboolean ALcompressorState_deviceUpdate(ALcompressorState *state, ALCdevice *device);
+static ALvoid ALcompressorState_update(ALcompressorState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props);
+static ALvoid ALcompressorState_process(ALcompressorState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels);
+DECLARE_DEFAULT_ALLOCATORS(ALcompressorState)
+
+DEFINE_ALEFFECTSTATE_VTABLE(ALcompressorState);
+
+
+static void ALcompressorState_Construct(ALcompressorState *state)
+{
+ ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
+ SET_VTABLE2(ALcompressorState, ALeffectState, state);
+
+ state->Enabled = AL_TRUE;
+ state->AttackMult = 1.0f;
+ state->ReleaseMult = 1.0f;
+ state->EnvFollower = 1.0f;
+}
+
+static ALvoid ALcompressorState_Destruct(ALcompressorState *state)
{
+ ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
}
static ALboolean ALcompressorState_deviceUpdate(ALcompressorState *state, ALCdevice *device)
{
- const ALfloat attackTime = device->Frequency * 0.2f; /* 200ms Attack */
- const ALfloat releaseTime = device->Frequency * 0.4f; /* 400ms Release */
-
- state->AttackRate = 1.0f / attackTime;
- state->ReleaseRate = 1.0f / releaseTime;
+ /* Number of samples to do a full attack and release (non-integer sample
+ * counts are okay).
+ */
+ const ALfloat attackCount = (ALfloat)device->Frequency * ATTACK_TIME;
+ const ALfloat releaseCount = (ALfloat)device->Frequency * RELEASE_TIME;
+
+ /* Calculate per-sample multipliers to attack and release at the desired
+ * rates.
+ */
+ state->AttackMult = powf(AMP_ENVELOPE_MAX/AMP_ENVELOPE_MIN, 1.0f/attackCount);
+ state->ReleaseMult = powf(AMP_ENVELOPE_MIN/AMP_ENVELOPE_MAX, 1.0f/releaseCount);
return AL_TRUE;
}
-static ALvoid ALcompressorState_update(ALcompressorState *state, ALCdevice *device, const ALeffectslot *slot)
+static ALvoid ALcompressorState_update(ALcompressorState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props)
{
- state->Enabled = slot->EffectProps.Compressor.OnOff;
+ const ALCdevice *device = context->Device;
+ ALuint i;
+
+ state->Enabled = props->Compressor.OnOff;
- ComputeAmbientGains(device, slot->Gain, state->Gain);
+ STATIC_CAST(ALeffectState,state)->OutBuffer = device->FOAOut.Buffer;
+ STATIC_CAST(ALeffectState,state)->OutChannels = device->FOAOut.NumChannels;
+ for(i = 0;i < 4;i++)
+ ComputePanGains(&device->FOAOut, IdentityMatrixf.m[i], slot->Params.Gain, state->Gain[i]);
}
-static ALvoid ALcompressorState_process(ALcompressorState *state, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[BUFFERSIZE], ALuint NumChannels)
+static ALvoid ALcompressorState_process(ALcompressorState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels)
{
- ALuint it, kt;
- ALuint base;
+ ALsizei i, j, k;
+ ALsizei base;
for(base = 0;base < SamplesToDo;)
{
- ALfloat temps[256];
- ALuint td = minu(256, SamplesToDo-base);
+ ALfloat gains[256];
+ ALsizei td = mini(256, SamplesToDo-base);
+ ALfloat env = state->EnvFollower;
+ /* Generate the per-sample gains from the signal envelope. */
if(state->Enabled)
{
- ALfloat output, smp, amplitude;
- ALfloat gain = state->GainCtrl;
-
- for(it = 0;it < td;it++)
+ for(i = 0;i < td;++i)
{
- smp = SamplesIn[it+base];
-
- amplitude = fabsf(smp);
- if(amplitude > gain)
- gain = minf(gain+state->AttackRate, amplitude);
- else if(amplitude < gain)
- gain = maxf(gain-state->ReleaseRate, amplitude);
- output = 1.0f / clampf(gain, 0.5f, 2.0f);
-
- temps[it] = smp * output;
+ /* Clamp the absolute amplitude to the defined envelope limits,
+ * then attack or release the envelope to reach it.
+ */
+ ALfloat amplitude = clampf(fabsf(SamplesIn[0][base+i]),
+ AMP_ENVELOPE_MIN, AMP_ENVELOPE_MAX);
+ if(amplitude > env)
+ env = minf(env*state->AttackMult, amplitude);
+ else if(amplitude < env)
+ env = maxf(env*state->ReleaseMult, amplitude);
+
+ /* Apply the reciprocal of the envelope to normalize the volume
+ * (compress the dynamic range).
+ */
+ gains[i] = 1.0f / env;
}
-
- state->GainCtrl = gain;
}
else
{
- ALfloat output, smp, amplitude;
- ALfloat gain = state->GainCtrl;
-
- for(it = 0;it < td;it++)
+ /* Same as above, except the amplitude is forced to 1. This helps
+ * ensure smooth gain changes when the compressor is turned on and
+ * off.
+ */
+ for(i = 0;i < td;++i)
{
- smp = SamplesIn[it+base];
-
- amplitude = 1.0f;
- if(amplitude > gain)
- gain = minf(gain+state->AttackRate, amplitude);
- else if(amplitude < gain)
- gain = maxf(gain-state->ReleaseRate, amplitude);
- output = 1.0f / clampf(gain, 0.5f, 2.0f);
+ ALfloat amplitude = 1.0f;
+ if(amplitude > env)
+ env = minf(env*state->AttackMult, amplitude);
+ else if(amplitude < env)
+ env = maxf(env*state->ReleaseMult, amplitude);
- temps[it] = smp * output;
+ gains[i] = 1.0f / env;
}
-
- state->GainCtrl = gain;
}
+ state->EnvFollower = env;
-
- for(kt = 0;kt < NumChannels;kt++)
+ /* Now compress the signal amplitude to output. */
+ for(j = 0;j < MAX_EFFECT_CHANNELS;j++)
{
- ALfloat gain = state->Gain[kt];
- if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
- continue;
+ for(k = 0;k < NumChannels;k++)
+ {
+ ALfloat gain = state->Gain[j][k];
+ if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
- for(it = 0;it < td;it++)
- SamplesOut[kt][base+it] += gain * temps[it];
+ for(i = 0;i < td;i++)
+ SamplesOut[k][base+i] += SamplesIn[j][base+i] * gains[i] * gain;
+ }
}
base += td;
}
}
-DECLARE_DEFAULT_ALLOCATORS(ALcompressorState)
-DEFINE_ALEFFECTSTATE_VTABLE(ALcompressorState);
+typedef struct CompressorStateFactory {
+ DERIVE_FROM_TYPE(EffectStateFactory);
+} CompressorStateFactory;
-
-typedef struct ALcompressorStateFactory {
- DERIVE_FROM_TYPE(ALeffectStateFactory);
-} ALcompressorStateFactory;
-
-static ALeffectState *ALcompressorStateFactory_create(ALcompressorStateFactory *UNUSED(factory))
+static ALeffectState *CompressorStateFactory_create(CompressorStateFactory *UNUSED(factory))
{
ALcompressorState *state;
- state = ALcompressorState_New(sizeof(*state));
+ NEW_OBJ0(state, ALcompressorState)();
if(!state) return NULL;
- SET_VTABLE2(ALcompressorState, ALeffectState, state);
-
- state->Enabled = AL_TRUE;
- state->AttackRate = 0.0f;
- state->ReleaseRate = 0.0f;
- state->GainCtrl = 1.0f;
return STATIC_CAST(ALeffectState, state);
}
-DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALcompressorStateFactory);
+DEFINE_EFFECTSTATEFACTORY_VTABLE(CompressorStateFactory);
-ALeffectStateFactory *ALcompressorStateFactory_getFactory(void)
+EffectStateFactory *CompressorStateFactory_getFactory(void)
{
- static ALcompressorStateFactory CompressorFactory = { { GET_VTABLE2(ALcompressorStateFactory, ALeffectStateFactory) } };
+ static CompressorStateFactory CompressorFactory = { { GET_VTABLE2(CompressorStateFactory, EffectStateFactory) } };
- return STATIC_CAST(ALeffectStateFactory, &CompressorFactory);
+ return STATIC_CAST(EffectStateFactory, &CompressorFactory);
}
@@ -172,24 +203,21 @@ void ALcompressor_setParami(ALeffect *effect, ALCcontext *context, ALenum param,
{
case AL_COMPRESSOR_ONOFF:
if(!(val >= AL_COMPRESSOR_MIN_ONOFF && val <= AL_COMPRESSOR_MAX_ONOFF))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Compressor state out of range");
props->Compressor.OnOff = val;
break;
- default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid compressor integer property 0x%04x",
+ param);
}
}
void ALcompressor_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
-{
- ALcompressor_setParami(effect, context, param, vals[0]);
-}
-void ALcompressor_setParamf(ALeffect *UNUSED(effect), ALCcontext *context, ALenum UNUSED(param), ALfloat UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-void ALcompressor_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
-{
- ALcompressor_setParamf(effect, context, param, vals[0]);
-}
+{ ALcompressor_setParami(effect, context, param, vals[0]); }
+void ALcompressor_setParamf(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALfloat UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid compressor float property 0x%04x", param); }
+void ALcompressor_setParamfv(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, const ALfloat *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid compressor float-vector property 0x%04x", param); }
void ALcompressor_getParami(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *val)
{
@@ -199,19 +227,17 @@ void ALcompressor_getParami(const ALeffect *effect, ALCcontext *context, ALenum
case AL_COMPRESSOR_ONOFF:
*val = props->Compressor.OnOff;
break;
+
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid compressor integer property 0x%04x",
+ param);
}
}
void ALcompressor_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
-{
- ALcompressor_getParami(effect, context, param, vals);
-}
-void ALcompressor_getParamf(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum UNUSED(param), ALfloat *UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-void ALcompressor_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
-{
- ALcompressor_getParamf(effect, context, param, vals);
-}
+{ ALcompressor_getParami(effect, context, param, vals); }
+void ALcompressor_getParamf(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALfloat *UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid compressor float property 0x%04x", param); }
+void ALcompressor_getParamfv(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALfloat *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid compressor float-vector property 0x%04x", param); }
DEFINE_ALEFFECT_VTABLE(ALcompressor);
diff --git a/Alc/effects/dedicated.c b/Alc/effects/dedicated.c
index e09cc682..0e1fd389 100644
--- a/Alc/effects/dedicated.c
+++ b/Alc/effects/dedicated.c
@@ -23,114 +23,126 @@
#include <stdlib.h>
#include "alMain.h"
-#include "alFilter.h"
#include "alAuxEffectSlot.h"
#include "alError.h"
#include "alu.h"
+#include "filters/defs.h"
typedef struct ALdedicatedState {
DERIVE_FROM_TYPE(ALeffectState);
- ALfloat gains[MAX_OUTPUT_CHANNELS];
+ ALfloat CurrentGains[MAX_OUTPUT_CHANNELS];
+ ALfloat TargetGains[MAX_OUTPUT_CHANNELS];
} ALdedicatedState;
+static ALvoid ALdedicatedState_Destruct(ALdedicatedState *state);
+static ALboolean ALdedicatedState_deviceUpdate(ALdedicatedState *state, ALCdevice *device);
+static ALvoid ALdedicatedState_update(ALdedicatedState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props);
+static ALvoid ALdedicatedState_process(ALdedicatedState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels);
+DECLARE_DEFAULT_ALLOCATORS(ALdedicatedState)
+
+DEFINE_ALEFFECTSTATE_VTABLE(ALdedicatedState);
+
+
+static void ALdedicatedState_Construct(ALdedicatedState *state)
+{
+ ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
+ SET_VTABLE2(ALdedicatedState, ALeffectState, state);
+}
-static ALvoid ALdedicatedState_Destruct(ALdedicatedState *UNUSED(state))
+static ALvoid ALdedicatedState_Destruct(ALdedicatedState *state)
{
+ ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
}
-static ALboolean ALdedicatedState_deviceUpdate(ALdedicatedState *UNUSED(state), ALCdevice *UNUSED(device))
+static ALboolean ALdedicatedState_deviceUpdate(ALdedicatedState *state, ALCdevice *UNUSED(device))
{
+ ALsizei i;
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ state->CurrentGains[i] = 0.0f;
return AL_TRUE;
}
-static ALvoid ALdedicatedState_update(ALdedicatedState *state, ALCdevice *device, const ALeffectslot *Slot)
+static ALvoid ALdedicatedState_update(ALdedicatedState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props)
{
+ const ALCdevice *device = context->Device;
ALfloat Gain;
- ALuint i;
+ ALsizei i;
for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
- state->gains[i] = 0.0f;
+ state->TargetGains[i] = 0.0f;
- Gain = Slot->Gain * Slot->EffectProps.Dedicated.Gain;
- if(Slot->EffectType == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT)
+ Gain = slot->Params.Gain * props->Dedicated.Gain;
+ if(slot->Params.EffectType == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT)
{
int idx;
- if((idx=GetChannelIdxByName(device, LFE)) != -1)
- state->gains[idx] = Gain;
+ if((idx=GetChannelIdxByName(&device->RealOut, LFE)) != -1)
+ {
+ STATIC_CAST(ALeffectState,state)->OutBuffer = device->RealOut.Buffer;
+ STATIC_CAST(ALeffectState,state)->OutChannels = device->RealOut.NumChannels;
+ state->TargetGains[idx] = Gain;
+ }
}
- else if(Slot->EffectType == AL_EFFECT_DEDICATED_DIALOGUE)
+ else if(slot->Params.EffectType == AL_EFFECT_DEDICATED_DIALOGUE)
{
int idx;
/* Dialog goes to the front-center speaker if it exists, otherwise it
* plays from the front-center location. */
- if((idx=GetChannelIdxByName(device, FrontCenter)) != -1)
- state->gains[idx] = Gain;
+ if((idx=GetChannelIdxByName(&device->RealOut, FrontCenter)) != -1)
+ {
+ STATIC_CAST(ALeffectState,state)->OutBuffer = device->RealOut.Buffer;
+ STATIC_CAST(ALeffectState,state)->OutChannels = device->RealOut.NumChannels;
+ state->TargetGains[idx] = Gain;
+ }
else
{
- static const ALfloat front_dir[3] = { 0.0f, 0.0f, -1.0f };
- ComputeDirectionalGains(device, front_dir, Gain, state->gains);
+ ALfloat coeffs[MAX_AMBI_COEFFS];
+ CalcAngleCoeffs(0.0f, 0.0f, 0.0f, coeffs);
+
+ STATIC_CAST(ALeffectState,state)->OutBuffer = device->Dry.Buffer;
+ STATIC_CAST(ALeffectState,state)->OutChannels = device->Dry.NumChannels;
+ ComputePanGains(&device->Dry, coeffs, Gain, state->TargetGains);
}
}
}
-static ALvoid ALdedicatedState_process(ALdedicatedState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)
+static ALvoid ALdedicatedState_process(ALdedicatedState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels)
{
- const ALfloat *gains = state->gains;
- ALuint i, c;
-
- for(c = 0;c < NumChannels;c++)
- {
- if(!(fabsf(gains[c]) > GAIN_SILENCE_THRESHOLD))
- continue;
-
- for(i = 0;i < SamplesToDo;i++)
- SamplesOut[c][i] = SamplesIn[i] * gains[c];
- }
+ MixSamples(SamplesIn[0], NumChannels, SamplesOut, state->CurrentGains,
+ state->TargetGains, SamplesToDo, 0, SamplesToDo);
}
-DECLARE_DEFAULT_ALLOCATORS(ALdedicatedState)
-
-DEFINE_ALEFFECTSTATE_VTABLE(ALdedicatedState);
-
-typedef struct ALdedicatedStateFactory {
- DERIVE_FROM_TYPE(ALeffectStateFactory);
-} ALdedicatedStateFactory;
+typedef struct DedicatedStateFactory {
+ DERIVE_FROM_TYPE(EffectStateFactory);
+} DedicatedStateFactory;
-ALeffectState *ALdedicatedStateFactory_create(ALdedicatedStateFactory *UNUSED(factory))
+ALeffectState *DedicatedStateFactory_create(DedicatedStateFactory *UNUSED(factory))
{
ALdedicatedState *state;
- ALsizei s;
- state = ALdedicatedState_New(sizeof(*state));
+ NEW_OBJ0(state, ALdedicatedState)();
if(!state) return NULL;
- SET_VTABLE2(ALdedicatedState, ALeffectState, state);
-
- for(s = 0;s < MAX_OUTPUT_CHANNELS;s++)
- state->gains[s] = 0.0f;
return STATIC_CAST(ALeffectState, state);
}
-DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALdedicatedStateFactory);
+DEFINE_EFFECTSTATEFACTORY_VTABLE(DedicatedStateFactory);
-ALeffectStateFactory *ALdedicatedStateFactory_getFactory(void)
+EffectStateFactory *DedicatedStateFactory_getFactory(void)
{
- static ALdedicatedStateFactory DedicatedFactory = { { GET_VTABLE2(ALdedicatedStateFactory, ALeffectStateFactory) } };
+ static DedicatedStateFactory DedicatedFactory = { { GET_VTABLE2(DedicatedStateFactory, EffectStateFactory) } };
- return STATIC_CAST(ALeffectStateFactory, &DedicatedFactory);
+ return STATIC_CAST(EffectStateFactory, &DedicatedFactory);
}
-void ALdedicated_setParami(ALeffect *UNUSED(effect), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-void ALdedicated_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
-{
- ALdedicated_setParami(effect, context, param, vals[0]);
-}
+void ALdedicated_setParami(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid dedicated integer property 0x%04x", param); }
+void ALdedicated_setParamiv(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, const ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid dedicated integer-vector property 0x%04x", param); }
void ALdedicated_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val)
{
ALeffectProps *props = &effect->Props;
@@ -138,25 +150,21 @@ void ALdedicated_setParamf(ALeffect *effect, ALCcontext *context, ALenum param,
{
case AL_DEDICATED_GAIN:
if(!(val >= 0.0f && isfinite(val)))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Dedicated gain out of range");
props->Dedicated.Gain = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid dedicated float property 0x%04x", param);
}
}
void ALdedicated_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
-{
- ALdedicated_setParamf(effect, context, param, vals[0]);
-}
+{ ALdedicated_setParamf(effect, context, param, vals[0]); }
-void ALdedicated_getParami(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-void ALdedicated_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
-{
- ALdedicated_getParami(effect, context, param, vals);
-}
+void ALdedicated_getParami(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint *UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid dedicated integer property 0x%04x", param); }
+void ALdedicated_getParamiv(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid dedicated integer-vector property 0x%04x", param); }
void ALdedicated_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
{
const ALeffectProps *props = &effect->Props;
@@ -167,12 +175,10 @@ void ALdedicated_getParamf(const ALeffect *effect, ALCcontext *context, ALenum p
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid dedicated float property 0x%04x", param);
}
}
void ALdedicated_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
-{
- ALdedicated_getParamf(effect, context, param, vals);
-}
+{ ALdedicated_getParamf(effect, context, param, vals); }
DEFINE_ALEFFECT_VTABLE(ALdedicated);
diff --git a/Alc/effects/distortion.c b/Alc/effects/distortion.c
index 221cec39..de8da4fe 100644
--- a/Alc/effects/distortion.c
+++ b/Alc/effects/distortion.c
@@ -24,10 +24,10 @@
#include <stdlib.h>
#include "alMain.h"
-#include "alFilter.h"
#include "alAuxEffectSlot.h"
#include "alError.h"
#include "alu.h"
+#include "filters/defs.h"
typedef struct ALdistortionState {
@@ -37,177 +37,172 @@ typedef struct ALdistortionState {
ALfloat Gain[MAX_OUTPUT_CHANNELS];
/* Effect parameters */
- ALfilterState lowpass;
- ALfilterState bandpass;
+ BiquadFilter lowpass;
+ BiquadFilter bandpass;
ALfloat attenuation;
ALfloat edge_coeff;
+
+ ALfloat Buffer[2][BUFFERSIZE];
} ALdistortionState;
-static ALvoid ALdistortionState_Destruct(ALdistortionState *UNUSED(state))
+static ALvoid ALdistortionState_Destruct(ALdistortionState *state);
+static ALboolean ALdistortionState_deviceUpdate(ALdistortionState *state, ALCdevice *device);
+static ALvoid ALdistortionState_update(ALdistortionState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props);
+static ALvoid ALdistortionState_process(ALdistortionState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels);
+DECLARE_DEFAULT_ALLOCATORS(ALdistortionState)
+
+DEFINE_ALEFFECTSTATE_VTABLE(ALdistortionState);
+
+
+static void ALdistortionState_Construct(ALdistortionState *state)
+{
+ ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
+ SET_VTABLE2(ALdistortionState, ALeffectState, state);
+}
+
+static ALvoid ALdistortionState_Destruct(ALdistortionState *state)
{
+ ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
}
-static ALboolean ALdistortionState_deviceUpdate(ALdistortionState *UNUSED(state), ALCdevice *UNUSED(device))
+static ALboolean ALdistortionState_deviceUpdate(ALdistortionState *state, ALCdevice *UNUSED(device))
{
+ BiquadFilter_clear(&state->lowpass);
+ BiquadFilter_clear(&state->bandpass);
return AL_TRUE;
}
-static ALvoid ALdistortionState_update(ALdistortionState *state, ALCdevice *Device, const ALeffectslot *Slot)
+static ALvoid ALdistortionState_update(ALdistortionState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props)
{
- ALfloat frequency = (ALfloat)Device->Frequency;
+ const ALCdevice *device = context->Device;
+ ALfloat frequency = (ALfloat)device->Frequency;
+ ALfloat coeffs[MAX_AMBI_COEFFS];
ALfloat bandwidth;
ALfloat cutoff;
ALfloat edge;
- /* Store distorted signal attenuation settings */
- state->attenuation = Slot->EffectProps.Distortion.Gain;
-
- /* Store waveshaper edge settings */
- edge = sinf(Slot->EffectProps.Distortion.Edge * (F_PI_2));
+ /* Store waveshaper edge settings. */
+ edge = sinf(props->Distortion.Edge * (F_PI_2));
edge = minf(edge, 0.99f);
state->edge_coeff = 2.0f * edge / (1.0f-edge);
- /* Lowpass filter */
- cutoff = Slot->EffectProps.Distortion.LowpassCutoff;
- /* Bandwidth value is constant in octaves */
+ cutoff = props->Distortion.LowpassCutoff;
+ /* Bandwidth value is constant in octaves. */
bandwidth = (cutoff / 2.0f) / (cutoff * 0.67f);
- ALfilterState_setParams(&state->lowpass, ALfilterType_LowPass, 1.0f,
+ /* Multiply sampling frequency by the amount of oversampling done during
+ * processing.
+ */
+ BiquadFilter_setParams(&state->lowpass, BiquadType_LowPass, 1.0f,
cutoff / (frequency*4.0f), calc_rcpQ_from_bandwidth(cutoff / (frequency*4.0f), bandwidth)
);
- /* Bandpass filter */
- cutoff = Slot->EffectProps.Distortion.EQCenter;
- /* Convert bandwidth in Hz to octaves */
- bandwidth = Slot->EffectProps.Distortion.EQBandwidth / (cutoff * 0.67f);
- ALfilterState_setParams(&state->bandpass, ALfilterType_BandPass, 1.0f,
+ cutoff = props->Distortion.EQCenter;
+ /* Convert bandwidth in Hz to octaves. */
+ bandwidth = props->Distortion.EQBandwidth / (cutoff * 0.67f);
+ BiquadFilter_setParams(&state->bandpass, BiquadType_BandPass, 1.0f,
cutoff / (frequency*4.0f), calc_rcpQ_from_bandwidth(cutoff / (frequency*4.0f), bandwidth)
);
- ComputeAmbientGains(Device, Slot->Gain, state->Gain);
+ CalcAngleCoeffs(0.0f, 0.0f, 0.0f, coeffs);
+ ComputePanGains(&device->Dry, coeffs, slot->Params.Gain*props->Distortion.Gain, state->Gain);
}
-static ALvoid ALdistortionState_process(ALdistortionState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)
+static ALvoid ALdistortionState_process(ALdistortionState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels)
{
+ ALfloat (*restrict buffer)[BUFFERSIZE] = state->Buffer;
const ALfloat fc = state->edge_coeff;
- ALuint base;
- ALuint it;
- ALuint ot;
- ALuint kt;
+ ALsizei base;
+ ALsizei i, k;
for(base = 0;base < SamplesToDo;)
{
- float oversample_buffer[64][4];
- ALuint td = minu(64, SamplesToDo-base);
-
- /* Perform 4x oversampling to avoid aliasing. */
- /* Oversampling greatly improves distortion */
- /* quality and allows to implement lowpass and */
- /* bandpass filters using high frequencies, at */
- /* which classic IIR filters became unstable. */
-
- /* Fill oversample buffer using zero stuffing */
- for(it = 0;it < td;it++)
+ /* Perform 4x oversampling to avoid aliasing. Oversampling greatly
+ * improves distortion quality and allows to implement lowpass and
+ * bandpass filters using high frequencies, at which classic IIR
+ * filters became unstable.
+ */
+ ALsizei todo = mini(BUFFERSIZE, (SamplesToDo-base) * 4);
+
+ /* Fill oversample buffer using zero stuffing. Multiply the sample by
+ * the amount of oversampling to maintain the signal's power.
+ */
+ for(i = 0;i < todo;i++)
+ buffer[0][i] = !(i&3) ? SamplesIn[0][(i>>2)+base] * 4.0f : 0.0f;
+
+ /* First step, do lowpass filtering of original signal. Additionally
+ * perform buffer interpolation and lowpass cutoff for oversampling
+ * (which is fortunately first step of distortion). So combine three
+ * operations into the one.
+ */
+ BiquadFilter_process(&state->lowpass, buffer[1], buffer[0], todo);
+
+ /* Second step, do distortion using waveshaper function to emulate
+ * signal processing during tube overdriving. Three steps of
+ * waveshaping are intended to modify waveform without boost/clipping/
+ * attenuation process.
+ */
+ for(i = 0;i < todo;i++)
{
- oversample_buffer[it][0] = SamplesIn[it+base];
- oversample_buffer[it][1] = 0.0f;
- oversample_buffer[it][2] = 0.0f;
- oversample_buffer[it][3] = 0.0f;
- }
+ ALfloat smp = buffer[1][i];
- /* First step, do lowpass filtering of original signal, */
- /* additionally perform buffer interpolation and lowpass */
- /* cutoff for oversampling (which is fortunately first */
- /* step of distortion). So combine three operations into */
- /* the one. */
- for(it = 0;it < td;it++)
- {
- for(ot = 0;ot < 4;ot++)
- {
- ALfloat smp;
- smp = ALfilterState_processSingle(&state->lowpass, oversample_buffer[it][ot]);
-
- /* Restore signal power by multiplying sample by amount of oversampling */
- oversample_buffer[it][ot] = smp * 4.0f;
- }
- }
+ smp = (1.0f + fc) * smp/(1.0f + fc*fabsf(smp));
+ smp = (1.0f + fc) * smp/(1.0f + fc*fabsf(smp)) * -1.0f;
+ smp = (1.0f + fc) * smp/(1.0f + fc*fabsf(smp));
- for(it = 0;it < td;it++)
- {
- /* Second step, do distortion using waveshaper function */
- /* to emulate signal processing during tube overdriving. */
- /* Three steps of waveshaping are intended to modify */
- /* waveform without boost/clipping/attenuation process. */
- for(ot = 0;ot < 4;ot++)
- {
- ALfloat smp = oversample_buffer[it][ot];
-
- smp = (1.0f + fc) * smp/(1.0f + fc*fabsf(smp));
- smp = (1.0f + fc) * smp/(1.0f + fc*fabsf(smp)) * -1.0f;
- smp = (1.0f + fc) * smp/(1.0f + fc*fabsf(smp));
-
- /* Third step, do bandpass filtering of distorted signal */
- smp = ALfilterState_processSingle(&state->bandpass, smp);
- oversample_buffer[it][ot] = smp;
- }
+ buffer[0][i] = smp;
}
- for(kt = 0;kt < NumChannels;kt++)
+ /* Third step, do bandpass filtering of distorted signal. */
+ BiquadFilter_process(&state->bandpass, buffer[1], buffer[0], todo);
+
+ todo >>= 2;
+ for(k = 0;k < NumChannels;k++)
{
/* Fourth step, final, do attenuation and perform decimation,
- * store only one sample out of 4.
+ * storing only one sample out of four.
*/
- ALfloat gain = state->Gain[kt] * state->attenuation;
+ ALfloat gain = state->Gain[k];
if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
continue;
- for(it = 0;it < td;it++)
- SamplesOut[kt][base+it] += gain * oversample_buffer[it][0];
+ for(i = 0;i < todo;i++)
+ SamplesOut[k][base+i] += gain * buffer[1][i*4];
}
- base += td;
+ base += todo;
}
}
-DECLARE_DEFAULT_ALLOCATORS(ALdistortionState)
-
-DEFINE_ALEFFECTSTATE_VTABLE(ALdistortionState);
-
-typedef struct ALdistortionStateFactory {
- DERIVE_FROM_TYPE(ALeffectStateFactory);
-} ALdistortionStateFactory;
+typedef struct DistortionStateFactory {
+ DERIVE_FROM_TYPE(EffectStateFactory);
+} DistortionStateFactory;
-static ALeffectState *ALdistortionStateFactory_create(ALdistortionStateFactory *UNUSED(factory))
+static ALeffectState *DistortionStateFactory_create(DistortionStateFactory *UNUSED(factory))
{
ALdistortionState *state;
- state = ALdistortionState_New(sizeof(*state));
+ NEW_OBJ0(state, ALdistortionState)();
if(!state) return NULL;
- SET_VTABLE2(ALdistortionState, ALeffectState, state);
-
- ALfilterState_clear(&state->lowpass);
- ALfilterState_clear(&state->bandpass);
return STATIC_CAST(ALeffectState, state);
}
-DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALdistortionStateFactory);
+DEFINE_EFFECTSTATEFACTORY_VTABLE(DistortionStateFactory);
-ALeffectStateFactory *ALdistortionStateFactory_getFactory(void)
+EffectStateFactory *DistortionStateFactory_getFactory(void)
{
- static ALdistortionStateFactory DistortionFactory = { { GET_VTABLE2(ALdistortionStateFactory, ALeffectStateFactory) } };
+ static DistortionStateFactory DistortionFactory = { { GET_VTABLE2(DistortionStateFactory, EffectStateFactory) } };
- return STATIC_CAST(ALeffectStateFactory, &DistortionFactory);
+ return STATIC_CAST(EffectStateFactory, &DistortionFactory);
}
-void ALdistortion_setParami(ALeffect *UNUSED(effect), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-void ALdistortion_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
-{
- ALdistortion_setParami(effect, context, param, vals[0]);
-}
+void ALdistortion_setParami(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid distortion integer property 0x%04x", param); }
+void ALdistortion_setParamiv(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, const ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid distortion integer-vector property 0x%04x", param); }
void ALdistortion_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val)
{
ALeffectProps *props = &effect->Props;
@@ -215,49 +210,46 @@ void ALdistortion_setParamf(ALeffect *effect, ALCcontext *context, ALenum param,
{
case AL_DISTORTION_EDGE:
if(!(val >= AL_DISTORTION_MIN_EDGE && val <= AL_DISTORTION_MAX_EDGE))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Distortion edge out of range");
props->Distortion.Edge = val;
break;
case AL_DISTORTION_GAIN:
if(!(val >= AL_DISTORTION_MIN_GAIN && val <= AL_DISTORTION_MAX_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Distortion gain out of range");
props->Distortion.Gain = val;
break;
case AL_DISTORTION_LOWPASS_CUTOFF:
if(!(val >= AL_DISTORTION_MIN_LOWPASS_CUTOFF && val <= AL_DISTORTION_MAX_LOWPASS_CUTOFF))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Distortion low-pass cutoff out of range");
props->Distortion.LowpassCutoff = val;
break;
case AL_DISTORTION_EQCENTER:
if(!(val >= AL_DISTORTION_MIN_EQCENTER && val <= AL_DISTORTION_MAX_EQCENTER))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Distortion EQ center out of range");
props->Distortion.EQCenter = val;
break;
case AL_DISTORTION_EQBANDWIDTH:
if(!(val >= AL_DISTORTION_MIN_EQBANDWIDTH && val <= AL_DISTORTION_MAX_EQBANDWIDTH))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Distortion EQ bandwidth out of range");
props->Distortion.EQBandwidth = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid distortion float property 0x%04x",
+ param);
}
}
void ALdistortion_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
-{
- ALdistortion_setParamf(effect, context, param, vals[0]);
-}
+{ ALdistortion_setParamf(effect, context, param, vals[0]); }
-void ALdistortion_getParami(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-void ALdistortion_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
-{
- ALdistortion_getParami(effect, context, param, vals);
-}
+void ALdistortion_getParami(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint *UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid distortion integer property 0x%04x", param); }
+void ALdistortion_getParamiv(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid distortion integer-vector property 0x%04x", param); }
void ALdistortion_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
{
const ALeffectProps *props = &effect->Props;
@@ -284,12 +276,11 @@ void ALdistortion_getParamf(const ALeffect *effect, ALCcontext *context, ALenum
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid distortion float property 0x%04x",
+ param);
}
}
void ALdistortion_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
-{
- ALdistortion_getParamf(effect, context, param, vals);
-}
+{ ALdistortion_getParamf(effect, context, param, vals); }
DEFINE_ALEFFECT_VTABLE(ALdistortion);
diff --git a/Alc/effects/echo.c b/Alc/effects/echo.c
index f5a53c36..4570fcb1 100644
--- a/Alc/effects/echo.c
+++ b/Alc/effects/echo.c
@@ -28,186 +28,207 @@
#include "alAuxEffectSlot.h"
#include "alError.h"
#include "alu.h"
+#include "filters/defs.h"
typedef struct ALechoState {
DERIVE_FROM_TYPE(ALeffectState);
ALfloat *SampleBuffer;
- ALuint BufferLength;
+ ALsizei BufferLength;
// The echo is two tap. The delay is the number of samples from before the
// current offset
struct {
- ALuint delay;
+ ALsizei delay;
} Tap[2];
- ALuint Offset;
+ ALsizei Offset;
+
/* The panning gains for the two taps */
- ALfloat Gain[2][MAX_OUTPUT_CHANNELS];
+ struct {
+ ALfloat Current[MAX_OUTPUT_CHANNELS];
+ ALfloat Target[MAX_OUTPUT_CHANNELS];
+ } Gains[2];
ALfloat FeedGain;
- ALfilterState Filter;
+ BiquadFilter Filter;
} ALechoState;
+static ALvoid ALechoState_Destruct(ALechoState *state);
+static ALboolean ALechoState_deviceUpdate(ALechoState *state, ALCdevice *Device);
+static ALvoid ALechoState_update(ALechoState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props);
+static ALvoid ALechoState_process(ALechoState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels);
+DECLARE_DEFAULT_ALLOCATORS(ALechoState)
+
+DEFINE_ALEFFECTSTATE_VTABLE(ALechoState);
+
+
+static void ALechoState_Construct(ALechoState *state)
+{
+ ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
+ SET_VTABLE2(ALechoState, ALeffectState, state);
+
+ state->BufferLength = 0;
+ state->SampleBuffer = NULL;
+
+ state->Tap[0].delay = 0;
+ state->Tap[1].delay = 0;
+ state->Offset = 0;
+
+ BiquadFilter_clear(&state->Filter);
+}
+
static ALvoid ALechoState_Destruct(ALechoState *state)
{
- free(state->SampleBuffer);
+ al_free(state->SampleBuffer);
state->SampleBuffer = NULL;
+ ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
}
static ALboolean ALechoState_deviceUpdate(ALechoState *state, ALCdevice *Device)
{
- ALuint maxlen, i;
+ ALsizei maxlen;
// 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 = fastf2u(AL_ECHO_MAX_DELAY * Device->Frequency) + 1;
- maxlen += fastf2u(AL_ECHO_MAX_LRDELAY * Device->Frequency) + 1;
- maxlen = NextPowerOf2(maxlen);
+ maxlen = float2int(AL_ECHO_MAX_DELAY*Device->Frequency + 0.5f) +
+ float2int(AL_ECHO_MAX_LRDELAY*Device->Frequency + 0.5f);
+ maxlen = NextPowerOf2(maxlen);
+ if(maxlen <= 0) return AL_FALSE;
if(maxlen != state->BufferLength)
{
- void *temp;
-
- temp = realloc(state->SampleBuffer, maxlen * sizeof(ALfloat));
+ void *temp = al_calloc(16, maxlen * sizeof(ALfloat));
if(!temp) return AL_FALSE;
+
+ al_free(state->SampleBuffer);
state->SampleBuffer = temp;
state->BufferLength = maxlen;
}
- for(i = 0;i < state->BufferLength;i++)
- state->SampleBuffer[i] = 0.0f;
+
+ memset(state->SampleBuffer, 0, state->BufferLength*sizeof(ALfloat));
+ memset(state->Gains, 0, sizeof(state->Gains));
return AL_TRUE;
}
-static ALvoid ALechoState_update(ALechoState *state, ALCdevice *Device, const ALeffectslot *Slot)
+static ALvoid ALechoState_update(ALechoState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props)
{
- ALfloat pandir[3] = { 0.0f, 0.0f, 0.0f };
- ALuint frequency = Device->Frequency;
- ALfloat gain, lrpan;
+ const ALCdevice *device = context->Device;
+ ALuint frequency = device->Frequency;
+ ALfloat coeffs[MAX_AMBI_COEFFS];
+ ALfloat gainhf, lrpan, spread;
- state->Tap[0].delay = fastf2u(Slot->EffectProps.Echo.Delay * frequency) + 1;
- state->Tap[1].delay = fastf2u(Slot->EffectProps.Echo.LRDelay * frequency);
+ state->Tap[0].delay = maxi(float2int(props->Echo.Delay*frequency + 0.5f), 1);
+ state->Tap[1].delay = float2int(props->Echo.LRDelay*frequency + 0.5f);
state->Tap[1].delay += state->Tap[0].delay;
- lrpan = Slot->EffectProps.Echo.Spread;
+ spread = props->Echo.Spread;
+ if(spread < 0.0f) lrpan = -1.0f;
+ else lrpan = 1.0f;
+ /* Convert echo spread (where 0 = omni, +/-1 = directional) to coverage
+ * spread (where 0 = point, tau = omni).
+ */
+ spread = asinf(1.0f - fabsf(spread))*4.0f;
- state->FeedGain = Slot->EffectProps.Echo.Feedback;
+ state->FeedGain = props->Echo.Feedback;
- gain = minf(1.0f - Slot->EffectProps.Echo.Damping, 0.01f);
- ALfilterState_setParams(&state->Filter, ALfilterType_HighShelf,
- gain, LOWPASSFREQREF/frequency,
- calc_rcpQ_from_slope(gain, 0.75f));
-
- gain = Slot->Gain;
+ gainhf = maxf(1.0f - props->Echo.Damping, 0.0625f); /* Limit -24dB */
+ BiquadFilter_setParams(&state->Filter, BiquadType_HighShelf,
+ gainhf, LOWPASSFREQREF/frequency, calc_rcpQ_from_slope(gainhf, 1.0f)
+ );
/* First tap panning */
- pandir[0] = -lrpan;
- ComputeDirectionalGains(Device, pandir, gain, state->Gain[0]);
+ CalcAngleCoeffs(-F_PI_2*lrpan, 0.0f, spread, coeffs);
+ ComputePanGains(&device->Dry, coeffs, slot->Params.Gain, state->Gains[0].Target);
/* Second tap panning */
- pandir[0] = +lrpan;
- ComputeDirectionalGains(Device, pandir, gain, state->Gain[1]);
+ CalcAngleCoeffs( F_PI_2*lrpan, 0.0f, spread, coeffs);
+ ComputePanGains(&device->Dry, coeffs, slot->Params.Gain, state->Gains[1].Target);
}
-static ALvoid ALechoState_process(ALechoState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)
+static ALvoid ALechoState_process(ALechoState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels)
{
- const ALuint mask = state->BufferLength-1;
- const ALuint tap1 = state->Tap[0].delay;
- const ALuint tap2 = state->Tap[1].delay;
- ALuint offset = state->Offset;
- ALfloat smp;
- ALuint base;
- ALuint i, k;
-
+ const ALsizei mask = state->BufferLength-1;
+ const ALsizei tap1 = state->Tap[0].delay;
+ const ALsizei tap2 = state->Tap[1].delay;
+ ALfloat *restrict delaybuf = state->SampleBuffer;
+ ALsizei offset = state->Offset;
+ ALfloat z1, z2, in, out;
+ ALsizei base;
+ ALsizei c, i;
+
+ z1 = state->Filter.z1;
+ z2 = state->Filter.z2;
for(base = 0;base < SamplesToDo;)
{
- ALfloat temps[128][2];
- ALuint td = minu(128, SamplesToDo-base);
+ alignas(16) ALfloat temps[2][128];
+ ALsizei td = mini(128, SamplesToDo-base);
for(i = 0;i < td;i++)
{
+ /* Feed the delay buffer's input first. */
+ delaybuf[offset&mask] = SamplesIn[0][i+base];
+
/* First tap */
- temps[i][0] = state->SampleBuffer[(offset-tap1) & mask];
+ temps[0][i] = delaybuf[(offset-tap1) & mask];
/* Second tap */
- temps[i][1] = state->SampleBuffer[(offset-tap2) & mask];
+ temps[1][i] = delaybuf[(offset-tap2) & mask];
- // Apply damping and feedback gain to the second tap, and mix in the
- // new sample
- smp = ALfilterState_processSingle(&state->Filter, temps[i][1]+SamplesIn[i+base]);
- state->SampleBuffer[offset&mask] = smp * state->FeedGain;
+ /* Apply damping to the second tap, then add it to the buffer with
+ * feedback attenuation.
+ */
+ in = temps[1][i];
+ out = in*state->Filter.b0 + z1;
+ z1 = in*state->Filter.b1 - out*state->Filter.a1 + z2;
+ z2 = in*state->Filter.b2 - out*state->Filter.a2;
+
+ delaybuf[offset&mask] += out * state->FeedGain;
offset++;
}
- for(k = 0;k < NumChannels;k++)
- {
- ALfloat gain = state->Gain[0][k];
- if(fabsf(gain) > GAIN_SILENCE_THRESHOLD)
- {
- for(i = 0;i < td;i++)
- SamplesOut[k][i+base] += temps[i][0] * gain;
- }
-
- gain = state->Gain[1][k];
- if(fabsf(gain) > GAIN_SILENCE_THRESHOLD)
- {
- for(i = 0;i < td;i++)
- SamplesOut[k][i+base] += temps[i][1] * gain;
- }
- }
+ for(c = 0;c < 2;c++)
+ MixSamples(temps[c], NumChannels, SamplesOut, state->Gains[c].Current,
+ state->Gains[c].Target, SamplesToDo-base, base, td);
base += td;
}
+ state->Filter.z1 = z1;
+ state->Filter.z2 = z2;
state->Offset = offset;
}
-DECLARE_DEFAULT_ALLOCATORS(ALechoState)
-
-DEFINE_ALEFFECTSTATE_VTABLE(ALechoState);
-
-typedef struct ALechoStateFactory {
- DERIVE_FROM_TYPE(ALeffectStateFactory);
-} ALechoStateFactory;
+typedef struct EchoStateFactory {
+ DERIVE_FROM_TYPE(EffectStateFactory);
+} EchoStateFactory;
-ALeffectState *ALechoStateFactory_create(ALechoStateFactory *UNUSED(factory))
+ALeffectState *EchoStateFactory_create(EchoStateFactory *UNUSED(factory))
{
ALechoState *state;
- state = ALechoState_New(sizeof(*state));
+ NEW_OBJ0(state, ALechoState)();
if(!state) return NULL;
- SET_VTABLE2(ALechoState, ALeffectState, state);
-
- state->BufferLength = 0;
- state->SampleBuffer = NULL;
-
- state->Tap[0].delay = 0;
- state->Tap[1].delay = 0;
- state->Offset = 0;
-
- ALfilterState_clear(&state->Filter);
return STATIC_CAST(ALeffectState, state);
}
-DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALechoStateFactory);
+DEFINE_EFFECTSTATEFACTORY_VTABLE(EchoStateFactory);
-ALeffectStateFactory *ALechoStateFactory_getFactory(void)
+EffectStateFactory *EchoStateFactory_getFactory(void)
{
- static ALechoStateFactory EchoFactory = { { GET_VTABLE2(ALechoStateFactory, ALeffectStateFactory) } };
+ static EchoStateFactory EchoFactory = { { GET_VTABLE2(EchoStateFactory, EffectStateFactory) } };
- return STATIC_CAST(ALeffectStateFactory, &EchoFactory);
+ return STATIC_CAST(EffectStateFactory, &EchoFactory);
}
-void ALecho_setParami(ALeffect *UNUSED(effect), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-void ALecho_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
-{
- ALecho_setParami(effect, context, param, vals[0]);
-}
+void ALecho_setParami(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid echo integer property 0x%04x", param); }
+void ALecho_setParamiv(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, const ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid echo integer-vector property 0x%04x", param); }
void ALecho_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val)
{
ALeffectProps *props = &effect->Props;
@@ -215,49 +236,45 @@ void ALecho_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALflo
{
case AL_ECHO_DELAY:
if(!(val >= AL_ECHO_MIN_DELAY && val <= AL_ECHO_MAX_DELAY))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Echo delay out of range");
props->Echo.Delay = val;
break;
case AL_ECHO_LRDELAY:
if(!(val >= AL_ECHO_MIN_LRDELAY && val <= AL_ECHO_MAX_LRDELAY))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Echo LR delay out of range");
props->Echo.LRDelay = val;
break;
case AL_ECHO_DAMPING:
if(!(val >= AL_ECHO_MIN_DAMPING && val <= AL_ECHO_MAX_DAMPING))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Echo damping out of range");
props->Echo.Damping = val;
break;
case AL_ECHO_FEEDBACK:
if(!(val >= AL_ECHO_MIN_FEEDBACK && val <= AL_ECHO_MAX_FEEDBACK))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Echo feedback out of range");
props->Echo.Feedback = val;
break;
case AL_ECHO_SPREAD:
if(!(val >= AL_ECHO_MIN_SPREAD && val <= AL_ECHO_MAX_SPREAD))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Echo spread out of range");
props->Echo.Spread = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid echo float property 0x%04x", param);
}
}
void ALecho_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
-{
- ALecho_setParamf(effect, context, param, vals[0]);
-}
+{ ALecho_setParamf(effect, context, param, vals[0]); }
-void ALecho_getParami(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-void ALecho_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
-{
- ALecho_getParami(effect, context, param, vals);
-}
+void ALecho_getParami(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint *UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid echo integer property 0x%04x", param); }
+void ALecho_getParamiv(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid echo integer-vector property 0x%04x", param); }
void ALecho_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
{
const ALeffectProps *props = &effect->Props;
@@ -284,12 +301,10 @@ void ALecho_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param,
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid echo float property 0x%04x", param);
}
}
void ALecho_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
-{
- ALecho_getParamf(effect, context, param, vals);
-}
+{ ALecho_getParamf(effect, context, param, vals); }
DEFINE_ALEFFECT_VTABLE(ALecho);
diff --git a/Alc/effects/equalizer.c b/Alc/effects/equalizer.c
index 244667ab..17106127 100644
--- a/Alc/effects/equalizer.c
+++ b/Alc/effects/equalizer.c
@@ -24,10 +24,10 @@
#include <stdlib.h>
#include "alMain.h"
-#include "alFilter.h"
#include "alAuxEffectSlot.h"
#include "alError.h"
#include "alu.h"
+#include "filters/defs.h"
/* The document "Effects Extension Guide.pdf" says that low and high *
@@ -71,139 +71,159 @@
* filter coefficients" by Robert Bristow-Johnson *
* http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt */
+
typedef struct ALequalizerState {
DERIVE_FROM_TYPE(ALeffectState);
- /* Effect gains for each channel */
- ALfloat Gain[MAX_OUTPUT_CHANNELS];
+ struct {
+ /* Effect parameters */
+ BiquadFilter filter[4];
+
+ /* Effect gains for each channel */
+ ALfloat CurrentGains[MAX_OUTPUT_CHANNELS];
+ ALfloat TargetGains[MAX_OUTPUT_CHANNELS];
+ } Chans[MAX_EFFECT_CHANNELS];
- /* Effect parameters */
- ALfilterState filter[4];
+ ALfloat SampleBuffer[MAX_EFFECT_CHANNELS][BUFFERSIZE];
} ALequalizerState;
-static ALvoid ALequalizerState_Destruct(ALequalizerState *UNUSED(state))
+static ALvoid ALequalizerState_Destruct(ALequalizerState *state);
+static ALboolean ALequalizerState_deviceUpdate(ALequalizerState *state, ALCdevice *device);
+static ALvoid ALequalizerState_update(ALequalizerState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props);
+static ALvoid ALequalizerState_process(ALequalizerState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels);
+DECLARE_DEFAULT_ALLOCATORS(ALequalizerState)
+
+DEFINE_ALEFFECTSTATE_VTABLE(ALequalizerState);
+
+
+static void ALequalizerState_Construct(ALequalizerState *state)
+{
+ ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
+ SET_VTABLE2(ALequalizerState, ALeffectState, state);
+}
+
+static ALvoid ALequalizerState_Destruct(ALequalizerState *state)
{
+ ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
}
-static ALboolean ALequalizerState_deviceUpdate(ALequalizerState *UNUSED(state), ALCdevice *UNUSED(device))
+static ALboolean ALequalizerState_deviceUpdate(ALequalizerState *state, ALCdevice *UNUSED(device))
{
+ ALsizei i, j;
+
+ for(i = 0; i < MAX_EFFECT_CHANNELS;i++)
+ {
+ for(j = 0;j < 4;j++)
+ BiquadFilter_clear(&state->Chans[i].filter[j]);
+ for(j = 0;j < MAX_OUTPUT_CHANNELS;j++)
+ state->Chans[i].CurrentGains[j] = 0.0f;
+ }
return AL_TRUE;
}
-static ALvoid ALequalizerState_update(ALequalizerState *state, ALCdevice *device, const ALeffectslot *slot)
+static ALvoid ALequalizerState_update(ALequalizerState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props)
{
+ const ALCdevice *device = context->Device;
ALfloat frequency = (ALfloat)device->Frequency;
- ALfloat gain, freq_mult;
-
- ComputeAmbientGains(device, slot->Gain, state->Gain);
+ ALfloat gain, f0norm;
+ ALuint i;
/* Calculate coefficients for the each type of filter. Note that the shelf
* filters' gain is for the reference frequency, which is the centerpoint
* of the transition band.
*/
- gain = sqrtf(slot->EffectProps.Equalizer.LowGain);
- freq_mult = slot->EffectProps.Equalizer.LowCutoff/frequency;
- ALfilterState_setParams(&state->filter[0], ALfilterType_LowShelf,
- gain, freq_mult, calc_rcpQ_from_slope(gain, 0.75f)
+ gain = maxf(sqrtf(props->Equalizer.LowGain), 0.0625f); /* Limit -24dB */
+ f0norm = props->Equalizer.LowCutoff/frequency;
+ BiquadFilter_setParams(&state->Chans[0].filter[0], BiquadType_LowShelf,
+ gain, f0norm, calc_rcpQ_from_slope(gain, 0.75f)
);
- gain = slot->EffectProps.Equalizer.Mid1Gain;
- freq_mult = slot->EffectProps.Equalizer.Mid1Center/frequency;
- ALfilterState_setParams(&state->filter[1], ALfilterType_Peaking,
- gain, freq_mult, calc_rcpQ_from_bandwidth(freq_mult, slot->EffectProps.Equalizer.Mid1Width)
+ gain = maxf(props->Equalizer.Mid1Gain, 0.0625f);
+ f0norm = props->Equalizer.Mid1Center/frequency;
+ BiquadFilter_setParams(&state->Chans[0].filter[1], BiquadType_Peaking,
+ gain, f0norm, calc_rcpQ_from_bandwidth(
+ f0norm, props->Equalizer.Mid1Width
+ )
);
- gain = slot->EffectProps.Equalizer.Mid2Gain;
- freq_mult = slot->EffectProps.Equalizer.Mid2Center/frequency;
- ALfilterState_setParams(&state->filter[2], ALfilterType_Peaking,
- gain, freq_mult, calc_rcpQ_from_bandwidth(freq_mult, slot->EffectProps.Equalizer.Mid2Width)
+ gain = maxf(props->Equalizer.Mid2Gain, 0.0625f);
+ f0norm = props->Equalizer.Mid2Center/frequency;
+ BiquadFilter_setParams(&state->Chans[0].filter[2], BiquadType_Peaking,
+ gain, f0norm, calc_rcpQ_from_bandwidth(
+ f0norm, props->Equalizer.Mid2Width
+ )
);
- gain = sqrtf(slot->EffectProps.Equalizer.HighGain);
- freq_mult = slot->EffectProps.Equalizer.HighCutoff/frequency;
- ALfilterState_setParams(&state->filter[3], ALfilterType_HighShelf,
- gain, freq_mult, calc_rcpQ_from_slope(gain, 0.75f)
+ gain = maxf(sqrtf(props->Equalizer.HighGain), 0.0625f);
+ f0norm = props->Equalizer.HighCutoff/frequency;
+ BiquadFilter_setParams(&state->Chans[0].filter[3], BiquadType_HighShelf,
+ gain, f0norm, calc_rcpQ_from_slope(gain, 0.75f)
);
-}
-
-static ALvoid ALequalizerState_process(ALequalizerState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)
-{
- ALuint base;
- ALuint it;
- ALuint kt;
- ALuint ft;
- for(base = 0;base < SamplesToDo;)
+ /* Copy the filter coefficients for the other input channels. */
+ for(i = 1;i < MAX_EFFECT_CHANNELS;i++)
{
- ALfloat temps[256];
- ALuint td = minu(256, SamplesToDo-base);
-
- for(it = 0;it < td;it++)
- {
- ALfloat smp = SamplesIn[base+it];
-
- for(ft = 0;ft < 4;ft++)
- smp = ALfilterState_processSingle(&state->filter[ft], smp);
-
- temps[it] = smp;
- }
+ BiquadFilter_copyParams(&state->Chans[i].filter[0], &state->Chans[0].filter[0]);
+ BiquadFilter_copyParams(&state->Chans[i].filter[1], &state->Chans[0].filter[1]);
+ BiquadFilter_copyParams(&state->Chans[i].filter[2], &state->Chans[0].filter[2]);
+ BiquadFilter_copyParams(&state->Chans[i].filter[3], &state->Chans[0].filter[3]);
+ }
- for(kt = 0;kt < NumChannels;kt++)
- {
- ALfloat gain = state->Gain[kt];
- if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
- continue;
+ STATIC_CAST(ALeffectState,state)->OutBuffer = device->FOAOut.Buffer;
+ STATIC_CAST(ALeffectState,state)->OutChannels = device->FOAOut.NumChannels;
+ for(i = 0;i < MAX_EFFECT_CHANNELS;i++)
+ ComputePanGains(&device->FOAOut, IdentityMatrixf.m[i], slot->Params.Gain,
+ state->Chans[i].TargetGains);
+}
- for(it = 0;it < td;it++)
- SamplesOut[kt][base+it] += gain * temps[it];
- }
+static ALvoid ALequalizerState_process(ALequalizerState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels)
+{
+ ALfloat (*restrict temps)[BUFFERSIZE] = state->SampleBuffer;
+ ALsizei c;
- base += td;
+ for(c = 0;c < MAX_EFFECT_CHANNELS;c++)
+ {
+ BiquadFilter_process(&state->Chans[c].filter[0], temps[0], SamplesIn[c], SamplesToDo);
+ BiquadFilter_process(&state->Chans[c].filter[1], temps[1], temps[0], SamplesToDo);
+ BiquadFilter_process(&state->Chans[c].filter[2], temps[2], temps[1], SamplesToDo);
+ BiquadFilter_process(&state->Chans[c].filter[3], temps[3], temps[2], SamplesToDo);
+
+ MixSamples(temps[3], NumChannels, SamplesOut,
+ state->Chans[c].CurrentGains, state->Chans[c].TargetGains,
+ SamplesToDo, 0, SamplesToDo
+ );
}
}
-DECLARE_DEFAULT_ALLOCATORS(ALequalizerState)
-
-DEFINE_ALEFFECTSTATE_VTABLE(ALequalizerState);
+typedef struct EqualizerStateFactory {
+ DERIVE_FROM_TYPE(EffectStateFactory);
+} EqualizerStateFactory;
-typedef struct ALequalizerStateFactory {
- DERIVE_FROM_TYPE(ALeffectStateFactory);
-} ALequalizerStateFactory;
-
-ALeffectState *ALequalizerStateFactory_create(ALequalizerStateFactory *UNUSED(factory))
+ALeffectState *EqualizerStateFactory_create(EqualizerStateFactory *UNUSED(factory))
{
ALequalizerState *state;
- int it;
- state = ALequalizerState_New(sizeof(*state));
+ NEW_OBJ0(state, ALequalizerState)();
if(!state) return NULL;
- SET_VTABLE2(ALequalizerState, ALeffectState, state);
-
- /* Initialize sample history only on filter creation to avoid */
- /* sound clicks if filter settings were changed in runtime. */
- for(it = 0; it < 4; it++)
- ALfilterState_clear(&state->filter[it]);
return STATIC_CAST(ALeffectState, state);
}
-DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALequalizerStateFactory);
+DEFINE_EFFECTSTATEFACTORY_VTABLE(EqualizerStateFactory);
-ALeffectStateFactory *ALequalizerStateFactory_getFactory(void)
+EffectStateFactory *EqualizerStateFactory_getFactory(void)
{
- static ALequalizerStateFactory EqualizerFactory = { { GET_VTABLE2(ALequalizerStateFactory, ALeffectStateFactory) } };
+ static EqualizerStateFactory EqualizerFactory = { { GET_VTABLE2(EqualizerStateFactory, EffectStateFactory) } };
- return STATIC_CAST(ALeffectStateFactory, &EqualizerFactory);
+ return STATIC_CAST(EffectStateFactory, &EqualizerFactory);
}
-void ALequalizer_setParami(ALeffect *UNUSED(effect), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-void ALequalizer_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
-{
- ALequalizer_setParami(effect, context, param, vals[0]);
-}
+void ALequalizer_setParami(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid equalizer integer property 0x%04x", param); }
+void ALequalizer_setParamiv(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, const ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid equalizer integer-vector property 0x%04x", param); }
void ALequalizer_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val)
{
ALeffectProps *props = &effect->Props;
@@ -211,79 +231,75 @@ void ALequalizer_setParamf(ALeffect *effect, ALCcontext *context, ALenum param,
{
case AL_EQUALIZER_LOW_GAIN:
if(!(val >= AL_EQUALIZER_MIN_LOW_GAIN && val <= AL_EQUALIZER_MAX_LOW_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Equalizer low-band gain out of range");
props->Equalizer.LowGain = val;
break;
case AL_EQUALIZER_LOW_CUTOFF:
if(!(val >= AL_EQUALIZER_MIN_LOW_CUTOFF && val <= AL_EQUALIZER_MAX_LOW_CUTOFF))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Equalizer low-band cutoff out of range");
props->Equalizer.LowCutoff = val;
break;
case AL_EQUALIZER_MID1_GAIN:
if(!(val >= AL_EQUALIZER_MIN_MID1_GAIN && val <= AL_EQUALIZER_MAX_MID1_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Equalizer mid1-band gain out of range");
props->Equalizer.Mid1Gain = val;
break;
case AL_EQUALIZER_MID1_CENTER:
if(!(val >= AL_EQUALIZER_MIN_MID1_CENTER && val <= AL_EQUALIZER_MAX_MID1_CENTER))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Equalizer mid1-band center out of range");
props->Equalizer.Mid1Center = val;
break;
case AL_EQUALIZER_MID1_WIDTH:
if(!(val >= AL_EQUALIZER_MIN_MID1_WIDTH && val <= AL_EQUALIZER_MAX_MID1_WIDTH))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Equalizer mid1-band width out of range");
props->Equalizer.Mid1Width = val;
break;
case AL_EQUALIZER_MID2_GAIN:
if(!(val >= AL_EQUALIZER_MIN_MID2_GAIN && val <= AL_EQUALIZER_MAX_MID2_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Equalizer mid2-band gain out of range");
props->Equalizer.Mid2Gain = val;
break;
case AL_EQUALIZER_MID2_CENTER:
if(!(val >= AL_EQUALIZER_MIN_MID2_CENTER && val <= AL_EQUALIZER_MAX_MID2_CENTER))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Equalizer mid2-band center out of range");
props->Equalizer.Mid2Center = val;
break;
case AL_EQUALIZER_MID2_WIDTH:
if(!(val >= AL_EQUALIZER_MIN_MID2_WIDTH && val <= AL_EQUALIZER_MAX_MID2_WIDTH))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Equalizer mid2-band width out of range");
props->Equalizer.Mid2Width = val;
break;
case AL_EQUALIZER_HIGH_GAIN:
if(!(val >= AL_EQUALIZER_MIN_HIGH_GAIN && val <= AL_EQUALIZER_MAX_HIGH_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Equalizer high-band gain out of range");
props->Equalizer.HighGain = val;
break;
case AL_EQUALIZER_HIGH_CUTOFF:
if(!(val >= AL_EQUALIZER_MIN_HIGH_CUTOFF && val <= AL_EQUALIZER_MAX_HIGH_CUTOFF))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Equalizer high-band cutoff out of range");
props->Equalizer.HighCutoff = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid equalizer float property 0x%04x", param);
}
}
void ALequalizer_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
-{
- ALequalizer_setParamf(effect, context, param, vals[0]);
-}
+{ ALequalizer_setParamf(effect, context, param, vals[0]); }
-void ALequalizer_getParami(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-void ALequalizer_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
-{
- ALequalizer_getParami(effect, context, param, vals);
-}
+void ALequalizer_getParami(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint *UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid equalizer integer property 0x%04x", param); }
+void ALequalizer_getParamiv(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid equalizer integer-vector property 0x%04x", param); }
void ALequalizer_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
{
const ALeffectProps *props = &effect->Props;
@@ -330,12 +346,10 @@ void ALequalizer_getParamf(const ALeffect *effect, ALCcontext *context, ALenum p
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid equalizer float property 0x%04x", param);
}
}
void ALequalizer_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
-{
- ALequalizer_getParamf(effect, context, param, vals);
-}
+{ ALequalizer_getParamf(effect, context, param, vals); }
DEFINE_ALEFFECT_VTABLE(ALequalizer);
diff --git a/Alc/effects/flanger.c b/Alc/effects/flanger.c
deleted file mode 100644
index f6191abd..00000000
--- a/Alc/effects/flanger.c
+++ /dev/null
@@ -1,398 +0,0 @@
-/**
- * OpenAL cross platform audio library
- * Copyright (C) 2013 by Mike Gorchak
- * 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 <math.h>
-#include <stdlib.h>
-
-#include "alMain.h"
-#include "alFilter.h"
-#include "alAuxEffectSlot.h"
-#include "alError.h"
-#include "alu.h"
-
-
-enum FlangerWaveForm {
- FWF_Triangle = AL_FLANGER_WAVEFORM_TRIANGLE,
- FWF_Sinusoid = AL_FLANGER_WAVEFORM_SINUSOID
-};
-
-typedef struct ALflangerState {
- DERIVE_FROM_TYPE(ALeffectState);
-
- ALfloat *SampleBuffer[2];
- ALuint BufferLength;
- ALuint offset;
- ALuint lfo_range;
- ALfloat lfo_scale;
- ALint lfo_disp;
-
- /* Gains for left and right sides */
- ALfloat Gain[2][MAX_OUTPUT_CHANNELS];
-
- /* effect parameters */
- enum FlangerWaveForm waveform;
- ALint delay;
- ALfloat depth;
- ALfloat feedback;
-} ALflangerState;
-
-static ALvoid ALflangerState_Destruct(ALflangerState *state)
-{
- free(state->SampleBuffer[0]);
- state->SampleBuffer[0] = NULL;
- state->SampleBuffer[1] = NULL;
-}
-
-static ALboolean ALflangerState_deviceUpdate(ALflangerState *state, ALCdevice *Device)
-{
- ALuint maxlen;
- ALuint it;
-
- maxlen = fastf2u(AL_FLANGER_MAX_DELAY * 3.0f * Device->Frequency) + 1;
- maxlen = NextPowerOf2(maxlen);
-
- if(maxlen != state->BufferLength)
- {
- void *temp;
-
- temp = realloc(state->SampleBuffer[0], maxlen * sizeof(ALfloat) * 2);
- if(!temp) return AL_FALSE;
- state->SampleBuffer[0] = temp;
- state->SampleBuffer[1] = state->SampleBuffer[0] + maxlen;
-
- state->BufferLength = maxlen;
- }
-
- for(it = 0;it < state->BufferLength;it++)
- {
- state->SampleBuffer[0][it] = 0.0f;
- state->SampleBuffer[1][it] = 0.0f;
- }
-
- return AL_TRUE;
-}
-
-static ALvoid ALflangerState_update(ALflangerState *state, ALCdevice *Device, const ALeffectslot *Slot)
-{
- static const ALfloat left_dir[3] = { -1.0f, 0.0f, 0.0f };
- static const ALfloat right_dir[3] = { 1.0f, 0.0f, 0.0f };
- ALfloat frequency = (ALfloat)Device->Frequency;
- ALfloat rate;
- ALint phase;
-
- switch(Slot->EffectProps.Flanger.Waveform)
- {
- case AL_FLANGER_WAVEFORM_TRIANGLE:
- state->waveform = FWF_Triangle;
- break;
- case AL_FLANGER_WAVEFORM_SINUSOID:
- state->waveform = FWF_Sinusoid;
- break;
- }
- state->depth = Slot->EffectProps.Flanger.Depth;
- state->feedback = Slot->EffectProps.Flanger.Feedback;
- state->delay = fastf2i(Slot->EffectProps.Flanger.Delay * frequency);
-
- /* Gains for left and right sides */
- ComputeDirectionalGains(Device, left_dir, Slot->Gain, state->Gain[0]);
- ComputeDirectionalGains(Device, right_dir, Slot->Gain, state->Gain[1]);
-
- phase = Slot->EffectProps.Flanger.Phase;
- rate = Slot->EffectProps.Flanger.Rate;
- if(!(rate > 0.0f))
- {
- state->lfo_scale = 0.0f;
- state->lfo_range = 1;
- state->lfo_disp = 0;
- }
- else
- {
- /* Calculate LFO coefficient */
- state->lfo_range = fastf2u(frequency/rate + 0.5f);
- switch(state->waveform)
- {
- case FWF_Triangle:
- state->lfo_scale = 4.0f / state->lfo_range;
- break;
- case FWF_Sinusoid:
- state->lfo_scale = F_TAU / state->lfo_range;
- break;
- }
-
- /* Calculate lfo phase displacement */
- state->lfo_disp = fastf2i(state->lfo_range * (phase/360.0f));
- }
-}
-
-static inline void Triangle(ALint *delay_left, ALint *delay_right, ALuint offset, const ALflangerState *state)
-{
- ALfloat lfo_value;
-
- lfo_value = 2.0f - fabsf(2.0f - state->lfo_scale*(offset%state->lfo_range));
- lfo_value *= state->depth * state->delay;
- *delay_left = fastf2i(lfo_value) + state->delay;
-
- offset += state->lfo_disp;
- lfo_value = 2.0f - fabsf(2.0f - state->lfo_scale*(offset%state->lfo_range));
- lfo_value *= state->depth * state->delay;
- *delay_right = fastf2i(lfo_value) + state->delay;
-}
-
-static inline void Sinusoid(ALint *delay_left, ALint *delay_right, ALuint offset, const ALflangerState *state)
-{
- ALfloat lfo_value;
-
- lfo_value = 1.0f + sinf(state->lfo_scale*(offset%state->lfo_range));
- lfo_value *= state->depth * state->delay;
- *delay_left = fastf2i(lfo_value) + state->delay;
-
- offset += state->lfo_disp;
- lfo_value = 1.0f + sinf(state->lfo_scale*(offset%state->lfo_range));
- lfo_value *= state->depth * state->delay;
- *delay_right = fastf2i(lfo_value) + state->delay;
-}
-
-#define DECL_TEMPLATE(Func) \
-static void Process##Func(ALflangerState *state, const ALuint SamplesToDo, \
- const ALfloat *restrict SamplesIn, ALfloat (*restrict out)[2]) \
-{ \
- const ALuint bufmask = state->BufferLength-1; \
- ALfloat *restrict leftbuf = state->SampleBuffer[0]; \
- ALfloat *restrict rightbuf = state->SampleBuffer[1]; \
- ALuint offset = state->offset; \
- const ALfloat feedback = state->feedback; \
- ALuint it; \
- \
- for(it = 0;it < SamplesToDo;it++) \
- { \
- ALint delay_left, delay_right; \
- Func(&delay_left, &delay_right, offset, state); \
- \
- out[it][0] = leftbuf[(offset-delay_left)&bufmask]; \
- leftbuf[offset&bufmask] = (out[it][0]+SamplesIn[it]) * feedback; \
- \
- out[it][1] = rightbuf[(offset-delay_right)&bufmask]; \
- rightbuf[offset&bufmask] = (out[it][1]+SamplesIn[it]) * feedback; \
- \
- offset++; \
- } \
- state->offset = offset; \
-}
-
-DECL_TEMPLATE(Triangle)
-DECL_TEMPLATE(Sinusoid)
-
-#undef DECL_TEMPLATE
-
-static ALvoid ALflangerState_process(ALflangerState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)
-{
- ALuint it, kt;
- ALuint base;
-
- for(base = 0;base < SamplesToDo;)
- {
- ALfloat temps[128][2];
- ALuint td = minu(128, SamplesToDo-base);
-
- switch(state->waveform)
- {
- case FWF_Triangle:
- ProcessTriangle(state, td, SamplesIn+base, temps);
- break;
- case FWF_Sinusoid:
- ProcessSinusoid(state, td, SamplesIn+base, temps);
- break;
- }
-
- for(kt = 0;kt < NumChannels;kt++)
- {
- ALfloat gain = state->Gain[0][kt];
- if(fabsf(gain) > GAIN_SILENCE_THRESHOLD)
- {
- for(it = 0;it < td;it++)
- SamplesOut[kt][it+base] += temps[it][0] * gain;
- }
-
- gain = state->Gain[1][kt];
- if(fabsf(gain) > GAIN_SILENCE_THRESHOLD)
- {
- for(it = 0;it < td;it++)
- SamplesOut[kt][it+base] += temps[it][1] * gain;
- }
- }
-
- base += td;
- }
-}
-
-DECLARE_DEFAULT_ALLOCATORS(ALflangerState)
-
-DEFINE_ALEFFECTSTATE_VTABLE(ALflangerState);
-
-
-typedef struct ALflangerStateFactory {
- DERIVE_FROM_TYPE(ALeffectStateFactory);
-} ALflangerStateFactory;
-
-ALeffectState *ALflangerStateFactory_create(ALflangerStateFactory *UNUSED(factory))
-{
- ALflangerState *state;
-
- state = ALflangerState_New(sizeof(*state));
- if(!state) return NULL;
- SET_VTABLE2(ALflangerState, ALeffectState, state);
-
- state->BufferLength = 0;
- state->SampleBuffer[0] = NULL;
- state->SampleBuffer[1] = NULL;
- state->offset = 0;
- state->lfo_range = 1;
- state->waveform = FWF_Triangle;
-
- return STATIC_CAST(ALeffectState, state);
-}
-
-DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALflangerStateFactory);
-
-ALeffectStateFactory *ALflangerStateFactory_getFactory(void)
-{
- static ALflangerStateFactory FlangerFactory = { { GET_VTABLE2(ALflangerStateFactory, ALeffectStateFactory) } };
-
- return STATIC_CAST(ALeffectStateFactory, &FlangerFactory);
-}
-
-
-void ALflanger_setParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val)
-{
- ALeffectProps *props = &effect->Props;
- switch(param)
- {
- case AL_FLANGER_WAVEFORM:
- if(!(val >= AL_FLANGER_MIN_WAVEFORM && val <= AL_FLANGER_MAX_WAVEFORM))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
- props->Flanger.Waveform = val;
- break;
-
- case AL_FLANGER_PHASE:
- if(!(val >= AL_FLANGER_MIN_PHASE && val <= AL_FLANGER_MAX_PHASE))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
- props->Flanger.Phase = val;
- break;
-
- default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
- }
-}
-void ALflanger_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
-{
- ALflanger_setParami(effect, context, param, vals[0]);
-}
-void ALflanger_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val)
-{
- ALeffectProps *props = &effect->Props;
- switch(param)
- {
- case AL_FLANGER_RATE:
- if(!(val >= AL_FLANGER_MIN_RATE && val <= AL_FLANGER_MAX_RATE))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
- props->Flanger.Rate = val;
- break;
-
- case AL_FLANGER_DEPTH:
- if(!(val >= AL_FLANGER_MIN_DEPTH && val <= AL_FLANGER_MAX_DEPTH))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
- props->Flanger.Depth = val;
- break;
-
- case AL_FLANGER_FEEDBACK:
- if(!(val >= AL_FLANGER_MIN_FEEDBACK && val <= AL_FLANGER_MAX_FEEDBACK))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
- props->Flanger.Feedback = val;
- break;
-
- case AL_FLANGER_DELAY:
- if(!(val >= AL_FLANGER_MIN_DELAY && val <= AL_FLANGER_MAX_DELAY))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
- props->Flanger.Delay = val;
- break;
-
- default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
- }
-}
-void ALflanger_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
-{
- ALflanger_setParamf(effect, context, param, vals[0]);
-}
-
-void ALflanger_getParami(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *val)
-{
- const ALeffectProps *props = &effect->Props;
- switch(param)
- {
- case AL_FLANGER_WAVEFORM:
- *val = props->Flanger.Waveform;
- break;
-
- case AL_FLANGER_PHASE:
- *val = props->Flanger.Phase;
- break;
-
- default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
- }
-}
-void ALflanger_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
-{
- ALflanger_getParami(effect, context, param, vals);
-}
-void ALflanger_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
-{
- const ALeffectProps *props = &effect->Props;
- switch(param)
- {
- case AL_FLANGER_RATE:
- *val = props->Flanger.Rate;
- break;
-
- case AL_FLANGER_DEPTH:
- *val = props->Flanger.Depth;
- break;
-
- case AL_FLANGER_FEEDBACK:
- *val = props->Flanger.Feedback;
- break;
-
- case AL_FLANGER_DELAY:
- *val = props->Flanger.Delay;
- break;
-
- default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
- }
-}
-void ALflanger_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
-{
- ALflanger_getParamf(effect, context, param, vals);
-}
-
-DEFINE_ALEFFECT_VTABLE(ALflanger);
diff --git a/Alc/effects/fshifter.c b/Alc/effects/fshifter.c
new file mode 100644
index 00000000..7d72472a
--- /dev/null
+++ b/Alc/effects/fshifter.c
@@ -0,0 +1,329 @@
+/**
+ * OpenAL cross platform audio library
+ * Copyright (C) 2018 by Raul Herraiz.
+ * 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 <math.h>
+#include <stdlib.h>
+
+#include "alMain.h"
+#include "alAuxEffectSlot.h"
+#include "alError.h"
+#include "alu.h"
+#include "filters/defs.h"
+
+#include "alcomplex.h"
+
+#define HIL_SIZE 1024
+#define OVERSAMP (1<<2)
+
+#define HIL_STEP (HIL_SIZE / OVERSAMP)
+#define FIFO_LATENCY (HIL_STEP * (OVERSAMP-1))
+
+
+typedef struct ALfshifterState {
+ DERIVE_FROM_TYPE(ALeffectState);
+
+ /* Effect parameters */
+ ALsizei count;
+ ALsizei PhaseStep;
+ ALsizei Phase;
+ ALdouble ld_sign;
+
+ /*Effects buffers*/
+ ALfloat InFIFO[HIL_SIZE];
+ ALcomplex OutFIFO[HIL_SIZE];
+ ALcomplex OutputAccum[HIL_SIZE];
+ ALcomplex Analytic[HIL_SIZE];
+ ALcomplex Outdata[BUFFERSIZE];
+
+ alignas(16) ALfloat BufferOut[BUFFERSIZE];
+
+ /* Effect gains for each output channel */
+ ALfloat CurrentGains[MAX_OUTPUT_CHANNELS];
+ ALfloat TargetGains[MAX_OUTPUT_CHANNELS];
+} ALfshifterState;
+
+static ALvoid ALfshifterState_Destruct(ALfshifterState *state);
+static ALboolean ALfshifterState_deviceUpdate(ALfshifterState *state, ALCdevice *device);
+static ALvoid ALfshifterState_update(ALfshifterState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props);
+static ALvoid ALfshifterState_process(ALfshifterState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels);
+DECLARE_DEFAULT_ALLOCATORS(ALfshifterState)
+
+DEFINE_ALEFFECTSTATE_VTABLE(ALfshifterState);
+
+/* Define a Hann window, used to filter the HIL input and output. */
+alignas(16) static ALdouble HannWindow[HIL_SIZE];
+
+static void InitHannWindow(void)
+{
+ ALsizei i;
+
+ /* Create lookup table of the Hann window for the desired size, i.e. HIL_SIZE */
+ for(i = 0;i < HIL_SIZE>>1;i++)
+ {
+ ALdouble val = sin(M_PI * (ALdouble)i / (ALdouble)(HIL_SIZE-1));
+ HannWindow[i] = HannWindow[HIL_SIZE-1-i] = val * val;
+ }
+}
+
+static alonce_flag HannInitOnce = AL_ONCE_FLAG_INIT;
+
+static void ALfshifterState_Construct(ALfshifterState *state)
+{
+ ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
+ SET_VTABLE2(ALfshifterState, ALeffectState, state);
+
+ alcall_once(&HannInitOnce, InitHannWindow);
+}
+
+static ALvoid ALfshifterState_Destruct(ALfshifterState *state)
+{
+ ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
+}
+
+static ALboolean ALfshifterState_deviceUpdate(ALfshifterState *state, ALCdevice *UNUSED(device))
+{
+ /* (Re-)initializing parameters and clear the buffers. */
+ state->count = FIFO_LATENCY;
+ state->PhaseStep = 0;
+ state->Phase = 0;
+ state->ld_sign = 1.0;
+
+ memset(state->InFIFO, 0, sizeof(state->InFIFO));
+ memset(state->OutFIFO, 0, sizeof(state->OutFIFO));
+ memset(state->OutputAccum, 0, sizeof(state->OutputAccum));
+ memset(state->Analytic, 0, sizeof(state->Analytic));
+
+ memset(state->CurrentGains, 0, sizeof(state->CurrentGains));
+ memset(state->TargetGains, 0, sizeof(state->TargetGains));
+
+ return AL_TRUE;
+}
+
+static ALvoid ALfshifterState_update(ALfshifterState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props)
+{
+ const ALCdevice *device = context->Device;
+ ALfloat coeffs[MAX_AMBI_COEFFS];
+ ALfloat step;
+
+ step = props->Fshifter.Frequency / (ALfloat)device->Frequency;
+ state->PhaseStep = fastf2i(minf(step, 0.5f) * FRACTIONONE);
+
+ switch(props->Fshifter.LeftDirection)
+ {
+ case AL_FREQUENCY_SHIFTER_DIRECTION_DOWN:
+ state->ld_sign = -1.0;
+ break;
+
+ case AL_FREQUENCY_SHIFTER_DIRECTION_UP:
+ state->ld_sign = 1.0;
+ break;
+
+ case AL_FREQUENCY_SHIFTER_DIRECTION_OFF:
+ state->Phase = 0;
+ state->PhaseStep = 0;
+ break;
+ }
+
+ CalcAngleCoeffs(0.0f, 0.0f, 0.0f, coeffs);
+ ComputePanGains(&device->Dry, coeffs, slot->Params.Gain, state->TargetGains);
+}
+
+static ALvoid ALfshifterState_process(ALfshifterState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels)
+{
+ static const ALcomplex complex_zero = { 0.0, 0.0 };
+ ALfloat *restrict BufferOut = state->BufferOut;
+ ALsizei j, k, base;
+
+ for(base = 0;base < SamplesToDo;)
+ {
+ ALsizei todo = mini(HIL_SIZE-state->count, SamplesToDo-base);
+
+ ASSUME(todo > 0);
+
+ /* Fill FIFO buffer with samples data */
+ k = state->count;
+ for(j = 0;j < todo;j++,k++)
+ {
+ state->InFIFO[k] = SamplesIn[0][base+j];
+ state->Outdata[base+j] = state->OutFIFO[k-FIFO_LATENCY];
+ }
+ state->count += todo;
+ base += todo;
+
+ /* Check whether FIFO buffer is filled */
+ if(state->count < HIL_SIZE) continue;
+
+ state->count = FIFO_LATENCY;
+
+ /* Real signal windowing and store in Analytic buffer */
+ for(k = 0;k < HIL_SIZE;k++)
+ {
+ state->Analytic[k].Real = state->InFIFO[k] * HannWindow[k];
+ state->Analytic[k].Imag = 0.0;
+ }
+
+ /* Processing signal by Discrete Hilbert Transform (analytical signal). */
+ complex_hilbert(state->Analytic, HIL_SIZE);
+
+ /* Windowing and add to output accumulator */
+ for(k = 0;k < HIL_SIZE;k++)
+ {
+ state->OutputAccum[k].Real += 2.0/OVERSAMP*HannWindow[k]*state->Analytic[k].Real;
+ state->OutputAccum[k].Imag += 2.0/OVERSAMP*HannWindow[k]*state->Analytic[k].Imag;
+ }
+
+ /* Shift accumulator, input & output FIFO */
+ for(k = 0;k < HIL_STEP;k++) state->OutFIFO[k] = state->OutputAccum[k];
+ for(j = 0;k < HIL_SIZE;k++,j++) state->OutputAccum[j] = state->OutputAccum[k];
+ for(;j < HIL_SIZE;j++) state->OutputAccum[j] = complex_zero;
+ for(k = 0;k < FIFO_LATENCY;k++)
+ state->InFIFO[k] = state->InFIFO[k+HIL_STEP];
+ }
+
+ /* Process frequency shifter using the analytic signal obtained. */
+ for(k = 0;k < SamplesToDo;k++)
+ {
+ ALdouble phase = state->Phase * ((1.0/FRACTIONONE) * 2.0*M_PI);
+ BufferOut[k] = (ALfloat)(state->Outdata[k].Real*cos(phase) +
+ state->Outdata[k].Imag*sin(phase)*state->ld_sign);
+
+ state->Phase += state->PhaseStep;
+ state->Phase &= FRACTIONMASK;
+ }
+
+ /* Now, mix the processed sound data to the output. */
+ MixSamples(BufferOut, NumChannels, SamplesOut, state->CurrentGains, state->TargetGains,
+ maxi(SamplesToDo, 512), 0, SamplesToDo);
+}
+
+typedef struct FshifterStateFactory {
+ DERIVE_FROM_TYPE(EffectStateFactory);
+} FshifterStateFactory;
+
+static ALeffectState *FshifterStateFactory_create(FshifterStateFactory *UNUSED(factory))
+{
+ ALfshifterState *state;
+
+ NEW_OBJ0(state, ALfshifterState)();
+ if(!state) return NULL;
+
+ return STATIC_CAST(ALeffectState, state);
+}
+
+DEFINE_EFFECTSTATEFACTORY_VTABLE(FshifterStateFactory);
+
+EffectStateFactory *FshifterStateFactory_getFactory(void)
+{
+ static FshifterStateFactory FshifterFactory = { { GET_VTABLE2(FshifterStateFactory, EffectStateFactory) } };
+
+ return STATIC_CAST(EffectStateFactory, &FshifterFactory);
+}
+
+void ALfshifter_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val)
+{
+ ALeffectProps *props = &effect->Props;
+ switch(param)
+ {
+ case AL_FREQUENCY_SHIFTER_FREQUENCY:
+ if(!(val >= AL_FREQUENCY_SHIFTER_MIN_FREQUENCY && val <= AL_FREQUENCY_SHIFTER_MAX_FREQUENCY))
+ SETERR_RETURN(context, AL_INVALID_VALUE,,"Frequency shifter frequency out of range");
+ props->Fshifter.Frequency = val;
+ break;
+
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid frequency shifter float property 0x%04x", param);
+ }
+}
+
+void ALfshifter_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
+{
+ ALfshifter_setParamf(effect, context, param, vals[0]);
+}
+
+void ALfshifter_setParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val)
+{
+ ALeffectProps *props = &effect->Props;
+ switch(param)
+ {
+ case AL_FREQUENCY_SHIFTER_LEFT_DIRECTION:
+ if(!(val >= AL_FREQUENCY_SHIFTER_MIN_LEFT_DIRECTION && val <= AL_FREQUENCY_SHIFTER_MAX_LEFT_DIRECTION))
+ SETERR_RETURN(context, AL_INVALID_VALUE,,"Frequency shifter left direction out of range");
+ props->Fshifter.LeftDirection = val;
+ break;
+
+ case AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION:
+ if(!(val >= AL_FREQUENCY_SHIFTER_MIN_RIGHT_DIRECTION && val <= AL_FREQUENCY_SHIFTER_MAX_RIGHT_DIRECTION))
+ SETERR_RETURN(context, AL_INVALID_VALUE,,"Frequency shifter right direction out of range");
+ props->Fshifter.RightDirection = val;
+ break;
+
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid frequency shifter integer property 0x%04x", param);
+ }
+}
+void ALfshifter_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
+{
+ ALfshifter_setParami(effect, context, param, vals[0]);
+}
+
+void ALfshifter_getParami(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *val)
+{
+ const ALeffectProps *props = &effect->Props;
+ switch(param)
+ {
+ case AL_FREQUENCY_SHIFTER_LEFT_DIRECTION:
+ *val = props->Fshifter.LeftDirection;
+ break;
+ case AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION:
+ *val = props->Fshifter.RightDirection;
+ break;
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid frequency shifter integer property 0x%04x", param);
+ }
+}
+void ALfshifter_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
+{
+ ALfshifter_getParami(effect, context, param, vals);
+}
+
+void ALfshifter_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
+{
+
+ const ALeffectProps *props = &effect->Props;
+ switch(param)
+ {
+ case AL_FREQUENCY_SHIFTER_FREQUENCY:
+ *val = props->Fshifter.Frequency;
+ break;
+
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid frequency shifter float property 0x%04x", param);
+ }
+
+}
+
+void ALfshifter_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
+{
+ ALfshifter_getParamf(effect, context, param, vals);
+}
+
+DEFINE_ALEFFECT_VTABLE(ALfshifter);
diff --git a/Alc/effects/modulator.c b/Alc/effects/modulator.c
index dceb408e..e368adb8 100644
--- a/Alc/effects/modulator.c
+++ b/Alc/effects/modulator.c
@@ -24,184 +24,197 @@
#include <stdlib.h>
#include "alMain.h"
-#include "alFilter.h"
#include "alAuxEffectSlot.h"
#include "alError.h"
#include "alu.h"
+#include "filters/defs.h"
+#define MAX_UPDATE_SAMPLES 128
+
typedef struct ALmodulatorState {
DERIVE_FROM_TYPE(ALeffectState);
- enum {
- SINUSOID,
- SAWTOOTH,
- SQUARE
- } Waveform;
+ void (*GetSamples)(ALfloat*, ALsizei, const ALsizei, ALsizei);
- ALuint index;
- ALuint step;
+ ALsizei index;
+ ALsizei step;
- ALfloat Gain[MAX_OUTPUT_CHANNELS];
+ struct {
+ BiquadFilter Filter;
- ALfilterState Filter;
+ ALfloat CurrentGains[MAX_OUTPUT_CHANNELS];
+ ALfloat TargetGains[MAX_OUTPUT_CHANNELS];
+ } Chans[MAX_EFFECT_CHANNELS];
} ALmodulatorState;
+static ALvoid ALmodulatorState_Destruct(ALmodulatorState *state);
+static ALboolean ALmodulatorState_deviceUpdate(ALmodulatorState *state, ALCdevice *device);
+static ALvoid ALmodulatorState_update(ALmodulatorState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props);
+static ALvoid ALmodulatorState_process(ALmodulatorState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels);
+DECLARE_DEFAULT_ALLOCATORS(ALmodulatorState)
+
+DEFINE_ALEFFECTSTATE_VTABLE(ALmodulatorState);
+
+
#define WAVEFORM_FRACBITS 24
#define WAVEFORM_FRACONE (1<<WAVEFORM_FRACBITS)
#define WAVEFORM_FRACMASK (WAVEFORM_FRACONE-1)
-static inline ALfloat Sin(ALuint index)
+static inline ALfloat Sin(ALsizei index)
{
- return sinf(index*(F_TAU/WAVEFORM_FRACONE) - F_PI)*0.5f + 0.5f;
+ return sinf((ALfloat)index * (F_TAU / WAVEFORM_FRACONE));
}
-static inline ALfloat Saw(ALuint index)
+static inline ALfloat Saw(ALsizei index)
{
- return (ALfloat)index / WAVEFORM_FRACONE;
+ return (ALfloat)index*(2.0f/WAVEFORM_FRACONE) - 1.0f;
}
-static inline ALfloat Square(ALuint index)
+static inline ALfloat Square(ALsizei index)
{
- return (ALfloat)((index >> (WAVEFORM_FRACBITS - 1)) & 1);
+ return (ALfloat)(((index>>(WAVEFORM_FRACBITS-2))&2) - 1);
+}
+
+static inline ALfloat One(ALsizei UNUSED(index))
+{
+ return 1.0f;
}
#define DECL_TEMPLATE(func) \
-static void Process##func(ALmodulatorState *state, ALuint SamplesToDo, \
- const ALfloat *restrict SamplesIn, \
- ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels) \
+static void Modulate##func(ALfloat *restrict dst, ALsizei index, \
+ const ALsizei step, ALsizei todo) \
{ \
- const ALuint step = state->step; \
- ALuint index = state->index; \
- ALuint base; \
- \
- for(base = 0;base < SamplesToDo;) \
+ ALsizei i; \
+ for(i = 0;i < todo;i++) \
{ \
- ALfloat temps[256]; \
- ALuint td = minu(256, SamplesToDo-base); \
- ALuint i, k; \
- \
- for(i = 0;i < td;i++) \
- { \
- ALfloat samp; \
- samp = SamplesIn[base+i]; \
- samp = ALfilterState_processSingle(&state->Filter, samp); \
- \
- index += step; \
- index &= WAVEFORM_FRACMASK; \
- temps[i] = samp * func(index); \
- } \
- \
- for(k = 0;k < NumChannels;k++) \
- { \
- ALfloat gain = state->Gain[k]; \
- if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD)) \
- continue; \
- \
- for(i = 0;i < td;i++) \
- SamplesOut[k][base+i] += gain * temps[i]; \
- } \
- \
- base += td; \
+ index += step; \
+ index &= WAVEFORM_FRACMASK; \
+ dst[i] = func(index); \
} \
- state->index = index; \
}
DECL_TEMPLATE(Sin)
DECL_TEMPLATE(Saw)
DECL_TEMPLATE(Square)
+DECL_TEMPLATE(One)
#undef DECL_TEMPLATE
-static ALvoid ALmodulatorState_Destruct(ALmodulatorState *UNUSED(state))
+static void ALmodulatorState_Construct(ALmodulatorState *state)
{
+ ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
+ SET_VTABLE2(ALmodulatorState, ALeffectState, state);
+
+ state->index = 0;
+ state->step = 1;
+}
+
+static ALvoid ALmodulatorState_Destruct(ALmodulatorState *state)
+{
+ ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
}
-static ALboolean ALmodulatorState_deviceUpdate(ALmodulatorState *UNUSED(state), ALCdevice *UNUSED(device))
+static ALboolean ALmodulatorState_deviceUpdate(ALmodulatorState *state, ALCdevice *UNUSED(device))
{
+ ALsizei i, j;
+ for(i = 0;i < MAX_EFFECT_CHANNELS;i++)
+ {
+ BiquadFilter_clear(&state->Chans[i].Filter);
+ for(j = 0;j < MAX_OUTPUT_CHANNELS;j++)
+ state->Chans[i].CurrentGains[j] = 0.0f;
+ }
return AL_TRUE;
}
-static ALvoid ALmodulatorState_update(ALmodulatorState *state, ALCdevice *Device, const ALeffectslot *Slot)
+static ALvoid ALmodulatorState_update(ALmodulatorState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props)
{
- ALfloat cw, a;
-
- if(Slot->EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SINUSOID)
- state->Waveform = SINUSOID;
- else if(Slot->EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SAWTOOTH)
- state->Waveform = SAWTOOTH;
- else if(Slot->EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SQUARE)
- state->Waveform = SQUARE;
-
- state->step = fastf2u(Slot->EffectProps.Modulator.Frequency*WAVEFORM_FRACONE /
- Device->Frequency);
- if(state->step == 0) state->step = 1;
-
- /* Custom filter coeffs, which match the old version instead of a low-shelf. */
- cw = cosf(F_TAU * Slot->EffectProps.Modulator.HighPassCutoff / Device->Frequency);
- a = (2.0f-cw) - sqrtf(powf(2.0f-cw, 2.0f) - 1.0f);
-
- state->Filter.b[0] = a;
- state->Filter.b[1] = -a;
- state->Filter.b[2] = 0.0f;
- state->Filter.a[0] = 1.0f;
- state->Filter.a[1] = -a;
- state->Filter.a[2] = 0.0f;
-
- ComputeAmbientGains(Device, Slot->Gain, state->Gain);
+ const ALCdevice *device = context->Device;
+ ALfloat f0norm;
+ ALsizei i;
+
+ state->step = fastf2i(props->Modulator.Frequency / (ALfloat)device->Frequency *
+ WAVEFORM_FRACONE);
+ state->step = clampi(state->step, 0, WAVEFORM_FRACONE-1);
+
+ if(state->step == 0)
+ state->GetSamples = ModulateOne;
+ else if(props->Modulator.Waveform == AL_RING_MODULATOR_SINUSOID)
+ state->GetSamples = ModulateSin;
+ else if(props->Modulator.Waveform == AL_RING_MODULATOR_SAWTOOTH)
+ state->GetSamples = ModulateSaw;
+ else /*if(Slot->Params.EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SQUARE)*/
+ state->GetSamples = ModulateSquare;
+
+ f0norm = props->Modulator.HighPassCutoff / (ALfloat)device->Frequency;
+ f0norm = clampf(f0norm, 1.0f/512.0f, 0.49f);
+ /* Bandwidth value is constant in octaves. */
+ BiquadFilter_setParams(&state->Chans[0].Filter, BiquadType_HighPass, 1.0f,
+ f0norm, calc_rcpQ_from_bandwidth(f0norm, 0.75f));
+ for(i = 1;i < MAX_EFFECT_CHANNELS;i++)
+ BiquadFilter_copyParams(&state->Chans[i].Filter, &state->Chans[0].Filter);
+
+ STATIC_CAST(ALeffectState,state)->OutBuffer = device->FOAOut.Buffer;
+ STATIC_CAST(ALeffectState,state)->OutChannels = device->FOAOut.NumChannels;
+ for(i = 0;i < MAX_EFFECT_CHANNELS;i++)
+ ComputePanGains(&device->FOAOut, IdentityMatrixf.m[i], slot->Params.Gain,
+ state->Chans[i].TargetGains);
}
-static ALvoid ALmodulatorState_process(ALmodulatorState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)
+static ALvoid ALmodulatorState_process(ALmodulatorState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels)
{
- switch(state->Waveform)
+ const ALsizei step = state->step;
+ ALsizei base;
+
+ for(base = 0;base < SamplesToDo;)
{
- case SINUSOID:
- ProcessSin(state, SamplesToDo, SamplesIn, SamplesOut, NumChannels);
- break;
+ alignas(16) ALfloat modsamples[MAX_UPDATE_SAMPLES];
+ ALsizei td = mini(MAX_UPDATE_SAMPLES, SamplesToDo-base);
+ ALsizei c, i;
- case SAWTOOTH:
- ProcessSaw(state, SamplesToDo, SamplesIn, SamplesOut, NumChannels);
- break;
+ state->GetSamples(modsamples, state->index, step, td);
+ state->index += (step*td) & WAVEFORM_FRACMASK;
+ state->index &= WAVEFORM_FRACMASK;
- case SQUARE:
- ProcessSquare(state, SamplesToDo, SamplesIn, SamplesOut, NumChannels);
- break;
- }
-}
+ for(c = 0;c < MAX_EFFECT_CHANNELS;c++)
+ {
+ alignas(16) ALfloat temps[MAX_UPDATE_SAMPLES];
-DECLARE_DEFAULT_ALLOCATORS(ALmodulatorState)
+ BiquadFilter_process(&state->Chans[c].Filter, temps, &SamplesIn[c][base], td);
+ for(i = 0;i < td;i++)
+ temps[i] *= modsamples[i];
-DEFINE_ALEFFECTSTATE_VTABLE(ALmodulatorState);
+ MixSamples(temps, NumChannels, SamplesOut, state->Chans[c].CurrentGains,
+ state->Chans[c].TargetGains, SamplesToDo-base, base, td);
+ }
+
+ base += td;
+ }
+}
-typedef struct ALmodulatorStateFactory {
- DERIVE_FROM_TYPE(ALeffectStateFactory);
-} ALmodulatorStateFactory;
+typedef struct ModulatorStateFactory {
+ DERIVE_FROM_TYPE(EffectStateFactory);
+} ModulatorStateFactory;
-static ALeffectState *ALmodulatorStateFactory_create(ALmodulatorStateFactory *UNUSED(factory))
+static ALeffectState *ModulatorStateFactory_create(ModulatorStateFactory *UNUSED(factory))
{
ALmodulatorState *state;
- state = ALmodulatorState_New(sizeof(*state));
+ NEW_OBJ0(state, ALmodulatorState)();
if(!state) return NULL;
- SET_VTABLE2(ALmodulatorState, ALeffectState, state);
-
- state->index = 0;
- state->step = 1;
-
- ALfilterState_clear(&state->Filter);
return STATIC_CAST(ALeffectState, state);
}
-DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALmodulatorStateFactory);
+DEFINE_EFFECTSTATEFACTORY_VTABLE(ModulatorStateFactory);
-ALeffectStateFactory *ALmodulatorStateFactory_getFactory(void)
+EffectStateFactory *ModulatorStateFactory_getFactory(void)
{
- static ALmodulatorStateFactory ModulatorFactory = { { GET_VTABLE2(ALmodulatorStateFactory, ALeffectStateFactory) } };
+ static ModulatorStateFactory ModulatorFactory = { { GET_VTABLE2(ModulatorStateFactory, EffectStateFactory) } };
- return STATIC_CAST(ALeffectStateFactory, &ModulatorFactory);
+ return STATIC_CAST(EffectStateFactory, &ModulatorFactory);
}
@@ -212,24 +225,22 @@ void ALmodulator_setParamf(ALeffect *effect, ALCcontext *context, ALenum param,
{
case AL_RING_MODULATOR_FREQUENCY:
if(!(val >= AL_RING_MODULATOR_MIN_FREQUENCY && val <= AL_RING_MODULATOR_MAX_FREQUENCY))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Modulator frequency out of range");
props->Modulator.Frequency = val;
break;
case AL_RING_MODULATOR_HIGHPASS_CUTOFF:
if(!(val >= AL_RING_MODULATOR_MIN_HIGHPASS_CUTOFF && val <= AL_RING_MODULATOR_MAX_HIGHPASS_CUTOFF))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Modulator high-pass cutoff out of range");
props->Modulator.HighPassCutoff = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid modulator float property 0x%04x", param);
}
}
void ALmodulator_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
-{
- ALmodulator_setParamf(effect, context, param, vals[0]);
-}
+{ ALmodulator_setParamf(effect, context, param, vals[0]); }
void ALmodulator_setParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val)
{
ALeffectProps *props = &effect->Props;
@@ -242,18 +253,16 @@ void ALmodulator_setParami(ALeffect *effect, ALCcontext *context, ALenum param,
case AL_RING_MODULATOR_WAVEFORM:
if(!(val >= AL_RING_MODULATOR_MIN_WAVEFORM && val <= AL_RING_MODULATOR_MAX_WAVEFORM))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid modulator waveform");
props->Modulator.Waveform = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid modulator integer property 0x%04x", param);
}
}
void ALmodulator_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
-{
- ALmodulator_setParami(effect, context, param, vals[0]);
-}
+{ ALmodulator_setParami(effect, context, param, vals[0]); }
void ALmodulator_getParami(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *val)
{
@@ -271,13 +280,11 @@ void ALmodulator_getParami(const ALeffect *effect, ALCcontext *context, ALenum p
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid modulator integer property 0x%04x", param);
}
}
void ALmodulator_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
-{
- ALmodulator_getParami(effect, context, param, vals);
-}
+{ ALmodulator_getParami(effect, context, param, vals); }
void ALmodulator_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
{
const ALeffectProps *props = &effect->Props;
@@ -291,12 +298,10 @@ void ALmodulator_getParamf(const ALeffect *effect, ALCcontext *context, ALenum p
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid modulator float property 0x%04x", param);
}
}
void ALmodulator_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
-{
- ALmodulator_getParamf(effect, context, param, vals);
-}
+{ ALmodulator_getParamf(effect, context, param, vals); }
DEFINE_ALEFFECT_VTABLE(ALmodulator);
diff --git a/Alc/effects/null.c b/Alc/effects/null.c
index adc4ca81..e57359e3 100644
--- a/Alc/effects/null.c
+++ b/Alc/effects/null.c
@@ -13,12 +13,35 @@ typedef struct ALnullState {
DERIVE_FROM_TYPE(ALeffectState);
} ALnullState;
+/* Forward-declare "virtual" functions to define the vtable with. */
+static ALvoid ALnullState_Destruct(ALnullState *state);
+static ALboolean ALnullState_deviceUpdate(ALnullState *state, ALCdevice *device);
+static ALvoid ALnullState_update(ALnullState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props);
+static ALvoid ALnullState_process(ALnullState *state, ALsizei samplesToDo, const ALfloat (*restrict samplesIn)[BUFFERSIZE], ALfloat (*restrict samplesOut)[BUFFERSIZE], ALsizei mumChannels);
+static void *ALnullState_New(size_t size);
+static void ALnullState_Delete(void *ptr);
+
+/* Define the ALeffectState vtable for this type. */
+DEFINE_ALEFFECTSTATE_VTABLE(ALnullState);
+
+
+/* This constructs the effect state. It's called when the object is first
+ * created. Make sure to call the parent Construct function first, and set the
+ * vtable!
+ */
+static void ALnullState_Construct(ALnullState *state)
+{
+ ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
+ SET_VTABLE2(ALnullState, ALeffectState, state);
+}
/* This destructs (not free!) the effect state. It's called only when the
- * effect slot is no longer used.
+ * effect slot is no longer used. Make sure to call the parent Destruct
+ * function before returning!
*/
-static ALvoid ALnullState_Destruct(ALnullState* UNUSED(state))
+static ALvoid ALnullState_Destruct(ALnullState *state)
{
+ ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
}
/* This updates the device-dependant effect state. This is called on
@@ -33,7 +56,7 @@ static ALboolean ALnullState_deviceUpdate(ALnullState* UNUSED(state), ALCdevice*
/* This updates the effect state. This is called any time the effect is
* (re)loaded into a slot.
*/
-static ALvoid ALnullState_update(ALnullState* UNUSED(state), ALCdevice* UNUSED(device), const ALeffectslot* UNUSED(slot))
+static ALvoid ALnullState_update(ALnullState* UNUSED(state), const ALCcontext* UNUSED(context), const ALeffectslot* UNUSED(slot), const ALeffectProps* UNUSED(props))
{
}
@@ -41,121 +64,115 @@ static ALvoid ALnullState_update(ALnullState* UNUSED(state), ALCdevice* UNUSED(d
* input to the output buffer. The result should be added to the output buffer,
* not replace it.
*/
-static ALvoid ALnullState_process(ALnullState* UNUSED(state), ALuint UNUSED(samplesToDo), const ALfloat *restrict UNUSED(samplesIn), ALfloatBUFFERSIZE*restrict UNUSED(samplesOut), ALuint UNUSED(NumChannels))
+static ALvoid ALnullState_process(ALnullState* UNUSED(state), ALsizei UNUSED(samplesToDo), const ALfloatBUFFERSIZE*restrict UNUSED(samplesIn), ALfloatBUFFERSIZE*restrict UNUSED(samplesOut), ALsizei UNUSED(numChannels))
{
}
/* This allocates memory to store the object, before it gets constructed.
- * DECLARE_DEFAULT_ALLOCATORS can be used to declate a default method.
+ * DECLARE_DEFAULT_ALLOCATORS can be used to declare a default method.
*/
static void *ALnullState_New(size_t size)
{
- return malloc(size);
+ return al_malloc(16, size);
}
/* This frees the memory used by the object, after it has been destructed.
- * DECLARE_DEFAULT_ALLOCATORS can be used to declate a default method.
+ * DECLARE_DEFAULT_ALLOCATORS can be used to declare a default method.
*/
static void ALnullState_Delete(void *ptr)
{
- free(ptr);
+ al_free(ptr);
}
-/* Define the forwards and the ALeffectState vtable for this type. */
-DEFINE_ALEFFECTSTATE_VTABLE(ALnullState);
-
-typedef struct ALnullStateFactory {
- DERIVE_FROM_TYPE(ALeffectStateFactory);
-} ALnullStateFactory;
+typedef struct NullStateFactory {
+ DERIVE_FROM_TYPE(EffectStateFactory);
+} NullStateFactory;
/* Creates ALeffectState objects of the appropriate type. */
-ALeffectState *ALnullStateFactory_create(ALnullStateFactory *UNUSED(factory))
+ALeffectState *NullStateFactory_create(NullStateFactory *UNUSED(factory))
{
ALnullState *state;
- state = ALnullState_New(sizeof(*state));
+ NEW_OBJ0(state, ALnullState)();
if(!state) return NULL;
- /* Set vtables for inherited types. */
- SET_VTABLE2(ALnullState, ALeffectState, state);
return STATIC_CAST(ALeffectState, state);
}
-/* Define the ALeffectStateFactory vtable for this type. */
-DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALnullStateFactory);
+/* Define the EffectStateFactory vtable for this type. */
+DEFINE_EFFECTSTATEFACTORY_VTABLE(NullStateFactory);
-ALeffectStateFactory *ALnullStateFactory_getFactory(void)
+EffectStateFactory *NullStateFactory_getFactory(void)
{
- static ALnullStateFactory NullFactory = { { GET_VTABLE2(ALnullStateFactory, ALeffectStateFactory) } };
-
- return STATIC_CAST(ALeffectStateFactory, &NullFactory);
+ static NullStateFactory NullFactory = { { GET_VTABLE2(NullStateFactory, EffectStateFactory) } };
+ return STATIC_CAST(EffectStateFactory, &NullFactory);
}
-void ALnull_setParami(ALeffect* UNUSED(effect), ALCcontext *context, ALenum param, ALint UNUSED(val))
+void ALnull_setParami(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint UNUSED(val))
{
switch(param)
{
- default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid null effect integer property 0x%04x", param);
}
}
-void ALnull_setParamiv(ALeffect* UNUSED(effect), ALCcontext *context, ALenum param, const ALint* UNUSED(vals))
+void ALnull_setParamiv(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, const ALint* UNUSED(vals))
{
switch(param)
{
- default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid null effect integer-vector property 0x%04x", param);
}
}
-void ALnull_setParamf(ALeffect* UNUSED(effect), ALCcontext *context, ALenum param, ALfloat UNUSED(val))
+void ALnull_setParamf(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALfloat UNUSED(val))
{
switch(param)
{
- default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid null effect float property 0x%04x", param);
}
}
-void ALnull_setParamfv(ALeffect* UNUSED(effect), ALCcontext *context, ALenum param, const ALfloat* UNUSED(vals))
+void ALnull_setParamfv(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, const ALfloat* UNUSED(vals))
{
switch(param)
{
- default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid null effect float-vector property 0x%04x", param);
}
}
-void ALnull_getParami(const ALeffect* UNUSED(effect), ALCcontext *context, ALenum param, ALint* UNUSED(val))
+void ALnull_getParami(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint* UNUSED(val))
{
switch(param)
{
- default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid null effect integer property 0x%04x", param);
}
}
-void ALnull_getParamiv(const ALeffect* UNUSED(effect), ALCcontext *context, ALenum param, ALint* UNUSED(vals))
+void ALnull_getParamiv(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALint* UNUSED(vals))
{
switch(param)
{
- default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid null effect integer-vector property 0x%04x", param);
}
}
-void ALnull_getParamf(const ALeffect* UNUSED(effect), ALCcontext *context, ALenum param, ALfloat* UNUSED(val))
+void ALnull_getParamf(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALfloat* UNUSED(val))
{
switch(param)
{
- default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid null effect float property 0x%04x", param);
}
}
-void ALnull_getParamfv(const ALeffect* UNUSED(effect), ALCcontext *context, ALenum param, ALfloat* UNUSED(vals))
+void ALnull_getParamfv(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALfloat* UNUSED(vals))
{
switch(param)
{
- default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid null effect float-vector property 0x%04x", param);
}
}
diff --git a/Alc/effects/pshifter.c b/Alc/effects/pshifter.c
new file mode 100644
index 00000000..ed18e9a8
--- /dev/null
+++ b/Alc/effects/pshifter.c
@@ -0,0 +1,441 @@
+/**
+ * OpenAL cross platform audio library
+ * Copyright (C) 2018 by Raul Herraiz.
+ * 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 <math.h>
+#include <stdlib.h>
+
+#include "alMain.h"
+#include "alAuxEffectSlot.h"
+#include "alError.h"
+#include "alu.h"
+#include "filters/defs.h"
+
+#include "alcomplex.h"
+
+
+#define STFT_SIZE 1024
+#define STFT_HALF_SIZE (STFT_SIZE>>1)
+#define OVERSAMP (1<<2)
+
+#define STFT_STEP (STFT_SIZE / OVERSAMP)
+#define FIFO_LATENCY (STFT_STEP * (OVERSAMP-1))
+
+
+typedef struct ALphasor {
+ ALdouble Amplitude;
+ ALdouble Phase;
+} ALphasor;
+
+typedef struct ALFrequencyDomain {
+ ALdouble Amplitude;
+ ALdouble Frequency;
+} ALfrequencyDomain;
+
+
+typedef struct ALpshifterState {
+ DERIVE_FROM_TYPE(ALeffectState);
+
+ /* Effect parameters */
+ ALsizei count;
+ ALsizei PitchShiftI;
+ ALfloat PitchShift;
+ ALfloat FreqPerBin;
+
+ /*Effects buffers*/
+ ALfloat InFIFO[STFT_SIZE];
+ ALfloat OutFIFO[STFT_STEP];
+ ALdouble LastPhase[STFT_HALF_SIZE+1];
+ ALdouble SumPhase[STFT_HALF_SIZE+1];
+ ALdouble OutputAccum[STFT_SIZE];
+
+ ALcomplex FFTbuffer[STFT_SIZE];
+
+ ALfrequencyDomain Analysis_buffer[STFT_HALF_SIZE+1];
+ ALfrequencyDomain Syntesis_buffer[STFT_HALF_SIZE+1];
+
+ alignas(16) ALfloat BufferOut[BUFFERSIZE];
+
+ /* Effect gains for each output channel */
+ ALfloat CurrentGains[MAX_OUTPUT_CHANNELS];
+ ALfloat TargetGains[MAX_OUTPUT_CHANNELS];
+} ALpshifterState;
+
+static ALvoid ALpshifterState_Destruct(ALpshifterState *state);
+static ALboolean ALpshifterState_deviceUpdate(ALpshifterState *state, ALCdevice *device);
+static ALvoid ALpshifterState_update(ALpshifterState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props);
+static ALvoid ALpshifterState_process(ALpshifterState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels);
+DECLARE_DEFAULT_ALLOCATORS(ALpshifterState)
+
+DEFINE_ALEFFECTSTATE_VTABLE(ALpshifterState);
+
+
+/* Define a Hann window, used to filter the STFT input and output. */
+alignas(16) static ALdouble HannWindow[STFT_SIZE];
+
+static void InitHannWindow(void)
+{
+ ALsizei i;
+
+ /* Create lookup table of the Hann window for the desired size, i.e. STFT_SIZE */
+ for(i = 0;i < STFT_SIZE>>1;i++)
+ {
+ ALdouble val = sin(M_PI * (ALdouble)i / (ALdouble)(STFT_SIZE-1));
+ HannWindow[i] = HannWindow[STFT_SIZE-1-i] = val * val;
+ }
+}
+static alonce_flag HannInitOnce = AL_ONCE_FLAG_INIT;
+
+
+static inline ALint double2int(ALdouble d)
+{
+#if ((defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__)) && \
+ !defined(__SSE2_MATH__)) || (defined(_MSC_VER) && defined(_M_IX86_FP) && _M_IX86_FP < 2)
+ ALint sign, shift;
+ ALint64 mant;
+ union {
+ ALdouble d;
+ ALint64 i64;
+ } conv;
+
+ conv.d = d;
+ sign = (conv.i64>>63) | 1;
+ shift = ((conv.i64>>52)&0x7ff) - (1023+52);
+
+ /* Over/underflow */
+ if(UNLIKELY(shift >= 63 || shift < -52))
+ return 0;
+
+ mant = (conv.i64&I64(0xfffffffffffff)) | I64(0x10000000000000);
+ if(LIKELY(shift < 0))
+ return (ALint)(mant >> -shift) * sign;
+ return (ALint)(mant << shift) * sign;
+
+#else
+
+ return (ALint)d;
+#endif
+}
+
+
+/* Converts ALcomplex to ALphasor */
+static inline ALphasor rect2polar(ALcomplex number)
+{
+ ALphasor polar;
+
+ polar.Amplitude = sqrt(number.Real*number.Real + number.Imag*number.Imag);
+ polar.Phase = atan2(number.Imag, number.Real);
+
+ return polar;
+}
+
+/* Converts ALphasor to ALcomplex */
+static inline ALcomplex polar2rect(ALphasor number)
+{
+ ALcomplex cartesian;
+
+ cartesian.Real = number.Amplitude * cos(number.Phase);
+ cartesian.Imag = number.Amplitude * sin(number.Phase);
+
+ return cartesian;
+}
+
+
+static void ALpshifterState_Construct(ALpshifterState *state)
+{
+ ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
+ SET_VTABLE2(ALpshifterState, ALeffectState, state);
+
+ alcall_once(&HannInitOnce, InitHannWindow);
+}
+
+static ALvoid ALpshifterState_Destruct(ALpshifterState *state)
+{
+ ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
+}
+
+static ALboolean ALpshifterState_deviceUpdate(ALpshifterState *state, ALCdevice *device)
+{
+ /* (Re-)initializing parameters and clear the buffers. */
+ state->count = FIFO_LATENCY;
+ state->PitchShiftI = FRACTIONONE;
+ state->PitchShift = 1.0f;
+ state->FreqPerBin = device->Frequency / (ALfloat)STFT_SIZE;
+
+ memset(state->InFIFO, 0, sizeof(state->InFIFO));
+ memset(state->OutFIFO, 0, sizeof(state->OutFIFO));
+ memset(state->FFTbuffer, 0, sizeof(state->FFTbuffer));
+ memset(state->LastPhase, 0, sizeof(state->LastPhase));
+ memset(state->SumPhase, 0, sizeof(state->SumPhase));
+ memset(state->OutputAccum, 0, sizeof(state->OutputAccum));
+ memset(state->Analysis_buffer, 0, sizeof(state->Analysis_buffer));
+ memset(state->Syntesis_buffer, 0, sizeof(state->Syntesis_buffer));
+
+ memset(state->CurrentGains, 0, sizeof(state->CurrentGains));
+ memset(state->TargetGains, 0, sizeof(state->TargetGains));
+
+ return AL_TRUE;
+}
+
+static ALvoid ALpshifterState_update(ALpshifterState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props)
+{
+ const ALCdevice *device = context->Device;
+ ALfloat coeffs[MAX_AMBI_COEFFS];
+ float pitch;
+
+ pitch = powf(2.0f,
+ (ALfloat)(props->Pshifter.CoarseTune*100 + props->Pshifter.FineTune) / 1200.0f
+ );
+ state->PitchShiftI = fastf2i(pitch*FRACTIONONE);
+ state->PitchShift = state->PitchShiftI * (1.0f/FRACTIONONE);
+
+ CalcAngleCoeffs(0.0f, 0.0f, 0.0f, coeffs);
+ ComputePanGains(&device->Dry, coeffs, slot->Params.Gain, state->TargetGains);
+}
+
+static ALvoid ALpshifterState_process(ALpshifterState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels)
+{
+ /* Pitch shifter engine based on the work of Stephan Bernsee.
+ * http://blogs.zynaptiq.com/bernsee/pitch-shifting-using-the-ft/
+ */
+
+ static const ALdouble expected = M_PI*2.0 / OVERSAMP;
+ const ALdouble freq_per_bin = state->FreqPerBin;
+ ALfloat *restrict bufferOut = state->BufferOut;
+ ALsizei count = state->count;
+ ALsizei i, j, k;
+
+ for(i = 0;i < SamplesToDo;)
+ {
+ do {
+ /* Fill FIFO buffer with samples data */
+ state->InFIFO[count] = SamplesIn[0][i];
+ bufferOut[i] = state->OutFIFO[count - FIFO_LATENCY];
+
+ count++;
+ } while(++i < SamplesToDo && count < STFT_SIZE);
+
+ /* Check whether FIFO buffer is filled */
+ if(count < STFT_SIZE) break;
+ count = FIFO_LATENCY;
+
+ /* Real signal windowing and store in FFTbuffer */
+ for(k = 0;k < STFT_SIZE;k++)
+ {
+ state->FFTbuffer[k].Real = state->InFIFO[k] * HannWindow[k];
+ state->FFTbuffer[k].Imag = 0.0;
+ }
+
+ /* ANALYSIS */
+ /* Apply FFT to FFTbuffer data */
+ complex_fft(state->FFTbuffer, STFT_SIZE, -1.0);
+
+ /* Analyze the obtained data. Since the real FFT is symmetric, only
+ * STFT_HALF_SIZE+1 samples are needed.
+ */
+ for(k = 0;k < STFT_HALF_SIZE+1;k++)
+ {
+ ALphasor component;
+ ALdouble tmp;
+ ALint qpd;
+
+ /* Compute amplitude and phase */
+ component = rect2polar(state->FFTbuffer[k]);
+
+ /* Compute phase difference and subtract expected phase difference */
+ tmp = (component.Phase - state->LastPhase[k]) - k*expected;
+
+ /* Map delta phase into +/- Pi interval */
+ qpd = double2int(tmp / M_PI);
+ tmp -= M_PI * (qpd + (qpd%2));
+
+ /* Get deviation from bin frequency from the +/- Pi interval */
+ tmp /= expected;
+
+ /* Compute the k-th partials' true frequency, twice the amplitude
+ * for maintain the gain (because half of bins are used) and store
+ * amplitude and true frequency in analysis buffer.
+ */
+ state->Analysis_buffer[k].Amplitude = 2.0 * component.Amplitude;
+ state->Analysis_buffer[k].Frequency = (k + tmp) * freq_per_bin;
+
+ /* Store actual phase[k] for the calculations in the next frame*/
+ state->LastPhase[k] = component.Phase;
+ }
+
+ /* PROCESSING */
+ /* pitch shifting */
+ for(k = 0;k < STFT_HALF_SIZE+1;k++)
+ {
+ state->Syntesis_buffer[k].Amplitude = 0.0;
+ state->Syntesis_buffer[k].Frequency = 0.0;
+ }
+
+ for(k = 0;k < STFT_HALF_SIZE+1;k++)
+ {
+ j = (k*state->PitchShiftI) >> FRACTIONBITS;
+ if(j >= STFT_HALF_SIZE+1) break;
+
+ state->Syntesis_buffer[j].Amplitude += state->Analysis_buffer[k].Amplitude;
+ state->Syntesis_buffer[j].Frequency = state->Analysis_buffer[k].Frequency *
+ state->PitchShift;
+ }
+
+ /* SYNTHESIS */
+ /* Synthesis the processing data */
+ for(k = 0;k < STFT_HALF_SIZE+1;k++)
+ {
+ ALphasor component;
+ ALdouble tmp;
+
+ /* Compute bin deviation from scaled freq */
+ tmp = state->Syntesis_buffer[k].Frequency/freq_per_bin - k;
+
+ /* Calculate actual delta phase and accumulate it to get bin phase */
+ state->SumPhase[k] += (k + tmp) * expected;
+
+ component.Amplitude = state->Syntesis_buffer[k].Amplitude;
+ component.Phase = state->SumPhase[k];
+
+ /* Compute phasor component to cartesian complex number and storage it into FFTbuffer*/
+ state->FFTbuffer[k] = polar2rect(component);
+ }
+ /* zero negative frequencies for recontruct a real signal */
+ for(k = STFT_HALF_SIZE+1;k < STFT_SIZE;k++)
+ {
+ state->FFTbuffer[k].Real = 0.0;
+ state->FFTbuffer[k].Imag = 0.0;
+ }
+
+ /* Apply iFFT to buffer data */
+ complex_fft(state->FFTbuffer, STFT_SIZE, 1.0);
+
+ /* Windowing and add to output */
+ for(k = 0;k < STFT_SIZE;k++)
+ state->OutputAccum[k] += HannWindow[k] * state->FFTbuffer[k].Real /
+ (0.5 * STFT_HALF_SIZE * OVERSAMP);
+
+ /* Shift accumulator, input & output FIFO */
+ for(k = 0;k < STFT_STEP;k++) state->OutFIFO[k] = (ALfloat)state->OutputAccum[k];
+ for(j = 0;k < STFT_SIZE;k++,j++) state->OutputAccum[j] = state->OutputAccum[k];
+ for(;j < STFT_SIZE;j++) state->OutputAccum[j] = 0.0;
+ for(k = 0;k < FIFO_LATENCY;k++)
+ state->InFIFO[k] = state->InFIFO[k+STFT_STEP];
+ }
+ state->count = count;
+
+ /* Now, mix the processed sound data to the output. */
+ MixSamples(bufferOut, NumChannels, SamplesOut, state->CurrentGains, state->TargetGains,
+ maxi(SamplesToDo, 512), 0, SamplesToDo);
+}
+
+typedef struct PshifterStateFactory {
+ DERIVE_FROM_TYPE(EffectStateFactory);
+} PshifterStateFactory;
+
+static ALeffectState *PshifterStateFactory_create(PshifterStateFactory *UNUSED(factory))
+{
+ ALpshifterState *state;
+
+ NEW_OBJ0(state, ALpshifterState)();
+ if(!state) return NULL;
+
+ return STATIC_CAST(ALeffectState, state);
+}
+
+DEFINE_EFFECTSTATEFACTORY_VTABLE(PshifterStateFactory);
+
+EffectStateFactory *PshifterStateFactory_getFactory(void)
+{
+ static PshifterStateFactory PshifterFactory = { { GET_VTABLE2(PshifterStateFactory, EffectStateFactory) } };
+
+ return STATIC_CAST(EffectStateFactory, &PshifterFactory);
+}
+
+
+void ALpshifter_setParamf(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALfloat UNUSED(val))
+{
+ alSetError( context, AL_INVALID_ENUM, "Invalid pitch shifter float property 0x%04x", param );
+}
+
+void ALpshifter_setParamfv(ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, const ALfloat *UNUSED(vals))
+{
+ alSetError( context, AL_INVALID_ENUM, "Invalid pitch shifter float-vector property 0x%04x", param );
+}
+
+void ALpshifter_setParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val)
+{
+ ALeffectProps *props = &effect->Props;
+ switch(param)
+ {
+ case AL_PITCH_SHIFTER_COARSE_TUNE:
+ if(!(val >= AL_PITCH_SHIFTER_MIN_COARSE_TUNE && val <= AL_PITCH_SHIFTER_MAX_COARSE_TUNE))
+ SETERR_RETURN(context, AL_INVALID_VALUE,,"Pitch shifter coarse tune out of range");
+ props->Pshifter.CoarseTune = val;
+ break;
+
+ case AL_PITCH_SHIFTER_FINE_TUNE:
+ if(!(val >= AL_PITCH_SHIFTER_MIN_FINE_TUNE && val <= AL_PITCH_SHIFTER_MAX_FINE_TUNE))
+ SETERR_RETURN(context, AL_INVALID_VALUE,,"Pitch shifter fine tune out of range");
+ props->Pshifter.FineTune = val;
+ break;
+
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid pitch shifter integer property 0x%04x", param);
+ }
+}
+void ALpshifter_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
+{
+ ALpshifter_setParami(effect, context, param, vals[0]);
+}
+
+void ALpshifter_getParami(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *val)
+{
+ const ALeffectProps *props = &effect->Props;
+ switch(param)
+ {
+ case AL_PITCH_SHIFTER_COARSE_TUNE:
+ *val = (ALint)props->Pshifter.CoarseTune;
+ break;
+ case AL_PITCH_SHIFTER_FINE_TUNE:
+ *val = (ALint)props->Pshifter.FineTune;
+ break;
+
+ default:
+ alSetError(context, AL_INVALID_ENUM, "Invalid pitch shifter integer property 0x%04x", param);
+ }
+}
+void ALpshifter_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
+{
+ ALpshifter_getParami(effect, context, param, vals);
+}
+
+void ALpshifter_getParamf(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALfloat *UNUSED(val))
+{
+ alSetError(context, AL_INVALID_ENUM, "Invalid pitch shifter float property 0x%04x", param);
+}
+
+void ALpshifter_getParamfv(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum param, ALfloat *UNUSED(vals))
+{
+ alSetError(context, AL_INVALID_ENUM, "Invalid pitch shifter float vector-property 0x%04x", param);
+}
+
+DEFINE_ALEFFECT_VTABLE(ALpshifter);
diff --git a/Alc/effects/reverb.c b/Alc/effects/reverb.c
index e1013309..8ebc089e 100644
--- a/Alc/effects/reverb.c
+++ b/Alc/effects/reverb.c
@@ -1,6 +1,6 @@
/**
- * Reverb for the OpenAL cross platform audio library
- * Copyright (C) 2008-2009 by Christopher Fitzgerald.
+ * Ambisonic reverb engine for the OpenAL cross platform audio library
+ * Copyright (C) 2008-2017 by Chris Robinson and Christopher Fitzgerald.
* 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
@@ -27,634 +27,464 @@
#include "alMain.h"
#include "alu.h"
#include "alAuxEffectSlot.h"
-#include "alEffect.h"
-#include "alFilter.h"
+#include "alListener.h"
#include "alError.h"
+#include "filters/defs.h"
+/* This is a user config option for modifying the overall output of the reverb
+ * effect.
+ */
+ALfloat ReverbBoost = 1.0f;
/* This is the maximum number of samples processed for each inner loop
* iteration. */
#define MAX_UPDATE_SAMPLES 256
-typedef struct DelayLine
-{
- // The delay lines use sample lengths that are powers of 2 to allow the
- // use of bit-masking instead of a modulus for wrapping.
- ALuint Mask;
- ALfloat *Line;
-} DelayLine;
+/* The number of samples used for cross-faded delay lines. This can be used
+ * to balance the compensation for abrupt line changes and attenuation due to
+ * minimally lengthed recursive lines. Try to keep this below the device
+ * update size.
+ */
+#define FADE_SAMPLES 128
-typedef struct ALreverbState {
- DERIVE_FROM_TYPE(ALeffectState);
+/* The number of spatialized lines or channels to process. Four channels allows
+ * for a 3D A-Format response. NOTE: This can't be changed without taking care
+ * of the conversion matrices, and a few places where the length arrays are
+ * assumed to have 4 elements.
+ */
+#define NUM_LINES 4
- ALboolean IsEax;
- // All delay lines are allocated as a single buffer to reduce memory
- // fragmentation and management code.
- ALfloat *SampleBuffer;
- ALuint TotalSamples;
+/* The B-Format to A-Format conversion matrix. The arrangement of rows is
+ * deliberately chosen to align the resulting lines to their spatial opposites
+ * (0:above front left <-> 3:above back right, 1:below front right <-> 2:below
+ * back left). It's not quite opposite, since the A-Format results in a
+ * tetrahedron, but it's close enough. Should the model be extended to 8-lines
+ * in the future, true opposites can be used.
+ */
+static const aluMatrixf B2A = {{
+ { 0.288675134595f, 0.288675134595f, 0.288675134595f, 0.288675134595f },
+ { 0.288675134595f, -0.288675134595f, -0.288675134595f, 0.288675134595f },
+ { 0.288675134595f, 0.288675134595f, -0.288675134595f, -0.288675134595f },
+ { 0.288675134595f, -0.288675134595f, 0.288675134595f, -0.288675134595f }
+}};
+
+/* Converts A-Format to B-Format. */
+static const aluMatrixf A2B = {{
+ { 0.866025403785f, 0.866025403785f, 0.866025403785f, 0.866025403785f },
+ { 0.866025403785f, -0.866025403785f, 0.866025403785f, -0.866025403785f },
+ { 0.866025403785f, -0.866025403785f, -0.866025403785f, 0.866025403785f },
+ { 0.866025403785f, 0.866025403785f, -0.866025403785f, -0.866025403785f }
+}};
+
+static const ALfloat FadeStep = 1.0f / FADE_SAMPLES;
+
+/* The all-pass and delay lines have a variable length dependent on the
+ * effect's density parameter, which helps alter the perceived environment
+ * size. The size-to-density conversion is a cubed scale:
+ *
+ * density = min(1.0, pow(size, 3.0) / DENSITY_SCALE);
+ *
+ * The line lengths scale linearly with room size, so the inverse density
+ * conversion is needed, taking the cube root of the re-scaled density to
+ * calculate the line length multiplier:
+ *
+ * length_mult = max(5.0, cbrtf(density*DENSITY_SCALE));
+ *
+ * The density scale below will result in a max line multiplier of 50, for an
+ * effective size range of 5m to 50m.
+ */
+static const ALfloat DENSITY_SCALE = 125000.0f;
- // Master effect filters
- ALfilterState LpFilter;
- ALfilterState HpFilter; // EAX only
+/* All delay line lengths are specified in seconds.
+ *
+ * To approximate early reflections, we break them up into primary (those
+ * arriving from the same direction as the source) and secondary (those
+ * arriving from the opposite direction).
+ *
+ * The early taps decorrelate the 4-channel signal to approximate an average
+ * room response for the primary reflections after the initial early delay.
+ *
+ * Given an average room dimension (d_a) and the speed of sound (c) we can
+ * calculate the average reflection delay (r_a) regardless of listener and
+ * source positions as:
+ *
+ * r_a = d_a / c
+ * c = 343.3
+ *
+ * This can extended to finding the average difference (r_d) between the
+ * maximum (r_1) and minimum (r_0) reflection delays:
+ *
+ * r_0 = 2 / 3 r_a
+ * = r_a - r_d / 2
+ * = r_d
+ * r_1 = 4 / 3 r_a
+ * = r_a + r_d / 2
+ * = 2 r_d
+ * r_d = 2 / 3 r_a
+ * = r_1 - r_0
+ *
+ * As can be determined by integrating the 1D model with a source (s) and
+ * listener (l) positioned across the dimension of length (d_a):
+ *
+ * r_d = int_(l=0)^d_a (int_(s=0)^d_a |2 d_a - 2 (l + s)| ds) dl / c
+ *
+ * The initial taps (T_(i=0)^N) are then specified by taking a power series
+ * that ranges between r_0 and half of r_1 less r_0:
+ *
+ * R_i = 2^(i / (2 N - 1)) r_d
+ * = r_0 + (2^(i / (2 N - 1)) - 1) r_d
+ * = r_0 + T_i
+ * T_i = R_i - r_0
+ * = (2^(i / (2 N - 1)) - 1) r_d
+ *
+ * Assuming an average of 1m, we get the following taps:
+ */
+static const ALfloat EARLY_TAP_LENGTHS[NUM_LINES] =
+{
+ 0.0000000e+0f, 2.0213520e-4f, 4.2531060e-4f, 6.7171600e-4f
+};
- struct {
- // Modulator delay line.
- DelayLine Delay;
-
- // The vibrato time is tracked with an index over a modulus-wrapped
- // range (in samples).
- ALuint Index;
- ALuint Range;
-
- // The depth of frequency change (also in samples) and its filter.
- ALfloat Depth;
- ALfloat Coeff;
- ALfloat Filter;
- } Mod;
-
- // Initial effect delay.
- DelayLine Delay;
- // The tap points for the initial delay. First tap goes to early
- // reflections, the last to late reverb.
- ALuint DelayTap[2];
+/* The early all-pass filter lengths are based on the early tap lengths:
+ *
+ * A_i = R_i / a
+ *
+ * Where a is the approximate maximum all-pass cycle limit (20).
+ */
+static const ALfloat EARLY_ALLPASS_LENGTHS[NUM_LINES] =
+{
+ 9.7096800e-5f, 1.0720356e-4f, 1.1836234e-4f, 1.3068260e-4f
+};
- struct {
- // Output gain for early reflections.
- ALfloat Gain;
+/* The early delay lines are used to transform the primary reflections into
+ * the secondary reflections. The A-format is arranged in such a way that
+ * the channels/lines are spatially opposite:
+ *
+ * C_i is opposite C_(N-i-1)
+ *
+ * The delays of the two opposing reflections (R_i and O_i) from a source
+ * anywhere along a particular dimension always sum to twice its full delay:
+ *
+ * 2 r_a = R_i + O_i
+ *
+ * With that in mind we can determine the delay between the two reflections
+ * and thus specify our early line lengths (L_(i=0)^N) using:
+ *
+ * O_i = 2 r_a - R_(N-i-1)
+ * L_i = O_i - R_(N-i-1)
+ * = 2 (r_a - R_(N-i-1))
+ * = 2 (r_a - T_(N-i-1) - r_0)
+ * = 2 r_a (1 - (2 / 3) 2^((N - i - 1) / (2 N - 1)))
+ *
+ * Using an average dimension of 1m, we get:
+ */
+static const ALfloat EARLY_LINE_LENGTHS[NUM_LINES] =
+{
+ 5.9850400e-4f, 1.0913150e-3f, 1.5376658e-3f, 1.9419362e-3f
+};
- // Early reflections are done with 4 delay lines.
- ALfloat Coeff[4];
- DelayLine Delay[4];
- ALuint Offset[4];
+/* The late all-pass filter lengths are based on the late line lengths:
+ *
+ * A_i = (5 / 3) L_i / r_1
+ */
+static const ALfloat LATE_ALLPASS_LENGTHS[NUM_LINES] =
+{
+ 1.6182800e-4f, 2.0389060e-4f, 2.8159360e-4f, 3.2365600e-4f
+};
- // The gain for each output channel based on 3D panning (only for the
- // EAX path).
- ALfloat PanGain[4][MAX_OUTPUT_CHANNELS];
- } Early;
+/* The late lines are used to approximate the decaying cycle of recursive
+ * late reflections.
+ *
+ * Splitting the lines in half, we start with the shortest reflection paths
+ * (L_(i=0)^(N/2)):
+ *
+ * L_i = 2^(i / (N - 1)) r_d
+ *
+ * Then for the opposite (longest) reflection paths (L_(i=N/2)^N):
+ *
+ * L_i = 2 r_a - L_(i-N/2)
+ * = 2 r_a - 2^((i - N / 2) / (N - 1)) r_d
+ *
+ * For our 1m average room, we get:
+ */
+static const ALfloat LATE_LINE_LENGTHS[NUM_LINES] =
+{
+ 1.9419362e-3f, 2.4466860e-3f, 3.3791220e-3f, 3.8838720e-3f
+};
- // Decorrelator delay line.
- DelayLine Decorrelator;
- // There are actually 4 decorrelator taps, but the first occurs at the
- // initial sample.
- ALuint DecoTap[3];
- struct {
- // Output gain for late reverb.
- ALfloat Gain;
+typedef struct DelayLineI {
+ /* The delay lines use interleaved samples, with the lengths being powers
+ * of 2 to allow the use of bit-masking instead of a modulus for wrapping.
+ */
+ ALsizei Mask;
+ ALfloat (*Line)[NUM_LINES];
+} DelayLineI;
+
+typedef struct VecAllpass {
+ DelayLineI Delay;
+ ALfloat Coeff;
+ ALsizei Offset[NUM_LINES][2];
+} VecAllpass;
+
+typedef struct T60Filter {
+ /* Two filters are used to adjust the signal. One to control the low
+ * frequencies, and one to control the high frequencies.
+ */
+ ALfloat MidGain[2];
+ BiquadFilter HFFilter, LFFilter;
+} T60Filter;
- // Attenuation to compensate for the modal density and decay rate of
- // the late lines.
- ALfloat DensityGain;
+typedef struct EarlyReflections {
+ /* A Gerzon vector all-pass filter is used to simulate initial diffusion.
+ * The spread from this filter also helps smooth out the reverb tail.
+ */
+ VecAllpass VecAp;
- // The feed-back and feed-forward all-pass coefficient.
- ALfloat ApFeedCoeff;
+ /* An echo line is used to complete the second half of the early
+ * reflections.
+ */
+ DelayLineI Delay;
+ ALsizei Offset[NUM_LINES][2];
+ ALfloat Coeff[NUM_LINES][2];
+
+ /* The gain for each output channel based on 3D panning. */
+ ALfloat CurrentGain[NUM_LINES][MAX_OUTPUT_CHANNELS];
+ ALfloat PanGain[NUM_LINES][MAX_OUTPUT_CHANNELS];
+} EarlyReflections;
+
+typedef struct LateReverb {
+ /* A recursive delay line is used fill in the reverb tail. */
+ DelayLineI Delay;
+ ALsizei Offset[NUM_LINES][2];
+
+ /* Attenuation to compensate for the modal density and decay rate of the
+ * late lines.
+ */
+ ALfloat DensityGain[2];
- // Mixing matrix coefficient.
- ALfloat MixCoeff;
+ /* T60 decay filters are used to simulate absorption. */
+ T60Filter T60[NUM_LINES];
- // Late reverb has 4 parallel all-pass filters.
- ALfloat ApCoeff[4];
- DelayLine ApDelay[4];
- ALuint ApOffset[4];
+ /* A Gerzon vector all-pass filter is used to simulate diffusion. */
+ VecAllpass VecAp;
- // In addition to 4 cyclical delay lines.
- ALfloat Coeff[4];
- DelayLine Delay[4];
- ALuint Offset[4];
+ /* The gain for each output channel based on 3D panning. */
+ ALfloat CurrentGain[NUM_LINES][MAX_OUTPUT_CHANNELS];
+ ALfloat PanGain[NUM_LINES][MAX_OUTPUT_CHANNELS];
+} LateReverb;
- // The cyclical delay lines are 1-pole low-pass filtered.
- ALfloat LpCoeff[4];
- ALfloat LpSample[4];
+typedef struct ReverbState {
+ DERIVE_FROM_TYPE(ALeffectState);
- // The gain for each output channel based on 3D panning (only for the
- // EAX path).
- ALfloat PanGain[4][MAX_OUTPUT_CHANNELS];
- } Late;
+ /* All delay lines are allocated as a single buffer to reduce memory
+ * fragmentation and management code.
+ */
+ ALfloat *SampleBuffer;
+ ALuint TotalSamples;
struct {
- // Attenuation to compensate for the modal density and decay rate of
- // the echo line.
- ALfloat DensityGain;
-
- // Echo delay and all-pass lines.
- DelayLine Delay;
- DelayLine ApDelay;
-
- ALfloat Coeff;
- ALfloat ApFeedCoeff;
- ALfloat ApCoeff;
-
- ALuint Offset;
- ALuint ApOffset;
-
- // The echo line is 1-pole low-pass filtered.
- ALfloat LpCoeff;
- ALfloat LpSample;
-
- // Echo mixing coefficient.
- ALfloat MixCoeff;
- } Echo;
-
- // The current read offset for all delay lines.
- ALuint Offset;
-
- // The gain for each output channel (non-EAX path only; aliased from
- // Late.PanGain)
- ALfloat (*Gain)[MAX_OUTPUT_CHANNELS];
+ /* Calculated parameters which indicate if cross-fading is needed after
+ * an update.
+ */
+ ALfloat Density, Diffusion;
+ ALfloat DecayTime, HFDecayTime, LFDecayTime;
+ ALfloat HFReference, LFReference;
+ } Params;
- /* Temporary storage used when processing. */
- ALfloat ReverbSamples[MAX_UPDATE_SAMPLES][4];
- ALfloat EarlySamples[MAX_UPDATE_SAMPLES][4];
-} ALreverbState;
+ /* Master effect filters */
+ struct {
+ BiquadFilter Lp;
+ BiquadFilter Hp;
+ } Filter[NUM_LINES];
-/* This is a user config option for modifying the overall output of the reverb
- * effect.
- */
-ALfloat ReverbBoost = 1.0f;
+ /* Core delay line (early reflections and late reverb tap from this). */
+ DelayLineI Delay;
-/* Specifies whether to use a standard reverb effect in place of EAX reverb */
-ALboolean EmulateEAXReverb = AL_FALSE;
+ /* Tap points for early reflection delay. */
+ ALsizei EarlyDelayTap[NUM_LINES][2];
+ ALfloat EarlyDelayCoeff[NUM_LINES][2];
-/* This coefficient is used to define the maximum frequency range controlled
- * by the modulation depth. The current value of 0.1 will allow it to swing
- * from 0.9x to 1.1x. This value must be below 1. At 1 it will cause the
- * sampler to stall on the downswing, and above 1 it will cause it to sample
- * backwards.
- */
-static const ALfloat MODULATION_DEPTH_COEFF = 0.1f;
+ /* Tap points for late reverb feed and delay. */
+ ALsizei LateFeedTap;
+ ALsizei LateDelayTap[NUM_LINES][2];
-/* A filter is used to avoid the terrible distortion caused by changing
- * modulation time and/or depth. To be consistent across different sample
- * rates, the coefficient must be raised to a constant divided by the sample
- * rate: coeff^(constant / rate).
- */
-static const ALfloat MODULATION_FILTER_COEFF = 0.048f;
-static const ALfloat MODULATION_FILTER_CONST = 100000.0f;
+ /* Coefficients for the all-pass and line scattering matrices. */
+ ALfloat MixX;
+ ALfloat MixY;
-// When diffusion is above 0, an all-pass filter is used to take the edge off
-// the echo effect. It uses the following line length (in seconds).
-static const ALfloat ECHO_ALLPASS_LENGTH = 0.0133f;
+ EarlyReflections Early;
-// Input into the late reverb is decorrelated between four channels. Their
-// timings are dependent on a fraction and multiplier. See the
-// UpdateDecorrelator() routine for the calculations involved.
-static const ALfloat DECO_FRACTION = 0.15f;
-static const ALfloat DECO_MULTIPLIER = 2.0f;
+ LateReverb Late;
-// All delay line lengths are specified in seconds.
+ /* Indicates the cross-fade point for delay line reads [0,FADE_SAMPLES]. */
+ ALsizei FadeCount;
-// The lengths of the early delay lines.
-static const ALfloat EARLY_LINE_LENGTH[4] =
-{
- 0.0015f, 0.0045f, 0.0135f, 0.0405f
-};
+ /* Maximum number of samples to process at once. */
+ ALsizei MaxUpdate[2];
-// The lengths of the late all-pass delay lines.
-static const ALfloat ALLPASS_LINE_LENGTH[4] =
-{
- 0.0151f, 0.0167f, 0.0183f, 0.0200f,
-};
+ /* The current write offset for all delay lines. */
+ ALsizei Offset;
-// The lengths of the late cyclical delay lines.
-static const ALfloat LATE_LINE_LENGTH[4] =
-{
- 0.0211f, 0.0311f, 0.0461f, 0.0680f
-};
+ /* Temporary storage used when processing. */
+ alignas(16) ALfloat TempSamples[NUM_LINES][MAX_UPDATE_SAMPLES];
+ alignas(16) ALfloat MixSamples[NUM_LINES][MAX_UPDATE_SAMPLES];
+} ReverbState;
-// The late cyclical delay lines have a variable length dependent on the
-// effect's density parameter (inverted for some reason) and this multiplier.
-static const ALfloat LATE_LINE_MULTIPLIER = 4.0f;
+static ALvoid ReverbState_Destruct(ReverbState *State);
+static ALboolean ReverbState_deviceUpdate(ReverbState *State, ALCdevice *Device);
+static ALvoid ReverbState_update(ReverbState *State, const ALCcontext *Context, const ALeffectslot *Slot, const ALeffectProps *props);
+static ALvoid ReverbState_process(ReverbState *State, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels);
+DECLARE_DEFAULT_ALLOCATORS(ReverbState)
+DEFINE_ALEFFECTSTATE_VTABLE(ReverbState);
-// Basic delay line input/output routines.
-static inline ALfloat DelayLineOut(DelayLine *Delay, ALuint offset)
+static void ReverbState_Construct(ReverbState *state)
{
- return Delay->Line[offset&Delay->Mask];
-}
+ ALsizei i, j;
-static inline ALvoid DelayLineIn(DelayLine *Delay, ALuint offset, ALfloat in)
-{
- Delay->Line[offset&Delay->Mask] = in;
-}
+ ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
+ SET_VTABLE2(ReverbState, ALeffectState, state);
-// Given an input sample, this function produces modulation for the late
-// reverb.
-static inline ALfloat EAXModulation(ALreverbState *State, ALuint offset, ALfloat in)
-{
- ALfloat sinus, frac, fdelay;
- ALfloat out0, out1;
- ALuint delay;
-
- // Calculate the sinus rythm (dependent on modulation time and the
- // sampling rate). The center of the sinus is moved to reduce the delay
- // of the effect when the time or depth are low.
- sinus = 1.0f - cosf(F_TAU * State->Mod.Index / State->Mod.Range);
-
- // Step the modulation index forward, keeping it bound to its range.
- State->Mod.Index = (State->Mod.Index + 1) % State->Mod.Range;
-
- // The depth determines the range over which to read the input samples
- // from, so it must be filtered to reduce the distortion caused by even
- // small parameter changes.
- State->Mod.Filter = lerp(State->Mod.Filter, State->Mod.Depth,
- State->Mod.Coeff);
-
- // Calculate the read offset and fraction between it and the next sample.
- frac = modff(State->Mod.Filter*sinus + 1.0f, &fdelay);
- delay = fastf2u(fdelay);
-
- // Get the two samples crossed by the offset, and feed the delay line
- // with the next input sample.
- out0 = DelayLineOut(&State->Mod.Delay, offset - delay);
- out1 = DelayLineOut(&State->Mod.Delay, offset - delay - 1);
- DelayLineIn(&State->Mod.Delay, offset, in);
-
- // The output is obtained by linearly interpolating the two samples that
- // were acquired above.
- return lerp(out0, out1, frac);
-}
+ state->TotalSamples = 0;
+ state->SampleBuffer = NULL;
-// Given some input sample, this function produces four-channel outputs for the
-// early reflections.
-static inline ALvoid EarlyReflection(ALreverbState *State, ALuint todo, ALfloat (*restrict out)[4])
-{
- ALfloat d[4], v, f[4];
- ALuint i;
+ state->Params.Density = AL_EAXREVERB_DEFAULT_DENSITY;
+ state->Params.Diffusion = AL_EAXREVERB_DEFAULT_DIFFUSION;
+ state->Params.DecayTime = AL_EAXREVERB_DEFAULT_DECAY_TIME;
+ state->Params.HFDecayTime = AL_EAXREVERB_DEFAULT_DECAY_TIME*AL_EAXREVERB_DEFAULT_DECAY_HFRATIO;
+ state->Params.LFDecayTime = AL_EAXREVERB_DEFAULT_DECAY_TIME*AL_EAXREVERB_DEFAULT_DECAY_LFRATIO;
+ state->Params.HFReference = AL_EAXREVERB_DEFAULT_HFREFERENCE;
+ state->Params.LFReference = AL_EAXREVERB_DEFAULT_LFREFERENCE;
- for(i = 0;i < todo;i++)
+ for(i = 0;i < NUM_LINES;i++)
{
- ALuint offset = State->Offset+i;
-
- // Obtain the decayed results of each early delay line.
- d[0] = DelayLineOut(&State->Early.Delay[0], offset-State->Early.Offset[0]) * State->Early.Coeff[0];
- d[1] = DelayLineOut(&State->Early.Delay[1], offset-State->Early.Offset[1]) * State->Early.Coeff[1];
- d[2] = DelayLineOut(&State->Early.Delay[2], offset-State->Early.Offset[2]) * State->Early.Coeff[2];
- d[3] = DelayLineOut(&State->Early.Delay[3], offset-State->Early.Offset[3]) * State->Early.Coeff[3];
-
- /* The following uses a lossless scattering junction from waveguide
- * theory. It actually amounts to a householder mixing matrix, which
- * will produce a maximally diffuse response, and means this can
- * probably be considered a simple feed-back delay network (FDN).
- * N
- * ---
- * \
- * v = 2/N / d_i
- * ---
- * i=1
- */
- v = (d[0] + d[1] + d[2] + d[3]) * 0.5f;
- // The junction is loaded with the input here.
- v += DelayLineOut(&State->Delay, offset-State->DelayTap[0]);
-
- // Calculate the feed values for the delay lines.
- f[0] = v - d[0];
- f[1] = v - d[1];
- f[2] = v - d[2];
- f[3] = v - d[3];
-
- // Re-feed the delay lines.
- DelayLineIn(&State->Early.Delay[0], offset, f[0]);
- DelayLineIn(&State->Early.Delay[1], offset, f[1]);
- DelayLineIn(&State->Early.Delay[2], offset, f[2]);
- DelayLineIn(&State->Early.Delay[3], offset, f[3]);
-
- // Output the results of the junction for all four channels.
- out[i][0] = State->Early.Gain * f[0];
- out[i][1] = State->Early.Gain * f[1];
- out[i][2] = State->Early.Gain * f[2];
- out[i][3] = State->Early.Gain * f[3];
+ BiquadFilter_clear(&state->Filter[i].Lp);
+ BiquadFilter_clear(&state->Filter[i].Hp);
}
-}
-
-// Basic attenuated all-pass input/output routine.
-static inline ALfloat AllpassInOut(DelayLine *Delay, ALuint outOffset, ALuint inOffset, ALfloat in, ALfloat feedCoeff, ALfloat coeff)
-{
- ALfloat out, feed;
-
- out = DelayLineOut(Delay, outOffset);
- feed = feedCoeff * in;
- DelayLineIn(Delay, inOffset, (feedCoeff * (out - feed)) + in);
-
- // The time-based attenuation is only applied to the delay output to
- // keep it from affecting the feed-back path (which is already controlled
- // by the all-pass feed coefficient).
- return (coeff * out) - feed;
-}
-// All-pass input/output routine for late reverb.
-static inline ALfloat LateAllPassInOut(ALreverbState *State, ALuint offset, ALuint index, ALfloat in)
-{
- return AllpassInOut(&State->Late.ApDelay[index],
- offset - State->Late.ApOffset[index],
- offset, in, State->Late.ApFeedCoeff,
- State->Late.ApCoeff[index]);
-}
-
-// Low-pass filter input/output routine for late reverb.
-static inline ALfloat LateLowPassInOut(ALreverbState *State, ALuint index, ALfloat in)
-{
- in = lerp(in, State->Late.LpSample[index], State->Late.LpCoeff[index]);
- State->Late.LpSample[index] = in;
- return in;
-}
-
-// Given four decorrelated input samples, this function produces four-channel
-// output for the late reverb.
-static inline ALvoid LateReverb(ALreverbState *State, ALuint todo, ALfloat (*restrict out)[4])
-{
- ALfloat d[4], f[4];
- ALuint i;
+ state->Delay.Mask = 0;
+ state->Delay.Line = NULL;
- for(i = 0;i < todo;i++)
+ for(i = 0;i < NUM_LINES;i++)
{
- ALuint offset = State->Offset+i;
-
- f[0] = DelayLineOut(&State->Decorrelator, offset);
- f[1] = DelayLineOut(&State->Decorrelator, offset-State->DecoTap[0]);
- f[2] = DelayLineOut(&State->Decorrelator, offset-State->DecoTap[1]);
- f[3] = DelayLineOut(&State->Decorrelator, offset-State->DecoTap[2]);
-
- // Obtain the decayed results of the cyclical delay lines, and add the
- // corresponding input channels. Then pass the results through the
- // low-pass filters.
- f[0] += DelayLineOut(&State->Late.Delay[0], offset-State->Late.Offset[0]) * State->Late.Coeff[0];
- f[1] += DelayLineOut(&State->Late.Delay[1], offset-State->Late.Offset[1]) * State->Late.Coeff[1];
- f[2] += DelayLineOut(&State->Late.Delay[2], offset-State->Late.Offset[2]) * State->Late.Coeff[2];
- f[3] += DelayLineOut(&State->Late.Delay[3], offset-State->Late.Offset[3]) * State->Late.Coeff[3];
-
- // This is where the feed-back cycles from line 0 to 1 to 3 to 2 and
- // back to 0.
- d[0] = LateLowPassInOut(State, 2, f[2]);
- d[1] = LateLowPassInOut(State, 0, f[0]);
- d[2] = LateLowPassInOut(State, 3, f[3]);
- d[3] = LateLowPassInOut(State, 1, f[1]);
-
- // To help increase diffusion, run each line through an all-pass filter.
- // When there is no diffusion, the shortest all-pass filter will feed
- // the shortest delay line.
- d[0] = LateAllPassInOut(State, offset, 0, d[0]);
- d[1] = LateAllPassInOut(State, offset, 1, d[1]);
- d[2] = LateAllPassInOut(State, offset, 2, d[2]);
- d[3] = LateAllPassInOut(State, offset, 3, d[3]);
-
- /* Late reverb is done with a modified feed-back delay network (FDN)
- * topology. Four input lines are each fed through their own all-pass
- * filter and then into the mixing matrix. The four outputs of the
- * mixing matrix are then cycled back to the inputs. Each output feeds
- * a different input to form a circlular feed cycle.
- *
- * The mixing matrix used is a 4D skew-symmetric rotation matrix
- * derived using a single unitary rotational parameter:
- *
- * [ d, a, b, c ] 1 = a^2 + b^2 + c^2 + d^2
- * [ -a, d, c, -b ]
- * [ -b, -c, d, a ]
- * [ -c, b, -a, d ]
- *
- * The rotation is constructed from the effect's diffusion parameter,
- * yielding: 1 = x^2 + 3 y^2; where a, b, and c are the coefficient y
- * with differing signs, and d is the coefficient x. The matrix is
- * thus:
- *
- * [ x, y, -y, y ] n = sqrt(matrix_order - 1)
- * [ -y, x, y, y ] t = diffusion_parameter * atan(n)
- * [ y, -y, x, y ] x = cos(t)
- * [ -y, -y, -y, x ] y = sin(t) / n
- *
- * To reduce the number of multiplies, the x coefficient is applied
- * with the cyclical delay line coefficients. Thus only the y
- * coefficient is applied when mixing, and is modified to be: y / x.
- */
- f[0] = d[0] + (State->Late.MixCoeff * ( d[1] + -d[2] + d[3]));
- f[1] = d[1] + (State->Late.MixCoeff * (-d[0] + d[2] + d[3]));
- f[2] = d[2] + (State->Late.MixCoeff * ( d[0] + -d[1] + d[3]));
- f[3] = d[3] + (State->Late.MixCoeff * (-d[0] + -d[1] + -d[2] ));
-
- // Output the results of the matrix for all four channels, attenuated by
- // the late reverb gain (which is attenuated by the 'x' mix coefficient).
- // Mix early reflections and late reverb.
- out[i][0] += State->Late.Gain * f[0];
- out[i][1] += State->Late.Gain * f[1];
- out[i][2] += State->Late.Gain * f[2];
- out[i][3] += State->Late.Gain * f[3];
-
- // Re-feed the cyclical delay lines.
- DelayLineIn(&State->Late.Delay[0], offset, f[0]);
- DelayLineIn(&State->Late.Delay[1], offset, f[1]);
- DelayLineIn(&State->Late.Delay[2], offset, f[2]);
- DelayLineIn(&State->Late.Delay[3], offset, f[3]);
+ state->EarlyDelayTap[i][0] = 0;
+ state->EarlyDelayTap[i][1] = 0;
+ state->EarlyDelayCoeff[i][0] = 0.0f;
+ state->EarlyDelayCoeff[i][1] = 0.0f;
}
-}
-// Given an input sample, this function mixes echo into the four-channel late
-// reverb.
-static inline ALvoid EAXEcho(ALreverbState *State, ALuint todo, ALfloat (*restrict late)[4])
-{
- ALfloat out, feed;
- ALuint i;
+ state->LateFeedTap = 0;
- for(i = 0;i < todo;i++)
+ for(i = 0;i < NUM_LINES;i++)
{
- ALuint offset = State->Offset+i;
-
- // Get the latest attenuated echo sample for output.
- feed = DelayLineOut(&State->Echo.Delay, offset-State->Echo.Offset) *
- State->Echo.Coeff;
-
- // Mix the output into the late reverb channels.
- out = State->Echo.MixCoeff * feed;
- late[i][0] += out;
- late[i][1] += out;
- late[i][2] += out;
- late[i][3] += out;
-
- // Mix the energy-attenuated input with the output and pass it through
- // the echo low-pass filter.
- feed += DelayLineOut(&State->Delay, offset-State->DelayTap[1]) *
- State->Echo.DensityGain;
- feed = lerp(feed, State->Echo.LpSample, State->Echo.LpCoeff);
- State->Echo.LpSample = feed;
-
- // Then the echo all-pass filter.
- feed = AllpassInOut(&State->Echo.ApDelay, offset-State->Echo.ApOffset,
- offset, feed, State->Echo.ApFeedCoeff,
- State->Echo.ApCoeff);
-
- // Feed the delay with the mixed and filtered sample.
- DelayLineIn(&State->Echo.Delay, offset, feed);
+ state->LateDelayTap[i][0] = 0;
+ state->LateDelayTap[i][1] = 0;
}
-}
-// Perform the non-EAX reverb pass on a given input sample, resulting in
-// four-channel output.
-static inline ALvoid VerbPass(ALreverbState *State, ALuint todo, const ALfloat *in, ALfloat (*restrict out)[4])
-{
- ALuint i;
+ state->MixX = 0.0f;
+ state->MixY = 0.0f;
- // Low-pass filter the incoming samples.
- for(i = 0;i < todo;i++)
- DelayLineIn(&State->Delay, State->Offset+i,
- ALfilterState_processSingle(&State->LpFilter, in[i])
- );
-
- // Calculate the early reflection from the first delay tap.
- EarlyReflection(State, todo, out);
-
- // Feed the decorrelator from the energy-attenuated output of the second
- // delay tap.
- for(i = 0;i < todo;i++)
+ state->Early.VecAp.Delay.Mask = 0;
+ state->Early.VecAp.Delay.Line = NULL;
+ state->Early.VecAp.Coeff = 0.0f;
+ state->Early.Delay.Mask = 0;
+ state->Early.Delay.Line = NULL;
+ for(i = 0;i < NUM_LINES;i++)
{
- ALuint offset = State->Offset+i;
- ALfloat sample = DelayLineOut(&State->Delay, offset - State->DelayTap[1]) *
- State->Late.DensityGain;
- DelayLineIn(&State->Decorrelator, offset, sample);
+ state->Early.VecAp.Offset[i][0] = 0;
+ state->Early.VecAp.Offset[i][1] = 0;
+ state->Early.Offset[i][0] = 0;
+ state->Early.Offset[i][1] = 0;
+ state->Early.Coeff[i][0] = 0.0f;
+ state->Early.Coeff[i][1] = 0.0f;
}
- // Calculate the late reverb from the decorrelator taps.
- LateReverb(State, todo, out);
-
- // Step all delays forward one sample.
- State->Offset += todo;
-}
-
-// Perform the EAX reverb pass on a given input sample, resulting in four-
-// channel output.
-static inline ALvoid EAXVerbPass(ALreverbState *State, ALuint todo, const ALfloat *input, ALfloat (*restrict early)[4], ALfloat (*restrict late)[4])
-{
- ALuint i;
-
- // Band-pass and modulate the incoming samples.
- for(i = 0;i < todo;i++)
+ state->Late.DensityGain[0] = 0.0f;
+ state->Late.DensityGain[1] = 0.0f;
+ state->Late.Delay.Mask = 0;
+ state->Late.Delay.Line = NULL;
+ state->Late.VecAp.Delay.Mask = 0;
+ state->Late.VecAp.Delay.Line = NULL;
+ state->Late.VecAp.Coeff = 0.0f;
+ for(i = 0;i < NUM_LINES;i++)
{
- ALfloat sample = input[i];
- sample = ALfilterState_processSingle(&State->LpFilter, sample);
- sample = ALfilterState_processSingle(&State->HpFilter, sample);
+ state->Late.Offset[i][0] = 0;
+ state->Late.Offset[i][1] = 0;
- // Perform any modulation on the input.
- sample = EAXModulation(State, State->Offset+i, sample);
+ state->Late.VecAp.Offset[i][0] = 0;
+ state->Late.VecAp.Offset[i][1] = 0;
- // Feed the initial delay line.
- DelayLineIn(&State->Delay, State->Offset+i, sample);
+ state->Late.T60[i].MidGain[0] = 0.0f;
+ state->Late.T60[i].MidGain[1] = 0.0f;
+ BiquadFilter_clear(&state->Late.T60[i].HFFilter);
+ BiquadFilter_clear(&state->Late.T60[i].LFFilter);
}
- // Calculate the early reflection from the first delay tap.
- EarlyReflection(State, todo, early);
-
- // Feed the decorrelator from the energy-attenuated output of the second
- // delay tap.
- for(i = 0;i < todo;i++)
- {
- ALuint offset = State->Offset+i;
- ALfloat sample = DelayLineOut(&State->Delay, offset - State->DelayTap[1]) *
- State->Late.DensityGain;
- DelayLineIn(&State->Decorrelator, offset, sample);
- }
-
- // Calculate the late reverb from the decorrelator taps.
- memset(late, 0, sizeof(*late)*todo);
- LateReverb(State, todo, late);
-
- // Calculate and mix in any echo.
- EAXEcho(State, todo, late);
-
- // Step all delays forward.
- State->Offset += todo;
-}
-
-static ALvoid ALreverbState_processStandard(ALreverbState *State, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)
-{
- ALfloat (*restrict out)[4] = State->ReverbSamples;
- ALuint index, c, i, l;
-
- /* Process reverb for these samples. */
- for(index = 0;index < SamplesToDo;)
+ for(i = 0;i < NUM_LINES;i++)
{
- ALuint todo = minu(SamplesToDo-index, MAX_UPDATE_SAMPLES);
-
- VerbPass(State, todo, &SamplesIn[index], out);
-
- for(l = 0;l < 4;l++)
+ for(j = 0;j < MAX_OUTPUT_CHANNELS;j++)
{
- for(c = 0;c < NumChannels;c++)
- {
- ALfloat gain = State->Gain[l][c];
- if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
- continue;
- for(i = 0;i < todo;i++)
- SamplesOut[c][index+i] += gain*out[i][l];
- }
+ state->Early.CurrentGain[i][j] = 0.0f;
+ state->Early.PanGain[i][j] = 0.0f;
+ state->Late.CurrentGain[i][j] = 0.0f;
+ state->Late.PanGain[i][j] = 0.0f;
}
-
- index += todo;
}
+
+ state->FadeCount = 0;
+ state->MaxUpdate[0] = MAX_UPDATE_SAMPLES;
+ state->MaxUpdate[1] = MAX_UPDATE_SAMPLES;
+ state->Offset = 0;
}
-static ALvoid ALreverbState_processEax(ALreverbState *State, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)
+static ALvoid ReverbState_Destruct(ReverbState *State)
{
- ALfloat (*restrict early)[4] = State->EarlySamples;
- ALfloat (*restrict late)[4] = State->ReverbSamples;
- ALuint index, c, i, l;
- ALfloat gain;
-
- /* Process reverb for these samples. */
- for(index = 0;index < SamplesToDo;)
- {
- ALuint todo = minu(SamplesToDo-index, MAX_UPDATE_SAMPLES);
-
- EAXVerbPass(State, todo, &SamplesIn[index], early, late);
-
- for(l = 0;l < 4;l++)
- {
- for(c = 0;c < NumChannels;c++)
- {
- gain = State->Early.PanGain[l][c];
- if(fabsf(gain) > GAIN_SILENCE_THRESHOLD)
- {
- for(i = 0;i < todo;i++)
- SamplesOut[c][index+i] += gain*early[i][l];
- }
- gain = State->Late.PanGain[l][c];
- if(fabsf(gain) > GAIN_SILENCE_THRESHOLD)
- {
- for(i = 0;i < todo;i++)
- SamplesOut[c][index+i] += gain*late[i][l];
- }
- }
- }
+ al_free(State->SampleBuffer);
+ State->SampleBuffer = NULL;
- index += todo;
- }
+ ALeffectState_Destruct(STATIC_CAST(ALeffectState,State));
}
-static ALvoid ALreverbState_process(ALreverbState *State, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALuint NumChannels)
+/**************************************
+ * Device Update *
+ **************************************/
+
+static inline ALfloat CalcDelayLengthMult(ALfloat density)
{
- if(State->IsEax)
- ALreverbState_processEax(State, SamplesToDo, SamplesIn, SamplesOut, NumChannels);
- else
- ALreverbState_processStandard(State, SamplesToDo, SamplesIn, SamplesOut, NumChannels);
+ return maxf(5.0f, cbrtf(density*DENSITY_SCALE));
}
-// Given the allocated sample buffer, this function updates each delay line
-// offset.
-static inline ALvoid RealizeLineOffset(ALfloat *sampleBuffer, DelayLine *Delay)
+/* Given the allocated sample buffer, this function updates each delay line
+ * offset.
+ */
+static inline ALvoid RealizeLineOffset(ALfloat *sampleBuffer, DelayLineI *Delay)
{
- Delay->Line = &sampleBuffer[(ptrdiff_t)Delay->Line];
+ union {
+ ALfloat *f;
+ ALfloat (*f4)[NUM_LINES];
+ } u;
+ u.f = &sampleBuffer[(ptrdiff_t)Delay->Line * NUM_LINES];
+ Delay->Line = u.f4;
}
-// Calculate the length of a delay line and store its mask and offset.
-static ALuint CalcLineLength(ALfloat length, ptrdiff_t offset, ALuint frequency, ALuint extra, DelayLine *Delay)
+/* Calculate the length of a delay line and store its mask and offset. */
+static ALuint CalcLineLength(const ALfloat length, const ptrdiff_t offset, const ALuint frequency,
+ const ALuint extra, DelayLineI *Delay)
{
ALuint samples;
- // All line lengths are powers of 2, calculated from their lengths, with
- // an additional sample in case of rounding errors.
- samples = fastf2u(length*frequency) + extra;
- samples = NextPowerOf2(samples + 1);
- // All lines share a single sample buffer.
+ /* All line lengths are powers of 2, calculated from their lengths in
+ * seconds, rounded up.
+ */
+ samples = float2int(ceilf(length*frequency));
+ samples = NextPowerOf2(samples + extra);
+
+ /* All lines share a single sample buffer. */
Delay->Mask = samples - 1;
- Delay->Line = (ALfloat*)offset;
- // Return the sample count for accumulation.
+ Delay->Line = (ALfloat(*)[NUM_LINES])offset;
+
+ /* Return the sample count for accumulation. */
return samples;
}
@@ -662,144 +492,173 @@ static ALuint CalcLineLength(ALfloat length, ptrdiff_t offset, ALuint frequency,
* for all lines given the sample rate (frequency). If an allocation failure
* occurs, it returns AL_FALSE.
*/
-static ALboolean AllocLines(ALuint frequency, ALreverbState *State)
+static ALboolean AllocLines(const ALuint frequency, ReverbState *State)
{
- ALuint totalSamples, index;
- ALfloat length;
- ALfloat *newBuffer = NULL;
+ ALuint totalSamples, i;
+ ALfloat multiplier, length;
- // All delay line lengths are calculated to accomodate the full range of
- // lengths given their respective paramters.
+ /* All delay line lengths are calculated to accomodate the full range of
+ * lengths given their respective paramters.
+ */
totalSamples = 0;
- /* The modulator's line length is calculated from the maximum modulation
- * time and depth coefficient, and halfed for the low-to-high frequency
- * swing. An additional sample is added to keep it stable when there is no
- * modulation.
+ /* Multiplier for the maximum density value, i.e. density=1, which is
+ * actually the least density...
*/
- length = (AL_EAXREVERB_MAX_MODULATION_TIME*MODULATION_DEPTH_COEFF/2.0f);
- totalSamples += CalcLineLength(length, totalSamples, frequency, 1,
- &State->Mod.Delay);
-
- // The initial delay is the sum of the reflections and late reverb
- // delays. This must include space for storing a loop update to feed the
- // early reflections, decorrelator, and echo.
- length = AL_EAXREVERB_MAX_REFLECTIONS_DELAY +
- AL_EAXREVERB_MAX_LATE_REVERB_DELAY;
- totalSamples += CalcLineLength(length, totalSamples, frequency,
- MAX_UPDATE_SAMPLES, &State->Delay);
-
- // The early reflection lines.
- for(index = 0;index < 4;index++)
- totalSamples += CalcLineLength(EARLY_LINE_LENGTH[index], totalSamples,
- frequency, 0, &State->Early.Delay[index]);
-
- // The decorrelator line is calculated from the lowest reverb density (a
- // parameter value of 1). This must include space for storing a loop update
- // to feed the late reverb.
- length = (DECO_FRACTION * DECO_MULTIPLIER * DECO_MULTIPLIER) *
- LATE_LINE_LENGTH[0] * (1.0f + LATE_LINE_MULTIPLIER);
+ multiplier = CalcDelayLengthMult(AL_EAXREVERB_MAX_DENSITY);
+
+ /* The main delay length includes the maximum early reflection delay, the
+ * largest early tap width, the maximum late reverb delay, and the
+ * largest late tap width. Finally, it must also be extended by the
+ * update size (MAX_UPDATE_SAMPLES) for block processing.
+ */
+ length = AL_EAXREVERB_MAX_REFLECTIONS_DELAY + EARLY_TAP_LENGTHS[NUM_LINES-1]*multiplier +
+ AL_EAXREVERB_MAX_LATE_REVERB_DELAY +
+ (LATE_LINE_LENGTHS[NUM_LINES-1] - LATE_LINE_LENGTHS[0])*0.25f*multiplier;
totalSamples += CalcLineLength(length, totalSamples, frequency, MAX_UPDATE_SAMPLES,
- &State->Decorrelator);
+ &State->Delay);
- // The late all-pass lines.
- for(index = 0;index < 4;index++)
- totalSamples += CalcLineLength(ALLPASS_LINE_LENGTH[index], totalSamples,
- frequency, 0, &State->Late.ApDelay[index]);
+ /* The early vector all-pass line. */
+ length = EARLY_ALLPASS_LENGTHS[NUM_LINES-1] * multiplier;
+ totalSamples += CalcLineLength(length, totalSamples, frequency, 0,
+ &State->Early.VecAp.Delay);
- // The late delay lines are calculated from the lowest reverb density.
- for(index = 0;index < 4;index++)
- {
- length = LATE_LINE_LENGTH[index] * (1.0f + LATE_LINE_MULTIPLIER);
- totalSamples += CalcLineLength(length, totalSamples, frequency, 0,
- &State->Late.Delay[index]);
- }
+ /* The early reflection line. */
+ length = EARLY_LINE_LENGTHS[NUM_LINES-1] * multiplier;
+ totalSamples += CalcLineLength(length, totalSamples, frequency, 0,
+ &State->Early.Delay);
+
+ /* The late vector all-pass line. */
+ length = LATE_ALLPASS_LENGTHS[NUM_LINES-1] * multiplier;
+ totalSamples += CalcLineLength(length, totalSamples, frequency, 0,
+ &State->Late.VecAp.Delay);
- // The echo all-pass and delay lines.
- totalSamples += CalcLineLength(ECHO_ALLPASS_LENGTH, totalSamples,
- frequency, 0, &State->Echo.ApDelay);
- totalSamples += CalcLineLength(AL_EAXREVERB_MAX_ECHO_TIME, totalSamples,
- frequency, 0, &State->Echo.Delay);
+ /* The late delay lines are calculated from the largest maximum density
+ * line length.
+ */
+ length = LATE_LINE_LENGTHS[NUM_LINES-1] * multiplier;
+ totalSamples += CalcLineLength(length, totalSamples, frequency, 0,
+ &State->Late.Delay);
if(totalSamples != State->TotalSamples)
{
- TRACE("New reverb buffer length: %u samples (%f sec)\n", totalSamples, totalSamples/(float)frequency);
- newBuffer = realloc(State->SampleBuffer, sizeof(ALfloat) * totalSamples);
- if(newBuffer == NULL)
- return AL_FALSE;
+ ALfloat *newBuffer;
+
+ TRACE("New reverb buffer length: %ux4 samples\n", totalSamples);
+ newBuffer = al_calloc(16, sizeof(ALfloat[NUM_LINES]) * totalSamples);
+ if(!newBuffer) return AL_FALSE;
+
+ al_free(State->SampleBuffer);
State->SampleBuffer = newBuffer;
State->TotalSamples = totalSamples;
}
- // Update all delays to reflect the new sample buffer.
+ /* Update all delays to reflect the new sample buffer. */
RealizeLineOffset(State->SampleBuffer, &State->Delay);
- RealizeLineOffset(State->SampleBuffer, &State->Decorrelator);
- for(index = 0;index < 4;index++)
- {
- RealizeLineOffset(State->SampleBuffer, &State->Early.Delay[index]);
- RealizeLineOffset(State->SampleBuffer, &State->Late.ApDelay[index]);
- RealizeLineOffset(State->SampleBuffer, &State->Late.Delay[index]);
- }
- RealizeLineOffset(State->SampleBuffer, &State->Mod.Delay);
- RealizeLineOffset(State->SampleBuffer, &State->Echo.ApDelay);
- RealizeLineOffset(State->SampleBuffer, &State->Echo.Delay);
+ RealizeLineOffset(State->SampleBuffer, &State->Early.VecAp.Delay);
+ RealizeLineOffset(State->SampleBuffer, &State->Early.Delay);
+ RealizeLineOffset(State->SampleBuffer, &State->Late.VecAp.Delay);
+ RealizeLineOffset(State->SampleBuffer, &State->Late.Delay);
- // Clear the sample buffer.
- for(index = 0;index < State->TotalSamples;index++)
- State->SampleBuffer[index] = 0.0f;
+ /* Clear the sample buffer. */
+ for(i = 0;i < State->TotalSamples;i++)
+ State->SampleBuffer[i] = 0.0f;
return AL_TRUE;
}
-static ALboolean ALreverbState_deviceUpdate(ALreverbState *State, ALCdevice *Device)
+static ALboolean ReverbState_deviceUpdate(ReverbState *State, ALCdevice *Device)
{
- ALuint frequency = Device->Frequency, index;
+ ALuint frequency = Device->Frequency;
+ ALfloat multiplier;
+ ALsizei i, j;
- // Allocate the delay lines.
+ /* Allocate the delay lines. */
if(!AllocLines(frequency, State))
return AL_FALSE;
- // Calculate the modulation filter coefficient. Notice that the exponent
- // is calculated given the current sample rate. This ensures that the
- // resulting filter response over time is consistent across all sample
- // rates.
- State->Mod.Coeff = powf(MODULATION_FILTER_COEFF,
- MODULATION_FILTER_CONST / frequency);
+ multiplier = CalcDelayLengthMult(AL_EAXREVERB_MAX_DENSITY);
+
+ /* The late feed taps are set a fixed position past the latest delay tap. */
+ State->LateFeedTap = float2int((AL_EAXREVERB_MAX_REFLECTIONS_DELAY +
+ EARLY_TAP_LENGTHS[NUM_LINES-1]*multiplier) *
+ frequency);
- // The early reflection and late all-pass filter line lengths are static,
- // so their offsets only need to be calculated once.
- for(index = 0;index < 4;index++)
+ /* Clear filters and gain coefficients since the delay lines were all just
+ * cleared (if not reallocated).
+ */
+ for(i = 0;i < NUM_LINES;i++)
{
- State->Early.Offset[index] = fastf2u(EARLY_LINE_LENGTH[index] *
- frequency);
- State->Late.ApOffset[index] = fastf2u(ALLPASS_LINE_LENGTH[index] *
- frequency);
+ BiquadFilter_clear(&State->Filter[i].Lp);
+ BiquadFilter_clear(&State->Filter[i].Hp);
}
- // The echo all-pass filter line length is static, so its offset only
- // needs to be calculated once.
- State->Echo.ApOffset = fastf2u(ECHO_ALLPASS_LENGTH * frequency);
+ for(i = 0;i < NUM_LINES;i++)
+ {
+ State->EarlyDelayCoeff[i][0] = 0.0f;
+ State->EarlyDelayCoeff[i][1] = 0.0f;
+ }
+
+ for(i = 0;i < NUM_LINES;i++)
+ {
+ State->Early.Coeff[i][0] = 0.0f;
+ State->Early.Coeff[i][1] = 0.0f;
+ }
+
+ State->Late.DensityGain[0] = 0.0f;
+ State->Late.DensityGain[1] = 0.0f;
+ for(i = 0;i < NUM_LINES;i++)
+ {
+ State->Late.T60[i].MidGain[0] = 0.0f;
+ State->Late.T60[i].MidGain[1] = 0.0f;
+ BiquadFilter_clear(&State->Late.T60[i].HFFilter);
+ BiquadFilter_clear(&State->Late.T60[i].LFFilter);
+ }
+
+ for(i = 0;i < NUM_LINES;i++)
+ {
+ for(j = 0;j < MAX_OUTPUT_CHANNELS;j++)
+ {
+ State->Early.CurrentGain[i][j] = 0.0f;
+ State->Early.PanGain[i][j] = 0.0f;
+ State->Late.CurrentGain[i][j] = 0.0f;
+ State->Late.PanGain[i][j] = 0.0f;
+ }
+ }
+
+ /* Reset counters and offset base. */
+ State->FadeCount = 0;
+ State->MaxUpdate[0] = MAX_UPDATE_SAMPLES;
+ State->MaxUpdate[1] = MAX_UPDATE_SAMPLES;
+ State->Offset = 0;
return AL_TRUE;
}
-// Calculate a decay coefficient given the length of each cycle and the time
-// until the decay reaches -60 dB.
-static inline ALfloat CalcDecayCoeff(ALfloat length, ALfloat decayTime)
+/**************************************
+ * Effect Update *
+ **************************************/
+
+/* Calculate a decay coefficient given the length of each cycle and the time
+ * until the decay reaches -60 dB.
+ */
+static inline ALfloat CalcDecayCoeff(const ALfloat length, const ALfloat decayTime)
{
- return powf(0.001f/*-60 dB*/, length/decayTime);
+ return powf(REVERB_DECAY_GAIN, length/decayTime);
}
-// Calculate a decay length from a coefficient and the time until the decay
-// reaches -60 dB.
-static inline ALfloat CalcDecayLength(ALfloat coeff, ALfloat decayTime)
+/* Calculate a decay length from a coefficient and the time until the decay
+ * reaches -60 dB.
+ */
+static inline ALfloat CalcDecayLength(const ALfloat coeff, const ALfloat decayTime)
{
- return log10f(coeff) * decayTime / log10f(0.001f)/*-60 dB*/;
+ return log10f(coeff) * decayTime / log10f(REVERB_DECAY_GAIN);
}
-// Calculate an attenuation to be applied to the input of any echo models to
-// compensate for modal density and decay time.
-static inline ALfloat CalcDensityGain(ALfloat a)
+/* Calculate an attenuation to be applied to the input of any echo models to
+ * compensate for modal density and decay time.
+ */
+static inline ALfloat CalcDensityGain(const ALfloat a)
{
/* The energy of a signal can be obtained by finding the area under the
* squared signal. This takes the form of Sum(x_n^2), where x is the
@@ -809,32 +668,34 @@ static inline ALfloat CalcDensityGain(ALfloat a)
* where a is the attenuation coefficient, and n is the sample. The area
* under this decay curve can be calculated as: 1 / (1 - a).
*
- * Modifying the above equation to find the squared area under the curve
+ * Modifying the above equation to find the area under the squared curve
* (for energy) yields: 1 / (1 - a^2). Input attenuation can then be
* calculated by inverting the square root of this approximation,
* yielding: 1 / sqrt(1 / (1 - a^2)), simplified to: sqrt(1 - a^2).
*/
- return sqrtf(1.0f - (a * a));
+ return sqrtf(1.0f - a*a);
}
-// Calculate the mixing matrix coefficients given a diffusion factor.
-static inline ALvoid CalcMatrixCoeffs(ALfloat diffusion, ALfloat *x, ALfloat *y)
+/* Calculate the scattering matrix coefficients given a diffusion factor. */
+static inline ALvoid CalcMatrixCoeffs(const ALfloat diffusion, ALfloat *x, ALfloat *y)
{
ALfloat n, t;
- // The matrix is of order 4, so n is sqrt (4 - 1).
+ /* The matrix is of order 4, so n is sqrt(4 - 1). */
n = sqrtf(3.0f);
t = diffusion * atanf(n);
- // Calculate the first mixing matrix coefficient.
+ /* Calculate the first mixing matrix coefficient. */
*x = cosf(t);
- // Calculate the second mixing matrix coefficient.
+ /* Calculate the second mixing matrix coefficient. */
*y = sinf(t) / n;
}
-// Calculate the limited HF ratio for use with the late reverb low-pass
-// filters.
-static ALfloat CalcLimitedHfRatio(ALfloat hfRatio, ALfloat airAbsorptionGainHF, ALfloat decayTime)
+/* Calculate the limited HF ratio for use with the late reverb low-pass
+ * filters.
+ */
+static ALfloat CalcLimitedHfRatio(const ALfloat hfRatio, const ALfloat airAbsorptionGainHF,
+ const ALfloat decayTime, const ALfloat SpeedOfSound)
{
ALfloat limitRatio;
@@ -843,464 +704,906 @@ static ALfloat CalcLimitedHfRatio(ALfloat hfRatio, ALfloat airAbsorptionGainHF,
* equation, solve for HF ratio. The delay length is cancelled out of
* the equation, so it can be calculated once for all lines.
*/
- limitRatio = 1.0f / (CalcDecayLength(airAbsorptionGainHF, decayTime) *
- SPEEDOFSOUNDMETRESPERSEC);
- /* Using the limit calculated above, apply the upper bound to the HF
- * ratio. Also need to limit the result to a minimum of 0.1, just like the
- * HF ratio parameter. */
- return clampf(limitRatio, 0.1f, hfRatio);
-}
+ limitRatio = 1.0f / (CalcDecayLength(airAbsorptionGainHF, decayTime) * SpeedOfSound);
-// Calculate the coefficient for a HF (and eventually LF) decay damping
-// filter.
-static inline ALfloat CalcDampingCoeff(ALfloat hfRatio, ALfloat length, ALfloat decayTime, ALfloat decayCoeff, ALfloat cw)
-{
- ALfloat coeff, g;
+ /* Using the limit calculated above, apply the upper bound to the HF ratio.
+ */
+ return minf(limitRatio, hfRatio);
+}
- // Eventually this should boost the high frequencies when the ratio
- // exceeds 1.
- coeff = 0.0f;
- if (hfRatio < 1.0f)
- {
- // Calculate the low-pass coefficient by dividing the HF decay
- // coefficient by the full decay coefficient.
- g = CalcDecayCoeff(length, decayTime * hfRatio) / decayCoeff;
- // Damping is done with a 1-pole filter, so g needs to be squared.
- g *= g;
- if(g < 0.9999f) /* 1-epsilon */
- {
- /* Be careful with gains < 0.001, as that causes the coefficient
- * head towards 1, which will flatten the signal. */
- g = maxf(g, 0.001f);
- coeff = (1 - g*cw - sqrtf(2*g*(1-cw) - g*g*(1 - cw*cw))) /
- (1 - g);
- }
-
- // Very low decay times will produce minimal output, so apply an
- // upper bound to the coefficient.
- coeff = minf(coeff, 0.98f);
- }
- return coeff;
+/* Calculates the 3-band T60 damping coefficients for a particular delay line
+ * of specified length, using a combination of two shelf filter sections given
+ * decay times for each band split at two reference frequencies.
+ */
+static void CalcT60DampingCoeffs(const ALfloat length, const ALfloat lfDecayTime,
+ const ALfloat mfDecayTime, const ALfloat hfDecayTime,
+ const ALfloat lf0norm, const ALfloat hf0norm,
+ T60Filter *filter)
+{
+ ALfloat lfGain = CalcDecayCoeff(length, lfDecayTime);
+ ALfloat mfGain = CalcDecayCoeff(length, mfDecayTime);
+ ALfloat hfGain = CalcDecayCoeff(length, hfDecayTime);
+
+ filter->MidGain[1] = mfGain;
+ BiquadFilter_setParams(&filter->LFFilter, BiquadType_LowShelf, lfGain/mfGain, lf0norm,
+ calc_rcpQ_from_slope(lfGain/mfGain, 1.0f));
+ BiquadFilter_setParams(&filter->HFFilter, BiquadType_HighShelf, hfGain/mfGain, hf0norm,
+ calc_rcpQ_from_slope(hfGain/mfGain, 1.0f));
}
-// Update the EAX modulation index, range, and depth. Keep in mind that this
-// kind of vibrato is additive and not multiplicative as one may expect. The
-// downswing will sound stronger than the upswing.
-static ALvoid UpdateModulator(ALfloat modTime, ALfloat modDepth, ALuint frequency, ALreverbState *State)
+/* Update the offsets for the main effect delay line. */
+static ALvoid UpdateDelayLine(const ALfloat earlyDelay, const ALfloat lateDelay, const ALfloat density, const ALfloat decayTime, const ALuint frequency, ReverbState *State)
{
- ALuint range;
+ ALfloat multiplier, length;
+ ALuint i;
- /* Modulation is calculated in two parts.
+ multiplier = CalcDelayLengthMult(density);
+
+ /* Early reflection taps are decorrelated by means of an average room
+ * reflection approximation described above the definition of the taps.
+ * This approximation is linear and so the above density multiplier can
+ * be applied to adjust the width of the taps. A single-band decay
+ * coefficient is applied to simulate initial attenuation and absorption.
*
- * The modulation time effects the sinus applied to the change in
- * frequency. An index out of the current time range (both in samples)
- * is incremented each sample. The range is bound to a reasonable
- * minimum (1 sample) and when the timing changes, the index is rescaled
- * to the new range (to keep the sinus consistent).
- */
- range = maxu(fastf2u(modTime*frequency), 1);
- State->Mod.Index = (ALuint)(State->Mod.Index * (ALuint64)range /
- State->Mod.Range);
- State->Mod.Range = range;
-
- /* The modulation depth effects the amount of frequency change over the
- * range of the sinus. It needs to be scaled by the modulation time so
- * that a given depth produces a consistent change in frequency over all
- * ranges of time. Since the depth is applied to a sinus value, it needs
- * to be halfed once for the sinus range and again for the sinus swing
- * in time (half of it is spent decreasing the frequency, half is spent
- * increasing it).
+ * Late reverb taps are based on the late line lengths to allow a zero-
+ * delay path and offsets that would continue the propagation naturally
+ * into the late lines.
*/
- State->Mod.Depth = modDepth * MODULATION_DEPTH_COEFF * modTime / 2.0f /
- 2.0f * frequency;
-}
+ for(i = 0;i < NUM_LINES;i++)
+ {
+ length = earlyDelay + EARLY_TAP_LENGTHS[i]*multiplier;
+ State->EarlyDelayTap[i][1] = float2int(length * frequency);
-// Update the offsets for the initial effect delay line.
-static ALvoid UpdateDelayLine(ALfloat earlyDelay, ALfloat lateDelay, ALuint frequency, ALreverbState *State)
-{
- // Calculate the initial delay taps.
- State->DelayTap[0] = fastf2u(earlyDelay * frequency);
- State->DelayTap[1] = fastf2u((earlyDelay + lateDelay) * frequency);
-}
+ length = EARLY_TAP_LENGTHS[i]*multiplier;
+ State->EarlyDelayCoeff[i][1] = CalcDecayCoeff(length, decayTime);
-// Update the early reflections gain and line coefficients.
-static ALvoid UpdateEarlyLines(ALfloat reverbGain, ALfloat earlyGain, ALfloat lateDelay, ALreverbState *State)
-{
- ALuint index;
-
- // Calculate the early reflections gain (from the master effect gain, and
- // reflections gain parameters) with a constant attenuation of 0.5.
- State->Early.Gain = 0.5f * reverbGain * earlyGain;
-
- // Calculate the gain (coefficient) for each early delay line using the
- // late delay time. This expands the early reflections to the start of
- // the late reverb.
- for(index = 0;index < 4;index++)
- State->Early.Coeff[index] = CalcDecayCoeff(EARLY_LINE_LENGTH[index],
- lateDelay);
+ length = lateDelay + (LATE_LINE_LENGTHS[i] - LATE_LINE_LENGTHS[0])*0.25f*multiplier;
+ State->LateDelayTap[i][1] = State->LateFeedTap + float2int(length * frequency);
+ }
}
-// Update the offsets for the decorrelator line.
-static ALvoid UpdateDecorrelator(ALfloat density, ALuint frequency, ALreverbState *State)
+/* Update the early reflection line lengths and gain coefficients. */
+static ALvoid UpdateEarlyLines(const ALfloat density, const ALfloat diffusion, const ALfloat decayTime, const ALuint frequency, EarlyReflections *Early)
{
- ALuint index;
- ALfloat length;
+ ALfloat multiplier, length;
+ ALsizei i;
- /* The late reverb inputs are decorrelated to smooth the reverb tail and
- * reduce harsh echos. The first tap occurs immediately, while the
- * remaining taps are delayed by multiples of a fraction of the smallest
- * cyclical delay time.
- *
- * offset[index] = (FRACTION (MULTIPLIER^index)) smallest_delay
- */
- for(index = 0;index < 3;index++)
+ multiplier = CalcDelayLengthMult(density);
+
+ /* Calculate the all-pass feed-back/forward coefficient. */
+ Early->VecAp.Coeff = sqrtf(0.5f) * powf(diffusion, 2.0f);
+
+ for(i = 0;i < NUM_LINES;i++)
{
- length = (DECO_FRACTION * powf(DECO_MULTIPLIER, (ALfloat)index)) *
- LATE_LINE_LENGTH[0] * (1.0f + (density * LATE_LINE_MULTIPLIER));
- State->DecoTap[index] = fastf2u(length * frequency);
+ /* Calculate the length (in seconds) of each all-pass line. */
+ length = EARLY_ALLPASS_LENGTHS[i] * multiplier;
+
+ /* Calculate the delay offset for each all-pass line. */
+ Early->VecAp.Offset[i][1] = float2int(length * frequency);
+
+ /* Calculate the length (in seconds) of each delay line. */
+ length = EARLY_LINE_LENGTHS[i] * multiplier;
+
+ /* Calculate the delay offset for each delay line. */
+ Early->Offset[i][1] = float2int(length * frequency);
+
+ /* Calculate the gain (coefficient) for each line. */
+ Early->Coeff[i][1] = CalcDecayCoeff(length, decayTime);
}
}
-// Update the late reverb gains, line lengths, and line coefficients.
-static ALvoid UpdateLateLines(ALfloat reverbGain, ALfloat lateGain, ALfloat xMix, ALfloat density, ALfloat decayTime, ALfloat diffusion, ALfloat echoDepth, ALfloat hfRatio, ALfloat cw, ALuint frequency, ALreverbState *State)
+/* Update the late reverb line lengths and T60 coefficients. */
+static ALvoid UpdateLateLines(const ALfloat density, const ALfloat diffusion, const ALfloat lfDecayTime, const ALfloat mfDecayTime, const ALfloat hfDecayTime, const ALfloat lf0norm, const ALfloat hf0norm, const ALuint frequency, LateReverb *Late)
{
- ALfloat length;
- ALuint index;
-
- /* Calculate the late reverb gain (from the master effect gain, and late
- * reverb gain parameters). Since the output is tapped prior to the
- * application of the next delay line coefficients, this gain needs to be
- * attenuated by the 'x' mixing matrix coefficient as well. Also attenuate
- * the late reverb when echo depth is high and diffusion is low, so the
- * echo is slightly stronger than the decorrelated echos in the reverb
- * tail.
+ /* Scaling factor to convert the normalized reference frequencies from
+ * representing 0...freq to 0...max_reference.
*/
- State->Late.Gain = reverbGain * lateGain * xMix *
- (1.0f - (echoDepth*0.5f*(1.0f - diffusion)));
+ const ALfloat norm_weight_factor = (ALfloat)frequency / AL_EAXREVERB_MAX_HFREFERENCE;
+ ALfloat multiplier, length, bandWeights[3];
+ ALsizei i;
/* To compensate for changes in modal density and decay time of the late
* reverb signal, the input is attenuated based on the maximal energy of
* the outgoing signal. This approximation is used to keep the apparent
* energy of the signal equal for all ranges of density and decay time.
*
- * The average length of the cyclcical delay lines is used to calculate
- * the attenuation coefficient.
+ * The average length of the delay lines is used to calculate the
+ * attenuation coefficient.
+ */
+ multiplier = CalcDelayLengthMult(density);
+ length = (LATE_LINE_LENGTHS[0] + LATE_LINE_LENGTHS[1] +
+ LATE_LINE_LENGTHS[2] + LATE_LINE_LENGTHS[3]) / 4.0f * multiplier;
+ length += (LATE_ALLPASS_LENGTHS[0] + LATE_ALLPASS_LENGTHS[1] +
+ LATE_ALLPASS_LENGTHS[2] + LATE_ALLPASS_LENGTHS[3]) / 4.0f * multiplier;
+ /* The density gain calculation uses an average decay time weighted by
+ * approximate bandwidth. This attempts to compensate for losses of energy
+ * that reduce decay time due to scattering into highly attenuated bands.
*/
- length = (LATE_LINE_LENGTH[0] + LATE_LINE_LENGTH[1] +
- LATE_LINE_LENGTH[2] + LATE_LINE_LENGTH[3]) / 4.0f;
- length *= 1.0f + (density * LATE_LINE_MULTIPLIER);
- State->Late.DensityGain = CalcDensityGain(
- CalcDecayCoeff(length, decayTime)
+ bandWeights[0] = lf0norm*norm_weight_factor;
+ bandWeights[1] = hf0norm*norm_weight_factor - lf0norm*norm_weight_factor;
+ bandWeights[2] = 1.0f - hf0norm*norm_weight_factor;
+ Late->DensityGain[1] = CalcDensityGain(
+ CalcDecayCoeff(length,
+ bandWeights[0]*lfDecayTime + bandWeights[1]*mfDecayTime + bandWeights[2]*hfDecayTime
+ )
);
- // Calculate the all-pass feed-back and feed-forward coefficient.
- State->Late.ApFeedCoeff = 0.5f * powf(diffusion, 2.0f);
+ /* Calculate the all-pass feed-back/forward coefficient. */
+ Late->VecAp.Coeff = sqrtf(0.5f) * powf(diffusion, 2.0f);
- for(index = 0;index < 4;index++)
+ for(i = 0;i < NUM_LINES;i++)
{
- // Calculate the gain (coefficient) for each all-pass line.
- State->Late.ApCoeff[index] = CalcDecayCoeff(
- ALLPASS_LINE_LENGTH[index], decayTime
- );
+ /* Calculate the length (in seconds) of each all-pass line. */
+ length = LATE_ALLPASS_LENGTHS[i] * multiplier;
- // Calculate the length (in seconds) of each cyclical delay line.
- length = LATE_LINE_LENGTH[index] *
- (1.0f + (density * LATE_LINE_MULTIPLIER));
+ /* Calculate the delay offset for each all-pass line. */
+ Late->VecAp.Offset[i][1] = float2int(length * frequency);
- // Calculate the delay offset for each cyclical delay line.
- State->Late.Offset[index] = fastf2u(length * frequency);
+ /* Calculate the length (in seconds) of each delay line. */
+ length = LATE_LINE_LENGTHS[i] * multiplier;
- // Calculate the gain (coefficient) for each cyclical line.
- State->Late.Coeff[index] = CalcDecayCoeff(length, decayTime);
+ /* Calculate the delay offset for each delay line. */
+ Late->Offset[i][1] = float2int(length*frequency + 0.5f);
- // Calculate the damping coefficient for each low-pass filter.
- State->Late.LpCoeff[index] = CalcDampingCoeff(
- hfRatio, length, decayTime, State->Late.Coeff[index], cw
- );
+ /* Approximate the absorption that the vector all-pass would exhibit
+ * given the current diffusion so we don't have to process a full T60
+ * filter for each of its four lines.
+ */
+ length += lerp(LATE_ALLPASS_LENGTHS[i],
+ (LATE_ALLPASS_LENGTHS[0] + LATE_ALLPASS_LENGTHS[1] +
+ LATE_ALLPASS_LENGTHS[2] + LATE_ALLPASS_LENGTHS[3]) / 4.0f,
+ diffusion) * multiplier;
+
+ /* Calculate the T60 damping coefficients for each line. */
+ CalcT60DampingCoeffs(length, lfDecayTime, mfDecayTime, hfDecayTime,
+ lf0norm, hf0norm, &Late->T60[i]);
+ }
+}
- // Attenuate the cyclical line coefficients by the mixing coefficient
- // (x).
- State->Late.Coeff[index] *= xMix;
+/* Creates a transform matrix given a reverb vector. The vector pans the reverb
+ * reflections toward the given direction, using its magnitude (up to 1) as a
+ * focal strength. This function results in a B-Format transformation matrix
+ * that spatially focuses the signal in the desired direction.
+ */
+static aluMatrixf GetTransformFromVector(const ALfloat *vec)
+{
+ aluMatrixf focus;
+ ALfloat norm[3];
+ ALfloat mag;
+
+ /* Normalize the panning vector according to the N3D scale, which has an
+ * extra sqrt(3) term on the directional components. Converting from OpenAL
+ * to B-Format also requires negating X (ACN 1) and Z (ACN 3). Note however
+ * that the reverb panning vectors use left-handed coordinates, unlike the
+ * rest of OpenAL which use right-handed. This is fixed by negating Z,
+ * which cancels out with the B-Format Z negation.
+ */
+ mag = sqrtf(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]);
+ if(mag > 1.0f)
+ {
+ norm[0] = vec[0] / mag * -SQRTF_3;
+ norm[1] = vec[1] / mag * SQRTF_3;
+ norm[2] = vec[2] / mag * SQRTF_3;
+ mag = 1.0f;
}
+ else
+ {
+ /* If the magnitude is less than or equal to 1, just apply the sqrt(3)
+ * term. There's no need to renormalize the magnitude since it would
+ * just be reapplied in the matrix.
+ */
+ norm[0] = vec[0] * -SQRTF_3;
+ norm[1] = vec[1] * SQRTF_3;
+ norm[2] = vec[2] * SQRTF_3;
+ }
+
+ aluMatrixfSet(&focus,
+ 1.0f, 0.0f, 0.0f, 0.0f,
+ norm[0], 1.0f-mag, 0.0f, 0.0f,
+ norm[1], 0.0f, 1.0f-mag, 0.0f,
+ norm[2], 0.0f, 0.0f, 1.0f-mag
+ );
+
+ return focus;
}
-// Update the echo gain, line offset, line coefficients, and mixing
-// coefficients.
-static ALvoid UpdateEchoLine(ALfloat reverbGain, ALfloat lateGain, ALfloat echoTime, ALfloat decayTime, ALfloat diffusion, ALfloat echoDepth, ALfloat hfRatio, ALfloat cw, ALuint frequency, ALreverbState *State)
+/* Update the early and late 3D panning gains. */
+static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *ReflectionsPan, const ALfloat *LateReverbPan, const ALfloat earlyGain, const ALfloat lateGain, ReverbState *State)
{
- // Update the offset and coefficient for the echo delay line.
- State->Echo.Offset = fastf2u(echoTime * frequency);
+ aluMatrixf transform, rot;
+ ALsizei i;
+
+ STATIC_CAST(ALeffectState,State)->OutBuffer = Device->FOAOut.Buffer;
+ STATIC_CAST(ALeffectState,State)->OutChannels = Device->FOAOut.NumChannels;
+
+ /* Note: _res is transposed. */
+#define MATRIX_MULT(_res, _m1, _m2) do { \
+ int row, col; \
+ for(col = 0;col < 4;col++) \
+ { \
+ for(row = 0;row < 4;row++) \
+ _res.m[col][row] = _m1.m[row][0]*_m2.m[0][col] + _m1.m[row][1]*_m2.m[1][col] + \
+ _m1.m[row][2]*_m2.m[2][col] + _m1.m[row][3]*_m2.m[3][col]; \
+ } \
+} while(0)
+ /* Create a matrix that first converts A-Format to B-Format, then
+ * transforms the B-Format signal according to the panning vector.
+ */
+ rot = GetTransformFromVector(ReflectionsPan);
+ MATRIX_MULT(transform, rot, A2B);
+ memset(&State->Early.PanGain, 0, sizeof(State->Early.PanGain));
+ for(i = 0;i < MAX_EFFECT_CHANNELS;i++)
+ ComputePanGains(&Device->FOAOut, transform.m[i], earlyGain,
+ State->Early.PanGain[i]);
+
+ rot = GetTransformFromVector(LateReverbPan);
+ MATRIX_MULT(transform, rot, A2B);
+ memset(&State->Late.PanGain, 0, sizeof(State->Late.PanGain));
+ for(i = 0;i < MAX_EFFECT_CHANNELS;i++)
+ ComputePanGains(&Device->FOAOut, transform.m[i], lateGain,
+ State->Late.PanGain[i]);
+#undef MATRIX_MULT
+}
- // Calculate the decay coefficient for the echo line.
- State->Echo.Coeff = CalcDecayCoeff(echoTime, decayTime);
+static void ReverbState_update(ReverbState *State, const ALCcontext *Context, const ALeffectslot *Slot, const ALeffectProps *props)
+{
+ const ALCdevice *Device = Context->Device;
+ const ALlistener *Listener = Context->Listener;
+ ALuint frequency = Device->Frequency;
+ ALfloat lf0norm, hf0norm, hfRatio;
+ ALfloat lfDecayTime, hfDecayTime;
+ ALfloat gain, gainlf, gainhf;
+ ALsizei i;
+
+ /* Calculate the master filters */
+ hf0norm = minf(props->Reverb.HFReference / frequency, 0.49f);
+ /* Restrict the filter gains from going below -60dB to keep the filter from
+ * killing most of the signal.
+ */
+ gainhf = maxf(props->Reverb.GainHF, 0.001f);
+ BiquadFilter_setParams(&State->Filter[0].Lp, BiquadType_HighShelf, gainhf, hf0norm,
+ calc_rcpQ_from_slope(gainhf, 1.0f));
+ lf0norm = minf(props->Reverb.LFReference / frequency, 0.49f);
+ gainlf = maxf(props->Reverb.GainLF, 0.001f);
+ BiquadFilter_setParams(&State->Filter[0].Hp, BiquadType_LowShelf, gainlf, lf0norm,
+ calc_rcpQ_from_slope(gainlf, 1.0f));
+ for(i = 1;i < NUM_LINES;i++)
+ {
+ BiquadFilter_copyParams(&State->Filter[i].Lp, &State->Filter[0].Lp);
+ BiquadFilter_copyParams(&State->Filter[i].Hp, &State->Filter[0].Hp);
+ }
- // Calculate the energy-based attenuation coefficient for the echo delay
- // line.
- State->Echo.DensityGain = CalcDensityGain(State->Echo.Coeff);
+ /* Update the main effect delay and associated taps. */
+ UpdateDelayLine(props->Reverb.ReflectionsDelay, props->Reverb.LateReverbDelay,
+ props->Reverb.Density, props->Reverb.DecayTime, frequency,
+ State);
- // Calculate the echo all-pass feed coefficient.
- State->Echo.ApFeedCoeff = 0.5f * powf(diffusion, 2.0f);
+ /* Update the early lines. */
+ UpdateEarlyLines(props->Reverb.Density, props->Reverb.Diffusion,
+ props->Reverb.DecayTime, frequency, &State->Early);
- // Calculate the echo all-pass attenuation coefficient.
- State->Echo.ApCoeff = CalcDecayCoeff(ECHO_ALLPASS_LENGTH, decayTime);
+ /* Get the mixing matrix coefficients. */
+ CalcMatrixCoeffs(props->Reverb.Diffusion, &State->MixX, &State->MixY);
- // Calculate the damping coefficient for each low-pass filter.
- State->Echo.LpCoeff = CalcDampingCoeff(hfRatio, echoTime, decayTime,
- State->Echo.Coeff, cw);
+ /* If the HF limit parameter is flagged, calculate an appropriate limit
+ * based on the air absorption parameter.
+ */
+ hfRatio = props->Reverb.DecayHFRatio;
+ if(props->Reverb.DecayHFLimit && props->Reverb.AirAbsorptionGainHF < 1.0f)
+ hfRatio = CalcLimitedHfRatio(hfRatio, props->Reverb.AirAbsorptionGainHF,
+ props->Reverb.DecayTime, Listener->Params.ReverbSpeedOfSound
+ );
+
+ /* Calculate the LF/HF decay times. */
+ lfDecayTime = clampf(props->Reverb.DecayTime * props->Reverb.DecayLFRatio,
+ AL_EAXREVERB_MIN_DECAY_TIME, AL_EAXREVERB_MAX_DECAY_TIME);
+ hfDecayTime = clampf(props->Reverb.DecayTime * hfRatio,
+ AL_EAXREVERB_MIN_DECAY_TIME, AL_EAXREVERB_MAX_DECAY_TIME);
+
+ /* Update the late lines. */
+ UpdateLateLines(props->Reverb.Density, props->Reverb.Diffusion,
+ lfDecayTime, props->Reverb.DecayTime, hfDecayTime, lf0norm, hf0norm,
+ frequency, &State->Late
+ );
+
+ /* Update early and late 3D panning. */
+ gain = props->Reverb.Gain * Slot->Params.Gain * ReverbBoost;
+ Update3DPanning(Device, props->Reverb.ReflectionsPan, props->Reverb.LateReverbPan,
+ props->Reverb.ReflectionsGain*gain, props->Reverb.LateReverbGain*gain,
+ State);
+
+ /* Calculate the max update size from the smallest relevant delay. */
+ State->MaxUpdate[1] = mini(MAX_UPDATE_SAMPLES,
+ mini(State->Early.Offset[0][1], State->Late.Offset[0][1])
+ );
- /* Calculate the echo mixing coefficients. The first is applied to the
- * echo itself. The second is used to attenuate the late reverb when
- * echo depth is high and diffusion is low, so the echo is slightly
- * stronger than the decorrelated echos in the reverb tail.
+ /* Determine if delay-line cross-fading is required. Density is essentially
+ * a master control for the feedback delays, so changes the offsets of many
+ * delay lines.
*/
- State->Echo.MixCoeff = reverbGain * lateGain * echoDepth;
+ if(State->Params.Density != props->Reverb.Density ||
+ /* Diffusion and decay times influences the decay rate (gain) of the
+ * late reverb T60 filter.
+ */
+ State->Params.Diffusion != props->Reverb.Diffusion ||
+ State->Params.DecayTime != props->Reverb.DecayTime ||
+ State->Params.HFDecayTime != hfDecayTime ||
+ State->Params.LFDecayTime != lfDecayTime ||
+ /* HF/LF References control the weighting used to calculate the density
+ * gain.
+ */
+ State->Params.HFReference != props->Reverb.HFReference ||
+ State->Params.LFReference != props->Reverb.LFReference)
+ State->FadeCount = 0;
+ State->Params.Density = props->Reverb.Density;
+ State->Params.Diffusion = props->Reverb.Diffusion;
+ State->Params.DecayTime = props->Reverb.DecayTime;
+ State->Params.HFDecayTime = hfDecayTime;
+ State->Params.LFDecayTime = lfDecayTime;
+ State->Params.HFReference = props->Reverb.HFReference;
+ State->Params.LFReference = props->Reverb.LFReference;
}
-// Update the early and late 3D panning gains.
-static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *ReflectionsPan, const ALfloat *LateReverbPan, ALfloat Gain, ALreverbState *State)
+
+/**************************************
+ * Effect Processing *
+ **************************************/
+
+/* Basic delay line input/output routines. */
+static inline ALfloat DelayLineOut(const DelayLineI *Delay, const ALsizei offset, const ALsizei c)
{
- static const ALfloat EarlyPanAngles[4] = {
- DEG2RAD(0.0f), DEG2RAD(-90.0f), DEG2RAD(90.0f), DEG2RAD(180.0f)
- }, LatePanAngles[4] = {
- DEG2RAD(45.0f), DEG2RAD(-45.0f), DEG2RAD(135.0f), DEG2RAD(-135.0f)
- };
- ALfloat length, ev, az;
- ALuint i;
+ return Delay->Line[offset&Delay->Mask][c];
+}
+
+/* Cross-faded delay line output routine. Instead of interpolating the
+ * offsets, this interpolates (cross-fades) the outputs at each offset.
+ */
+static inline ALfloat FadedDelayLineOut(const DelayLineI *Delay, const ALsizei off0,
+ const ALsizei off1, const ALsizei c,
+ const ALfloat sc0, const ALfloat sc1)
+{
+ return Delay->Line[off0&Delay->Mask][c]*sc0 +
+ Delay->Line[off1&Delay->Mask][c]*sc1;
+}
+
+
+static inline void DelayLineIn(const DelayLineI *Delay, ALsizei offset, const ALsizei c,
+ const ALfloat *restrict in, ALsizei count)
+{
+ ALsizei i;
+ for(i = 0;i < count;i++)
+ Delay->Line[(offset++)&Delay->Mask][c] = *(in++);
+}
- length = sqrtf(ReflectionsPan[0]*ReflectionsPan[0] + ReflectionsPan[1]*ReflectionsPan[1] + ReflectionsPan[2]*ReflectionsPan[2]);
- if(!(length > FLT_EPSILON))
+/* Applies a scattering matrix to the 4-line (vector) input. This is used
+ * for both the below vector all-pass model and to perform modal feed-back
+ * delay network (FDN) mixing.
+ *
+ * The matrix is derived from a skew-symmetric matrix to form a 4D rotation
+ * matrix with a single unitary rotational parameter:
+ *
+ * [ d, a, b, c ] 1 = a^2 + b^2 + c^2 + d^2
+ * [ -a, d, c, -b ]
+ * [ -b, -c, d, a ]
+ * [ -c, b, -a, d ]
+ *
+ * The rotation is constructed from the effect's diffusion parameter,
+ * yielding:
+ *
+ * 1 = x^2 + 3 y^2
+ *
+ * Where a, b, and c are the coefficient y with differing signs, and d is the
+ * coefficient x. The final matrix is thus:
+ *
+ * [ x, y, -y, y ] n = sqrt(matrix_order - 1)
+ * [ -y, x, y, y ] t = diffusion_parameter * atan(n)
+ * [ y, -y, x, y ] x = cos(t)
+ * [ -y, -y, -y, x ] y = sin(t) / n
+ *
+ * Any square orthogonal matrix with an order that is a power of two will
+ * work (where ^T is transpose, ^-1 is inverse):
+ *
+ * M^T = M^-1
+ *
+ * Using that knowledge, finding an appropriate matrix can be accomplished
+ * naively by searching all combinations of:
+ *
+ * M = D + S - S^T
+ *
+ * Where D is a diagonal matrix (of x), and S is a triangular matrix (of y)
+ * whose combination of signs are being iterated.
+ */
+static inline void VectorPartialScatter(ALfloat *restrict out, const ALfloat *restrict in,
+ const ALfloat xCoeff, const ALfloat yCoeff)
+{
+ out[0] = xCoeff*in[0] + yCoeff*( in[1] + -in[2] + in[3]);
+ out[1] = xCoeff*in[1] + yCoeff*(-in[0] + in[2] + in[3]);
+ out[2] = xCoeff*in[2] + yCoeff*( in[0] + -in[1] + in[3]);
+ out[3] = xCoeff*in[3] + yCoeff*(-in[0] + -in[1] + -in[2] );
+}
+#define VectorScatterDelayIn(delay, o, in, xcoeff, ycoeff) \
+ VectorPartialScatter((delay)->Line[(o)&(delay)->Mask], in, xcoeff, ycoeff)
+
+/* Utilizes the above, but reverses the input channels. */
+static inline void VectorScatterRevDelayIn(const DelayLineI *Delay, ALint offset,
+ const ALfloat xCoeff, const ALfloat yCoeff,
+ const ALfloat (*restrict in)[MAX_UPDATE_SAMPLES],
+ const ALsizei count)
+{
+ const DelayLineI delay = *Delay;
+ ALsizei i, j;
+
+ for(i = 0;i < count;++i)
{
- for(i = 0;i < 4;i++)
- ComputeAngleGains(Device, EarlyPanAngles[i], 0.0f, Gain, State->Early.PanGain[i]);
+ ALfloat f[NUM_LINES];
+ for(j = 0;j < NUM_LINES;j++)
+ f[NUM_LINES-1-j] = in[j][i];
+
+ VectorScatterDelayIn(&delay, offset++, f, xCoeff, yCoeff);
}
- else
+}
+
+/* This applies a Gerzon multiple-in/multiple-out (MIMO) vector all-pass
+ * filter to the 4-line input.
+ *
+ * It works by vectorizing a regular all-pass filter and replacing the delay
+ * element with a scattering matrix (like the one above) and a diagonal
+ * matrix of delay elements.
+ *
+ * Two static specializations are used for transitional (cross-faded) delay
+ * line processing and non-transitional processing.
+ */
+static void VectorAllpass_Unfaded(ALfloat (*restrict samples)[MAX_UPDATE_SAMPLES], ALsizei offset,
+ const ALfloat xCoeff, const ALfloat yCoeff, ALsizei todo,
+ VecAllpass *Vap)
+{
+ const DelayLineI delay = Vap->Delay;
+ const ALfloat feedCoeff = Vap->Coeff;
+ ALsizei vap_offset[NUM_LINES];
+ ALsizei i, j;
+
+ ASSUME(todo > 0);
+
+ for(j = 0;j < NUM_LINES;j++)
+ vap_offset[j] = offset-Vap->Offset[j][0];
+ for(i = 0;i < todo;i++)
{
- ev = asinf(clampf(ReflectionsPan[1]/length, -1.0f, 1.0f));
- az = atan2f(ReflectionsPan[0], ReflectionsPan[2]);
+ ALfloat f[NUM_LINES];
- length = minf(length, 1.0f);
- for(i = 0;i < 4;i++)
+ for(j = 0;j < NUM_LINES;j++)
{
- /* This is essentially just a lerp, but takes the shortest path
- * with respect to circular wrapping. e.g.
- * -135 -> +/-180 -> +135
- * instead of
- * -135 -> 0 -> +135 */
- float offset, naz, nev;
- naz = EarlyPanAngles[i] + (modff((az-EarlyPanAngles[i])*length/F_TAU + 1.5f, &offset)-0.5f)*F_TAU;
- nev = (modff((ev )*length/F_TAU + 1.5f, &offset)-0.5f)*F_TAU;
- ComputeAngleGains(Device, naz, nev, Gain, State->Early.PanGain[i]);
+ ALfloat input = samples[j][i];
+ ALfloat out = DelayLineOut(&delay, vap_offset[j]++, j) - feedCoeff*input;
+ f[j] = input + feedCoeff*out;
+
+ samples[j][i] = out;
}
+
+ VectorScatterDelayIn(&delay, offset, f, xCoeff, yCoeff);
+ ++offset;
}
+}
+static void VectorAllpass_Faded(ALfloat (*restrict samples)[MAX_UPDATE_SAMPLES], ALsizei offset,
+ const ALfloat xCoeff, const ALfloat yCoeff, ALfloat fade,
+ ALsizei todo, VecAllpass *Vap)
+{
+ const DelayLineI delay = Vap->Delay;
+ const ALfloat feedCoeff = Vap->Coeff;
+ ALsizei vap_offset[NUM_LINES][2];
+ ALsizei i, j;
+
+ ASSUME(todo > 0);
- length = sqrtf(LateReverbPan[0]*LateReverbPan[0] + LateReverbPan[1]*LateReverbPan[1] + LateReverbPan[2]*LateReverbPan[2]);
- if(!(length > FLT_EPSILON))
+ fade *= 1.0f/FADE_SAMPLES;
+ for(j = 0;j < NUM_LINES;j++)
{
- for(i = 0;i < 4;i++)
- ComputeAngleGains(Device, LatePanAngles[i], 0.0f, Gain, State->Late.PanGain[i]);
+ vap_offset[j][0] = offset-Vap->Offset[j][0];
+ vap_offset[j][1] = offset-Vap->Offset[j][1];
}
- else
+ for(i = 0;i < todo;i++)
{
- ev = asinf(clampf(LateReverbPan[1]/length, -1.0f, 1.0f));
- az = atan2f(LateReverbPan[0], LateReverbPan[2]);
+ ALfloat f[NUM_LINES];
- length = minf(length, 1.0f);
- for(i = 0;i < 4;i++)
+ for(j = 0;j < NUM_LINES;j++)
{
- float offset, naz, nev;
- naz = LatePanAngles[i] + (modff((az-LatePanAngles[i])*length/F_TAU + 1.5f, &offset)-0.5f)*F_TAU;
- nev = (modff((ev )*length/F_TAU + 1.5f, &offset)-0.5f)*F_TAU;
- ComputeAngleGains(Device, naz, nev, Gain, State->Late.PanGain[i]);
+ ALfloat input = samples[j][i];
+ ALfloat out =
+ FadedDelayLineOut(&delay, vap_offset[j][0]++, vap_offset[j][1]++, j,
+ 1.0f-fade, fade
+ ) - feedCoeff*input;
+ f[j] = input + feedCoeff*out;
+
+ samples[j][i] = out;
}
+ fade += FadeStep;
+
+ VectorScatterDelayIn(&delay, offset, f, xCoeff, yCoeff);
+ ++offset;
}
}
-static ALvoid ALreverbState_update(ALreverbState *State, ALCdevice *Device, const ALeffectslot *Slot)
+/* This generates early reflections.
+ *
+ * This is done by obtaining the primary reflections (those arriving from the
+ * same direction as the source) from the main delay line. These are
+ * attenuated and all-pass filtered (based on the diffusion parameter).
+ *
+ * The early lines are then fed in reverse (according to the approximately
+ * opposite spatial location of the A-Format lines) to create the secondary
+ * reflections (those arriving from the opposite direction as the source).
+ *
+ * The early response is then completed by combining the primary reflections
+ * with the delayed and attenuated output from the early lines.
+ *
+ * Finally, the early response is reversed, scattered (based on diffusion),
+ * and fed into the late reverb section of the main delay line.
+ *
+ * Two static specializations are used for transitional (cross-faded) delay
+ * line processing and non-transitional processing.
+ */
+static void EarlyReflection_Unfaded(ReverbState *State, ALsizei offset, const ALsizei todo,
+ ALfloat (*restrict out)[MAX_UPDATE_SAMPLES])
{
- const ALeffectProps *props = &Slot->EffectProps;
- ALuint frequency = Device->Frequency;
- ALfloat lfscale, hfscale, hfRatio;
- ALfloat gainlf, gainhf;
- ALfloat cw, x, y;
-
- if(Slot->EffectType == AL_EFFECT_EAXREVERB && !EmulateEAXReverb)
- State->IsEax = AL_TRUE;
- else if(Slot->EffectType == AL_EFFECT_REVERB || EmulateEAXReverb)
- State->IsEax = AL_FALSE;
-
- // Calculate the master filters
- hfscale = props->Reverb.HFReference / frequency;
- gainhf = maxf(props->Reverb.GainHF, 0.0001f);
- ALfilterState_setParams(&State->LpFilter, ALfilterType_HighShelf,
- gainhf, hfscale, calc_rcpQ_from_slope(gainhf, 0.75f));
- lfscale = props->Reverb.LFReference / frequency;
- gainlf = maxf(props->Reverb.GainLF, 0.0001f);
- ALfilterState_setParams(&State->HpFilter, ALfilterType_LowShelf,
- gainlf, lfscale, calc_rcpQ_from_slope(gainlf, 0.75f));
-
- // Update the modulator line.
- UpdateModulator(props->Reverb.ModulationTime, props->Reverb.ModulationDepth,
- frequency, State);
-
- // Update the initial effect delay.
- UpdateDelayLine(props->Reverb.ReflectionsDelay, props->Reverb.LateReverbDelay,
- frequency, State);
+ ALfloat (*restrict temps)[MAX_UPDATE_SAMPLES] = State->TempSamples;
+ const DelayLineI early_delay = State->Early.Delay;
+ const DelayLineI main_delay = State->Delay;
+ const ALfloat mixX = State->MixX;
+ const ALfloat mixY = State->MixY;
+ ALsizei late_feed_tap;
+ ALsizei i, j;
+
+ ASSUME(todo > 0);
+
+ /* First, load decorrelated samples from the main delay line as the primary
+ * reflections.
+ */
+ for(j = 0;j < NUM_LINES;j++)
+ {
+ ALsizei early_delay_tap = offset - State->EarlyDelayTap[j][0];
+ ALfloat coeff = State->EarlyDelayCoeff[j][0];
+ for(i = 0;i < todo;i++)
+ temps[j][i] = DelayLineOut(&main_delay, early_delay_tap++, j) * coeff;
+ }
- // Update the early lines.
- UpdateEarlyLines(props->Reverb.Gain, props->Reverb.ReflectionsGain,
- props->Reverb.LateReverbDelay, State);
+ /* Apply a vector all-pass, to help color the initial reflections based on
+ * the diffusion strength.
+ */
+ VectorAllpass_Unfaded(temps, offset, mixX, mixY, todo, &State->Early.VecAp);
- // Update the decorrelator.
- UpdateDecorrelator(props->Reverb.Density, frequency, State);
+ /* Apply a delay and bounce to generate secondary reflections, combine with
+ * the primary reflections and write out the result for mixing.
+ */
+ for(j = 0;j < NUM_LINES;j++)
+ {
+ ALint early_feedb_tap = offset - State->Early.Offset[j][0];
+ ALfloat early_feedb_coeff = State->Early.Coeff[j][0];
- // Get the mixing matrix coefficients (x and y).
- CalcMatrixCoeffs(props->Reverb.Diffusion, &x, &y);
- // Then divide x into y to simplify the matrix calculation.
- State->Late.MixCoeff = y / x;
+ for(i = 0;i < todo;i++)
+ out[j][i] = DelayLineOut(&early_delay, early_feedb_tap++, j)*early_feedb_coeff +
+ temps[j][i];
+ }
+ for(j = 0;j < NUM_LINES;j++)
+ DelayLineIn(&early_delay, offset, NUM_LINES-1-j, temps[j], todo);
- // If the HF limit parameter is flagged, calculate an appropriate limit
- // based on the air absorption parameter.
- hfRatio = props->Reverb.DecayHFRatio;
- if(props->Reverb.DecayHFLimit && props->Reverb.AirAbsorptionGainHF < 1.0f)
- hfRatio = CalcLimitedHfRatio(hfRatio, props->Reverb.AirAbsorptionGainHF,
- props->Reverb.DecayTime);
-
- cw = cosf(F_TAU * hfscale);
- // Update the late lines.
- UpdateLateLines(props->Reverb.Gain, props->Reverb.LateReverbGain, x,
- props->Reverb.Density, props->Reverb.DecayTime,
- props->Reverb.Diffusion, props->Reverb.EchoDepth,
- hfRatio, cw, frequency, State);
-
- // Update the echo line.
- UpdateEchoLine(props->Reverb.Gain, props->Reverb.LateReverbGain,
- props->Reverb.EchoTime, props->Reverb.DecayTime,
- props->Reverb.Diffusion, props->Reverb.EchoDepth,
- hfRatio, cw, frequency, State);
-
- // Update early and late 3D panning.
- Update3DPanning(Device, props->Reverb.ReflectionsPan,
- props->Reverb.LateReverbPan,
- Slot->Gain * ReverbBoost, State);
+ /* Also write the result back to the main delay line for the late reverb
+ * stage to pick up at the appropriate time, appplying a scatter and
+ * bounce to improve the initial diffusion in the late reverb.
+ */
+ late_feed_tap = offset - State->LateFeedTap;
+ VectorScatterRevDelayIn(&main_delay, late_feed_tap, mixX, mixY, out, todo);
}
+static void EarlyReflection_Faded(ReverbState *State, ALsizei offset, const ALsizei todo,
+ const ALfloat fade, ALfloat (*restrict out)[MAX_UPDATE_SAMPLES])
+{
+ ALfloat (*restrict temps)[MAX_UPDATE_SAMPLES] = State->TempSamples;
+ const DelayLineI early_delay = State->Early.Delay;
+ const DelayLineI main_delay = State->Delay;
+ const ALfloat mixX = State->MixX;
+ const ALfloat mixY = State->MixY;
+ ALsizei late_feed_tap;
+ ALsizei i, j;
+ ASSUME(todo > 0);
-static ALvoid ALreverbState_Destruct(ALreverbState *State)
-{
- free(State->SampleBuffer);
- State->SampleBuffer = NULL;
-}
+ for(j = 0;j < NUM_LINES;j++)
+ {
+ ALsizei early_delay_tap0 = offset - State->EarlyDelayTap[j][0];
+ ALsizei early_delay_tap1 = offset - State->EarlyDelayTap[j][1];
+ ALfloat oldCoeff = State->EarlyDelayCoeff[j][0];
+ ALfloat oldCoeffStep = -oldCoeff / FADE_SAMPLES;
+ ALfloat newCoeffStep = State->EarlyDelayCoeff[j][1] / FADE_SAMPLES;
+ ALfloat fadeCount = fade;
+
+ for(i = 0;i < todo;i++)
+ {
+ const ALfloat fade0 = oldCoeff + oldCoeffStep*fadeCount;
+ const ALfloat fade1 = newCoeffStep*fadeCount;
+ temps[j][i] = FadedDelayLineOut(&main_delay,
+ early_delay_tap0++, early_delay_tap1++, j, fade0, fade1
+ );
+ fadeCount += 1.0f;
+ }
+ }
-DECLARE_DEFAULT_ALLOCATORS(ALreverbState)
+ VectorAllpass_Faded(temps, offset, mixX, mixY, fade, todo, &State->Early.VecAp);
-DEFINE_ALEFFECTSTATE_VTABLE(ALreverbState);
+ for(j = 0;j < NUM_LINES;j++)
+ {
+ ALint feedb_tap0 = offset - State->Early.Offset[j][0];
+ ALint feedb_tap1 = offset - State->Early.Offset[j][1];
+ ALfloat feedb_oldCoeff = State->Early.Coeff[j][0];
+ ALfloat feedb_oldCoeffStep = -feedb_oldCoeff / FADE_SAMPLES;
+ ALfloat feedb_newCoeffStep = State->Early.Coeff[j][1] / FADE_SAMPLES;
+ ALfloat fadeCount = fade;
+
+ for(i = 0;i < todo;i++)
+ {
+ const ALfloat fade0 = feedb_oldCoeff + feedb_oldCoeffStep*fadeCount;
+ const ALfloat fade1 = feedb_newCoeffStep*fadeCount;
+ out[j][i] = FadedDelayLineOut(&early_delay,
+ feedb_tap0++, feedb_tap1++, j, fade0, fade1
+ ) + temps[j][i];
+ fadeCount += 1.0f;
+ }
+ }
+ for(j = 0;j < NUM_LINES;j++)
+ DelayLineIn(&early_delay, offset, NUM_LINES-1-j, temps[j], todo);
+ late_feed_tap = offset - State->LateFeedTap;
+ VectorScatterRevDelayIn(&main_delay, late_feed_tap, mixX, mixY, out, todo);
+}
-typedef struct ALreverbStateFactory {
- DERIVE_FROM_TYPE(ALeffectStateFactory);
-} ALreverbStateFactory;
+/* Applies the two T60 damping filter sections. */
+static inline void LateT60Filter(ALfloat *restrict samples, const ALsizei todo, T60Filter *filter)
+{
+ ALfloat temp[MAX_UPDATE_SAMPLES];
+ BiquadFilter_process(&filter->HFFilter, temp, samples, todo);
+ BiquadFilter_process(&filter->LFFilter, samples, temp, todo);
+}
-static ALeffectState *ALreverbStateFactory_create(ALreverbStateFactory* UNUSED(factory))
+/* This generates the reverb tail using a modified feed-back delay network
+ * (FDN).
+ *
+ * Results from the early reflections are mixed with the output from the late
+ * delay lines.
+ *
+ * The late response is then completed by T60 and all-pass filtering the mix.
+ *
+ * Finally, the lines are reversed (so they feed their opposite directions)
+ * and scattered with the FDN matrix before re-feeding the delay lines.
+ *
+ * Two variations are made, one for for transitional (cross-faded) delay line
+ * processing and one for non-transitional processing.
+ */
+static void LateReverb_Unfaded(ReverbState *State, ALsizei offset, const ALsizei todo,
+ ALfloat (*restrict out)[MAX_UPDATE_SAMPLES])
{
- ALreverbState *state;
- ALuint index, l;
+ ALfloat (*restrict temps)[MAX_UPDATE_SAMPLES] = State->TempSamples;
+ const DelayLineI late_delay = State->Late.Delay;
+ const DelayLineI main_delay = State->Delay;
+ const ALfloat mixX = State->MixX;
+ const ALfloat mixY = State->MixY;
+ ALsizei i, j;
- state = ALreverbState_New(sizeof(*state));
- if(!state) return NULL;
- SET_VTABLE2(ALreverbState, ALeffectState, state);
+ ASSUME(todo > 0);
- state->TotalSamples = 0;
- state->SampleBuffer = NULL;
+ /* First, load decorrelated samples from the main and feedback delay lines.
+ * Filter the signal to apply its frequency-dependent decay.
+ */
+ for(j = 0;j < NUM_LINES;j++)
+ {
+ ALsizei late_delay_tap = offset - State->LateDelayTap[j][0];
+ ALsizei late_feedb_tap = offset - State->Late.Offset[j][0];
+ ALfloat midGain = State->Late.T60[j].MidGain[0];
+ const ALfloat densityGain = State->Late.DensityGain[0] * midGain;
+ for(i = 0;i < todo;i++)
+ temps[j][i] = DelayLineOut(&main_delay, late_delay_tap++, j)*densityGain +
+ DelayLineOut(&late_delay, late_feedb_tap++, j)*midGain;
+ LateT60Filter(temps[j], todo, &State->Late.T60[j]);
+ }
- ALfilterState_clear(&state->LpFilter);
- ALfilterState_clear(&state->HpFilter);
+ /* Apply a vector all-pass to improve micro-surface diffusion, and write
+ * out the results for mixing.
+ */
+ VectorAllpass_Unfaded(temps, offset, mixX, mixY, todo, &State->Late.VecAp);
- state->Mod.Delay.Mask = 0;
- state->Mod.Delay.Line = NULL;
- state->Mod.Index = 0;
- state->Mod.Range = 1;
- state->Mod.Depth = 0.0f;
- state->Mod.Coeff = 0.0f;
- state->Mod.Filter = 0.0f;
+ for(j = 0;j < NUM_LINES;j++)
+ memcpy(out[j], temps[j], todo*sizeof(ALfloat));
- state->Delay.Mask = 0;
- state->Delay.Line = NULL;
- state->DelayTap[0] = 0;
- state->DelayTap[1] = 0;
+ /* Finally, scatter and bounce the results to refeed the feedback buffer. */
+ VectorScatterRevDelayIn(&late_delay, offset, mixX, mixY, out, todo);
+}
+static void LateReverb_Faded(ReverbState *State, ALsizei offset, const ALsizei todo,
+ const ALfloat fade, ALfloat (*restrict out)[MAX_UPDATE_SAMPLES])
+{
+ ALfloat (*restrict temps)[MAX_UPDATE_SAMPLES] = State->TempSamples;
+ const DelayLineI late_delay = State->Late.Delay;
+ const DelayLineI main_delay = State->Delay;
+ const ALfloat mixX = State->MixX;
+ const ALfloat mixY = State->MixY;
+ ALsizei i, j;
- state->Early.Gain = 0.0f;
- for(index = 0;index < 4;index++)
- {
- state->Early.Coeff[index] = 0.0f;
- state->Early.Delay[index].Mask = 0;
- state->Early.Delay[index].Line = NULL;
- state->Early.Offset[index] = 0;
- }
+ ASSUME(todo > 0);
- state->Decorrelator.Mask = 0;
- state->Decorrelator.Line = NULL;
- state->DecoTap[0] = 0;
- state->DecoTap[1] = 0;
- state->DecoTap[2] = 0;
-
- state->Late.Gain = 0.0f;
- state->Late.DensityGain = 0.0f;
- state->Late.ApFeedCoeff = 0.0f;
- state->Late.MixCoeff = 0.0f;
- for(index = 0;index < 4;index++)
+ for(j = 0;j < NUM_LINES;j++)
{
- state->Late.ApCoeff[index] = 0.0f;
- state->Late.ApDelay[index].Mask = 0;
- state->Late.ApDelay[index].Line = NULL;
- state->Late.ApOffset[index] = 0;
-
- state->Late.Coeff[index] = 0.0f;
- state->Late.Delay[index].Mask = 0;
- state->Late.Delay[index].Line = NULL;
- state->Late.Offset[index] = 0;
-
- state->Late.LpCoeff[index] = 0.0f;
- state->Late.LpSample[index] = 0.0f;
+ const ALfloat oldMidGain = State->Late.T60[j].MidGain[0];
+ const ALfloat midGain = State->Late.T60[j].MidGain[1];
+ const ALfloat oldMidStep = -oldMidGain / FADE_SAMPLES;
+ const ALfloat midStep = midGain / FADE_SAMPLES;
+ const ALfloat oldDensityGain = State->Late.DensityGain[0] * oldMidGain;
+ const ALfloat densityGain = State->Late.DensityGain[1] * midGain;
+ const ALfloat oldDensityStep = -oldDensityGain / FADE_SAMPLES;
+ const ALfloat densityStep = densityGain / FADE_SAMPLES;
+ ALsizei late_delay_tap0 = offset - State->LateDelayTap[j][0];
+ ALsizei late_delay_tap1 = offset - State->LateDelayTap[j][1];
+ ALsizei late_feedb_tap0 = offset - State->Late.Offset[j][0];
+ ALsizei late_feedb_tap1 = offset - State->Late.Offset[j][1];
+ ALfloat fadeCount = fade;
+
+ for(i = 0;i < todo;i++)
+ {
+ const ALfloat fade0 = oldDensityGain + oldDensityStep*fadeCount;
+ const ALfloat fade1 = densityStep*fadeCount;
+ const ALfloat gfade0 = oldMidGain + oldMidStep*fadeCount;
+ const ALfloat gfade1 = midStep*fadeCount;
+ temps[j][i] =
+ FadedDelayLineOut(&main_delay, late_delay_tap0++, late_delay_tap1++, j,
+ fade0, fade1) +
+ FadedDelayLineOut(&late_delay, late_feedb_tap0++, late_feedb_tap1++, j,
+ gfade0, gfade1);
+ fadeCount += 1.0f;
+ }
+ LateT60Filter(temps[j], todo, &State->Late.T60[j]);
}
- for(l = 0;l < 4;l++)
+ VectorAllpass_Faded(temps, offset, mixX, mixY, fade, todo, &State->Late.VecAp);
+
+ for(j = 0;j < NUM_LINES;j++)
+ memcpy(out[j], temps[j], todo*sizeof(ALfloat));
+
+ VectorScatterRevDelayIn(&late_delay, offset, mixX, mixY, temps, todo);
+}
+
+static ALvoid ReverbState_process(ReverbState *State, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels)
+{
+ ALfloat (*restrict afmt)[MAX_UPDATE_SAMPLES] = State->TempSamples;
+ ALfloat (*restrict samples)[MAX_UPDATE_SAMPLES] = State->MixSamples;
+ ALsizei fadeCount = State->FadeCount;
+ ALsizei offset = State->Offset;
+ ALsizei base, c;
+
+ /* Process reverb for these samples. */
+ for(base = 0;base < SamplesToDo;)
{
- for(index = 0;index < MAX_OUTPUT_CHANNELS;index++)
+ ALsizei todo = SamplesToDo - base;
+ /* If cross-fading, don't do more samples than there are to fade. */
+ if(FADE_SAMPLES-fadeCount > 0)
{
- state->Early.PanGain[l][index] = 0.0f;
- state->Late.PanGain[l][index] = 0.0f;
+ todo = mini(todo, FADE_SAMPLES-fadeCount);
+ todo = mini(todo, State->MaxUpdate[0]);
}
+ todo = mini(todo, State->MaxUpdate[1]);
+ /* If this is not the final update, ensure the update size is a
+ * multiple of 4 for the SIMD mixers.
+ */
+ if(todo < SamplesToDo-base)
+ todo &= ~3;
+
+ /* Convert B-Format to A-Format for processing. */
+ memset(afmt, 0, sizeof(*afmt)*NUM_LINES);
+ for(c = 0;c < NUM_LINES;c++)
+ MixRowSamples(afmt[c], B2A.m[c],
+ SamplesIn, MAX_EFFECT_CHANNELS, base, todo
+ );
+
+ /* Process the samples for reverb. */
+ for(c = 0;c < NUM_LINES;c++)
+ {
+ /* Band-pass the incoming samples. */
+ BiquadFilter_process(&State->Filter[c].Lp, samples[0], afmt[c], todo);
+ BiquadFilter_process(&State->Filter[c].Hp, samples[1], samples[0], todo);
+
+ /* Feed the initial delay line. */
+ DelayLineIn(&State->Delay, offset, c, samples[1], todo);
+ }
+
+ if(UNLIKELY(fadeCount < FADE_SAMPLES))
+ {
+ ALfloat fade = (ALfloat)fadeCount;
+
+ /* Generate early reflections. */
+ EarlyReflection_Faded(State, offset, todo, fade, samples);
+ /* Mix the A-Format results to output, implicitly converting back
+ * to B-Format.
+ */
+ for(c = 0;c < NUM_LINES;c++)
+ MixSamples(samples[c], NumChannels, SamplesOut,
+ State->Early.CurrentGain[c], State->Early.PanGain[c],
+ SamplesToDo-base, base, todo
+ );
+
+ /* Generate and mix late reverb. */
+ LateReverb_Faded(State, offset, todo, fade, samples);
+ for(c = 0;c < NUM_LINES;c++)
+ MixSamples(samples[c], NumChannels, SamplesOut,
+ State->Late.CurrentGain[c], State->Late.PanGain[c],
+ SamplesToDo-base, base, todo
+ );
+
+ /* Step fading forward. */
+ fadeCount += todo;
+ if(LIKELY(fadeCount >= FADE_SAMPLES))
+ {
+ /* Update the cross-fading delay line taps. */
+ fadeCount = FADE_SAMPLES;
+ for(c = 0;c < NUM_LINES;c++)
+ {
+ State->EarlyDelayTap[c][0] = State->EarlyDelayTap[c][1];
+ State->EarlyDelayCoeff[c][0] = State->EarlyDelayCoeff[c][1];
+ State->Early.VecAp.Offset[c][0] = State->Early.VecAp.Offset[c][1];
+ State->Early.Offset[c][0] = State->Early.Offset[c][1];
+ State->Early.Coeff[c][0] = State->Early.Coeff[c][1];
+ State->LateDelayTap[c][0] = State->LateDelayTap[c][1];
+ State->Late.VecAp.Offset[c][0] = State->Late.VecAp.Offset[c][1];
+ State->Late.Offset[c][0] = State->Late.Offset[c][1];
+ State->Late.T60[c].MidGain[0] = State->Late.T60[c].MidGain[1];
+ }
+ State->Late.DensityGain[0] = State->Late.DensityGain[1];
+ State->MaxUpdate[0] = State->MaxUpdate[1];
+ }
+ }
+ else
+ {
+ /* Generate and mix early reflections. */
+ EarlyReflection_Unfaded(State, offset, todo, samples);
+ for(c = 0;c < NUM_LINES;c++)
+ MixSamples(samples[c], NumChannels, SamplesOut,
+ State->Early.CurrentGain[c], State->Early.PanGain[c],
+ SamplesToDo-base, base, todo
+ );
+
+ /* Generate and mix late reverb. */
+ LateReverb_Unfaded(State, offset, todo, samples);
+ for(c = 0;c < NUM_LINES;c++)
+ MixSamples(samples[c], NumChannels, SamplesOut,
+ State->Late.CurrentGain[c], State->Late.PanGain[c],
+ SamplesToDo-base, base, todo
+ );
+ }
+
+ /* Step all delays forward. */
+ offset += todo;
+
+ base += todo;
}
+ State->Offset = offset;
+ State->FadeCount = fadeCount;
+}
- state->Echo.DensityGain = 0.0f;
- state->Echo.Delay.Mask = 0;
- state->Echo.Delay.Line = NULL;
- state->Echo.ApDelay.Mask = 0;
- state->Echo.ApDelay.Line = NULL;
- state->Echo.Coeff = 0.0f;
- state->Echo.ApFeedCoeff = 0.0f;
- state->Echo.ApCoeff = 0.0f;
- state->Echo.Offset = 0;
- state->Echo.ApOffset = 0;
- state->Echo.LpCoeff = 0.0f;
- state->Echo.LpSample = 0.0f;
- state->Echo.MixCoeff = 0.0f;
- state->Offset = 0;
+typedef struct ReverbStateFactory {
+ DERIVE_FROM_TYPE(EffectStateFactory);
+} ReverbStateFactory;
- state->Gain = state->Late.PanGain;
+static ALeffectState *ReverbStateFactory_create(ReverbStateFactory* UNUSED(factory))
+{
+ ReverbState *state;
+
+ NEW_OBJ0(state, ReverbState)();
+ if(!state) return NULL;
return STATIC_CAST(ALeffectState, state);
}
-DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALreverbStateFactory);
+DEFINE_EFFECTSTATEFACTORY_VTABLE(ReverbStateFactory);
-ALeffectStateFactory *ALreverbStateFactory_getFactory(void)
+EffectStateFactory *ReverbStateFactory_getFactory(void)
{
- static ALreverbStateFactory ReverbFactory = { { GET_VTABLE2(ALreverbStateFactory, ALeffectStateFactory) } };
+ static ReverbStateFactory ReverbFactory = { { GET_VTABLE2(ReverbStateFactory, EffectStateFactory) } };
- return STATIC_CAST(ALeffectStateFactory, &ReverbFactory);
+ return STATIC_CAST(EffectStateFactory, &ReverbFactory);
}
@@ -1311,18 +1614,17 @@ void ALeaxreverb_setParami(ALeffect *effect, ALCcontext *context, ALenum param,
{
case AL_EAXREVERB_DECAY_HFLIMIT:
if(!(val >= AL_EAXREVERB_MIN_DECAY_HFLIMIT && val <= AL_EAXREVERB_MAX_DECAY_HFLIMIT))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb decay hflimit out of range");
props->Reverb.DecayHFLimit = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid EAX reverb integer property 0x%04x",
+ param);
}
}
void ALeaxreverb_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
-{
- ALeaxreverb_setParami(effect, context, param, vals[0]);
-}
+{ ALeaxreverb_setParami(effect, context, param, vals[0]); }
void ALeaxreverb_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val)
{
ALeffectProps *props = &effect->Props;
@@ -1330,126 +1632,127 @@ void ALeaxreverb_setParamf(ALeffect *effect, ALCcontext *context, ALenum param,
{
case AL_EAXREVERB_DENSITY:
if(!(val >= AL_EAXREVERB_MIN_DENSITY && val <= AL_EAXREVERB_MAX_DENSITY))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb density out of range");
props->Reverb.Density = val;
break;
case AL_EAXREVERB_DIFFUSION:
if(!(val >= AL_EAXREVERB_MIN_DIFFUSION && val <= AL_EAXREVERB_MAX_DIFFUSION))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb diffusion out of range");
props->Reverb.Diffusion = val;
break;
case AL_EAXREVERB_GAIN:
if(!(val >= AL_EAXREVERB_MIN_GAIN && val <= AL_EAXREVERB_MAX_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb gain out of range");
props->Reverb.Gain = val;
break;
case AL_EAXREVERB_GAINHF:
if(!(val >= AL_EAXREVERB_MIN_GAINHF && val <= AL_EAXREVERB_MAX_GAINHF))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb gainhf out of range");
props->Reverb.GainHF = val;
break;
case AL_EAXREVERB_GAINLF:
if(!(val >= AL_EAXREVERB_MIN_GAINLF && val <= AL_EAXREVERB_MAX_GAINLF))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb gainlf out of range");
props->Reverb.GainLF = val;
break;
case AL_EAXREVERB_DECAY_TIME:
if(!(val >= AL_EAXREVERB_MIN_DECAY_TIME && val <= AL_EAXREVERB_MAX_DECAY_TIME))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb decay time out of range");
props->Reverb.DecayTime = val;
break;
case AL_EAXREVERB_DECAY_HFRATIO:
if(!(val >= AL_EAXREVERB_MIN_DECAY_HFRATIO && val <= AL_EAXREVERB_MAX_DECAY_HFRATIO))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb decay hfratio out of range");
props->Reverb.DecayHFRatio = val;
break;
case AL_EAXREVERB_DECAY_LFRATIO:
if(!(val >= AL_EAXREVERB_MIN_DECAY_LFRATIO && val <= AL_EAXREVERB_MAX_DECAY_LFRATIO))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb decay lfratio out of range");
props->Reverb.DecayLFRatio = val;
break;
case AL_EAXREVERB_REFLECTIONS_GAIN:
if(!(val >= AL_EAXREVERB_MIN_REFLECTIONS_GAIN && val <= AL_EAXREVERB_MAX_REFLECTIONS_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb reflections gain out of range");
props->Reverb.ReflectionsGain = val;
break;
case AL_EAXREVERB_REFLECTIONS_DELAY:
if(!(val >= AL_EAXREVERB_MIN_REFLECTIONS_DELAY && val <= AL_EAXREVERB_MAX_REFLECTIONS_DELAY))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb reflections delay out of range");
props->Reverb.ReflectionsDelay = val;
break;
case AL_EAXREVERB_LATE_REVERB_GAIN:
if(!(val >= AL_EAXREVERB_MIN_LATE_REVERB_GAIN && val <= AL_EAXREVERB_MAX_LATE_REVERB_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb late reverb gain out of range");
props->Reverb.LateReverbGain = val;
break;
case AL_EAXREVERB_LATE_REVERB_DELAY:
if(!(val >= AL_EAXREVERB_MIN_LATE_REVERB_DELAY && val <= AL_EAXREVERB_MAX_LATE_REVERB_DELAY))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb late reverb delay out of range");
props->Reverb.LateReverbDelay = val;
break;
case AL_EAXREVERB_AIR_ABSORPTION_GAINHF:
if(!(val >= AL_EAXREVERB_MIN_AIR_ABSORPTION_GAINHF && val <= AL_EAXREVERB_MAX_AIR_ABSORPTION_GAINHF))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb air absorption gainhf out of range");
props->Reverb.AirAbsorptionGainHF = val;
break;
case AL_EAXREVERB_ECHO_TIME:
if(!(val >= AL_EAXREVERB_MIN_ECHO_TIME && val <= AL_EAXREVERB_MAX_ECHO_TIME))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb echo time out of range");
props->Reverb.EchoTime = val;
break;
case AL_EAXREVERB_ECHO_DEPTH:
if(!(val >= AL_EAXREVERB_MIN_ECHO_DEPTH && val <= AL_EAXREVERB_MAX_ECHO_DEPTH))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb echo depth out of range");
props->Reverb.EchoDepth = val;
break;
case AL_EAXREVERB_MODULATION_TIME:
if(!(val >= AL_EAXREVERB_MIN_MODULATION_TIME && val <= AL_EAXREVERB_MAX_MODULATION_TIME))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb modulation time out of range");
props->Reverb.ModulationTime = val;
break;
case AL_EAXREVERB_MODULATION_DEPTH:
if(!(val >= AL_EAXREVERB_MIN_MODULATION_DEPTH && val <= AL_EAXREVERB_MAX_MODULATION_DEPTH))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb modulation depth out of range");
props->Reverb.ModulationDepth = val;
break;
case AL_EAXREVERB_HFREFERENCE:
if(!(val >= AL_EAXREVERB_MIN_HFREFERENCE && val <= AL_EAXREVERB_MAX_HFREFERENCE))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb hfreference out of range");
props->Reverb.HFReference = val;
break;
case AL_EAXREVERB_LFREFERENCE:
if(!(val >= AL_EAXREVERB_MIN_LFREFERENCE && val <= AL_EAXREVERB_MAX_LFREFERENCE))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb lfreference out of range");
props->Reverb.LFReference = val;
break;
case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR:
if(!(val >= AL_EAXREVERB_MIN_ROOM_ROLLOFF_FACTOR && val <= AL_EAXREVERB_MAX_ROOM_ROLLOFF_FACTOR))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb room rolloff factor out of range");
props->Reverb.RoomRolloffFactor = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid EAX reverb float property 0x%04x",
+ param);
}
}
void ALeaxreverb_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
@@ -1459,21 +1762,17 @@ void ALeaxreverb_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param,
{
case AL_EAXREVERB_REFLECTIONS_PAN:
if(!(isfinite(vals[0]) && isfinite(vals[1]) && isfinite(vals[2])))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
- LockContext(context);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb reflections pan out of range");
props->Reverb.ReflectionsPan[0] = vals[0];
props->Reverb.ReflectionsPan[1] = vals[1];
props->Reverb.ReflectionsPan[2] = vals[2];
- UnlockContext(context);
break;
case AL_EAXREVERB_LATE_REVERB_PAN:
if(!(isfinite(vals[0]) && isfinite(vals[1]) && isfinite(vals[2])))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
- LockContext(context);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "EAX Reverb late reverb pan out of range");
props->Reverb.LateReverbPan[0] = vals[0];
props->Reverb.LateReverbPan[1] = vals[1];
props->Reverb.LateReverbPan[2] = vals[2];
- UnlockContext(context);
break;
default:
@@ -1492,13 +1791,12 @@ void ALeaxreverb_getParami(const ALeffect *effect, ALCcontext *context, ALenum p
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid EAX reverb integer property 0x%04x",
+ param);
}
}
void ALeaxreverb_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
-{
- ALeaxreverb_getParami(effect, context, param, vals);
-}
+{ ALeaxreverb_getParami(effect, context, param, vals); }
void ALeaxreverb_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
{
const ALeffectProps *props = &effect->Props;
@@ -1585,7 +1883,8 @@ void ALeaxreverb_getParamf(const ALeffect *effect, ALCcontext *context, ALenum p
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid EAX reverb float property 0x%04x",
+ param);
}
}
void ALeaxreverb_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
@@ -1594,18 +1893,14 @@ void ALeaxreverb_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum
switch(param)
{
case AL_EAXREVERB_REFLECTIONS_PAN:
- LockContext(context);
vals[0] = props->Reverb.ReflectionsPan[0];
vals[1] = props->Reverb.ReflectionsPan[1];
vals[2] = props->Reverb.ReflectionsPan[2];
- UnlockContext(context);
break;
case AL_EAXREVERB_LATE_REVERB_PAN:
- LockContext(context);
vals[0] = props->Reverb.LateReverbPan[0];
vals[1] = props->Reverb.LateReverbPan[1];
vals[2] = props->Reverb.LateReverbPan[2];
- UnlockContext(context);
break;
default:
@@ -1623,18 +1918,16 @@ void ALreverb_setParami(ALeffect *effect, ALCcontext *context, ALenum param, ALi
{
case AL_REVERB_DECAY_HFLIMIT:
if(!(val >= AL_REVERB_MIN_DECAY_HFLIMIT && val <= AL_REVERB_MAX_DECAY_HFLIMIT))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Reverb decay hflimit out of range");
props->Reverb.DecayHFLimit = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid reverb integer property 0x%04x", param);
}
}
void ALreverb_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
-{
- ALreverb_setParami(effect, context, param, vals[0]);
-}
+{ ALreverb_setParami(effect, context, param, vals[0]); }
void ALreverb_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val)
{
ALeffectProps *props = &effect->Props;
@@ -1642,84 +1935,82 @@ void ALreverb_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALf
{
case AL_REVERB_DENSITY:
if(!(val >= AL_REVERB_MIN_DENSITY && val <= AL_REVERB_MAX_DENSITY))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Reverb density out of range");
props->Reverb.Density = val;
break;
case AL_REVERB_DIFFUSION:
if(!(val >= AL_REVERB_MIN_DIFFUSION && val <= AL_REVERB_MAX_DIFFUSION))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Reverb diffusion out of range");
props->Reverb.Diffusion = val;
break;
case AL_REVERB_GAIN:
if(!(val >= AL_REVERB_MIN_GAIN && val <= AL_REVERB_MAX_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Reverb gain out of range");
props->Reverb.Gain = val;
break;
case AL_REVERB_GAINHF:
if(!(val >= AL_REVERB_MIN_GAINHF && val <= AL_REVERB_MAX_GAINHF))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Reverb gainhf out of range");
props->Reverb.GainHF = val;
break;
case AL_REVERB_DECAY_TIME:
if(!(val >= AL_REVERB_MIN_DECAY_TIME && val <= AL_REVERB_MAX_DECAY_TIME))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Reverb decay time out of range");
props->Reverb.DecayTime = val;
break;
case AL_REVERB_DECAY_HFRATIO:
if(!(val >= AL_REVERB_MIN_DECAY_HFRATIO && val <= AL_REVERB_MAX_DECAY_HFRATIO))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Reverb decay hfratio out of range");
props->Reverb.DecayHFRatio = val;
break;
case AL_REVERB_REFLECTIONS_GAIN:
if(!(val >= AL_REVERB_MIN_REFLECTIONS_GAIN && val <= AL_REVERB_MAX_REFLECTIONS_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Reverb reflections gain out of range");
props->Reverb.ReflectionsGain = val;
break;
case AL_REVERB_REFLECTIONS_DELAY:
if(!(val >= AL_REVERB_MIN_REFLECTIONS_DELAY && val <= AL_REVERB_MAX_REFLECTIONS_DELAY))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Reverb reflections delay out of range");
props->Reverb.ReflectionsDelay = val;
break;
case AL_REVERB_LATE_REVERB_GAIN:
if(!(val >= AL_REVERB_MIN_LATE_REVERB_GAIN && val <= AL_REVERB_MAX_LATE_REVERB_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Reverb late reverb gain out of range");
props->Reverb.LateReverbGain = val;
break;
case AL_REVERB_LATE_REVERB_DELAY:
if(!(val >= AL_REVERB_MIN_LATE_REVERB_DELAY && val <= AL_REVERB_MAX_LATE_REVERB_DELAY))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Reverb late reverb delay out of range");
props->Reverb.LateReverbDelay = val;
break;
case AL_REVERB_AIR_ABSORPTION_GAINHF:
if(!(val >= AL_REVERB_MIN_AIR_ABSORPTION_GAINHF && val <= AL_REVERB_MAX_AIR_ABSORPTION_GAINHF))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Reverb air absorption gainhf out of range");
props->Reverb.AirAbsorptionGainHF = val;
break;
case AL_REVERB_ROOM_ROLLOFF_FACTOR:
if(!(val >= AL_REVERB_MIN_ROOM_ROLLOFF_FACTOR && val <= AL_REVERB_MAX_ROOM_ROLLOFF_FACTOR))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Reverb room rolloff factor out of range");
props->Reverb.RoomRolloffFactor = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid reverb float property 0x%04x", param);
}
}
void ALreverb_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
-{
- ALreverb_setParamf(effect, context, param, vals[0]);
-}
+{ ALreverb_setParamf(effect, context, param, vals[0]); }
void ALreverb_getParami(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *val)
{
@@ -1731,13 +2022,11 @@ void ALreverb_getParami(const ALeffect *effect, ALCcontext *context, ALenum para
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid reverb integer property 0x%04x", param);
}
}
void ALreverb_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
-{
- ALreverb_getParami(effect, context, param, vals);
-}
+{ ALreverb_getParami(effect, context, param, vals); }
void ALreverb_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
{
const ALeffectProps *props = &effect->Props;
@@ -1792,12 +2081,10 @@ void ALreverb_getParamf(const ALeffect *effect, ALCcontext *context, ALenum para
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid reverb float property 0x%04x", param);
}
}
void ALreverb_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
-{
- ALreverb_getParamf(effect, context, param, vals);
-}
+{ ALreverb_getParamf(effect, context, param, vals); }
DEFINE_ALEFFECT_VTABLE(ALreverb);
diff --git a/Alc/filters/defs.h b/Alc/filters/defs.h
new file mode 100644
index 00000000..133a85eb
--- /dev/null
+++ b/Alc/filters/defs.h
@@ -0,0 +1,112 @@
+#ifndef ALC_FILTER_H
+#define ALC_FILTER_H
+
+#include "AL/al.h"
+#include "math_defs.h"
+
+/* Filters implementation is based on the "Cookbook formulae for audio
+ * EQ biquad filter coefficients" by Robert Bristow-Johnson
+ * http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
+ */
+/* Implementation note: For the shelf filters, the specified gain is for the
+ * reference frequency, which is the centerpoint of the transition band. This
+ * better matches EFX filter design. To set the gain for the shelf itself, use
+ * the square root of the desired linear gain (or halve the dB gain).
+ */
+
+typedef enum BiquadType {
+ /** EFX-style low-pass filter, specifying a gain and reference frequency. */
+ BiquadType_HighShelf,
+ /** EFX-style high-pass filter, specifying a gain and reference frequency. */
+ BiquadType_LowShelf,
+ /** Peaking filter, specifying a gain and reference frequency. */
+ BiquadType_Peaking,
+
+ /** Low-pass cut-off filter, specifying a cut-off frequency. */
+ BiquadType_LowPass,
+ /** High-pass cut-off filter, specifying a cut-off frequency. */
+ BiquadType_HighPass,
+ /** Band-pass filter, specifying a center frequency. */
+ BiquadType_BandPass,
+} BiquadType;
+
+typedef struct BiquadFilter {
+ ALfloat z1, z2; /* Last two delayed components for direct form II. */
+ ALfloat b0, b1, b2; /* Transfer function coefficients "b" (numerator) */
+ ALfloat a1, a2; /* Transfer function coefficients "a" (denominator; a0 is
+ * pre-applied). */
+} BiquadFilter;
+/* Currently only a C-based filter process method is implemented. */
+#define BiquadFilter_process BiquadFilter_processC
+
+/**
+ * Calculates the rcpQ (i.e. 1/Q) coefficient for shelving filters, using the
+ * reference gain and shelf slope parameter.
+ * \param gain 0 < gain
+ * \param slope 0 < slope <= 1
+ */
+inline ALfloat calc_rcpQ_from_slope(ALfloat gain, ALfloat slope)
+{
+ return sqrtf((gain + 1.0f/gain)*(1.0f/slope - 1.0f) + 2.0f);
+}
+/**
+ * Calculates the rcpQ (i.e. 1/Q) coefficient for filters, using the normalized
+ * reference frequency and bandwidth.
+ * \param f0norm 0 < f0norm < 0.5.
+ * \param bandwidth 0 < bandwidth
+ */
+inline ALfloat calc_rcpQ_from_bandwidth(ALfloat f0norm, ALfloat bandwidth)
+{
+ ALfloat w0 = F_TAU * f0norm;
+ return 2.0f*sinhf(logf(2.0f)/2.0f*bandwidth*w0/sinf(w0));
+}
+
+inline void BiquadFilter_clear(BiquadFilter *filter)
+{
+ filter->z1 = 0.0f;
+ filter->z2 = 0.0f;
+}
+
+/**
+ * Sets up the filter state for the specified filter type and its parameters.
+ *
+ * \param filter The filter object to prepare.
+ * \param type The type of filter for the object to apply.
+ * \param gain The gain for the reference frequency response. Only used by the
+ * Shelf and Peaking filter types.
+ * \param f0norm The normalized reference frequency (ref_freq / sample_rate).
+ * This is the center point for the Shelf, Peaking, and BandPass
+ * filter types, or the cutoff frequency for the LowPass and
+ * HighPass filter types.
+ * \param rcpQ The reciprocal of the Q coefficient for the filter's transition
+ * band. Can be generated from calc_rcpQ_from_slope or
+ * calc_rcpQ_from_bandwidth depending on the available data.
+ */
+void BiquadFilter_setParams(BiquadFilter *filter, BiquadType type, ALfloat gain, ALfloat f0norm, ALfloat rcpQ);
+
+inline void BiquadFilter_copyParams(BiquadFilter *restrict dst, const BiquadFilter *restrict src)
+{
+ dst->b0 = src->b0;
+ dst->b1 = src->b1;
+ dst->b2 = src->b2;
+ dst->a1 = src->a1;
+ dst->a2 = src->a2;
+}
+
+void BiquadFilter_processC(BiquadFilter *filter, ALfloat *restrict dst, const ALfloat *restrict src, ALsizei numsamples);
+
+inline void BiquadFilter_passthru(BiquadFilter *filter, ALsizei numsamples)
+{
+ if(LIKELY(numsamples >= 2))
+ {
+ filter->z1 = 0.0f;
+ filter->z2 = 0.0f;
+ }
+ else if(numsamples == 1)
+ {
+ filter->z1 = filter->z2;
+ filter->z2 = 0.0f;
+ }
+}
+
+#endif /* ALC_FILTER_H */
diff --git a/Alc/filters/filter.c b/Alc/filters/filter.c
new file mode 100644
index 00000000..2b370f89
--- /dev/null
+++ b/Alc/filters/filter.c
@@ -0,0 +1,129 @@
+
+#include "config.h"
+
+#include "AL/alc.h"
+#include "AL/al.h"
+
+#include "alMain.h"
+#include "defs.h"
+
+extern inline void BiquadFilter_clear(BiquadFilter *filter);
+extern inline void BiquadFilter_copyParams(BiquadFilter *restrict dst, const BiquadFilter *restrict src);
+extern inline void BiquadFilter_passthru(BiquadFilter *filter, ALsizei numsamples);
+extern inline ALfloat calc_rcpQ_from_slope(ALfloat gain, ALfloat slope);
+extern inline ALfloat calc_rcpQ_from_bandwidth(ALfloat f0norm, ALfloat bandwidth);
+
+
+void BiquadFilter_setParams(BiquadFilter *filter, BiquadType type, ALfloat gain, ALfloat f0norm, ALfloat rcpQ)
+{
+ ALfloat alpha, sqrtgain_alpha_2;
+ ALfloat w0, sin_w0, cos_w0;
+ ALfloat a[3] = { 1.0f, 0.0f, 0.0f };
+ ALfloat b[3] = { 1.0f, 0.0f, 0.0f };
+
+ // Limit gain to -100dB
+ assert(gain > 0.00001f);
+
+ w0 = F_TAU * f0norm;
+ sin_w0 = sinf(w0);
+ cos_w0 = cosf(w0);
+ alpha = sin_w0/2.0f * rcpQ;
+
+ /* Calculate filter coefficients depending on filter type */
+ switch(type)
+ {
+ case BiquadType_HighShelf:
+ sqrtgain_alpha_2 = 2.0f * sqrtf(gain) * alpha;
+ b[0] = gain*((gain+1.0f) + (gain-1.0f)*cos_w0 + sqrtgain_alpha_2);
+ b[1] = -2.0f*gain*((gain-1.0f) + (gain+1.0f)*cos_w0 );
+ b[2] = gain*((gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2);
+ a[0] = (gain+1.0f) - (gain-1.0f)*cos_w0 + sqrtgain_alpha_2;
+ a[1] = 2.0f* ((gain-1.0f) - (gain+1.0f)*cos_w0 );
+ a[2] = (gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2;
+ break;
+ case BiquadType_LowShelf:
+ sqrtgain_alpha_2 = 2.0f * sqrtf(gain) * alpha;
+ b[0] = gain*((gain+1.0f) - (gain-1.0f)*cos_w0 + sqrtgain_alpha_2);
+ b[1] = 2.0f*gain*((gain-1.0f) - (gain+1.0f)*cos_w0 );
+ b[2] = gain*((gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2);
+ a[0] = (gain+1.0f) + (gain-1.0f)*cos_w0 + sqrtgain_alpha_2;
+ a[1] = -2.0f* ((gain-1.0f) + (gain+1.0f)*cos_w0 );
+ a[2] = (gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2;
+ break;
+ case BiquadType_Peaking:
+ gain = sqrtf(gain);
+ b[0] = 1.0f + alpha * gain;
+ b[1] = -2.0f * cos_w0;
+ b[2] = 1.0f - alpha * gain;
+ a[0] = 1.0f + alpha / gain;
+ a[1] = -2.0f * cos_w0;
+ a[2] = 1.0f - alpha / gain;
+ break;
+
+ case BiquadType_LowPass:
+ b[0] = (1.0f - cos_w0) / 2.0f;
+ b[1] = 1.0f - cos_w0;
+ b[2] = (1.0f - cos_w0) / 2.0f;
+ a[0] = 1.0f + alpha;
+ a[1] = -2.0f * cos_w0;
+ a[2] = 1.0f - alpha;
+ break;
+ case BiquadType_HighPass:
+ b[0] = (1.0f + cos_w0) / 2.0f;
+ b[1] = -(1.0f + cos_w0);
+ b[2] = (1.0f + cos_w0) / 2.0f;
+ a[0] = 1.0f + alpha;
+ a[1] = -2.0f * cos_w0;
+ a[2] = 1.0f - alpha;
+ break;
+ case BiquadType_BandPass:
+ b[0] = alpha;
+ b[1] = 0;
+ b[2] = -alpha;
+ a[0] = 1.0f + alpha;
+ a[1] = -2.0f * cos_w0;
+ a[2] = 1.0f - alpha;
+ break;
+ }
+
+ filter->a1 = a[1] / a[0];
+ filter->a2 = a[2] / a[0];
+ filter->b0 = b[0] / a[0];
+ filter->b1 = b[1] / a[0];
+ filter->b2 = b[2] / a[0];
+}
+
+
+void BiquadFilter_processC(BiquadFilter *filter, ALfloat *restrict dst, const ALfloat *restrict src, ALsizei numsamples)
+{
+ const ALfloat a1 = filter->a1;
+ const ALfloat a2 = filter->a2;
+ const ALfloat b0 = filter->b0;
+ const ALfloat b1 = filter->b1;
+ const ALfloat b2 = filter->b2;
+ ALfloat z1 = filter->z1;
+ ALfloat z2 = filter->z2;
+ ALsizei i;
+
+ ASSUME(numsamples > 0);
+
+ /* Processing loop is Transposed Direct Form II. This requires less storage
+ * compared to Direct Form I (only two delay components, instead of a four-
+ * sample history; the last two inputs and outputs), and works better for
+ * floating-point which favors summing similarly-sized values while being
+ * less bothered by overflow.
+ *
+ * See: http://www.earlevel.com/main/2003/02/28/biquads/
+ */
+ for(i = 0;i < numsamples;i++)
+ {
+ ALfloat input = src[i];
+ ALfloat output = input*b0 + z1;
+ z1 = input*b1 - output*a1 + z2;
+ z2 = input*b2 - output*a2;
+ dst[i] = output;
+ }
+
+ filter->z1 = z1;
+ filter->z2 = z2;
+}
diff --git a/Alc/filters/nfc.c b/Alc/filters/nfc.c
new file mode 100644
index 00000000..8869d1d0
--- /dev/null
+++ b/Alc/filters/nfc.c
@@ -0,0 +1,426 @@
+
+#include "config.h"
+
+#include "nfc.h"
+#include "alMain.h"
+
+#include <string.h>
+
+
+/* Near-field control filters are the basis for handling the near-field effect.
+ * The near-field effect is a bass-boost present in the directional components
+ * of a recorded signal, created as a result of the wavefront curvature (itself
+ * a function of sound distance). Proper reproduction dictates this be
+ * compensated for using a bass-cut given the playback speaker distance, to
+ * avoid excessive bass in the playback.
+ *
+ * For real-time rendered audio, emulating the near-field effect based on the
+ * sound source's distance, and subsequently compensating for it at output
+ * based on the speaker distances, can create a more realistic perception of
+ * sound distance beyond a simple 1/r attenuation.
+ *
+ * These filters do just that. Each one applies a low-shelf filter, created as
+ * the combination of a bass-boost for a given sound source distance (near-
+ * field emulation) along with a bass-cut for a given control/speaker distance
+ * (near-field compensation).
+ *
+ * Note that it is necessary to apply a cut along with the boost, since the
+ * boost alone is unstable in higher-order ambisonics as it causes an infinite
+ * DC gain (even first-order ambisonics requires there to be no DC offset for
+ * the boost to work). Consequently, ambisonics requires a control parameter to
+ * be used to avoid an unstable boost-only filter. NFC-HOA defines this control
+ * as a reference delay, calculated with:
+ *
+ * reference_delay = control_distance / speed_of_sound
+ *
+ * This means w0 (for input) or w1 (for output) should be set to:
+ *
+ * wN = 1 / (reference_delay * sample_rate)
+ *
+ * when dealing with NFC-HOA content. For FOA input content, which does not
+ * specify a reference_delay variable, w0 should be set to 0 to apply only
+ * near-field compensation for output. It's important that w1 be a finite,
+ * positive, non-0 value or else the bass-boost will become unstable again.
+ * Also, w0 should not be too large compared to w1, to avoid excessively loud
+ * low frequencies.
+ */
+
+static const float B[4][3] = {
+ { 0.0f },
+ { 1.0f },
+ { 3.0f, 3.0f },
+ { 3.6778f, 6.4595f, 2.3222f },
+ /*{ 4.2076f, 11.4877f, 5.7924f, 9.1401f }*/
+};
+
+static void NfcFilterCreate1(struct NfcFilter1 *nfc, const float w0, const float w1)
+{
+ float b_00, g_0;
+ float r;
+
+ nfc->base_gain = 1.0f;
+ nfc->gain = 1.0f;
+
+ /* Calculate bass-boost coefficients. */
+ r = 0.5f * w0;
+ b_00 = B[1][0] * r;
+ g_0 = 1.0f + b_00;
+
+ nfc->gain *= g_0;
+ nfc->b1 = 2.0f * b_00 / g_0;
+
+ /* Calculate bass-cut coefficients. */
+ r = 0.5f * w1;
+ b_00 = B[1][0] * r;
+ g_0 = 1.0f + b_00;
+
+ nfc->base_gain /= g_0;
+ nfc->gain /= g_0;
+ nfc->a1 = 2.0f * b_00 / g_0;
+}
+
+static void NfcFilterAdjust1(struct NfcFilter1 *nfc, const float w0)
+{
+ float b_00, g_0;
+ float r;
+
+ r = 0.5f * w0;
+ b_00 = B[1][0] * r;
+ g_0 = 1.0f + b_00;
+
+ nfc->gain = nfc->base_gain * g_0;
+ nfc->b1 = 2.0f * b_00 / g_0;
+}
+
+
+static void NfcFilterCreate2(struct NfcFilter2 *nfc, const float w0, const float w1)
+{
+ float b_10, b_11, g_1;
+ float r;
+
+ nfc->base_gain = 1.0f;
+ nfc->gain = 1.0f;
+
+ /* Calculate bass-boost coefficients. */
+ r = 0.5f * w0;
+ b_10 = B[2][0] * r;
+ b_11 = B[2][1] * r * r;
+ g_1 = 1.0f + b_10 + b_11;
+
+ nfc->gain *= g_1;
+ nfc->b1 = (2.0f*b_10 + 4.0f*b_11) / g_1;
+ nfc->b2 = 4.0f * b_11 / g_1;
+
+ /* Calculate bass-cut coefficients. */
+ r = 0.5f * w1;
+ b_10 = B[2][0] * r;
+ b_11 = B[2][1] * r * r;
+ g_1 = 1.0f + b_10 + b_11;
+
+ nfc->base_gain /= g_1;
+ nfc->gain /= g_1;
+ nfc->a1 = (2.0f*b_10 + 4.0f*b_11) / g_1;
+ nfc->a2 = 4.0f * b_11 / g_1;
+}
+
+static void NfcFilterAdjust2(struct NfcFilter2 *nfc, const float w0)
+{
+ float b_10, b_11, g_1;
+ float r;
+
+ r = 0.5f * w0;
+ b_10 = B[2][0] * r;
+ b_11 = B[2][1] * r * r;
+ g_1 = 1.0f + b_10 + b_11;
+
+ nfc->gain = nfc->base_gain * g_1;
+ nfc->b1 = (2.0f*b_10 + 4.0f*b_11) / g_1;
+ nfc->b2 = 4.0f * b_11 / g_1;
+}
+
+
+static void NfcFilterCreate3(struct NfcFilter3 *nfc, const float w0, const float w1)
+{
+ float b_10, b_11, g_1;
+ float b_00, g_0;
+ float r;
+
+ nfc->base_gain = 1.0f;
+ nfc->gain = 1.0f;
+
+ /* Calculate bass-boost coefficients. */
+ r = 0.5f * w0;
+ b_10 = B[3][0] * r;
+ b_11 = B[3][1] * r * r;
+ g_1 = 1.0f + b_10 + b_11;
+
+ nfc->gain *= g_1;
+ nfc->b1 = (2.0f*b_10 + 4.0f*b_11) / g_1;
+ nfc->b2 = 4.0f * b_11 / g_1;
+
+ b_00 = B[3][2] * r;
+ g_0 = 1.0f + b_00;
+
+ nfc->gain *= g_0;
+ nfc->b3 = 2.0f * b_00 / g_0;
+
+ /* Calculate bass-cut coefficients. */
+ r = 0.5f * w1;
+ b_10 = B[3][0] * r;
+ b_11 = B[3][1] * r * r;
+ g_1 = 1.0f + b_10 + b_11;
+
+ nfc->base_gain /= g_1;
+ nfc->gain /= g_1;
+ nfc->a1 = (2.0f*b_10 + 4.0f*b_11) / g_1;
+ nfc->a2 = 4.0f * b_11 / g_1;
+
+ b_00 = B[3][2] * r;
+ g_0 = 1.0f + b_00;
+
+ nfc->base_gain /= g_0;
+ nfc->gain /= g_0;
+ nfc->a3 = 2.0f * b_00 / g_0;
+}
+
+static void NfcFilterAdjust3(struct NfcFilter3 *nfc, const float w0)
+{
+ float b_10, b_11, g_1;
+ float b_00, g_0;
+ float r;
+
+ r = 0.5f * w0;
+ b_10 = B[3][0] * r;
+ b_11 = B[3][1] * r * r;
+ g_1 = 1.0f + b_10 + b_11;
+
+ nfc->gain = nfc->base_gain * g_1;
+ nfc->b1 = (2.0f*b_10 + 4.0f*b_11) / g_1;
+ nfc->b2 = 4.0f * b_11 / g_1;
+
+ b_00 = B[3][2] * r;
+ g_0 = 1.0f + b_00;
+
+ nfc->gain *= g_0;
+ nfc->b3 = 2.0f * b_00 / g_0;
+}
+
+
+void NfcFilterCreate(NfcFilter *nfc, const float w0, const float w1)
+{
+ memset(nfc, 0, sizeof(*nfc));
+ NfcFilterCreate1(&nfc->first, w0, w1);
+ NfcFilterCreate2(&nfc->second, w0, w1);
+ NfcFilterCreate3(&nfc->third, w0, w1);
+}
+
+void NfcFilterAdjust(NfcFilter *nfc, const float w0)
+{
+ NfcFilterAdjust1(&nfc->first, w0);
+ NfcFilterAdjust2(&nfc->second, w0);
+ NfcFilterAdjust3(&nfc->third, w0);
+}
+
+
+void NfcFilterProcess1(NfcFilter *nfc, float *restrict dst, const float *restrict src, const int count)
+{
+ const float gain = nfc->first.gain;
+ const float b1 = nfc->first.b1;
+ const float a1 = nfc->first.a1;
+ float z1 = nfc->first.z[0];
+ int i;
+
+ ASSUME(count > 0);
+
+ for(i = 0;i < count;i++)
+ {
+ float y = src[i]*gain - a1*z1;
+ float out = y + b1*z1;
+ z1 += y;
+
+ dst[i] = out;
+ }
+ nfc->first.z[0] = z1;
+}
+
+void NfcFilterProcess2(NfcFilter *nfc, float *restrict dst, const float *restrict src, const int count)
+{
+ const float gain = nfc->second.gain;
+ const float b1 = nfc->second.b1;
+ const float b2 = nfc->second.b2;
+ const float a1 = nfc->second.a1;
+ const float a2 = nfc->second.a2;
+ float z1 = nfc->second.z[0];
+ float z2 = nfc->second.z[1];
+ int i;
+
+ ASSUME(count > 0);
+
+ for(i = 0;i < count;i++)
+ {
+ float y = src[i]*gain - a1*z1 - a2*z2;
+ float out = y + b1*z1 + b2*z2;
+ z2 += z1;
+ z1 += y;
+
+ dst[i] = out;
+ }
+ nfc->second.z[0] = z1;
+ nfc->second.z[1] = z2;
+}
+
+void NfcFilterProcess3(NfcFilter *nfc, float *restrict dst, const float *restrict src, const int count)
+{
+ const float gain = nfc->third.gain;
+ const float b1 = nfc->third.b1;
+ const float b2 = nfc->third.b2;
+ const float b3 = nfc->third.b3;
+ const float a1 = nfc->third.a1;
+ const float a2 = nfc->third.a2;
+ const float a3 = nfc->third.a3;
+ float z1 = nfc->third.z[0];
+ float z2 = nfc->third.z[1];
+ float z3 = nfc->third.z[2];
+ int i;
+
+ ASSUME(count > 0);
+
+ for(i = 0;i < count;i++)
+ {
+ float y = src[i]*gain - a1*z1 - a2*z2;
+ float out = y + b1*z1 + b2*z2;
+ z2 += z1;
+ z1 += y;
+
+ y = out - a3*z3;
+ out = y + b3*z3;
+ z3 += y;
+
+ dst[i] = out;
+ }
+ nfc->third.z[0] = z1;
+ nfc->third.z[1] = z2;
+ nfc->third.z[2] = z3;
+}
+
+#if 0 /* Original methods the above are derived from. */
+static void NfcFilterCreate(NfcFilter *nfc, const ALsizei order, const float src_dist, const float ctl_dist, const float rate)
+{
+ static const float B[4][5] = {
+ { },
+ { 1.0f },
+ { 3.0f, 3.0f },
+ { 3.6778f, 6.4595f, 2.3222f },
+ { 4.2076f, 11.4877f, 5.7924f, 9.1401f }
+ };
+ float w0 = SPEEDOFSOUNDMETRESPERSEC / (src_dist * rate);
+ float w1 = SPEEDOFSOUNDMETRESPERSEC / (ctl_dist * rate);
+ ALsizei i;
+ float r;
+
+ nfc->g = 1.0f;
+ nfc->coeffs[0] = 1.0f;
+
+ /* NOTE: Slight adjustment from the literature to raise the center
+ * frequency a bit (0.5 -> 1.0).
+ */
+ r = 1.0f * w0;
+ for(i = 0; i < (order-1);i += 2)
+ {
+ float b_10 = B[order][i ] * r;
+ float b_11 = B[order][i+1] * r * r;
+ float g_1 = 1.0f + b_10 + b_11;
+
+ nfc->b[i] = b_10;
+ nfc->b[i + 1] = b_11;
+ nfc->coeffs[0] *= g_1;
+ nfc->coeffs[i+1] = ((2.0f * b_10) + (4.0f * b_11)) / g_1;
+ nfc->coeffs[i+2] = (4.0f * b_11) / g_1;
+ }
+ if(i < order)
+ {
+ float b_00 = B[order][i] * r;
+ float g_0 = 1.0f + b_00;
+
+ nfc->b[i] = b_00;
+ nfc->coeffs[0] *= g_0;
+ nfc->coeffs[i+1] = (2.0f * b_00) / g_0;
+ }
+
+ r = 1.0f * w1;
+ for(i = 0;i < (order-1);i += 2)
+ {
+ float b_10 = B[order][i ] * r;
+ float b_11 = B[order][i+1] * r * r;
+ float g_1 = 1.0f + b_10 + b_11;
+
+ nfc->g /= g_1;
+ nfc->coeffs[0] /= g_1;
+ nfc->coeffs[order+i+1] = ((2.0f * b_10) + (4.0f * b_11)) / g_1;
+ nfc->coeffs[order+i+2] = (4.0f * b_11) / g_1;
+ }
+ if(i < order)
+ {
+ float b_00 = B[order][i] * r;
+ float g_0 = 1.0f + b_00;
+
+ nfc->g /= g_0;
+ nfc->coeffs[0] /= g_0;
+ nfc->coeffs[order+i+1] = (2.0f * b_00) / g_0;
+ }
+
+ for(i = 0; i < MAX_AMBI_ORDER; i++)
+ nfc->history[i] = 0.0f;
+}
+
+static void NfcFilterAdjust(NfcFilter *nfc, const float distance)
+{
+ int i;
+
+ nfc->coeffs[0] = nfc->g;
+
+ for(i = 0;i < (nfc->order-1);i += 2)
+ {
+ float b_10 = nfc->b[i] / distance;
+ float b_11 = nfc->b[i+1] / (distance * distance);
+ float g_1 = 1.0f + b_10 + b_11;
+
+ nfc->coeffs[0] *= g_1;
+ nfc->coeffs[i+1] = ((2.0f * b_10) + (4.0f * b_11)) / g_1;
+ nfc->coeffs[i+2] = (4.0f * b_11) / g_1;
+ }
+ if(i < nfc->order)
+ {
+ float b_00 = nfc->b[i] / distance;
+ float g_0 = 1.0f + b_00;
+
+ nfc->coeffs[0] *= g_0;
+ nfc->coeffs[i+1] = (2.0f * b_00) / g_0;
+ }
+}
+
+static float NfcFilterProcess(const float in, NfcFilter *nfc)
+{
+ int i;
+ float out = in * nfc->coeffs[0];
+
+ for(i = 0;i < (nfc->order-1);i += 2)
+ {
+ float y = out - (nfc->coeffs[nfc->order+i+1] * nfc->history[i]) -
+ (nfc->coeffs[nfc->order+i+2] * nfc->history[i+1]) + 1.0e-30f;
+ out = y + (nfc->coeffs[i+1]*nfc->history[i]) + (nfc->coeffs[i+2]*nfc->history[i+1]);
+
+ nfc->history[i+1] += nfc->history[i];
+ nfc->history[i] += y;
+ }
+ if(i < nfc->order)
+ {
+ float y = out - (nfc->coeffs[nfc->order+i+1] * nfc->history[i]) + 1.0e-30f;
+
+ out = y + (nfc->coeffs[i+1] * nfc->history[i]);
+ nfc->history[i] += y;
+ }
+
+ return out;
+}
+#endif
diff --git a/Alc/filters/nfc.h b/Alc/filters/nfc.h
new file mode 100644
index 00000000..12a5a18f
--- /dev/null
+++ b/Alc/filters/nfc.h
@@ -0,0 +1,49 @@
+#ifndef FILTER_NFC_H
+#define FILTER_NFC_H
+
+struct NfcFilter1 {
+ float base_gain, gain;
+ float b1, a1;
+ float z[1];
+};
+struct NfcFilter2 {
+ float base_gain, gain;
+ float b1, b2, a1, a2;
+ float z[2];
+};
+struct NfcFilter3 {
+ float base_gain, gain;
+ float b1, b2, b3, a1, a2, a3;
+ float z[3];
+};
+
+typedef struct NfcFilter {
+ struct NfcFilter1 first;
+ struct NfcFilter2 second;
+ struct NfcFilter3 third;
+} NfcFilter;
+
+
+/* NOTE:
+ * w0 = speed_of_sound / (source_distance * sample_rate);
+ * w1 = speed_of_sound / (control_distance * sample_rate);
+ *
+ * Generally speaking, the control distance should be approximately the average
+ * speaker distance, or based on the reference delay if outputing NFC-HOA. It
+ * must not be negative, 0, or infinite. The source distance should not be too
+ * small relative to the control distance.
+ */
+
+void NfcFilterCreate(NfcFilter *nfc, const float w0, const float w1);
+void NfcFilterAdjust(NfcFilter *nfc, const float w0);
+
+/* Near-field control filter for first-order ambisonic channels (1-3). */
+void NfcFilterProcess1(NfcFilter *nfc, float *restrict dst, const float *restrict src, const int count);
+
+/* Near-field control filter for second-order ambisonic channels (4-8). */
+void NfcFilterProcess2(NfcFilter *nfc, float *restrict dst, const float *restrict src, const int count);
+
+/* Near-field control filter for third-order ambisonic channels (9-15). */
+void NfcFilterProcess3(NfcFilter *nfc, float *restrict dst, const float *restrict src, const int count);
+
+#endif /* FILTER_NFC_H */
diff --git a/Alc/filters/splitter.c b/Alc/filters/splitter.c
new file mode 100644
index 00000000..e99f4b95
--- /dev/null
+++ b/Alc/filters/splitter.c
@@ -0,0 +1,109 @@
+
+#include "config.h"
+
+#include "splitter.h"
+
+#include "math_defs.h"
+
+
+void bandsplit_init(BandSplitter *splitter, ALfloat f0norm)
+{
+ ALfloat w = f0norm * F_TAU;
+ ALfloat cw = cosf(w);
+ if(cw > FLT_EPSILON)
+ splitter->coeff = (sinf(w) - 1.0f) / cw;
+ else
+ splitter->coeff = cw * -0.5f;
+
+ splitter->lp_z1 = 0.0f;
+ splitter->lp_z2 = 0.0f;
+ splitter->hp_z1 = 0.0f;
+}
+
+void bandsplit_clear(BandSplitter *splitter)
+{
+ splitter->lp_z1 = 0.0f;
+ splitter->lp_z2 = 0.0f;
+ splitter->hp_z1 = 0.0f;
+}
+
+void bandsplit_process(BandSplitter *splitter, ALfloat *restrict hpout, ALfloat *restrict lpout,
+ const ALfloat *input, ALsizei count)
+{
+ ALfloat lp_coeff, hp_coeff, lp_y, hp_y, d;
+ ALfloat lp_z1, lp_z2, hp_z1;
+ ALsizei i;
+
+ ASSUME(count > 0);
+
+ hp_coeff = splitter->coeff;
+ lp_coeff = splitter->coeff*0.5f + 0.5f;
+ lp_z1 = splitter->lp_z1;
+ lp_z2 = splitter->lp_z2;
+ hp_z1 = splitter->hp_z1;
+ for(i = 0;i < count;i++)
+ {
+ ALfloat in = input[i];
+
+ /* Low-pass sample processing. */
+ d = (in - lp_z1) * lp_coeff;
+ lp_y = lp_z1 + d;
+ lp_z1 = lp_y + d;
+
+ d = (lp_y - lp_z2) * lp_coeff;
+ lp_y = lp_z2 + d;
+ lp_z2 = lp_y + d;
+
+ lpout[i] = lp_y;
+
+ /* All-pass sample processing. */
+ hp_y = in*hp_coeff + hp_z1;
+ hp_z1 = in - hp_y*hp_coeff;
+
+ /* High-pass generated from removing low-passed output. */
+ hpout[i] = hp_y - lp_y;
+ }
+ splitter->lp_z1 = lp_z1;
+ splitter->lp_z2 = lp_z2;
+ splitter->hp_z1 = hp_z1;
+}
+
+
+void splitterap_init(SplitterAllpass *splitter, ALfloat f0norm)
+{
+ ALfloat w = f0norm * F_TAU;
+ ALfloat cw = cosf(w);
+ if(cw > FLT_EPSILON)
+ splitter->coeff = (sinf(w) - 1.0f) / cw;
+ else
+ splitter->coeff = cw * -0.5f;
+
+ splitter->z1 = 0.0f;
+}
+
+void splitterap_clear(SplitterAllpass *splitter)
+{
+ splitter->z1 = 0.0f;
+}
+
+void splitterap_process(SplitterAllpass *splitter, ALfloat *restrict samples, ALsizei count)
+{
+ ALfloat coeff, in, out;
+ ALfloat z1;
+ ALsizei i;
+
+ ASSUME(count > 0);
+
+ coeff = splitter->coeff;
+ z1 = splitter->z1;
+ for(i = 0;i < count;i++)
+ {
+ in = samples[i];
+
+ out = in*coeff + z1;
+ z1 = in - out*coeff;
+
+ samples[i] = out;
+ }
+ splitter->z1 = z1;
+}
diff --git a/Alc/filters/splitter.h b/Alc/filters/splitter.h
new file mode 100644
index 00000000..a788bc3e
--- /dev/null
+++ b/Alc/filters/splitter.h
@@ -0,0 +1,40 @@
+#ifndef FILTER_SPLITTER_H
+#define FILTER_SPLITTER_H
+
+#include "alMain.h"
+
+
+/* Band splitter. Splits a signal into two phase-matching frequency bands. */
+typedef struct BandSplitter {
+ ALfloat coeff;
+ ALfloat lp_z1;
+ ALfloat lp_z2;
+ ALfloat hp_z1;
+} BandSplitter;
+
+void bandsplit_init(BandSplitter *splitter, ALfloat f0norm);
+void bandsplit_clear(BandSplitter *splitter);
+void bandsplit_process(BandSplitter *splitter, ALfloat *restrict hpout, ALfloat *restrict lpout,
+ const ALfloat *input, ALsizei count);
+
+/* The all-pass portion of the band splitter. Applies the same phase shift
+ * without splitting the signal.
+ */
+typedef struct SplitterAllpass {
+ ALfloat coeff;
+ ALfloat z1;
+} SplitterAllpass;
+
+void splitterap_init(SplitterAllpass *splitter, ALfloat f0norm);
+void splitterap_clear(SplitterAllpass *splitter);
+void splitterap_process(SplitterAllpass *splitter, ALfloat *restrict samples, ALsizei count);
+
+
+typedef struct FrontStablizer {
+ SplitterAllpass APFilter[MAX_OUTPUT_CHANNELS];
+ BandSplitter LFilter, RFilter;
+ alignas(16) ALfloat LSplit[2][BUFFERSIZE];
+ alignas(16) ALfloat RSplit[2][BUFFERSIZE];
+} FrontStablizer;
+
+#endif /* FILTER_SPLITTER_H */
diff --git a/Alc/fpu_modes.h b/Alc/fpu_modes.h
new file mode 100644
index 00000000..eb305967
--- /dev/null
+++ b/Alc/fpu_modes.h
@@ -0,0 +1,34 @@
+#ifndef FPU_MODES_H
+#define FPU_MODES_H
+
+#ifdef HAVE_FENV_H
+#include <fenv.h>
+#endif
+
+
+typedef struct FPUCtl {
+#if defined(__GNUC__) && defined(HAVE_SSE)
+ unsigned int sse_state;
+#elif defined(HAVE___CONTROL87_2)
+ unsigned int state;
+ unsigned int sse_state;
+#elif defined(HAVE__CONTROLFP)
+ unsigned int state;
+#endif
+} FPUCtl;
+void SetMixerFPUMode(FPUCtl *ctl);
+void RestoreFPUMode(const FPUCtl *ctl);
+
+#ifdef __GNUC__
+/* Use an alternate macro set with GCC to avoid accidental continue or break
+ * statements within the mixer mode.
+ */
+#define START_MIXER_MODE() __extension__({ FPUCtl _oldMode; SetMixerFPUMode(&_oldMode)
+#define END_MIXER_MODE() RestoreFPUMode(&_oldMode); })
+#else
+#define START_MIXER_MODE() do { FPUCtl _oldMode; SetMixerFPUMode(&_oldMode)
+#define END_MIXER_MODE() RestoreFPUMode(&_oldMode); } while(0)
+#endif
+#define LEAVE_MIXER_MODE() RestoreFPUMode(&_oldMode)
+
+#endif /* FPU_MODES_H */
diff --git a/Alc/helpers.c b/Alc/helpers.c
index 7b9e58e0..d2cb6253 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -32,12 +32,21 @@
#include <time.h>
#include <errno.h>
#include <stdarg.h>
+#include <ctype.h>
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif
+#ifdef HAVE_PROC_PIDPATH
+#include <libproc.h>
+#endif
+
+#ifdef __FreeBSD__
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
#ifndef AL_NO_UID_DEFS
#if defined(HAVE_GUIDDEF_H) || defined(HAVE_INITGUID_H)
@@ -60,11 +69,13 @@ DEFINE_GUID(IID_IAudioClient, 0x1cb9ad4c, 0xdbfa, 0x4c32, 0xb1,0x78, 0xc
DEFINE_GUID(IID_IAudioRenderClient, 0xf294acfc, 0x3146, 0x4483, 0xa7,0xbf, 0xad,0xdc,0xa7,0xc2,0x60,0xe2);
DEFINE_GUID(IID_IAudioCaptureClient, 0xc8adbd64, 0xe71e, 0x48a0, 0xa4,0xde, 0x18,0x5c,0x39,0x5c,0xd3,0x17);
-#ifdef HAVE_MMDEVAPI
+#ifdef HAVE_WASAPI
+#include <wtypes.h>
#include <devpropdef.h>
#include <propkeydef.h>
DEFINE_DEVPROPKEY(DEVPKEY_Device_FriendlyName, 0xa45c254e, 0xdf1c, 0x4efd, 0x80,0x20, 0x67,0xd1,0x46,0xa8,0x50,0xe0, 14);
DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_FormFactor, 0x1da5d803, 0xd492, 0x4edd, 0x8c,0x23, 0xe0,0xc0,0xff,0xee,0x7f,0x0e, 0);
+DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_GUID, 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23,0xe0, 0xc0,0xff,0xee,0x7f,0x0e, 4 );
#endif
#endif
#endif /* AL_NO_UID_DEFS */
@@ -89,6 +100,10 @@ DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_FormFactor, 0x1da5d803, 0xd492, 0x4edd, 0x
#endif
#ifndef _WIN32
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <fcntl.h>
#include <unistd.h>
#elif defined(_WIN32_IE)
#include <shlobj.h>
@@ -96,6 +111,8 @@ DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_FormFactor, 0x1da5d803, 0xd492, 0x4edd, 0x
#include "alMain.h"
#include "alu.h"
+#include "cpu_caps.h"
+#include "fpu_modes.h"
#include "atomic.h"
#include "uintmap.h"
#include "vector.h"
@@ -105,71 +122,51 @@ DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_FormFactor, 0x1da5d803, 0xd492, 0x4edd, 0x
extern inline ALuint NextPowerOf2(ALuint value);
+extern inline size_t RoundUp(size_t value, size_t r);
extern inline ALint fastf2i(ALfloat f);
-extern inline ALuint fastf2u(ALfloat f);
+extern inline int float2int(float f);
+extern inline float fast_roundf(float f);
+#ifndef __GNUC__
+#if defined(HAVE_BITSCANFORWARD64_INTRINSIC)
+extern inline int msvc64_ctz64(ALuint64 v);
+#elif defined(HAVE_BITSCANFORWARD_INTRINSIC)
+extern inline int msvc_ctz64(ALuint64 v);
+#else
+extern inline int fallback_popcnt64(ALuint64 v);
+extern inline int fallback_ctz64(ALuint64 value);
+#endif
+#endif
-ALuint CPUCapFlags = 0;
+#if defined(HAVE_GCC_GET_CPUID) && (defined(__i386__) || defined(__x86_64__) || \
+ defined(_M_IX86) || defined(_M_X64))
+typedef unsigned int reg_type;
+static inline void get_cpuid(int f, reg_type *regs)
+{ __get_cpuid(f, &regs[0], &regs[1], &regs[2], &regs[3]); }
+#define CAN_GET_CPUID
+#elif defined(HAVE_CPUID_INTRINSIC) && (defined(__i386__) || defined(__x86_64__) || \
+ defined(_M_IX86) || defined(_M_X64))
+typedef int reg_type;
+static inline void get_cpuid(int f, reg_type *regs)
+{ (__cpuid)(regs, f); }
+#define CAN_GET_CPUID
+#endif
+int CPUCapFlags = 0;
-void FillCPUCaps(ALuint capfilter)
+void FillCPUCaps(int capfilter)
{
- ALuint caps = 0;
+ int caps = 0;
/* FIXME: We really should get this for all available CPUs in case different
* CPUs have different caps (is that possible on one machine?). */
-#if defined(HAVE_GCC_GET_CPUID) && (defined(__i386__) || defined(__x86_64__) || \
- defined(_M_IX86) || defined(_M_X64))
+#ifdef CAN_GET_CPUID
union {
- unsigned int regs[4];
- char str[sizeof(unsigned int[4])];
- } cpuinf[3];
+ reg_type regs[4];
+ char str[sizeof(reg_type[4])];
+ } cpuinf[3] = {{ { 0, 0, 0, 0 } }};
- if(!__get_cpuid(0, &cpuinf[0].regs[0], &cpuinf[0].regs[1], &cpuinf[0].regs[2], &cpuinf[0].regs[3]))
- ERR("Failed to get CPUID\n");
- else
- {
- unsigned int maxfunc = cpuinf[0].regs[0];
- unsigned int maxextfunc = 0;
-
- if(__get_cpuid(0x80000000, &cpuinf[0].regs[0], &cpuinf[0].regs[1], &cpuinf[0].regs[2], &cpuinf[0].regs[3]))
- maxextfunc = cpuinf[0].regs[0];
- TRACE("Detected max CPUID function: 0x%x (ext. 0x%x)\n", maxfunc, maxextfunc);
-
- TRACE("Vendor ID: \"%.4s%.4s%.4s\"\n", cpuinf[0].str+4, cpuinf[0].str+12, cpuinf[0].str+8);
- if(maxextfunc >= 0x80000004 &&
- __get_cpuid(0x80000002, &cpuinf[0].regs[0], &cpuinf[0].regs[1], &cpuinf[0].regs[2], &cpuinf[0].regs[3]) &&
- __get_cpuid(0x80000003, &cpuinf[1].regs[0], &cpuinf[1].regs[1], &cpuinf[1].regs[2], &cpuinf[1].regs[3]) &&
- __get_cpuid(0x80000004, &cpuinf[2].regs[0], &cpuinf[2].regs[1], &cpuinf[2].regs[2], &cpuinf[2].regs[3]))
- TRACE("Name: \"%.16s%.16s%.16s\"\n", cpuinf[0].str, cpuinf[1].str, cpuinf[2].str);
-
- if(maxfunc >= 1 &&
- __get_cpuid(1, &cpuinf[0].regs[0], &cpuinf[0].regs[1], &cpuinf[0].regs[2], &cpuinf[0].regs[3]))
- {
- if((cpuinf[0].regs[3]&(1<<25)))
- {
- caps |= CPU_CAP_SSE;
- if((cpuinf[0].regs[3]&(1<<26)))
- {
- caps |= CPU_CAP_SSE2;
- if((cpuinf[0].regs[2]&(1<<0)))
- {
- caps |= CPU_CAP_SSE3;
- if((cpuinf[0].regs[2]&(1<<19)))
- caps |= CPU_CAP_SSE4_1;
- }
- }
- }
- }
- }
-#elif defined(HAVE_CPUID_INTRINSIC) && (defined(__i386__) || defined(__x86_64__) || \
- defined(_M_IX86) || defined(_M_X64))
- union {
- int regs[4];
- char str[sizeof(int[4])];
- } cpuinf[3];
-
- (__cpuid)(cpuinf[0].regs, 0);
+ get_cpuid(0, cpuinf[0].regs);
if(cpuinf[0].regs[0] == 0)
ERR("Failed to get CPUID\n");
else
@@ -177,7 +174,7 @@ void FillCPUCaps(ALuint capfilter)
unsigned int maxfunc = cpuinf[0].regs[0];
unsigned int maxextfunc;
- (__cpuid)(cpuinf[0].regs, 0x80000000);
+ get_cpuid(0x80000000, cpuinf[0].regs);
maxextfunc = cpuinf[0].regs[0];
TRACE("Detected max CPUID function: 0x%x (ext. 0x%x)\n", maxfunc, maxextfunc);
@@ -185,29 +182,23 @@ void FillCPUCaps(ALuint capfilter)
TRACE("Vendor ID: \"%.4s%.4s%.4s\"\n", cpuinf[0].str+4, cpuinf[0].str+12, cpuinf[0].str+8);
if(maxextfunc >= 0x80000004)
{
- (__cpuid)(cpuinf[0].regs, 0x80000002);
- (__cpuid)(cpuinf[1].regs, 0x80000003);
- (__cpuid)(cpuinf[2].regs, 0x80000004);
+ get_cpuid(0x80000002, cpuinf[0].regs);
+ get_cpuid(0x80000003, cpuinf[1].regs);
+ get_cpuid(0x80000004, cpuinf[2].regs);
TRACE("Name: \"%.16s%.16s%.16s\"\n", cpuinf[0].str, cpuinf[1].str, cpuinf[2].str);
}
if(maxfunc >= 1)
{
- (__cpuid)(cpuinf[0].regs, 1);
+ get_cpuid(1, cpuinf[0].regs);
if((cpuinf[0].regs[3]&(1<<25)))
- {
caps |= CPU_CAP_SSE;
- if((cpuinf[0].regs[3]&(1<<26)))
- {
- caps |= CPU_CAP_SSE2;
- if((cpuinf[0].regs[2]&(1<<0)))
- {
- caps |= CPU_CAP_SSE3;
- if((cpuinf[0].regs[2]&(1<<19)))
- caps |= CPU_CAP_SSE4_1;
- }
- }
- }
+ if((caps&CPU_CAP_SSE) && (cpuinf[0].regs[3]&(1<<26)))
+ caps |= CPU_CAP_SSE2;
+ if((caps&CPU_CAP_SSE2) && (cpuinf[0].regs[2]&(1<<0)))
+ caps |= CPU_CAP_SSE3;
+ if((caps&CPU_CAP_SSE3) && (cpuinf[0].regs[2]&(1<<19)))
+ caps |= CPU_CAP_SSE4_1;
}
}
#else
@@ -227,8 +218,50 @@ void FillCPUCaps(ALuint capfilter)
#endif
#endif
#ifdef HAVE_NEON
- /* Assume Neon support if compiled with it */
- caps |= CPU_CAP_NEON;
+ FILE *file = fopen("/proc/cpuinfo", "rt");
+ if(!file)
+ ERR("Failed to open /proc/cpuinfo, cannot check for NEON support\n");
+ else
+ {
+ al_string features = AL_STRING_INIT_STATIC();
+ char buf[256];
+
+ while(fgets(buf, sizeof(buf), file) != NULL)
+ {
+ if(strncmp(buf, "Features\t:", 10) != 0)
+ continue;
+
+ alstr_copy_cstr(&features, buf+10);
+ while(VECTOR_BACK(features) != '\n')
+ {
+ if(fgets(buf, sizeof(buf), file) == NULL)
+ break;
+ alstr_append_cstr(&features, buf);
+ }
+ break;
+ }
+ fclose(file);
+ file = NULL;
+
+ if(!alstr_empty(features))
+ {
+ const char *str = alstr_get_cstr(features);
+ while(isspace(str[0])) ++str;
+
+ TRACE("Got features string:%s\n", str);
+ while((str=strstr(str, "neon")) != NULL)
+ {
+ if(isspace(*(str-1)) && (str[4] == 0 || isspace(str[4])))
+ {
+ caps |= CPU_CAP_NEON;
+ break;
+ }
+ ++str;
+ }
+ }
+
+ alstr_reset(&features);
+ }
#endif
TRACE("Extensions:%s%s%s%s%s%s\n",
@@ -236,136 +269,125 @@ void FillCPUCaps(ALuint capfilter)
((capfilter&CPU_CAP_SSE2) ? ((caps&CPU_CAP_SSE2) ? " +SSE2" : " -SSE2") : ""),
((capfilter&CPU_CAP_SSE3) ? ((caps&CPU_CAP_SSE3) ? " +SSE3" : " -SSE3") : ""),
((capfilter&CPU_CAP_SSE4_1) ? ((caps&CPU_CAP_SSE4_1) ? " +SSE4.1" : " -SSE4.1") : ""),
- ((capfilter&CPU_CAP_NEON) ? ((caps&CPU_CAP_NEON) ? " +Neon" : " -Neon") : ""),
+ ((capfilter&CPU_CAP_NEON) ? ((caps&CPU_CAP_NEON) ? " +NEON" : " -NEON") : ""),
((!capfilter) ? " -none-" : "")
);
CPUCapFlags = caps & capfilter;
}
-void *al_malloc(size_t alignment, size_t size)
-{
-#if defined(HAVE_ALIGNED_ALLOC)
- size = (size+(alignment-1))&~(alignment-1);
- return aligned_alloc(alignment, size);
-#elif defined(HAVE_POSIX_MEMALIGN)
- void *ret;
- if(posix_memalign(&ret, alignment, size) == 0)
- return ret;
- return NULL;
-#elif defined(HAVE__ALIGNED_MALLOC)
- return _aligned_malloc(size, alignment);
-#else
- char *ret = malloc(size+alignment);
- if(ret != NULL)
- {
- *(ret++) = 0x00;
- while(((ptrdiff_t)ret&(alignment-1)) != 0)
- *(ret++) = 0x55;
- }
- return ret;
-#endif
-}
-
-void *al_calloc(size_t alignment, size_t size)
-{
- void *ret = al_malloc(alignment, size);
- if(ret) memset(ret, 0, size);
- return ret;
-}
-
-void al_free(void *ptr)
-{
-#if defined(HAVE_ALIGNED_ALLOC) || defined(HAVE_POSIX_MEMALIGN)
- free(ptr);
-#elif defined(HAVE__ALIGNED_MALLOC)
- _aligned_free(ptr);
-#else
- if(ptr != NULL)
- {
- char *finder = ptr;
- do {
- --finder;
- } while(*finder == 0x55);
- free(finder);
- }
-#endif
-}
-
-
void SetMixerFPUMode(FPUCtl *ctl)
{
-#ifdef HAVE_FENV_H
- fegetenv(STATIC_CAST(fenv_t, ctl));
-#if defined(__GNUC__) && defined(HAVE_SSE)
- /* FIXME: Some fegetenv implementations can get the SSE environment too?
- * How to tell when it does? */
- if((CPUCapFlags&CPU_CAP_SSE))
- __asm__ __volatile__("stmxcsr %0" : "=m" (*&ctl->sse_state));
-#endif
-
-#ifdef FE_TOWARDZERO
- fesetround(FE_TOWARDZERO);
-#endif
#if defined(__GNUC__) && defined(HAVE_SSE)
if((CPUCapFlags&CPU_CAP_SSE))
{
- int sseState = ctl->sse_state;
- sseState |= 0x6000; /* set round-to-zero */
+ __asm__ __volatile__("stmxcsr %0" : "=m" (*&ctl->sse_state));
+ unsigned int sseState = ctl->sse_state;
sseState |= 0x8000; /* set flush-to-zero */
if((CPUCapFlags&CPU_CAP_SSE2))
sseState |= 0x0040; /* set denormals-are-zero */
__asm__ __volatile__("ldmxcsr %0" : : "m" (*&sseState));
}
-#endif
#elif defined(HAVE___CONTROL87_2)
- int mode;
- __control87_2(0, 0, &ctl->state, NULL);
- __control87_2(_RC_CHOP, _MCW_RC, &mode, NULL);
-#ifdef HAVE_SSE
- if((CPUCapFlags&CPU_CAP_SSE))
- {
- __control87_2(0, 0, NULL, &ctl->sse_state);
- __control87_2(_RC_CHOP|_DN_FLUSH, _MCW_RC|_MCW_DN, NULL, &mode);
- }
-#endif
+ __control87_2(0, 0, &ctl->state, &ctl->sse_state);
+ _control87(_DN_FLUSH, _MCW_DN);
#elif defined(HAVE__CONTROLFP)
ctl->state = _controlfp(0, 0);
- (void)_controlfp(_RC_CHOP, _MCW_RC);
+ _controlfp(_DN_FLUSH, _MCW_DN);
#endif
}
void RestoreFPUMode(const FPUCtl *ctl)
{
-#ifdef HAVE_FENV_H
- fesetenv(STATIC_CAST(fenv_t, ctl));
#if defined(__GNUC__) && defined(HAVE_SSE)
if((CPUCapFlags&CPU_CAP_SSE))
__asm__ __volatile__("ldmxcsr %0" : : "m" (*&ctl->sse_state));
-#endif
#elif defined(HAVE___CONTROL87_2)
int mode;
- __control87_2(ctl->state, _MCW_RC, &mode, NULL);
-#ifdef HAVE_SSE
- if((CPUCapFlags&CPU_CAP_SSE))
- __control87_2(ctl->sse_state, _MCW_RC|_MCW_DN, NULL, &mode);
-#endif
+ __control87_2(ctl->state, _MCW_DN, &mode, NULL);
+ __control87_2(ctl->sse_state, _MCW_DN, NULL, &mode);
#elif defined(HAVE__CONTROLFP)
- _controlfp(ctl->state, _MCW_RC);
+ _controlfp(ctl->state, _MCW_DN);
#endif
}
+static int StringSortCompare(const void *str1, const void *str2)
+{
+ return alstr_cmp(*(const_al_string*)str1, *(const_al_string*)str2);
+}
+
#ifdef _WIN32
+static WCHAR *strrchrW(WCHAR *str, WCHAR ch)
+{
+ WCHAR *ret = NULL;
+ while(*str)
+ {
+ if(*str == ch)
+ ret = str;
+ ++str;
+ }
+ return ret;
+}
+
+void GetProcBinary(al_string *path, al_string *fname)
+{
+ WCHAR *pathname, *sep;
+ DWORD pathlen;
+ DWORD len;
+
+ pathlen = 256;
+ pathname = malloc(pathlen * sizeof(pathname[0]));
+ while(pathlen > 0 && (len=GetModuleFileNameW(NULL, pathname, pathlen)) == pathlen)
+ {
+ free(pathname);
+ pathlen <<= 1;
+ pathname = malloc(pathlen * sizeof(pathname[0]));
+ }
+ if(len == 0)
+ {
+ free(pathname);
+ ERR("Failed to get process name: error %lu\n", GetLastError());
+ return;
+ }
+
+ pathname[len] = 0;
+ if((sep=strrchrW(pathname, '\\')) != NULL)
+ {
+ WCHAR *sep2 = strrchrW(sep+1, '/');
+ if(sep2) sep = sep2;
+ }
+ else
+ sep = strrchrW(pathname, '/');
+
+ if(sep)
+ {
+ if(path) alstr_copy_wrange(path, pathname, sep);
+ if(fname) alstr_copy_wcstr(fname, sep+1);
+ }
+ else
+ {
+ if(path) alstr_clear(path);
+ if(fname) alstr_copy_wcstr(fname, pathname);
+ }
+ free(pathname);
+
+ if(path && fname)
+ TRACE("Got: %s, %s\n", alstr_get_cstr(*path), alstr_get_cstr(*fname));
+ else if(path) TRACE("Got path: %s\n", alstr_get_cstr(*path));
+ else if(fname) TRACE("Got filename: %s\n", alstr_get_cstr(*fname));
+}
+
+
static WCHAR *FromUTF8(const char *str)
{
WCHAR *out = NULL;
@@ -471,363 +493,290 @@ void al_print(const char *type, const char *func, const char *fmt, ...)
static inline int is_slash(int c)
{ return (c == '\\' || c == '/'); }
-FILE *OpenDataFile(const char *fname, const char *subdir)
+static void DirectorySearch(const char *path, const char *ext, vector_al_string *results)
{
- static const int ids[2] = { CSIDL_APPDATA, CSIDL_COMMON_APPDATA };
- WCHAR *wname=NULL, *wsubdir=NULL;
- FILE *f;
- size_t i;
+ al_string pathstr = AL_STRING_INIT_STATIC();
+ WIN32_FIND_DATAW fdata;
+ WCHAR *wpath;
+ HANDLE hdl;
- wname = FromUTF8(fname);
- if(!wname)
- {
- ERR("Failed to convert UTF-8 filename: \"%s\"\n", fname);
- return NULL;
- }
+ alstr_copy_cstr(&pathstr, path);
+ alstr_append_cstr(&pathstr, "\\*");
+ alstr_append_cstr(&pathstr, ext);
- /* If the path is absolute, open it directly. */
- if(wname[0] != '\0' && wname[1] == ':' && is_slash(wname[2]))
- {
- f = _wfopen(wname, L"rb");
- if(f) TRACE("Opened %s\n", fname);
- else WARN("Could not open %s\n", fname);
- free(wname);
- return f;
- }
+ TRACE("Searching %s\n", alstr_get_cstr(pathstr));
- /* Try the current directory first before the data directories. */
- if((f=_wfopen(wname, L"rb")) != NULL)
- {
- TRACE("Opened %s\n", fname);
- free(wname);
- return f;
- }
-
- wsubdir = FromUTF8(subdir);
- if(!wsubdir)
- {
- ERR("Failed to convert UTF-8 subdir: \"%s\"\n", subdir);
- free(wname);
- return NULL;
- }
+ wpath = FromUTF8(alstr_get_cstr(pathstr));
- for(i = 0;i < COUNTOF(ids);i++)
+ hdl = FindFirstFileW(wpath, &fdata);
+ if(hdl != INVALID_HANDLE_VALUE)
{
- WCHAR buffer[PATH_MAX];
- size_t len;
-
- if(SHGetSpecialFolderPathW(NULL, buffer, ids[i], FALSE) == FALSE)
- continue;
-
- len = lstrlenW(buffer);
- if(len > 0 && is_slash(buffer[len-1]))
- buffer[--len] = '\0';
- _snwprintf(buffer+len, PATH_MAX-len, L"/%ls/%ls", wsubdir, wname);
- len = lstrlenW(buffer);
- while(len > 0)
- {
- --len;
- if(buffer[len] == '/')
- buffer[len] = '\\';
- }
-
- if((f=_wfopen(buffer, L"rb")) != NULL)
- {
- al_string filepath = AL_STRING_INIT_STATIC();
- al_string_copy_wcstr(&filepath, buffer);
- TRACE("Opened %s\n", al_string_get_cstr(filepath));
- al_string_deinit(&filepath);
- break;
- }
+ size_t base = VECTOR_SIZE(*results);
+ do {
+ al_string str = AL_STRING_INIT_STATIC();
+ alstr_copy_cstr(&str, path);
+ alstr_append_char(&str, '\\');
+ alstr_append_wcstr(&str, fdata.cFileName);
+ TRACE("Got result %s\n", alstr_get_cstr(str));
+ VECTOR_PUSH_BACK(*results, str);
+ } while(FindNextFileW(hdl, &fdata));
+ FindClose(hdl);
+
+ if(VECTOR_SIZE(*results) > base)
+ qsort(VECTOR_BEGIN(*results)+base, VECTOR_SIZE(*results)-base,
+ sizeof(VECTOR_FRONT(*results)), StringSortCompare);
}
- free(wname);
- free(wsubdir);
- if(f == NULL)
- WARN("Could not open %s\\%s\n", subdir, fname);
- return f;
+ free(wpath);
+ alstr_reset(&pathstr);
}
-
-static const WCHAR *strchrW(const WCHAR *str, WCHAR ch)
+vector_al_string SearchDataFiles(const char *ext, const char *subdir)
{
- for(;*str != 0;++str)
- {
- if(*str == ch)
- return str;
- }
- return NULL;
-}
+ static const int ids[2] = { CSIDL_APPDATA, CSIDL_COMMON_APPDATA };
+ static RefCount search_lock;
+ vector_al_string results = VECTOR_INIT_STATIC();
+ size_t i;
-static const WCHAR *strrchrW(const WCHAR *str, WCHAR ch)
-{
- const WCHAR *ret = NULL;
- for(;*str != 0;++str)
+ while(ATOMIC_EXCHANGE_SEQ(&search_lock, 1) == 1)
+ althrd_yield();
+
+ /* If the path is absolute, use it directly. */
+ if(isalpha(subdir[0]) && subdir[1] == ':' && is_slash(subdir[2]))
{
- if(*str == ch)
- ret = str;
+ al_string path = AL_STRING_INIT_STATIC();
+ alstr_copy_cstr(&path, subdir);
+#define FIX_SLASH(i) do { if(*(i) == '/') *(i) = '\\'; } while(0)
+ VECTOR_FOR_EACH(char, path, FIX_SLASH);
+#undef FIX_SLASH
+
+ DirectorySearch(alstr_get_cstr(path), ext, &results);
+
+ alstr_reset(&path);
}
- return ret;
-}
+ else if(subdir[0] == '\\' && subdir[1] == '\\' && subdir[2] == '?' && subdir[3] == '\\')
+ DirectorySearch(subdir, ext, &results);
+ else
+ {
+ al_string path = AL_STRING_INIT_STATIC();
+ WCHAR *cwdbuf;
-/* Compares the filename in the find data with the match string. The match
- * string may contain the "%r" marker to signifiy a sample rate (really any
- * positive integer), or "%%" to signify a single '%'.
- */
-static int MatchFilter(const WCHAR *match, const WIN32_FIND_DATAW *fdata)
-{
- const WCHAR *name = fdata->cFileName;
- int ret = 1;
-
- do {
- const WCHAR *p = strchrW(match, '%');
- if(!p)
- ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE,
- match, -1, name, -1) == CSTR_EQUAL;
+ /* Search the app-local directory. */
+ if((cwdbuf=_wgetenv(L"ALSOFT_LOCAL_PATH")) && *cwdbuf != '\0')
+ {
+ alstr_copy_wcstr(&path, cwdbuf);
+ if(is_slash(VECTOR_BACK(path)))
+ {
+ VECTOR_POP_BACK(path);
+ *VECTOR_END(path) = 0;
+ }
+ }
+ else if(!(cwdbuf=_wgetcwd(NULL, 0)))
+ alstr_copy_cstr(&path, ".");
else
{
- int len = p-match;
- ret = lstrlenW(name) >= len;
- if(ret)
- ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE,
- match, len, name, len) == CSTR_EQUAL;
- if(ret)
+ alstr_copy_wcstr(&path, cwdbuf);
+ if(is_slash(VECTOR_BACK(path)))
{
- match += len;
- name += len;
-
- ++p;
- if(*p == 'r')
- {
- unsigned long l = 0;
- while(*name >= '0' && *name <= '9')
- {
- l = l*10 + (*name-'0');
- ++name;
- }
- ret = l > 0;
- ++p;
- }
+ VECTOR_POP_BACK(path);
+ *VECTOR_END(path) = 0;
}
+ free(cwdbuf);
}
+#define FIX_SLASH(i) do { if(*(i) == '/') *(i) = '\\'; } while(0)
+ VECTOR_FOR_EACH(char, path, FIX_SLASH);
+#undef FIX_SLASH
+ DirectorySearch(alstr_get_cstr(path), ext, &results);
- match = p;
- } while(ret && match && *match);
-
- return ret;
-}
-
-static void RecurseDirectorySearch(const char *path, const WCHAR *match, vector_al_string *results)
-{
- WIN32_FIND_DATAW fdata;
- const WCHAR *sep, *p;
- HANDLE hdl;
+ /* Search the local and global data dirs. */
+ for(i = 0;i < COUNTOF(ids);i++)
+ {
+ WCHAR buffer[MAX_PATH];
+ if(SHGetSpecialFolderPathW(NULL, buffer, ids[i], FALSE) != FALSE)
+ {
+ alstr_copy_wcstr(&path, buffer);
+ if(!is_slash(VECTOR_BACK(path)))
+ alstr_append_char(&path, '\\');
+ alstr_append_cstr(&path, subdir);
+#define FIX_SLASH(i) do { if(*(i) == '/') *(i) = '\\'; } while(0)
+ VECTOR_FOR_EACH(char, path, FIX_SLASH);
+#undef FIX_SLASH
- if(!match[0])
- return;
+ DirectorySearch(alstr_get_cstr(path), ext, &results);
+ }
+ }
- /* Find the last directory separator and the next '%' marker in the match
- * string. */
- sep = strrchrW(match, '\\');
- p = strchrW(match, '%');
+ alstr_reset(&path);
+ }
- /* If there's no separator, test the files in the specified path against
- * the match string, and add the results. */
- if(!sep)
- {
- al_string pathstr = AL_STRING_INIT_STATIC();
- WCHAR *wpath;
+ ATOMIC_STORE_SEQ(&search_lock, 0);
- TRACE("Searching %s for %ls\n", path, match);
+ return results;
+}
- al_string_append_cstr(&pathstr, path);
- al_string_append_cstr(&pathstr, "\\*.*");
- wpath = FromUTF8(al_string_get_cstr(pathstr));
- hdl = FindFirstFileW(wpath, &fdata);
- if(hdl != INVALID_HANDLE_VALUE)
- {
- do {
- if(MatchFilter(match, &fdata))
- {
- al_string str = AL_STRING_INIT_STATIC();
- al_string_copy_cstr(&str, path);
- al_string_append_char(&str, '\\');
- al_string_append_wcstr(&str, fdata.cFileName);
- TRACE("Got result %s\n", al_string_get_cstr(str));
- VECTOR_PUSH_BACK(*results, str);
- }
- } while(FindNextFileW(hdl, &fdata));
- FindClose(hdl);
- }
+struct FileMapping MapFileToMem(const char *fname)
+{
+ struct FileMapping ret = { NULL, NULL, NULL, 0 };
+ MEMORY_BASIC_INFORMATION meminfo;
+ HANDLE file, fmap;
+ WCHAR *wname;
+ void *ptr;
- free(wpath);
- al_string_deinit(&pathstr);
+ wname = FromUTF8(fname);
- return;
+ file = CreateFileW(wname, GENERIC_READ, FILE_SHARE_READ, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ if(file == INVALID_HANDLE_VALUE)
+ {
+ ERR("Failed to open %s: %lu\n", fname, GetLastError());
+ free(wname);
+ return ret;
}
+ free(wname);
+ wname = NULL;
- /* If there's no '%' marker, or it's after the final separator, append the
- * remaining directories to the path and recurse into it with the remaining
- * filename portion. */
- if(!p || p-sep >= 0)
+ fmap = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
+ if(!fmap)
{
- al_string npath = AL_STRING_INIT_STATIC();
- al_string_append_cstr(&npath, path);
- al_string_append_char(&npath, '\\');
- al_string_append_wrange(&npath, match, sep);
-
- TRACE("Recursing into %s with %ls\n", al_string_get_cstr(npath), sep+1);
- RecurseDirectorySearch(al_string_get_cstr(npath), sep+1, results);
-
- al_string_deinit(&npath);
- return;
+ ERR("Failed to create map for %s: %lu\n", fname, GetLastError());
+ CloseHandle(file);
+ return ret;
}
- /* Look for the last separator before the '%' marker, and the first
- * separator after it. */
- sep = strchrW(match, '\\');
- if(sep-p >= 0) sep = NULL;
- for(;;)
+ ptr = MapViewOfFile(fmap, FILE_MAP_READ, 0, 0, 0);
+ if(!ptr)
{
- const WCHAR *next = strchrW(sep?sep+1:match, '\\');
- if(next-p < 0)
- {
- al_string npath = AL_STRING_INIT_STATIC();
- WCHAR *nwpath, *nwmatch;
-
- /* Append up to the last directory before the one with a '%'. */
- al_string_copy_cstr(&npath, path);
- if(sep)
- {
- al_string_append_char(&npath, '\\');
- al_string_append_wrange(&npath, match, sep);
- }
- al_string_append_cstr(&npath, "\\*.*");
- nwpath = FromUTF8(al_string_get_cstr(npath));
-
- /* Take the directory name containing a '%' as a new string to
- * match against. */
- if(!sep)
- {
- nwmatch = calloc(2, next-match+1);
- memcpy(nwmatch, match, (next-match)*2);
- }
- else
- {
- nwmatch = calloc(2, next-(sep+1)+1);
- memcpy(nwmatch, sep+1, (next-(sep+1))*2);
- }
-
- /* For each matching directory name, recurse into it with the
- * remaining string. */
- TRACE("Searching %s for %ls\n", al_string_get_cstr(npath), nwmatch);
- hdl = FindFirstFileW(nwpath, &fdata);
- if(hdl != INVALID_HANDLE_VALUE)
- {
- do {
- if(MatchFilter(nwmatch, &fdata))
- {
- al_string ndir = AL_STRING_INIT_STATIC();
- al_string_copy(&ndir, npath);
- al_string_append_char(&ndir, '\\');
- al_string_append_wcstr(&ndir, fdata.cFileName);
- TRACE("Recursing %s with %ls\n", al_string_get_cstr(ndir), next+1);
- RecurseDirectorySearch(al_string_get_cstr(ndir), next+1, results);
- al_string_deinit(&ndir);
- }
- } while(FindNextFileW(hdl, &fdata));
- FindClose(hdl);
- }
+ ERR("Failed to map %s: %lu\n", fname, GetLastError());
+ CloseHandle(fmap);
+ CloseHandle(file);
+ return ret;
+ }
- free(nwmatch);
- free(nwpath);
- al_string_deinit(&npath);
- break;
- }
- sep = next;
+ if(VirtualQuery(ptr, &meminfo, sizeof(meminfo)) != sizeof(meminfo))
+ {
+ ERR("Failed to get map size for %s: %lu\n", fname, GetLastError());
+ UnmapViewOfFile(ptr);
+ CloseHandle(fmap);
+ CloseHandle(file);
+ return ret;
}
+
+ ret.file = file;
+ ret.fmap = fmap;
+ ret.ptr = ptr;
+ ret.len = meminfo.RegionSize;
+ return ret;
}
-vector_al_string SearchDataFiles(const char *match, const char *subdir)
+void UnmapFileMem(const struct FileMapping *mapping)
{
- static const int ids[2] = { CSIDL_APPDATA, CSIDL_COMMON_APPDATA };
- static RefCount search_lock;
- vector_al_string results = VECTOR_INIT_STATIC();
- WCHAR *wmatch;
- size_t i;
+ UnmapViewOfFile(mapping->ptr);
+ CloseHandle(mapping->fmap);
+ CloseHandle(mapping->file);
+}
- while(ATOMIC_EXCHANGE(uint, &search_lock, 1) == 1)
- althrd_yield();
+#else
- wmatch = FromUTF8(match);
- if(!wmatch)
- {
- ERR("Failed to convert UTF-8 filename: \"%s\"\n", match);
- return results;
- }
- for(i = 0;wmatch[i];++i)
- {
- if(wmatch[i] == '/')
- wmatch[i] = '\\';
- }
+void GetProcBinary(al_string *path, al_string *fname)
+{
+ char *pathname = NULL;
+ size_t pathlen;
- /* If the path is absolute, use it directly. */
- if(isalpha(wmatch[0]) && wmatch[1] == ':' && is_slash(wmatch[2]))
+#ifdef __FreeBSD__
+ int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
+ if(sysctl(mib, 4, NULL, &pathlen, NULL, 0) == -1)
+ WARN("Failed to sysctl kern.proc.pathname: %s\n", strerror(errno));
+ else
{
- char drv[3] = { (char)wmatch[0], ':', 0 };
- RecurseDirectorySearch(drv, wmatch+3, &results);
+ pathname = malloc(pathlen + 1);
+ sysctl(mib, 4, (void*)pathname, &pathlen, NULL, 0);
+ pathname[pathlen] = 0;
}
- else if(wmatch[0] == '\\' && wmatch[1] == '\\' && wmatch[2] == '?' && wmatch[3] == '\\')
- RecurseDirectorySearch("\\\\?", wmatch+4, &results);
- else
+#endif
+#ifdef HAVE_PROC_PIDPATH
+ if(!pathname)
{
- al_string path = AL_STRING_INIT_STATIC();
- WCHAR *cwdbuf;
+ const pid_t pid = getpid();
+ char procpath[PROC_PIDPATHINFO_MAXSIZE];
+ int ret;
- /* Search the CWD. */
- if(!(cwdbuf=_wgetcwd(NULL, 0)))
- al_string_copy_cstr(&path, ".");
+ ret = proc_pidpath(pid, procpath, sizeof(procpath));
+ if(ret < 1)
+ {
+ WARN("proc_pidpath(%d, ...) failed: %s\n", pid, strerror(errno));
+ free(pathname);
+ pathname = NULL;
+ }
else
{
- al_string_copy_wcstr(&path, cwdbuf);
- if(is_slash(VECTOR_BACK(path)))
- {
- VECTOR_POP_BACK(path);
- *VECTOR_ITER_END(path) = 0;
- }
- free(cwdbuf);
+ pathlen = strlen(procpath);
+ pathname = strdup(procpath);
}
- RecurseDirectorySearch(al_string_get_cstr(path), wmatch, &results);
+ }
+#endif
+ if(!pathname)
+ {
+ const char *selfname;
+ ssize_t len;
- /* Search the local and global data dirs. */
- for(i = 0;i < COUNTOF(ids);i++)
+ pathlen = 256;
+ pathname = malloc(pathlen);
+
+ selfname = "/proc/self/exe";
+ len = readlink(selfname, pathname, pathlen);
+ if(len == -1 && errno == ENOENT)
{
- WCHAR buffer[PATH_MAX];
- if(SHGetSpecialFolderPathW(NULL, buffer, ids[i], FALSE) != FALSE)
- {
- al_string_copy_wcstr(&path, buffer);
- if(!is_slash(VECTOR_BACK(path)))
- al_string_append_char(&path, '\\');
- al_string_append_cstr(&path, subdir);
-#define FIX_SLASH(i) do { if(*(i) == '/') *(i) = '\\'; } while(0)
- VECTOR_FOR_EACH(char, path, FIX_SLASH);
-#undef FIX_SLASH
+ selfname = "/proc/self/file";
+ len = readlink(selfname, pathname, pathlen);
+ }
+ if(len == -1 && errno == ENOENT)
+ {
+ selfname = "/proc/curproc/exe";
+ len = readlink(selfname, pathname, pathlen);
+ }
+ if(len == -1 && errno == ENOENT)
+ {
+ selfname = "/proc/curproc/file";
+ len = readlink(selfname, pathname, pathlen);
+ }
- RecurseDirectorySearch(al_string_get_cstr(path), wmatch, &results);
- }
+ while(len > 0 && (size_t)len == pathlen)
+ {
+ free(pathname);
+ pathlen <<= 1;
+ pathname = malloc(pathlen);
+ len = readlink(selfname, pathname, pathlen);
+ }
+ if(len <= 0)
+ {
+ free(pathname);
+ WARN("Failed to readlink %s: %s\n", selfname, strerror(errno));
+ return;
}
- al_string_deinit(&path);
+ pathname[len] = 0;
}
- free(wmatch);
- ATOMIC_STORE(&search_lock, 0);
+ char *sep = strrchr(pathname, '/');
+ if(sep)
+ {
+ if(path) alstr_copy_range(path, pathname, sep);
+ if(fname) alstr_copy_cstr(fname, sep+1);
+ }
+ else
+ {
+ if(path) alstr_clear(path);
+ if(fname) alstr_copy_cstr(fname, pathname);
+ }
+ free(pathname);
- return results;
+ if(path && fname)
+ TRACE("Got: %s, %s\n", alstr_get_cstr(*path), alstr_get_cstr(*fname));
+ else if(path) TRACE("Got path: %s\n", alstr_get_cstr(*path));
+ else if(fname) TRACE("Got filename: %s\n", alstr_get_cstr(*fname));
}
-#else
#ifdef HAVE_DLFCN_H
@@ -874,251 +823,108 @@ void al_print(const char *type, const char *func, const char *fmt, ...)
}
-FILE *OpenDataFile(const char *fname, const char *subdir)
+static void DirectorySearch(const char *path, const char *ext, vector_al_string *results)
{
- char buffer[PATH_MAX] = "";
- const char *str, *next;
- FILE *f;
-
- if(fname[0] == '/')
- {
- if((f=al_fopen(fname, "rb")) != NULL)
- {
- TRACE("Opened %s\n", fname);
- return f;
- }
- WARN("Could not open %s\n", fname);
- return NULL;
- }
-
- if((f=al_fopen(fname, "rb")) != NULL)
- {
- TRACE("Opened %s\n", fname);
- return f;
- }
-
- if((str=getenv("XDG_DATA_HOME")) != NULL && str[0] != '\0')
- snprintf(buffer, sizeof(buffer), "%s/%s/%s", str, subdir, fname);
- else if((str=getenv("HOME")) != NULL && str[0] != '\0')
- snprintf(buffer, sizeof(buffer), "%s/.local/share/%s/%s", str, subdir, fname);
- if(buffer[0])
- {
- if((f=al_fopen(buffer, "rb")) != NULL)
- {
- TRACE("Opened %s\n", buffer);
- return f;
- }
- }
+ size_t extlen = strlen(ext);
+ DIR *dir;
- if((str=getenv("XDG_DATA_DIRS")) == NULL || str[0] == '\0')
- str = "/usr/local/share/:/usr/share/";
-
- next = str;
- while((str=next) != NULL && str[0] != '\0')
+ TRACE("Searching %s for *%s\n", path, ext);
+ dir = opendir(path);
+ if(dir != NULL)
{
- size_t len;
- next = strchr(str, ':');
-
- if(!next)
- len = strlen(str);
- else
+ size_t base = VECTOR_SIZE(*results);
+ struct dirent *dirent;
+ while((dirent=readdir(dir)) != NULL)
{
- len = next - str;
- next++;
+ al_string str;
+ size_t len;
+ if(strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0)
+ continue;
+
+ len = strlen(dirent->d_name);
+ if(!(len > extlen))
+ continue;
+ if(strcasecmp(dirent->d_name+len-extlen, ext) != 0)
+ continue;
+
+ AL_STRING_INIT(str);
+ alstr_copy_cstr(&str, path);
+ if(VECTOR_BACK(str) != '/')
+ alstr_append_char(&str, '/');
+ alstr_append_cstr(&str, dirent->d_name);
+ TRACE("Got result %s\n", alstr_get_cstr(str));
+ VECTOR_PUSH_BACK(*results, str);
}
+ closedir(dir);
- if(len > sizeof(buffer)-1)
- len = sizeof(buffer)-1;
- strncpy(buffer, str, len);
- buffer[len] = '\0';
- snprintf(buffer+len, sizeof(buffer)-len, "/%s/%s", subdir, fname);
-
- if((f=al_fopen(buffer, "rb")) != NULL)
- {
- TRACE("Opened %s\n", buffer);
- return f;
- }
+ if(VECTOR_SIZE(*results) > base)
+ qsort(VECTOR_BEGIN(*results)+base, VECTOR_SIZE(*results)-base,
+ sizeof(VECTOR_FRONT(*results)), StringSortCompare);
}
- WARN("Could not open %s/%s\n", subdir, fname);
-
- return NULL;
-}
-
-
-static const char *MatchString;
-static int MatchFilter(const struct dirent *dir)
-{
- const char *match = MatchString;
- const char *name = dir->d_name;
- int ret = 1;
-
- do {
- const char *p = strchr(match, '%');
- if(!p)
- ret = strcmp(match, name) == 0;
- else
- {
- size_t len = p-match;
- ret = strncmp(match, name, len) == 0;
- if(ret)
- {
- match += len;
- name += len;
-
- ++p;
- if(*p == 'r')
- {
- char *end;
- ret = strtoul(name, &end, 10) > 0;
- if(ret) name = end;
- ++p;
- }
- }
- }
-
- match = p;
- } while(ret && match && *match);
-
- return ret;
}
-static void RecurseDirectorySearch(const char *path, const char *match, vector_al_string *results)
+vector_al_string SearchDataFiles(const char *ext, const char *subdir)
{
- struct dirent **namelist;
- char *sep, *p;
- int n, i;
-
- if(!match[0])
- return;
-
- sep = strrchr(match, '/');
- p = strchr(match, '%');
-
- if(!sep)
- {
- MatchString = match;
- TRACE("Searching %s for %s\n", path?path:"/", match);
- n = scandir(path?path:"/", &namelist, MatchFilter, alphasort);
- if(n >= 0)
- {
- for(i = 0;i < n;++i)
- {
- al_string str = AL_STRING_INIT_STATIC();
- if(path) al_string_copy_cstr(&str, path);
- al_string_append_char(&str, '/');
- al_string_append_cstr(&str, namelist[i]->d_name);
- TRACE("Got result %s\n", al_string_get_cstr(str));
- VECTOR_PUSH_BACK(*results, str);
- free(namelist[i]);
- }
- free(namelist);
- }
+ static RefCount search_lock;
+ vector_al_string results = VECTOR_INIT_STATIC();
- return;
- }
+ while(ATOMIC_EXCHANGE_SEQ(&search_lock, 1) == 1)
+ althrd_yield();
- if(!p || p-sep >= 0)
+ if(subdir[0] == '/')
+ DirectorySearch(subdir, ext, &results);
+ else
{
- al_string npath = AL_STRING_INIT_STATIC();
- if(path) al_string_append_cstr(&npath, path);
- al_string_append_char(&npath, '/');
- al_string_append_range(&npath, match, sep);
-
- TRACE("Recursing into %s with %s\n", al_string_get_cstr(npath), sep+1);
- RecurseDirectorySearch(al_string_get_cstr(npath), sep+1, results);
-
- al_string_deinit(&npath);
- return;
- }
+ al_string path = AL_STRING_INIT_STATIC();
+ const char *str, *next;
- sep = strchr(match, '/');
- if(sep-p >= 0) sep = NULL;
- for(;;)
- {
- char *next = strchr(sep?sep+1:match, '/');
- if(next-p < 0)
+ /* Search the app-local directory. */
+ if((str=getenv("ALSOFT_LOCAL_PATH")) && *str != '\0')
+ DirectorySearch(str, ext, &results);
+ else
{
- al_string npath = AL_STRING_INIT_STATIC();
- al_string nmatch = AL_STRING_INIT_STATIC();
-
- if(!sep)
+ size_t cwdlen = 256;
+ char *cwdbuf = malloc(cwdlen);
+ while(!getcwd(cwdbuf, cwdlen))
{
- al_string_append_cstr(&npath, path?path:"/.");
- MatchString = match;
+ free(cwdbuf);
+ cwdbuf = NULL;
+ if(errno != ERANGE)
+ break;
+ cwdlen <<= 1;
+ cwdbuf = malloc(cwdlen);
}
+ if(!cwdbuf)
+ DirectorySearch(".", ext, &results);
else
{
- if(path) al_string_append_cstr(&npath, path);
- al_string_append_char(&npath, '/');
- al_string_append_range(&npath, match, sep);
-
- al_string_append_range(&nmatch, sep+1, next);
- MatchString = al_string_get_cstr(nmatch);
- }
-
- TRACE("Searching %s for %s\n", al_string_get_cstr(npath), MatchString);
- n = scandir(al_string_get_cstr(npath), &namelist, MatchFilter, alphasort);
- if(n >= 0)
- {
- al_string ndir = AL_STRING_INIT_STATIC();
- for(i = 0;i < n;++i)
- {
- al_string_copy(&ndir, npath);
- al_string_append_char(&ndir, '/');
- al_string_append_cstr(&ndir, namelist[i]->d_name);
- free(namelist[i]);
- TRACE("Recursing %s with %s\n", al_string_get_cstr(ndir), next+1);
- RecurseDirectorySearch(al_string_get_cstr(ndir), next+1, results);
- }
- al_string_deinit(&ndir);
- free(namelist);
+ DirectorySearch(cwdbuf, ext, &results);
+ free(cwdbuf);
+ cwdbuf = NULL;
}
-
- al_string_deinit(&nmatch);
- al_string_deinit(&npath);
- break;
}
- sep = next;
- }
-}
-
-vector_al_string SearchDataFiles(const char *match, const char *subdir)
-{
- static RefCount search_lock;
- vector_al_string results = VECTOR_INIT_STATIC();
-
- while(ATOMIC_EXCHANGE(uint, &search_lock, 1) == 1)
- althrd_yield();
-
- if(match[0] == '/')
- RecurseDirectorySearch(NULL, match+1, &results);
- else
- {
- al_string path = AL_STRING_INIT_STATIC();
- const char *str, *next;
- char cwdbuf[PATH_MAX];
-
- // Search CWD
- if(!getcwd(cwdbuf, sizeof(cwdbuf)))
- strcpy(cwdbuf, ".");
- RecurseDirectorySearch(cwdbuf, match, &results);
-
// Search local data dir
if((str=getenv("XDG_DATA_HOME")) != NULL && str[0] != '\0')
{
- al_string_append_cstr(&path, str);
- al_string_append_char(&path, '/');
- al_string_append_cstr(&path, subdir);
+ alstr_copy_cstr(&path, str);
+ if(VECTOR_BACK(path) != '/')
+ alstr_append_char(&path, '/');
+ alstr_append_cstr(&path, subdir);
+ DirectorySearch(alstr_get_cstr(path), ext, &results);
}
else if((str=getenv("HOME")) != NULL && str[0] != '\0')
{
- al_string_append_cstr(&path, str);
- al_string_append_cstr(&path, "/.local/share/");
- al_string_append_cstr(&path, subdir);
+ alstr_copy_cstr(&path, str);
+ if(VECTOR_BACK(path) == '/')
+ {
+ VECTOR_POP_BACK(path);
+ *VECTOR_END(path) = 0;
+ }
+ alstr_append_cstr(&path, "/.local/share/");
+ alstr_append_cstr(&path, subdir);
+ DirectorySearch(alstr_get_cstr(path), ext, &results);
}
- if(!al_string_empty(path))
- RecurseDirectorySearch(al_string_get_cstr(path), match, &results);
// Search global data dirs
if((str=getenv("XDG_DATA_DIRS")) == NULL || str[0] == '\0')
@@ -1129,30 +935,71 @@ vector_al_string SearchDataFiles(const char *match, const char *subdir)
{
next = strchr(str, ':');
if(!next)
- al_string_copy_cstr(&path, str);
+ alstr_copy_cstr(&path, str);
else
{
- al_string_clear(&path);
- al_string_append_range(&path, str, next);
+ alstr_copy_range(&path, str, next);
++next;
}
- if(!al_string_empty(path))
+ if(!alstr_empty(path))
{
- al_string_append_char(&path, '/');
- al_string_append_cstr(&path, subdir);
+ if(VECTOR_BACK(path) != '/')
+ alstr_append_char(&path, '/');
+ alstr_append_cstr(&path, subdir);
- RecurseDirectorySearch(al_string_get_cstr(path), match, &results);
+ DirectorySearch(alstr_get_cstr(path), ext, &results);
}
}
- al_string_deinit(&path);
+ alstr_reset(&path);
}
- ATOMIC_STORE(&search_lock, 0);
+ ATOMIC_STORE_SEQ(&search_lock, 0);
return results;
}
+
+struct FileMapping MapFileToMem(const char *fname)
+{
+ struct FileMapping ret = { -1, NULL, 0 };
+ struct stat sbuf;
+ void *ptr;
+ int fd;
+
+ fd = open(fname, O_RDONLY, 0);
+ if(fd == -1)
+ {
+ ERR("Failed to open %s: (%d) %s\n", fname, errno, strerror(errno));
+ return ret;
+ }
+ if(fstat(fd, &sbuf) == -1)
+ {
+ ERR("Failed to stat %s: (%d) %s\n", fname, errno, strerror(errno));
+ close(fd);
+ return ret;
+ }
+
+ ptr = mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+ if(ptr == MAP_FAILED)
+ {
+ ERR("Failed to map %s: (%d) %s\n", fname, errno, strerror(errno));
+ close(fd);
+ return ret;
+ }
+
+ ret.fd = fd;
+ ret.ptr = ptr;
+ ret.len = sbuf.st_size;
+ return ret;
+}
+
+void UnmapFileMem(const struct FileMapping *mapping)
+{
+ munmap(mapping->ptr, mapping->len);
+ close(mapping->fd);
+}
+
#endif
@@ -1181,93 +1028,26 @@ void SetRTPriority(void)
}
-ALboolean vector_reserve(char *ptr, size_t base_size, size_t obj_size, size_t obj_count, ALboolean exact)
-{
- vector_ *vecptr = (vector_*)ptr;
- if((*vecptr ? (*vecptr)->Capacity : 0) < obj_count)
- {
- size_t old_size = (*vecptr ? (*vecptr)->Size : 0);
- void *temp;
-
- /* Use the next power-of-2 size if we don't need to allocate the exact
- * amount. This is preferred when regularly increasing the vector since
- * it means fewer reallocations. Though it means it also wastes some
- * memory. */
- if(exact == AL_FALSE && obj_count < INT_MAX)
- obj_count = NextPowerOf2((ALuint)obj_count);
-
- /* Need to be explicit with the caller type's base size, because it
- * could have extra padding before the start of the array (that is,
- * sizeof(*vector_) may not equal base_size). */
- temp = realloc(*vecptr, base_size + obj_size*obj_count);
- if(temp == NULL) return AL_FALSE;
-
- *vecptr = temp;
- (*vecptr)->Capacity = obj_count;
- (*vecptr)->Size = old_size;
- }
- return AL_TRUE;
-}
-
-ALboolean vector_resize(char *ptr, size_t base_size, size_t obj_size, size_t obj_count)
-{
- vector_ *vecptr = (vector_*)ptr;
- if(*vecptr || obj_count > 0)
- {
- if(!vector_reserve((char*)vecptr, base_size, obj_size, obj_count, AL_TRUE))
- return AL_FALSE;
- (*vecptr)->Size = obj_count;
- }
- return AL_TRUE;
-}
+extern inline void alstr_reset(al_string *str);
+extern inline size_t alstr_length(const_al_string str);
+extern inline ALboolean alstr_empty(const_al_string str);
+extern inline const al_string_char_type *alstr_get_cstr(const_al_string str);
-ALboolean vector_insert(char *ptr, size_t base_size, size_t obj_size, void *ins_pos, const void *datstart, const void *datend)
+void alstr_clear(al_string *str)
{
- vector_ *vecptr = (vector_*)ptr;
- if(datstart != datend)
+ if(!alstr_empty(*str))
{
- ptrdiff_t ins_elem = (*vecptr ? ((char*)ins_pos - ((char*)(*vecptr) + base_size)) :
- ((char*)ins_pos - (char*)NULL)) /
- obj_size;
- ptrdiff_t numins = ((const char*)datend - (const char*)datstart) / obj_size;
-
- assert(numins > 0);
- if((size_t)numins + VECTOR_SIZE(*vecptr) < (size_t)numins ||
- !vector_reserve((char*)vecptr, base_size, obj_size, VECTOR_SIZE(*vecptr)+numins, AL_TRUE))
- return AL_FALSE;
-
- /* NOTE: ins_pos may have been invalidated if *vecptr moved. Use ins_elem instead. */
- if((size_t)ins_elem < (*vecptr)->Size)
- {
- memmove((char*)(*vecptr) + base_size + ((ins_elem+numins)*obj_size),
- (char*)(*vecptr) + base_size + ((ins_elem )*obj_size),
- ((*vecptr)->Size-ins_elem)*obj_size);
- }
- memcpy((char*)(*vecptr) + base_size + (ins_elem*obj_size),
- datstart, numins*obj_size);
- (*vecptr)->Size += numins;
+ /* Reserve one more character than the total size of the string. This
+ * is to ensure we have space to add a null terminator in the string
+ * data so it can be used as a C-style string.
+ */
+ VECTOR_RESIZE(*str, 0, 1);
+ VECTOR_ELEM(*str, 0) = 0;
}
- return AL_TRUE;
-}
-
-
-extern inline void al_string_deinit(al_string *str);
-extern inline size_t al_string_length(const_al_string str);
-extern inline ALboolean al_string_empty(const_al_string str);
-extern inline const al_string_char_type *al_string_get_cstr(const_al_string str);
-
-void al_string_clear(al_string *str)
-{
- /* Reserve one more character than the total size of the string. This is to
- * ensure we have space to add a null terminator in the string data so it
- * can be used as a C-style string. */
- VECTOR_RESERVE(*str, 1);
- VECTOR_RESIZE(*str, 0);
- *VECTOR_ITER_END(*str) = 0;
}
-static inline int al_string_compare(const al_string_char_type *str1, size_t str1len,
- const al_string_char_type *str2, size_t str2len)
+static inline int alstr_compare(const al_string_char_type *str1, size_t str1len,
+ const al_string_char_type *str2, size_t str2len)
{
size_t complen = (str1len < str2len) ? str1len : str2len;
int ret = memcmp(str1, str2, complen);
@@ -1278,99 +1058,132 @@ static inline int al_string_compare(const al_string_char_type *str1, size_t str1
}
return ret;
}
-int al_string_cmp(const_al_string str1, const_al_string str2)
+int alstr_cmp(const_al_string str1, const_al_string str2)
{
- return al_string_compare(&VECTOR_FRONT(str1), al_string_length(str1),
- &VECTOR_FRONT(str2), al_string_length(str2));
+ return alstr_compare(&VECTOR_FRONT(str1), alstr_length(str1),
+ &VECTOR_FRONT(str2), alstr_length(str2));
}
-int al_string_cmp_cstr(const_al_string str1, const al_string_char_type *str2)
+int alstr_cmp_cstr(const_al_string str1, const al_string_char_type *str2)
{
- return al_string_compare(&VECTOR_FRONT(str1), al_string_length(str1),
- str2, strlen(str2));
+ return alstr_compare(&VECTOR_FRONT(str1), alstr_length(str1),
+ str2, strlen(str2));
}
-void al_string_copy(al_string *str, const_al_string from)
+void alstr_copy(al_string *str, const_al_string from)
{
- size_t len = al_string_length(from);
- VECTOR_RESERVE(*str, len+1);
- VECTOR_RESIZE(*str, 0);
- VECTOR_INSERT(*str, VECTOR_ITER_END(*str), VECTOR_ITER_BEGIN(from), VECTOR_ITER_BEGIN(from)+len);
- *VECTOR_ITER_END(*str) = 0;
+ size_t len = alstr_length(from);
+ size_t i;
+
+ VECTOR_RESIZE(*str, len, len+1);
+ for(i = 0;i < len;i++)
+ VECTOR_ELEM(*str, i) = VECTOR_ELEM(from, i);
+ VECTOR_ELEM(*str, i) = 0;
}
-void al_string_copy_cstr(al_string *str, const al_string_char_type *from)
+void alstr_copy_cstr(al_string *str, const al_string_char_type *from)
{
size_t len = strlen(from);
- VECTOR_RESERVE(*str, len+1);
- VECTOR_RESIZE(*str, 0);
- VECTOR_INSERT(*str, VECTOR_ITER_END(*str), from, from+len);
- *VECTOR_ITER_END(*str) = 0;
+ size_t i;
+
+ VECTOR_RESIZE(*str, len, len+1);
+ for(i = 0;i < len;i++)
+ VECTOR_ELEM(*str, i) = from[i];
+ VECTOR_ELEM(*str, i) = 0;
+}
+
+void alstr_copy_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to)
+{
+ size_t len = to - from;
+ size_t i;
+
+ VECTOR_RESIZE(*str, len, len+1);
+ for(i = 0;i < len;i++)
+ VECTOR_ELEM(*str, i) = from[i];
+ VECTOR_ELEM(*str, i) = 0;
}
-void al_string_append_char(al_string *str, const al_string_char_type c)
+void alstr_append_char(al_string *str, const al_string_char_type c)
{
- VECTOR_RESERVE(*str, al_string_length(*str)+2);
- VECTOR_PUSH_BACK(*str, c);
- *VECTOR_ITER_END(*str) = 0;
+ size_t len = alstr_length(*str);
+ VECTOR_RESIZE(*str, len+1, len+2);
+ VECTOR_BACK(*str) = c;
+ VECTOR_ELEM(*str, len+1) = 0;
}
-void al_string_append_cstr(al_string *str, const al_string_char_type *from)
+void alstr_append_cstr(al_string *str, const al_string_char_type *from)
{
size_t len = strlen(from);
if(len != 0)
{
- VECTOR_RESERVE(*str, al_string_length(*str)+len+1);
- VECTOR_INSERT(*str, VECTOR_ITER_END(*str), from, from+len);
- *VECTOR_ITER_END(*str) = 0;
+ size_t base = alstr_length(*str);
+ size_t i;
+
+ VECTOR_RESIZE(*str, base+len, base+len+1);
+ for(i = 0;i < len;i++)
+ VECTOR_ELEM(*str, base+i) = from[i];
+ VECTOR_ELEM(*str, base+i) = 0;
}
}
-void al_string_append_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to)
+void alstr_append_range(al_string *str, const al_string_char_type *from, const al_string_char_type *to)
{
- if(to != from)
+ size_t len = to - from;
+ if(len != 0)
{
- VECTOR_RESERVE(*str, al_string_length(*str)+(to-from)+1);
- VECTOR_INSERT(*str, VECTOR_ITER_END(*str), from, to);
- *VECTOR_ITER_END(*str) = 0;
+ size_t base = alstr_length(*str);
+ size_t i;
+
+ VECTOR_RESIZE(*str, base+len, base+len+1);
+ for(i = 0;i < len;i++)
+ VECTOR_ELEM(*str, base+i) = from[i];
+ VECTOR_ELEM(*str, base+i) = 0;
}
}
#ifdef _WIN32
-void al_string_copy_wcstr(al_string *str, const wchar_t *from)
+void alstr_copy_wcstr(al_string *str, const wchar_t *from)
{
int len;
if((len=WideCharToMultiByte(CP_UTF8, 0, from, -1, NULL, 0, NULL, NULL)) > 0)
{
- VECTOR_RESERVE(*str, len);
- VECTOR_RESIZE(*str, len-1);
+ VECTOR_RESIZE(*str, len-1, len);
WideCharToMultiByte(CP_UTF8, 0, from, -1, &VECTOR_FRONT(*str), len, NULL, NULL);
- *VECTOR_ITER_END(*str) = 0;
+ VECTOR_ELEM(*str, len-1) = 0;
}
}
-void al_string_append_wcstr(al_string *str, const wchar_t *from)
+void alstr_append_wcstr(al_string *str, const wchar_t *from)
{
int len;
if((len=WideCharToMultiByte(CP_UTF8, 0, from, -1, NULL, 0, NULL, NULL)) > 0)
{
- size_t strlen = al_string_length(*str);
- VECTOR_RESERVE(*str, strlen+len);
- VECTOR_RESIZE(*str, strlen+len-1);
- WideCharToMultiByte(CP_UTF8, 0, from, -1, &VECTOR_FRONT(*str) + strlen, len, NULL, NULL);
- *VECTOR_ITER_END(*str) = 0;
+ size_t base = alstr_length(*str);
+ VECTOR_RESIZE(*str, base+len-1, base+len);
+ WideCharToMultiByte(CP_UTF8, 0, from, -1, &VECTOR_ELEM(*str, base), len, NULL, NULL);
+ VECTOR_ELEM(*str, base+len-1) = 0;
+ }
+}
+
+void alstr_copy_wrange(al_string *str, const wchar_t *from, const wchar_t *to)
+{
+ int len;
+ if((len=WideCharToMultiByte(CP_UTF8, 0, from, (int)(to-from), NULL, 0, NULL, NULL)) > 0)
+ {
+ VECTOR_RESIZE(*str, len, len+1);
+ WideCharToMultiByte(CP_UTF8, 0, from, (int)(to-from), &VECTOR_FRONT(*str), len+1, NULL, NULL);
+ VECTOR_ELEM(*str, len) = 0;
}
}
-void al_string_append_wrange(al_string *str, const wchar_t *from, const wchar_t *to)
+void alstr_append_wrange(al_string *str, const wchar_t *from, const wchar_t *to)
{
int len;
if((len=WideCharToMultiByte(CP_UTF8, 0, from, (int)(to-from), NULL, 0, NULL, NULL)) > 0)
{
- size_t strlen = al_string_length(*str);
- VECTOR_RESERVE(*str, strlen+len+1);
- VECTOR_RESIZE(*str, strlen+len);
- WideCharToMultiByte(CP_UTF8, 0, from, (int)(to-from), &VECTOR_FRONT(*str) + strlen, len+1, NULL, NULL);
- *VECTOR_ITER_END(*str) = 0;
+ size_t base = alstr_length(*str);
+ VECTOR_RESIZE(*str, base+len, base+len+1);
+ WideCharToMultiByte(CP_UTF8, 0, from, (int)(to-from), &VECTOR_ELEM(*str, base), len+1, NULL, NULL);
+ VECTOR_ELEM(*str, base+len) = 0;
}
}
#endif
diff --git a/Alc/hrtf.c b/Alc/hrtf.c
index 71dd9d79..ddbd3a28 100644
--- a/Alc/hrtf.c
+++ b/Alc/hrtf.c
@@ -29,423 +29,460 @@
#include "alSource.h"
#include "alu.h"
#include "hrtf.h"
+#include "alconfig.h"
+#include "filters/splitter.h"
#include "compat.h"
+#include "almalloc.h"
/* Current data set limits defined by the makehrtf utility. */
#define MIN_IR_SIZE (8)
-#define MAX_IR_SIZE (128)
+#define MAX_IR_SIZE (512)
#define MOD_IR_SIZE (8)
+#define MIN_FD_COUNT (1)
+#define MAX_FD_COUNT (16)
+
+#define MIN_FD_DISTANCE (50)
+#define MAX_FD_DISTANCE (2500)
+
#define MIN_EV_COUNT (5)
#define MAX_EV_COUNT (128)
#define MIN_AZ_COUNT (1)
#define MAX_AZ_COUNT (128)
-struct Hrtf {
- ALuint sampleRate;
- ALuint irSize;
- ALubyte evCount;
+#define MAX_HRIR_DELAY (HRTF_HISTORY_LENGTH-1)
- const ALubyte *azCount;
- const ALushort *evOffset;
- const ALshort *coeffs;
- const ALubyte *delays;
-
- al_string filename;
- struct Hrtf *next;
+struct HrtfEntry {
+ struct HrtfEntry *next;
+ struct Hrtf *handle;
+ char filename[];
};
static const ALchar magicMarker00[8] = "MinPHR00";
static const ALchar magicMarker01[8] = "MinPHR01";
+static const ALchar magicMarker02[8] = "MinPHR02";
/* First value for pass-through coefficients (remaining are 0), used for omni-
* directional sounds. */
-static const ALfloat PassthruCoeff = 32767.0f * 0.707106781187f/*sqrt(0.5)*/;
+static const ALfloat PassthruCoeff = 0.707106781187f/*sqrt(0.5)*/;
+
+static ATOMIC_FLAG LoadedHrtfLock = ATOMIC_FLAG_INIT;
+static struct HrtfEntry *LoadedHrtfs = NULL;
-static struct Hrtf *LoadedHrtfs = NULL;
-/* Calculate the elevation indices given the polar elevation in radians.
- * This will return two indices between 0 and (evcount - 1) and an
- * interpolation factor between 0.0 and 1.0.
+/* Calculate the elevation index given the polar elevation in radians. This
+ * will return an index between 0 and (evcount - 1).
*/
-static void CalcEvIndices(ALuint evcount, ALfloat ev, ALuint *evidx, ALfloat *evmu)
+static ALsizei CalcEvIndex(ALsizei evcount, ALfloat ev, ALfloat *mu)
{
- ev = (F_PI_2 + ev) * (evcount-1) / F_PI;
- evidx[0] = fastf2u(ev);
- evidx[1] = minu(evidx[0] + 1, evcount-1);
- *evmu = ev - evidx[0];
+ ALsizei idx;
+ ev = (F_PI_2+ev) * (evcount-1) / F_PI;
+ idx = float2int(ev);
+
+ *mu = ev - idx;
+ return mini(idx, evcount-1);
}
-/* Calculate the azimuth indices given the polar azimuth in radians. This
- * will return two indices between 0 and (azcount - 1) and an interpolation
- * factor between 0.0 and 1.0.
+/* Calculate the azimuth index given the polar azimuth in radians. This will
+ * return an index between 0 and (azcount - 1).
*/
-static void CalcAzIndices(ALuint azcount, ALfloat az, ALuint *azidx, ALfloat *azmu)
+static ALsizei CalcAzIndex(ALsizei azcount, ALfloat az, ALfloat *mu)
{
- az = (F_TAU + az) * azcount / F_TAU;
- azidx[0] = fastf2u(az) % azcount;
- azidx[1] = (azidx[0] + 1) % azcount;
- *azmu = az - floorf(az);
+ ALsizei idx;
+ az = (F_TAU+az) * azcount / F_TAU;
+
+ idx = float2int(az);
+ *mu = az - idx;
+ return idx % azcount;
}
-/* Calculates static HRIR coefficients and delays for the given polar
- * elevation and azimuth in radians. Linear interpolation is used to
- * increase the apparent resolution of the HRIR data set. The coefficients
- * are also normalized and attenuated by the specified gain.
+/* Calculates static HRIR coefficients and delays for the given polar elevation
+ * and azimuth in radians. The coefficients are normalized.
*/
-void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat dirfact, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays)
+void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread,
+ ALfloat (*restrict coeffs)[2], ALsizei *delays)
{
- ALuint evidx[2], lidx[4], ridx[4];
- ALfloat mu[3], blend[4];
- ALuint i;
-
- /* Claculate elevation indices and interpolation factor. */
- CalcEvIndices(Hrtf->evCount, elevation, evidx, &mu[2]);
-
- for(i = 0;i < 2;i++)
+ ALsizei evidx, azidx, idx[4];
+ ALsizei evoffset;
+ ALfloat emu, amu[2];
+ ALfloat blend[4];
+ ALfloat dirfact;
+ ALsizei i, c;
+
+ dirfact = 1.0f - (spread / F_TAU);
+
+ /* Claculate the lower elevation index. */
+ evidx = CalcEvIndex(Hrtf->evCount, elevation, &emu);
+ evoffset = Hrtf->evOffset[evidx];
+
+ /* Calculate lower azimuth index. */
+ azidx= CalcAzIndex(Hrtf->azCount[evidx], azimuth, &amu[0]);
+
+ /* Calculate the lower HRIR indices. */
+ idx[0] = evoffset + azidx;
+ idx[1] = evoffset + ((azidx+1) % Hrtf->azCount[evidx]);
+ if(evidx < Hrtf->evCount-1)
{
- ALuint azcount = Hrtf->azCount[evidx[i]];
- ALuint evoffset = Hrtf->evOffset[evidx[i]];
- ALuint azidx[2];
+ /* Increment elevation to the next (upper) index. */
+ evidx++;
+ evoffset = Hrtf->evOffset[evidx];
- /* Calculate azimuth indices and interpolation factor for this elevation. */
- CalcAzIndices(azcount, azimuth, azidx, &mu[i]);
+ /* Calculate upper azimuth index. */
+ azidx = CalcAzIndex(Hrtf->azCount[evidx], azimuth, &amu[1]);
- /* Calculate a set of linear HRIR indices for left and right channels. */
- lidx[i*2 + 0] = evoffset + azidx[0];
- lidx[i*2 + 1] = evoffset + azidx[1];
- ridx[i*2 + 0] = evoffset + ((azcount-azidx[0]) % azcount);
- ridx[i*2 + 1] = evoffset + ((azcount-azidx[1]) % azcount);
+ /* Calculate the upper HRIR indices. */
+ idx[2] = evoffset + azidx;
+ idx[3] = evoffset + ((azidx+1) % Hrtf->azCount[evidx]);
+ }
+ else
+ {
+ /* If the lower elevation is the top index, the upper elevation is the
+ * same as the lower.
+ */
+ amu[1] = amu[0];
+ idx[2] = idx[0];
+ idx[3] = idx[1];
}
- /* Calculate 4 blending weights for 2D bilinear interpolation. */
- blend[0] = (1.0f-mu[0]) * (1.0f-mu[2]);
- blend[1] = ( mu[0]) * (1.0f-mu[2]);
- blend[2] = (1.0f-mu[1]) * ( mu[2]);
- blend[3] = ( mu[1]) * ( mu[2]);
-
- /* Calculate the HRIR delays using linear interpolation. */
- delays[0] = fastf2u((Hrtf->delays[lidx[0]]*blend[0] + Hrtf->delays[lidx[1]]*blend[1] +
- Hrtf->delays[lidx[2]]*blend[2] + Hrtf->delays[lidx[3]]*blend[3]) *
- dirfact + 0.5f) << HRTFDELAY_BITS;
- delays[1] = fastf2u((Hrtf->delays[ridx[0]]*blend[0] + Hrtf->delays[ridx[1]]*blend[1] +
- Hrtf->delays[ridx[2]]*blend[2] + Hrtf->delays[ridx[3]]*blend[3]) *
- dirfact + 0.5f) << HRTFDELAY_BITS;
+ /* Calculate bilinear blending weights, attenuated according to the
+ * directional panning factor.
+ */
+ blend[0] = (1.0f-emu) * (1.0f-amu[0]) * dirfact;
+ blend[1] = (1.0f-emu) * ( amu[0]) * dirfact;
+ blend[2] = ( emu) * (1.0f-amu[1]) * dirfact;
+ blend[3] = ( emu) * ( amu[1]) * dirfact;
+
+ /* Calculate the blended HRIR delays. */
+ delays[0] = fastf2i(
+ Hrtf->delays[idx[0]][0]*blend[0] + Hrtf->delays[idx[1]][0]*blend[1] +
+ Hrtf->delays[idx[2]][0]*blend[2] + Hrtf->delays[idx[3]][0]*blend[3]
+ );
+ delays[1] = fastf2i(
+ Hrtf->delays[idx[0]][1]*blend[0] + Hrtf->delays[idx[1]][1]*blend[1] +
+ Hrtf->delays[idx[2]][1]*blend[2] + Hrtf->delays[idx[3]][1]*blend[3]
+ );
/* Calculate the sample offsets for the HRIR indices. */
- lidx[0] *= Hrtf->irSize;
- lidx[1] *= Hrtf->irSize;
- lidx[2] *= Hrtf->irSize;
- lidx[3] *= Hrtf->irSize;
- ridx[0] *= Hrtf->irSize;
- ridx[1] *= Hrtf->irSize;
- ridx[2] *= Hrtf->irSize;
- ridx[3] *= Hrtf->irSize;
-
- /* Calculate the normalized and attenuated HRIR coefficients using linear
- * interpolation when there is enough gain to warrant it. Zero the
- * coefficients if gain is too low.
- */
- if(gain > 0.0001f)
+ idx[0] *= Hrtf->irSize;
+ idx[1] *= Hrtf->irSize;
+ idx[2] *= Hrtf->irSize;
+ idx[3] *= Hrtf->irSize;
+
+ ASSUME(Hrtf->irSize >= MIN_IR_SIZE && (Hrtf->irSize%MOD_IR_SIZE) == 0);
+ coeffs = ASSUME_ALIGNED(coeffs, 16);
+ /* Calculate the blended HRIR coefficients. */
+ coeffs[0][0] = PassthruCoeff * (1.0f-dirfact);
+ coeffs[0][1] = PassthruCoeff * (1.0f-dirfact);
+ for(i = 1;i < Hrtf->irSize;i++)
{
- ALfloat c;
-
- i = 0;
- c = (Hrtf->coeffs[lidx[0]+i]*blend[0] + Hrtf->coeffs[lidx[1]+i]*blend[1] +
- Hrtf->coeffs[lidx[2]+i]*blend[2] + Hrtf->coeffs[lidx[3]+i]*blend[3]);
- coeffs[i][0] = lerp(PassthruCoeff, c, dirfact) * gain * (1.0f/32767.0f);
- c = (Hrtf->coeffs[ridx[0]+i]*blend[0] + Hrtf->coeffs[ridx[1]+i]*blend[1] +
- Hrtf->coeffs[ridx[2]+i]*blend[2] + Hrtf->coeffs[ridx[3]+i]*blend[3]);
- coeffs[i][1] = lerp(PassthruCoeff, c, dirfact) * gain * (1.0f/32767.0f);
-
- for(i = 1;i < Hrtf->irSize;i++)
- {
- c = (Hrtf->coeffs[lidx[0]+i]*blend[0] + Hrtf->coeffs[lidx[1]+i]*blend[1] +
- Hrtf->coeffs[lidx[2]+i]*blend[2] + Hrtf->coeffs[lidx[3]+i]*blend[3]);
- coeffs[i][0] = lerp(0.0f, c, dirfact) * gain * (1.0f/32767.0f);
- c = (Hrtf->coeffs[ridx[0]+i]*blend[0] + Hrtf->coeffs[ridx[1]+i]*blend[1] +
- Hrtf->coeffs[ridx[2]+i]*blend[2] + Hrtf->coeffs[ridx[3]+i]*blend[3]);
- coeffs[i][1] = lerp(0.0f, c, dirfact) * gain * (1.0f/32767.0f);
- }
+ coeffs[i][0] = 0.0f;
+ coeffs[i][1] = 0.0f;
}
- else
+ for(c = 0;c < 4;c++)
{
+ const ALfloat (*restrict srccoeffs)[2] = ASSUME_ALIGNED(Hrtf->coeffs+idx[c], 16);
for(i = 0;i < Hrtf->irSize;i++)
{
- coeffs[i][0] = 0.0f;
- coeffs[i][1] = 0.0f;
+ coeffs[i][0] += srccoeffs[i][0] * blend[c];
+ coeffs[i][1] += srccoeffs[i][1] * blend[c];
}
}
}
-/* Calculates the moving HRIR target coefficients, target delays, and
- * stepping values for the given polar elevation and azimuth in radians.
- * Linear interpolation is used to increase the apparent resolution of the
- * HRIR data set. The coefficients are also normalized and attenuated by the
- * specified gain. Stepping resolution and count is determined using the
- * given delta factor between 0.0 and 1.0.
- */
-ALuint GetMovingHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat dirfact, ALfloat gain, ALfloat delta, ALint counter, ALfloat (*coeffs)[2], ALuint *delays, ALfloat (*coeffStep)[2], ALint *delayStep)
-{
- ALuint evidx[2], lidx[4], ridx[4];
- ALfloat mu[3], blend[4];
- ALfloat left, right;
- ALfloat steps;
- ALuint i;
- /* Claculate elevation indices and interpolation factor. */
- CalcEvIndices(Hrtf->evCount, elevation, evidx, &mu[2]);
-
- for(i = 0;i < 2;i++)
+void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei NumChannels, const struct AngularPoint *AmbiPoints, const ALfloat (*restrict AmbiMatrix)[MAX_AMBI_COEFFS], ALsizei AmbiCount, const ALfloat *restrict AmbiOrderHFGain)
+{
+/* Set this to 2 for dual-band HRTF processing. May require a higher quality
+ * band-splitter, or better calculation of the new IR length to deal with the
+ * tail generated by the filter.
+ */
+#define NUM_BANDS 2
+ BandSplitter splitter;
+ ALdouble (*tmpres)[HRIR_LENGTH][2];
+ ALsizei *restrict idx;
+ ALsizei min_delay = HRTF_HISTORY_LENGTH;
+ ALsizei max_delay = 0;
+ ALfloat temps[3][HRIR_LENGTH];
+ ALsizei max_length;
+ ALsizei i, c, b;
+
+ idx = al_calloc(DEF_ALIGN, AmbiCount*sizeof(*idx));
+
+ for(c = 0;c < AmbiCount;c++)
{
- ALuint azcount = Hrtf->azCount[evidx[i]];
- ALuint evoffset = Hrtf->evOffset[evidx[i]];
- ALuint azidx[2];
+ ALuint evidx, azidx;
+ ALuint evoffset;
+ ALuint azcount;
- /* Calculate azimuth indices and interpolation factor for this elevation. */
- CalcAzIndices(azcount, azimuth, azidx, &mu[i]);
+ /* Calculate elevation index. */
+ evidx = (ALsizei)((F_PI_2+AmbiPoints[c].Elev) * (Hrtf->evCount-1) / F_PI + 0.5f);
+ evidx = clampi(evidx, 0, Hrtf->evCount-1);
- /* Calculate a set of linear HRIR indices for left and right channels. */
- lidx[i*2 + 0] = evoffset + azidx[0];
- lidx[i*2 + 1] = evoffset + azidx[1];
- ridx[i*2 + 0] = evoffset + ((azcount-azidx[0]) % azcount);
- ridx[i*2 + 1] = evoffset + ((azcount-azidx[1]) % azcount);
- }
-
- // Calculate the stepping parameters.
- steps = maxf(floorf(delta*Hrtf->sampleRate + 0.5f), 1.0f);
- delta = 1.0f / steps;
+ azcount = Hrtf->azCount[evidx];
+ evoffset = Hrtf->evOffset[evidx];
- /* Calculate 4 blending weights for 2D bilinear interpolation. */
- blend[0] = (1.0f-mu[0]) * (1.0f-mu[2]);
- blend[1] = ( mu[0]) * (1.0f-mu[2]);
- blend[2] = (1.0f-mu[1]) * ( mu[2]);
- blend[3] = ( mu[1]) * ( mu[2]);
+ /* Calculate azimuth index for this elevation. */
+ azidx = (ALsizei)((F_TAU+AmbiPoints[c].Azim) * azcount / F_TAU + 0.5f) % azcount;
- /* Calculate the HRIR delays using linear interpolation. Then calculate
- * the delay stepping values using the target and previous running
- * delays.
- */
- left = (ALfloat)(delays[0] - (delayStep[0] * counter));
- right = (ALfloat)(delays[1] - (delayStep[1] * counter));
+ /* Calculate indices for left and right channels. */
+ idx[c] = evoffset + azidx;
- delays[0] = fastf2u((Hrtf->delays[lidx[0]]*blend[0] + Hrtf->delays[lidx[1]]*blend[1] +
- Hrtf->delays[lidx[2]]*blend[2] + Hrtf->delays[lidx[3]]*blend[3]) *
- dirfact + 0.5f) << HRTFDELAY_BITS;
- delays[1] = fastf2u((Hrtf->delays[ridx[0]]*blend[0] + Hrtf->delays[ridx[1]]*blend[1] +
- Hrtf->delays[ridx[2]]*blend[2] + Hrtf->delays[ridx[3]]*blend[3]) *
- dirfact + 0.5f) << HRTFDELAY_BITS;
+ min_delay = mini(min_delay, mini(Hrtf->delays[idx[c]][0], Hrtf->delays[idx[c]][1]));
+ max_delay = maxi(max_delay, maxi(Hrtf->delays[idx[c]][0], Hrtf->delays[idx[c]][1]));
+ }
- delayStep[0] = fastf2i(delta * (delays[0] - left));
- delayStep[1] = fastf2i(delta * (delays[1] - right));
+ tmpres = al_calloc(16, NumChannels * sizeof(*tmpres));
- /* Calculate the sample offsets for the HRIR indices. */
- lidx[0] *= Hrtf->irSize;
- lidx[1] *= Hrtf->irSize;
- lidx[2] *= Hrtf->irSize;
- lidx[3] *= Hrtf->irSize;
- ridx[0] *= Hrtf->irSize;
- ridx[1] *= Hrtf->irSize;
- ridx[2] *= Hrtf->irSize;
- ridx[3] *= Hrtf->irSize;
-
- /* Calculate the normalized and attenuated target HRIR coefficients using
- * linear interpolation when there is enough gain to warrant it. Zero
- * the target coefficients if gain is too low. Then calculate the
- * coefficient stepping values using the target and previous running
- * coefficients.
- */
- if(gain > 0.0001f)
+ memset(temps, 0, sizeof(temps));
+ bandsplit_init(&splitter, 400.0f / (ALfloat)Hrtf->sampleRate);
+ for(c = 0;c < AmbiCount;c++)
{
- ALfloat c;
-
- i = 0;
- left = coeffs[i][0] - (coeffStep[i][0] * counter);
- right = coeffs[i][1] - (coeffStep[i][1] * counter);
+ const ALfloat (*fir)[2] = &Hrtf->coeffs[idx[c] * Hrtf->irSize];
+ ALsizei ldelay = Hrtf->delays[idx[c]][0] - min_delay;
+ ALsizei rdelay = Hrtf->delays[idx[c]][1] - min_delay;
- c = (Hrtf->coeffs[lidx[0]+i]*blend[0] + Hrtf->coeffs[lidx[1]+i]*blend[1] +
- Hrtf->coeffs[lidx[2]+i]*blend[2] + Hrtf->coeffs[lidx[3]+i]*blend[3]);
- coeffs[i][0] = lerp(PassthruCoeff, c, dirfact) * gain * (1.0f/32767.0f);
- c = (Hrtf->coeffs[ridx[0]+i]*blend[0] + Hrtf->coeffs[ridx[1]+i]*blend[1] +
- Hrtf->coeffs[ridx[2]+i]*blend[2] + Hrtf->coeffs[ridx[3]+i]*blend[3]);
- coeffs[i][1] = lerp(PassthruCoeff, c, dirfact) * gain * (1.0f/32767.0f);
-
- coeffStep[i][0] = delta * (coeffs[i][0] - left);
- coeffStep[i][1] = delta * (coeffs[i][1] - right);
-
- for(i = 1;i < Hrtf->irSize;i++)
+ if(NUM_BANDS == 1)
+ {
+ for(i = 0;i < NumChannels;++i)
+ {
+ ALdouble mult = (ALdouble)AmbiOrderHFGain[(ALsizei)sqrt(i)] * AmbiMatrix[c][i];
+ ALsizei lidx = ldelay, ridx = rdelay;
+ ALsizei j = 0;
+ while(lidx < HRIR_LENGTH && ridx < HRIR_LENGTH && j < Hrtf->irSize)
+ {
+ tmpres[i][lidx++][0] += fir[j][0] * mult;
+ tmpres[i][ridx++][1] += fir[j][1] * mult;
+ j++;
+ }
+ }
+ }
+ else
{
- left = coeffs[i][0] - (coeffStep[i][0] * counter);
- right = coeffs[i][1] - (coeffStep[i][1] * counter);
+ /* Band-split left HRIR into low and high frequency responses. */
+ bandsplit_clear(&splitter);
+ for(i = 0;i < Hrtf->irSize;i++)
+ temps[2][i] = fir[i][0];
+ bandsplit_process(&splitter, temps[0], temps[1], temps[2], HRIR_LENGTH);
+
+ /* Apply left ear response with delay. */
+ for(i = 0;i < NumChannels;++i)
+ {
+ ALfloat hfgain = AmbiOrderHFGain[(ALsizei)sqrt(i)];
+ for(b = 0;b < NUM_BANDS;b++)
+ {
+ ALdouble mult = AmbiMatrix[c][i] * (ALdouble)((b==0) ? hfgain : 1.0);
+ ALsizei lidx = ldelay;
+ ALsizei j = 0;
+ while(lidx < HRIR_LENGTH)
+ tmpres[i][lidx++][0] += temps[b][j++] * mult;
+ }
+ }
- c = (Hrtf->coeffs[lidx[0]+i]*blend[0] + Hrtf->coeffs[lidx[1]+i]*blend[1] +
- Hrtf->coeffs[lidx[2]+i]*blend[2] + Hrtf->coeffs[lidx[3]+i]*blend[3]);
- coeffs[i][0] = lerp(0.0f, c, dirfact) * gain * (1.0f/32767.0f);
- c = (Hrtf->coeffs[ridx[0]+i]*blend[0] + Hrtf->coeffs[ridx[1]+i]*blend[1] +
- Hrtf->coeffs[ridx[2]+i]*blend[2] + Hrtf->coeffs[ridx[3]+i]*blend[3]);
- coeffs[i][1] = lerp(0.0f, c, dirfact) * gain * (1.0f/32767.0f);
+ /* Band-split right HRIR into low and high frequency responses. */
+ bandsplit_clear(&splitter);
+ for(i = 0;i < Hrtf->irSize;i++)
+ temps[2][i] = fir[i][1];
+ bandsplit_process(&splitter, temps[0], temps[1], temps[2], HRIR_LENGTH);
- coeffStep[i][0] = delta * (coeffs[i][0] - left);
- coeffStep[i][1] = delta * (coeffs[i][1] - right);
+ /* Apply right ear response with delay. */
+ for(i = 0;i < NumChannels;++i)
+ {
+ ALfloat hfgain = AmbiOrderHFGain[(ALsizei)sqrt(i)];
+ for(b = 0;b < NUM_BANDS;b++)
+ {
+ ALdouble mult = AmbiMatrix[c][i] * (ALdouble)((b==0) ? hfgain : 1.0);
+ ALsizei ridx = rdelay;
+ ALsizei j = 0;
+ while(ridx < HRIR_LENGTH)
+ tmpres[i][ridx++][1] += temps[b][j++] * mult;
+ }
+ }
}
}
- else
+
+ for(i = 0;i < NumChannels;++i)
{
- for(i = 0;i < Hrtf->irSize;i++)
+ int idx;
+ for(idx = 0;idx < HRIR_LENGTH;idx++)
{
- left = coeffs[i][0] - (coeffStep[i][0] * counter);
- right = coeffs[i][1] - (coeffStep[i][1] * counter);
-
- coeffs[i][0] = 0.0f;
- coeffs[i][1] = 0.0f;
-
- coeffStep[i][0] = delta * -left;
- coeffStep[i][1] = delta * -right;
+ state->Chan[i].Coeffs[idx][0] = (ALfloat)tmpres[i][idx][0];
+ state->Chan[i].Coeffs[idx][1] = (ALfloat)tmpres[i][idx][1];
}
}
+ al_free(tmpres);
+ tmpres = NULL;
+ al_free(idx);
+ idx = NULL;
- /* The stepping count is the number of samples necessary for the HRIR to
- * complete its transition. The mixer will only apply stepping for this
- * many samples.
- */
- return fastf2u(steps);
+ if(NUM_BANDS == 1)
+ max_length = mini(max_delay-min_delay + Hrtf->irSize, HRIR_LENGTH);
+ else
+ {
+ /* Increase the IR size by 2/3rds to account for the tail generated by
+ * the band-split filter.
+ */
+ const ALsizei irsize = mini(Hrtf->irSize*5/3, HRIR_LENGTH);
+ max_length = mini(max_delay-min_delay + irsize, HRIR_LENGTH);
+ }
+ /* Round up to the next IR size multiple. */
+ max_length += MOD_IR_SIZE-1;
+ max_length -= max_length%MOD_IR_SIZE;
+
+ TRACE("Skipped delay: %d, max delay: %d, new FIR length: %d\n",
+ min_delay, max_delay-min_delay, max_length);
+ state->IrSize = max_length;
+#undef NUM_BANDS
}
-/* Calculates HRTF coefficients for B-Format channels (only up to first-order).
- * Note that these will decode a B-Format output mix, which uses FuMa ordering
- * and scaling, not N3D!
- */
-void GetBFormatHrtfCoeffs(const struct Hrtf *Hrtf, const ALuint num_chans, ALfloat (**coeffs_list)[2], ALuint **delay_list)
+static struct Hrtf *CreateHrtfStore(ALuint rate, ALsizei irSize,
+ ALfloat distance, ALsizei evCount, ALsizei irCount, const ALubyte *azCount,
+ const ALushort *evOffset, const ALfloat (*coeffs)[2], const ALubyte (*delays)[2],
+ const char *filename)
{
- ALuint elev_idx, azi_idx;
- ALfloat scale;
- ALuint i, c;
-
- assert(num_chans <= 4);
-
- for(c = 0;c < num_chans;c++)
- {
- ALfloat (*coeffs)[2] = coeffs_list[c];
- ALuint *delay = delay_list[c];
-
- for(i = 0;i < Hrtf->irSize;i++)
- {
- coeffs[i][0] = 0.0f;
- coeffs[i][1] = 0.0f;
- }
- delay[0] = 0;
- delay[1] = 0;
- }
-
- /* NOTE: HRTF coefficients are generated by combining all the HRIRs in the
- * dataset, with each entry scaled according to how much it contributes to
- * the given B-Format channel based on its direction (including negative
- * contributions!).
- */
- scale = 0.0f;
- for(elev_idx = 0;elev_idx < Hrtf->evCount;elev_idx++)
+ struct Hrtf *Hrtf;
+ size_t total;
+
+ total = sizeof(struct Hrtf);
+ total += sizeof(Hrtf->azCount[0])*evCount;
+ total = RoundUp(total, sizeof(ALushort)); /* Align for ushort fields */
+ total += sizeof(Hrtf->evOffset[0])*evCount;
+ total = RoundUp(total, 16); /* Align for coefficients using SIMD */
+ total += sizeof(Hrtf->coeffs[0])*irSize*irCount;
+ total += sizeof(Hrtf->delays[0])*irCount;
+
+ Hrtf = al_calloc(16, total);
+ if(Hrtf == NULL)
+ ERR("Out of memory allocating storage for %s.\n", filename);
+ else
{
- ALfloat elev = (ALfloat)elev_idx/(ALfloat)(Hrtf->evCount-1)*F_PI - F_PI_2;
- ALuint evoffset = Hrtf->evOffset[elev_idx];
- ALuint azcount = Hrtf->azCount[elev_idx];
+ uintptr_t offset = sizeof(struct Hrtf);
+ char *base = (char*)Hrtf;
+ ALushort *_evOffset;
+ ALubyte *_azCount;
+ ALubyte (*_delays)[2];
+ ALfloat (*_coeffs)[2];
+ ALsizei i;
+
+ InitRef(&Hrtf->ref, 0);
+ Hrtf->sampleRate = rate;
+ Hrtf->irSize = irSize;
+ Hrtf->distance = distance;
+ Hrtf->evCount = evCount;
- scale += (ALfloat)azcount;
+ /* Set up pointers to storage following the main HRTF struct. */
+ _azCount = (ALubyte*)(base + offset);
+ offset += sizeof(_azCount[0])*evCount;
- for(azi_idx = 0;azi_idx < azcount;azi_idx++)
- {
- ALuint lidx, ridx;
- ALfloat ambi_coeffs[4];
- ALfloat az, gain;
- ALfloat x, y, z;
+ offset = RoundUp(offset, sizeof(ALushort)); /* Align for ushort fields */
+ _evOffset = (ALushort*)(base + offset);
+ offset += sizeof(_evOffset[0])*evCount;
- lidx = evoffset + azi_idx;
- ridx = evoffset + ((azcount-azi_idx) % azcount);
+ offset = RoundUp(offset, 16); /* Align for coefficients using SIMD */
+ _coeffs = (ALfloat(*)[2])(base + offset);
+ offset += sizeof(_coeffs[0])*irSize*irCount;
- az = (ALfloat)azi_idx / (ALfloat)azcount * F_TAU;
- if(az > F_PI) az -= F_TAU;
+ _delays = (ALubyte(*)[2])(base + offset);
+ offset += sizeof(_delays[0])*irCount;
- x = cosf(-az) * cosf(elev);
- y = sinf(-az) * cosf(elev);
- z = sinf(elev);
+ assert(offset == total);
- ambi_coeffs[0] = 1.414213562f;
- ambi_coeffs[1] = x;
- ambi_coeffs[2] = y;
- ambi_coeffs[3] = z;
+ /* Copy input data to storage. */
+ for(i = 0;i < evCount;i++) _azCount[i] = azCount[i];
+ for(i = 0;i < evCount;i++) _evOffset[i] = evOffset[i];
+ for(i = 0;i < irSize*irCount;i++)
+ {
+ _coeffs[i][0] = coeffs[i][0];
+ _coeffs[i][1] = coeffs[i][1];
+ }
+ for(i = 0;i < irCount;i++)
+ {
+ _delays[i][0] = delays[i][0];
+ _delays[i][1] = delays[i][1];
+ }
- for(c = 0;c < num_chans;c++)
- {
- ALfloat (*coeffs)[2] = coeffs_list[c];
- ALuint *delay = delay_list[c];
+ /* Finally, assign the storage pointers. */
+ Hrtf->azCount = _azCount;
+ Hrtf->evOffset = _evOffset;
+ Hrtf->coeffs = _coeffs;
+ Hrtf->delays = _delays;
+ }
- /* NOTE: Always include the total delay average since the
- * channels need to have matching delays. */
- delay[0] += Hrtf->delays[lidx];
- delay[1] += Hrtf->delays[ridx];
+ return Hrtf;
+}
- gain = ambi_coeffs[c];
- if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
- continue;
+static ALubyte GetLE_ALubyte(const ALubyte **data, size_t *len)
+{
+ ALubyte ret = (*data)[0];
+ *data += 1; *len -= 1;
+ return ret;
+}
- for(i = 0;i < Hrtf->irSize;i++)
- {
- coeffs[i][0] += Hrtf->coeffs[lidx*Hrtf->irSize + i]*(1.0f/32767.0f) * gain;
- coeffs[i][1] += Hrtf->coeffs[ridx*Hrtf->irSize + i]*(1.0f/32767.0f) * gain;
- }
- }
- }
- }
+static ALshort GetLE_ALshort(const ALubyte **data, size_t *len)
+{
+ ALshort ret = (*data)[0] | ((*data)[1]<<8);
+ *data += 2; *len -= 2;
+ return ret;
+}
- scale = 1.0f/scale;
+static ALushort GetLE_ALushort(const ALubyte **data, size_t *len)
+{
+ ALushort ret = (*data)[0] | ((*data)[1]<<8);
+ *data += 2; *len -= 2;
+ return ret;
+}
- for(c = 0;c < num_chans;c++)
- {
- ALfloat (*coeffs)[2] = coeffs_list[c];
- ALuint *delay = delay_list[c];
+static ALint GetLE_ALint24(const ALubyte **data, size_t *len)
+{
+ ALint ret = (*data)[0] | ((*data)[1]<<8) | ((*data)[2]<<16);
+ *data += 3; *len -= 3;
+ return (ret^0x800000) - 0x800000;
+}
- for(i = 0;i < Hrtf->irSize;i++)
- {
- coeffs[i][0] *= scale;
- coeffs[i][1] *= scale;
- }
- delay[0] = minu((ALuint)((ALfloat)delay[0] * scale), HRTF_HISTORY_LENGTH-1);
- delay[0] <<= HRTFDELAY_BITS;
- delay[1] = minu((ALuint)((ALfloat)delay[1] * scale), HRTF_HISTORY_LENGTH-1);
- delay[1] <<= HRTFDELAY_BITS;
- }
+static ALuint GetLE_ALuint(const ALubyte **data, size_t *len)
+{
+ ALuint ret = (*data)[0] | ((*data)[1]<<8) | ((*data)[2]<<16) | ((*data)[3]<<24);
+ *data += 4; *len -= 4;
+ return ret;
}
+static const ALubyte *Get_ALubytePtr(const ALubyte **data, size_t *len, size_t size)
+{
+ const ALubyte *ret = *data;
+ *data += size; *len -= size;
+ return ret;
+}
-static struct Hrtf *LoadHrtf00(FILE *f)
+static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const char *filename)
{
- const ALubyte maxDelay = HRTF_HISTORY_LENGTH-1;
struct Hrtf *Hrtf = NULL;
ALboolean failed = AL_FALSE;
- ALuint rate = 0, irCount = 0;
+ ALuint rate = 0;
+ ALushort irCount = 0;
ALushort irSize = 0;
ALubyte evCount = 0;
ALubyte *azCount = NULL;
ALushort *evOffset = NULL;
- ALshort *coeffs = NULL;
- ALubyte *delays = NULL;
- ALuint i, j;
+ ALfloat (*coeffs)[2] = NULL;
+ ALubyte (*delays)[2] = NULL;
+ ALsizei i, j;
+
+ if(datalen < 9)
+ {
+ ERR("Unexpected end of %s data (req %d, rem "SZFMT")\n", filename, 9, datalen);
+ return NULL;
+ }
- rate = fgetc(f);
- rate |= fgetc(f)<<8;
- rate |= fgetc(f)<<16;
- rate |= fgetc(f)<<24;
+ rate = GetLE_ALuint(&data, &datalen);
- irCount = fgetc(f);
- irCount |= fgetc(f)<<8;
+ irCount = GetLE_ALushort(&data, &datalen);
- irSize = fgetc(f);
- irSize |= fgetc(f)<<8;
+ irSize = GetLE_ALushort(&data, &datalen);
- evCount = fgetc(f);
+ evCount = GetLE_ALubyte(&data, &datalen);
if(irSize < MIN_IR_SIZE || irSize > MAX_IR_SIZE || (irSize%MOD_IR_SIZE))
{
@@ -459,10 +496,15 @@ static struct Hrtf *LoadHrtf00(FILE *f)
evCount, MIN_EV_COUNT, MAX_EV_COUNT);
failed = AL_TRUE;
}
-
if(failed)
return NULL;
+ if(datalen < evCount*2u)
+ {
+ ERR("Unexpected end of %s data (req %d, rem "SZFMT")\n", filename, evCount*2, datalen);
+ return NULL;
+ }
+
azCount = malloc(sizeof(azCount[0])*evCount);
evOffset = malloc(sizeof(evOffset[0])*evCount);
if(azCount == NULL || evOffset == NULL)
@@ -473,12 +515,10 @@ static struct Hrtf *LoadHrtf00(FILE *f)
if(!failed)
{
- evOffset[0] = fgetc(f);
- evOffset[0] |= fgetc(f)<<8;
+ evOffset[0] = GetLE_ALushort(&data, &datalen);
for(i = 1;i < evCount;i++)
{
- evOffset[i] = fgetc(f);
- evOffset[i] |= fgetc(f)<<8;
+ evOffset[i] = GetLE_ALushort(&data, &datalen);
if(evOffset[i] <= evOffset[i-1])
{
ERR("Invalid evOffset: evOffset[%d]=%d (last=%d)\n",
@@ -523,86 +563,89 @@ static struct Hrtf *LoadHrtf00(FILE *f)
if(!failed)
{
- for(i = 0;i < irCount*irSize;i+=irSize)
+ size_t reqsize = 2*irSize*irCount + irCount;
+ if(datalen < reqsize)
+ {
+ ERR("Unexpected end of %s data (req "SZFMT", rem "SZFMT")\n",
+ filename, reqsize, datalen);
+ failed = AL_TRUE;
+ }
+ }
+
+ if(!failed)
+ {
+ for(i = 0;i < irCount;i++)
{
for(j = 0;j < irSize;j++)
- {
- ALshort coeff;
- coeff = fgetc(f);
- coeff |= fgetc(f)<<8;
- coeffs[i+j] = coeff;
- }
+ coeffs[i*irSize + j][0] = GetLE_ALshort(&data, &datalen) / 32768.0f;
}
+
for(i = 0;i < irCount;i++)
{
- delays[i] = fgetc(f);
- if(delays[i] > maxDelay)
+ delays[i][0] = GetLE_ALubyte(&data, &datalen);
+ if(delays[i][0] > MAX_HRIR_DELAY)
{
- ERR("Invalid delays[%d]: %d (%d)\n", i, delays[i], maxDelay);
+ ERR("Invalid delays[%d]: %d (%d)\n", i, delays[i][0], MAX_HRIR_DELAY);
failed = AL_TRUE;
}
}
-
- if(feof(f))
- {
- ERR("Premature end of data\n");
- failed = AL_TRUE;
- }
}
if(!failed)
{
- Hrtf = malloc(sizeof(struct Hrtf));
- if(Hrtf == NULL)
+ /* Mirror the left ear responses to the right ear. */
+ for(i = 0;i < evCount;i++)
{
- ERR("Out of memory.\n");
- failed = AL_TRUE;
+ ALushort evoffset = evOffset[i];
+ ALubyte azcount = azCount[i];
+ for(j = 0;j < azcount;j++)
+ {
+ ALsizei lidx = evoffset + j;
+ ALsizei ridx = evoffset + ((azcount-j) % azcount);
+ ALsizei k;
+
+ for(k = 0;k < irSize;k++)
+ coeffs[ridx*irSize + k][1] = coeffs[lidx*irSize + k][0];
+ delays[ridx][1] = delays[lidx][0];
+ }
}
- }
- if(!failed)
- {
- Hrtf->sampleRate = rate;
- Hrtf->irSize = irSize;
- Hrtf->evCount = evCount;
- Hrtf->azCount = azCount;
- Hrtf->evOffset = evOffset;
- Hrtf->coeffs = coeffs;
- Hrtf->delays = delays;
- AL_STRING_INIT(Hrtf->filename);
- Hrtf->next = NULL;
- return Hrtf;
+ Hrtf = CreateHrtfStore(rate, irSize, 0.0f, evCount, irCount, azCount,
+ evOffset, coeffs, delays, filename);
}
free(azCount);
free(evOffset);
free(coeffs);
free(delays);
- return NULL;
+ return Hrtf;
}
-
-static struct Hrtf *LoadHrtf01(FILE *f)
+static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const char *filename)
{
- const ALubyte maxDelay = HRTF_HISTORY_LENGTH-1;
struct Hrtf *Hrtf = NULL;
ALboolean failed = AL_FALSE;
- ALuint rate = 0, irCount = 0;
- ALubyte irSize = 0, evCount = 0;
- ALubyte *azCount = NULL;
+ ALuint rate = 0;
+ ALushort irCount = 0;
+ ALushort irSize = 0;
+ ALubyte evCount = 0;
+ const ALubyte *azCount = NULL;
ALushort *evOffset = NULL;
- ALshort *coeffs = NULL;
- ALubyte *delays = NULL;
- ALuint i, j;
+ ALfloat (*coeffs)[2] = NULL;
+ ALubyte (*delays)[2] = NULL;
+ ALsizei i, j;
+
+ if(datalen < 6)
+ {
+ ERR("Unexpected end of %s data (req %d, rem "SZFMT"\n", filename, 6, datalen);
+ return NULL;
+ }
- rate = fgetc(f);
- rate |= fgetc(f)<<8;
- rate |= fgetc(f)<<16;
- rate |= fgetc(f)<<24;
+ rate = GetLE_ALuint(&data, &datalen);
- irSize = fgetc(f);
+ irSize = GetLE_ALubyte(&data, &datalen);
- evCount = fgetc(f);
+ evCount = GetLE_ALubyte(&data, &datalen);
if(irSize < MIN_IR_SIZE || irSize > MAX_IR_SIZE || (irSize%MOD_IR_SIZE))
{
@@ -616,11 +659,17 @@ static struct Hrtf *LoadHrtf01(FILE *f)
evCount, MIN_EV_COUNT, MAX_EV_COUNT);
failed = AL_TRUE;
}
-
if(failed)
return NULL;
- azCount = malloc(sizeof(azCount[0])*evCount);
+ if(datalen < evCount)
+ {
+ ERR("Unexpected end of %s data (req %d, rem "SZFMT"\n", filename, evCount, datalen);
+ return NULL;
+ }
+
+ azCount = Get_ALubytePtr(&data, &datalen, evCount);
+
evOffset = malloc(sizeof(evOffset[0])*evCount);
if(azCount == NULL || evOffset == NULL)
{
@@ -632,7 +681,6 @@ static struct Hrtf *LoadHrtf01(FILE *f)
{
for(i = 0;i < evCount;i++)
{
- azCount[i] = fgetc(f);
if(azCount[i] < MIN_AZ_COUNT || azCount[i] > MAX_AZ_COUNT)
{
ERR("Unsupported azimuth count: azCount[%d]=%d (%d to %d)\n",
@@ -663,37 +711,193 @@ static struct Hrtf *LoadHrtf01(FILE *f)
if(!failed)
{
- for(i = 0;i < irCount*irSize;i+=irSize)
+ size_t reqsize = 2*irSize*irCount + irCount;
+ if(datalen < reqsize)
+ {
+ ERR("Unexpected end of %s data (req "SZFMT", rem "SZFMT"\n",
+ filename, reqsize, datalen);
+ failed = AL_TRUE;
+ }
+ }
+
+ if(!failed)
+ {
+ for(i = 0;i < irCount;i++)
{
for(j = 0;j < irSize;j++)
- {
- ALshort coeff;
- coeff = fgetc(f);
- coeff |= fgetc(f)<<8;
- coeffs[i+j] = coeff;
- }
+ coeffs[i*irSize + j][0] = GetLE_ALshort(&data, &datalen) / 32768.0f;
}
+
for(i = 0;i < irCount;i++)
{
- delays[i] = fgetc(f);
- if(delays[i] > maxDelay)
+ delays[i][0] = GetLE_ALubyte(&data, &datalen);
+ if(delays[i][0] > MAX_HRIR_DELAY)
{
- ERR("Invalid delays[%d]: %d (%d)\n", i, delays[i], maxDelay);
+ ERR("Invalid delays[%d]: %d (%d)\n", i, delays[i][0], MAX_HRIR_DELAY);
failed = AL_TRUE;
}
}
+ }
- if(feof(f))
+ if(!failed)
+ {
+ /* Mirror the left ear responses to the right ear. */
+ for(i = 0;i < evCount;i++)
{
- ERR("Premature end of data\n");
+ ALushort evoffset = evOffset[i];
+ ALubyte azcount = azCount[i];
+ for(j = 0;j < azcount;j++)
+ {
+ ALsizei lidx = evoffset + j;
+ ALsizei ridx = evoffset + ((azcount-j) % azcount);
+ ALsizei k;
+
+ for(k = 0;k < irSize;k++)
+ coeffs[ridx*irSize + k][1] = coeffs[lidx*irSize + k][0];
+ delays[ridx][1] = delays[lidx][0];
+ }
+ }
+
+ Hrtf = CreateHrtfStore(rate, irSize, 0.0f, evCount, irCount, azCount,
+ evOffset, coeffs, delays, filename);
+ }
+
+ free(evOffset);
+ free(coeffs);
+ free(delays);
+ return Hrtf;
+}
+
+#define SAMPLETYPE_S16 0
+#define SAMPLETYPE_S24 1
+
+#define CHANTYPE_LEFTONLY 0
+#define CHANTYPE_LEFTRIGHT 1
+
+static struct Hrtf *LoadHrtf02(const ALubyte *data, size_t datalen, const char *filename)
+{
+ struct Hrtf *Hrtf = NULL;
+ ALboolean failed = AL_FALSE;
+ ALuint rate = 0;
+ ALubyte sampleType;
+ ALubyte channelType;
+ ALushort irCount = 0;
+ ALushort irSize = 0;
+ ALubyte fdCount = 0;
+ ALushort distance = 0;
+ ALubyte evCount = 0;
+ const ALubyte *azCount = NULL;
+ ALushort *evOffset = NULL;
+ ALfloat (*coeffs)[2] = NULL;
+ ALubyte (*delays)[2] = NULL;
+ ALsizei i, j;
+
+ if(datalen < 8)
+ {
+ ERR("Unexpected end of %s data (req %d, rem "SZFMT"\n", filename, 8, datalen);
+ return NULL;
+ }
+
+ rate = GetLE_ALuint(&data, &datalen);
+ sampleType = GetLE_ALubyte(&data, &datalen);
+ channelType = GetLE_ALubyte(&data, &datalen);
+
+ irSize = GetLE_ALubyte(&data, &datalen);
+
+ fdCount = GetLE_ALubyte(&data, &datalen);
+
+ if(sampleType > SAMPLETYPE_S24)
+ {
+ ERR("Unsupported sample type: %d\n", sampleType);
+ failed = AL_TRUE;
+ }
+ if(channelType > CHANTYPE_LEFTRIGHT)
+ {
+ ERR("Unsupported channel type: %d\n", channelType);
+ failed = AL_TRUE;
+ }
+
+ if(irSize < MIN_IR_SIZE || irSize > MAX_IR_SIZE || (irSize%MOD_IR_SIZE))
+ {
+ ERR("Unsupported HRIR size: irSize=%d (%d to %d by %d)\n",
+ irSize, MIN_IR_SIZE, MAX_IR_SIZE, MOD_IR_SIZE);
+ failed = AL_TRUE;
+ }
+ if(fdCount != 1)
+ {
+ ERR("Multiple field-depths not supported: fdCount=%d (%d to %d)\n",
+ evCount, MIN_FD_COUNT, MAX_FD_COUNT);
+ failed = AL_TRUE;
+ }
+ if(failed)
+ return NULL;
+
+ for(i = 0;i < fdCount;i++)
+ {
+ if(datalen < 3)
+ {
+ ERR("Unexpected end of %s data (req %d, rem "SZFMT"\n", filename, 3, datalen);
+ return NULL;
+ }
+
+ distance = GetLE_ALushort(&data, &datalen);
+ if(distance < MIN_FD_DISTANCE || distance > MAX_FD_DISTANCE)
+ {
+ ERR("Unsupported field distance: distance=%d (%dmm to %dmm)\n",
+ distance, MIN_FD_DISTANCE, MAX_FD_DISTANCE);
failed = AL_TRUE;
}
+
+ evCount = GetLE_ALubyte(&data, &datalen);
+ if(evCount < MIN_EV_COUNT || evCount > MAX_EV_COUNT)
+ {
+ ERR("Unsupported elevation count: evCount=%d (%d to %d)\n",
+ evCount, MIN_EV_COUNT, MAX_EV_COUNT);
+ failed = AL_TRUE;
+ }
+ if(failed)
+ return NULL;
+
+ if(datalen < evCount)
+ {
+ ERR("Unexpected end of %s data (req %d, rem "SZFMT"\n", filename, evCount, datalen);
+ return NULL;
+ }
+
+ azCount = Get_ALubytePtr(&data, &datalen, evCount);
+ for(j = 0;j < evCount;j++)
+ {
+ if(azCount[j] < MIN_AZ_COUNT || azCount[j] > MAX_AZ_COUNT)
+ {
+ ERR("Unsupported azimuth count: azCount[%d]=%d (%d to %d)\n",
+ j, azCount[j], MIN_AZ_COUNT, MAX_AZ_COUNT);
+ failed = AL_TRUE;
+ }
+ }
+ }
+ if(failed)
+ return NULL;
+
+ evOffset = malloc(sizeof(evOffset[0])*evCount);
+ if(azCount == NULL || evOffset == NULL)
+ {
+ ERR("Out of memory.\n");
+ failed = AL_TRUE;
}
if(!failed)
{
- Hrtf = malloc(sizeof(struct Hrtf));
- if(Hrtf == NULL)
+ evOffset[0] = 0;
+ irCount = azCount[0];
+ for(i = 1;i < evCount;i++)
+ {
+ evOffset[i] = evOffset[i-1] + azCount[i-1];
+ irCount += azCount[i];
+ }
+
+ coeffs = malloc(sizeof(coeffs[0])*irSize*irCount);
+ delays = malloc(sizeof(delays[0])*irCount);
+ if(coeffs == NULL || delays == NULL)
{
ERR("Out of memory.\n");
failed = AL_TRUE;
@@ -702,199 +906,560 @@ static struct Hrtf *LoadHrtf01(FILE *f)
if(!failed)
{
- Hrtf->sampleRate = rate;
- Hrtf->irSize = irSize;
- Hrtf->evCount = evCount;
- Hrtf->azCount = azCount;
- Hrtf->evOffset = evOffset;
- Hrtf->coeffs = coeffs;
- Hrtf->delays = delays;
- AL_STRING_INIT(Hrtf->filename);
- Hrtf->next = NULL;
- return Hrtf;
+ size_t reqsize = 2*irSize*irCount + irCount;
+ if(datalen < reqsize)
+ {
+ ERR("Unexpected end of %s data (req "SZFMT", rem "SZFMT"\n",
+ filename, reqsize, datalen);
+ failed = AL_TRUE;
+ }
+ }
+
+ if(!failed)
+ {
+ if(channelType == CHANTYPE_LEFTONLY)
+ {
+ if(sampleType == SAMPLETYPE_S16)
+ for(i = 0;i < irCount;i++)
+ {
+ for(j = 0;j < irSize;j++)
+ coeffs[i*irSize + j][0] = GetLE_ALshort(&data, &datalen) / 32768.0f;
+ }
+ else if(sampleType == SAMPLETYPE_S24)
+ for(i = 0;i < irCount;i++)
+ {
+ for(j = 0;j < irSize;j++)
+ coeffs[i*irSize + j][0] = GetLE_ALint24(&data, &datalen) / 8388608.0f;
+ }
+
+ for(i = 0;i < irCount;i++)
+ {
+ delays[i][0] = GetLE_ALubyte(&data, &datalen);
+ if(delays[i][0] > MAX_HRIR_DELAY)
+ {
+ ERR("Invalid delays[%d][0]: %d (%d)\n", i, delays[i][0], MAX_HRIR_DELAY);
+ failed = AL_TRUE;
+ }
+ }
+ }
+ else if(channelType == CHANTYPE_LEFTRIGHT)
+ {
+ if(sampleType == SAMPLETYPE_S16)
+ for(i = 0;i < irCount;i++)
+ {
+ for(j = 0;j < irSize;j++)
+ {
+ coeffs[i*irSize + j][0] = GetLE_ALshort(&data, &datalen) / 32768.0f;
+ coeffs[i*irSize + j][1] = GetLE_ALshort(&data, &datalen) / 32768.0f;
+ }
+ }
+ else if(sampleType == SAMPLETYPE_S24)
+ for(i = 0;i < irCount;i++)
+ {
+ for(j = 0;j < irSize;j++)
+ {
+ coeffs[i*irSize + j][0] = GetLE_ALint24(&data, &datalen) / 8388608.0f;
+ coeffs[i*irSize + j][1] = GetLE_ALint24(&data, &datalen) / 8388608.0f;
+ }
+ }
+
+ for(i = 0;i < irCount;i++)
+ {
+ delays[i][0] = GetLE_ALubyte(&data, &datalen);
+ if(delays[i][0] > MAX_HRIR_DELAY)
+ {
+ ERR("Invalid delays[%d][0]: %d (%d)\n", i, delays[i][0], MAX_HRIR_DELAY);
+ failed = AL_TRUE;
+ }
+ delays[i][1] = GetLE_ALubyte(&data, &datalen);
+ if(delays[i][1] > MAX_HRIR_DELAY)
+ {
+ ERR("Invalid delays[%d][1]: %d (%d)\n", i, delays[i][1], MAX_HRIR_DELAY);
+ failed = AL_TRUE;
+ }
+ }
+ }
+ }
+
+ if(!failed)
+ {
+ if(channelType == CHANTYPE_LEFTONLY)
+ {
+ /* Mirror the left ear responses to the right ear. */
+ for(i = 0;i < evCount;i++)
+ {
+ ALushort evoffset = evOffset[i];
+ ALubyte azcount = azCount[i];
+ for(j = 0;j < azcount;j++)
+ {
+ ALsizei lidx = evoffset + j;
+ ALsizei ridx = evoffset + ((azcount-j) % azcount);
+ ALsizei k;
+
+ for(k = 0;k < irSize;k++)
+ coeffs[ridx*irSize + k][1] = coeffs[lidx*irSize + k][0];
+ delays[ridx][1] = delays[lidx][0];
+ }
+ }
+ }
+
+ Hrtf = CreateHrtfStore(rate, irSize,
+ (ALfloat)distance / 1000.0f, evCount, irCount, azCount, evOffset,
+ coeffs, delays, filename
+ );
}
- free(azCount);
free(evOffset);
free(coeffs);
free(delays);
- return NULL;
+ return Hrtf;
}
-static void AddFileEntry(vector_HrtfEntry *list, al_string *filename)
+static void AddFileEntry(vector_EnumeratedHrtf *list, const_al_string filename)
{
- HrtfEntry entry = { AL_STRING_INIT_STATIC(), *filename, NULL };
- HrtfEntry *iter;
+ EnumeratedHrtf entry = { AL_STRING_INIT_STATIC(), NULL };
+ struct HrtfEntry *loaded_entry;
+ const EnumeratedHrtf *iter;
const char *name;
+ const char *ext;
int i;
- name = strrchr(al_string_get_cstr(entry.filename), '/');
- if(!name) name = strrchr(al_string_get_cstr(entry.filename), '\\');
- if(!name) name = al_string_get_cstr(entry.filename);
- else ++name;
-
- entry.hrtf = LoadedHrtfs;
- while(entry.hrtf)
+ /* Check if this file has already been loaded globally. */
+ loaded_entry = LoadedHrtfs;
+ while(loaded_entry)
{
- if(al_string_cmp(entry.filename, entry.hrtf->filename) == 0)
+ if(alstr_cmp_cstr(filename, loaded_entry->filename) == 0)
+ {
+ /* Check if this entry has already been added to the list. */
+#define MATCH_ENTRY(i) (loaded_entry == (i)->hrtf)
+ VECTOR_FIND_IF(iter, const EnumeratedHrtf, *list, MATCH_ENTRY);
+#undef MATCH_ENTRY
+ if(iter != VECTOR_END(*list))
+ {
+ TRACE("Skipping duplicate file entry %s\n", alstr_get_cstr(filename));
+ return;
+ }
+
break;
- entry.hrtf = entry.hrtf->next;
+ }
+ loaded_entry = loaded_entry->next;
}
- if(!entry.hrtf)
+ if(!loaded_entry)
{
- struct Hrtf *hrtf = NULL;
- ALchar magic[8];
- FILE *f;
+ TRACE("Got new file \"%s\"\n", alstr_get_cstr(filename));
+
+ loaded_entry = al_calloc(DEF_ALIGN,
+ FAM_SIZE(struct HrtfEntry, filename, alstr_length(filename)+1)
+ );
+ loaded_entry->next = LoadedHrtfs;
+ loaded_entry->handle = NULL;
+ strcpy(loaded_entry->filename, alstr_get_cstr(filename));
+ LoadedHrtfs = loaded_entry;
+ }
- TRACE("Loading %s...\n", al_string_get_cstr(entry.filename));
- f = al_fopen(al_string_get_cstr(entry.filename), "rb");
- if(f == NULL)
+ /* TODO: Get a human-readable name from the HRTF data (possibly coming in a
+ * format update). */
+ name = strrchr(alstr_get_cstr(filename), '/');
+ if(!name) name = strrchr(alstr_get_cstr(filename), '\\');
+ if(!name) name = alstr_get_cstr(filename);
+ else ++name;
+
+ ext = strrchr(name, '.');
+
+ i = 0;
+ do {
+ if(!ext)
+ alstr_copy_cstr(&entry.name, name);
+ else
+ alstr_copy_range(&entry.name, name, ext);
+ if(i != 0)
{
- ERR("Could not open %s\n", al_string_get_cstr(entry.filename));
- goto error;
+ char str[64];
+ snprintf(str, sizeof(str), " #%d", i+1);
+ alstr_append_cstr(&entry.name, str);
}
+ ++i;
- if(fread(magic, 1, sizeof(magic), f) != sizeof(magic))
- ERR("Failed to read header from %s\n", al_string_get_cstr(entry.filename));
- else
+#define MATCH_NAME(i) (alstr_cmp(entry.name, (i)->name) == 0)
+ VECTOR_FIND_IF(iter, const EnumeratedHrtf, *list, MATCH_NAME);
+#undef MATCH_NAME
+ } while(iter != VECTOR_END(*list));
+ entry.hrtf = loaded_entry;
+
+ TRACE("Adding entry \"%s\" from file \"%s\"\n", alstr_get_cstr(entry.name),
+ alstr_get_cstr(filename));
+ VECTOR_PUSH_BACK(*list, entry);
+}
+
+/* Unfortunate that we have to duplicate AddFileEntry to take a memory buffer
+ * for input instead of opening the given filename.
+ */
+static void AddBuiltInEntry(vector_EnumeratedHrtf *list, const_al_string filename, ALuint residx)
+{
+ EnumeratedHrtf entry = { AL_STRING_INIT_STATIC(), NULL };
+ struct HrtfEntry *loaded_entry;
+ struct Hrtf *hrtf = NULL;
+ const EnumeratedHrtf *iter;
+ const char *name;
+ const char *ext;
+ int i;
+
+ loaded_entry = LoadedHrtfs;
+ while(loaded_entry)
+ {
+ if(alstr_cmp_cstr(filename, loaded_entry->filename) == 0)
{
- if(memcmp(magic, magicMarker00, sizeof(magicMarker00)) == 0)
- {
- TRACE("Detected data set format v0\n");
- hrtf = LoadHrtf00(f);
- }
- else if(memcmp(magic, magicMarker01, sizeof(magicMarker01)) == 0)
+#define MATCH_ENTRY(i) (loaded_entry == (i)->hrtf)
+ VECTOR_FIND_IF(iter, const EnumeratedHrtf, *list, MATCH_ENTRY);
+#undef MATCH_ENTRY
+ if(iter != VECTOR_END(*list))
{
- TRACE("Detected data set format v1\n");
- hrtf = LoadHrtf01(f);
+ TRACE("Skipping duplicate file entry %s\n", alstr_get_cstr(filename));
+ return;
}
- else
- ERR("Invalid header in %s: \"%.8s\"\n", al_string_get_cstr(entry.filename), magic);
- }
- fclose(f);
- if(!hrtf)
- {
- ERR("Failed to load %s\n", al_string_get_cstr(entry.filename));
- goto error;
+ break;
}
+ loaded_entry = loaded_entry->next;
+ }
- al_string_copy(&hrtf->filename, entry.filename);
- hrtf->next = LoadedHrtfs;
- LoadedHrtfs = hrtf;
- TRACE("Loaded HRTF support for format: %s %uhz\n",
- DevFmtChannelsString(DevFmtStereo), hrtf->sampleRate);
- entry.hrtf = hrtf;
+ if(!loaded_entry)
+ {
+ size_t namelen = alstr_length(filename)+32;
+
+ TRACE("Got new file \"%s\"\n", alstr_get_cstr(filename));
+
+ loaded_entry = al_calloc(DEF_ALIGN,
+ FAM_SIZE(struct HrtfEntry, filename, namelen)
+ );
+ loaded_entry->next = LoadedHrtfs;
+ loaded_entry->handle = hrtf;
+ snprintf(loaded_entry->filename, namelen, "!%u_%s",
+ residx, alstr_get_cstr(filename));
+ LoadedHrtfs = loaded_entry;
}
/* TODO: Get a human-readable name from the HRTF data (possibly coming in a
* format update). */
+ name = strrchr(alstr_get_cstr(filename), '/');
+ if(!name) name = strrchr(alstr_get_cstr(filename), '\\');
+ if(!name) name = alstr_get_cstr(filename);
+ else ++name;
+
+ ext = strrchr(name, '.');
i = 0;
do {
- al_string_copy_cstr(&entry.name, name);
+ if(!ext)
+ alstr_copy_cstr(&entry.name, name);
+ else
+ alstr_copy_range(&entry.name, name, ext);
if(i != 0)
{
char str[64];
snprintf(str, sizeof(str), " #%d", i+1);
- al_string_append_cstr(&entry.name, str);
+ alstr_append_cstr(&entry.name, str);
}
++i;
-#define MATCH_NAME(i) (al_string_cmp(entry.name, (i)->name) == 0)
- VECTOR_FIND_IF(iter, HrtfEntry, *list, MATCH_NAME);
+#define MATCH_NAME(i) (alstr_cmp(entry.name, (i)->name) == 0)
+ VECTOR_FIND_IF(iter, const EnumeratedHrtf, *list, MATCH_NAME);
#undef MATCH_NAME
- } while(iter != VECTOR_ITER_END(*list));
+ } while(iter != VECTOR_END(*list));
+ entry.hrtf = loaded_entry;
- TRACE("Adding entry \"%s\" from file \"%s\"\n", al_string_get_cstr(entry.name),
- al_string_get_cstr(entry.filename));
+ TRACE("Adding built-in entry \"%s\"\n", alstr_get_cstr(entry.name));
VECTOR_PUSH_BACK(*list, entry);
- return;
+}
+
+
+#define IDR_DEFAULT_44100_MHR 1
+#define IDR_DEFAULT_48000_MHR 2
+
+#ifndef ALSOFT_EMBED_HRTF_DATA
-error:
- al_string_deinit(&entry.filename);
+static const ALubyte *GetResource(int UNUSED(name), size_t *size)
+{
+ *size = 0;
+ return NULL;
+}
+
+#else
+
+#include "default-44100.mhr.h"
+#include "default-48000.mhr.h"
+
+static const ALubyte *GetResource(int name, size_t *size)
+{
+ if(name == IDR_DEFAULT_44100_MHR)
+ {
+ *size = sizeof(hrtf_default_44100);
+ return hrtf_default_44100;
+ }
+ if(name == IDR_DEFAULT_48000_MHR)
+ {
+ *size = sizeof(hrtf_default_48000);
+ return hrtf_default_48000;
+ }
+ *size = 0;
+ return NULL;
}
+#endif
-vector_HrtfEntry EnumerateHrtf(const_al_string devname)
+vector_EnumeratedHrtf EnumerateHrtf(const_al_string devname)
{
- vector_HrtfEntry list = VECTOR_INIT_STATIC();
- const char *fnamelist = "default-%r.mhr";
+ vector_EnumeratedHrtf list = VECTOR_INIT_STATIC();
+ const char *defaulthrtf = "";
+ const char *pathlist = "";
+ bool usedefaults = true;
- ConfigValueStr(al_string_get_cstr(devname), NULL, "hrtf_tables", &fnamelist);
- while(fnamelist && *fnamelist)
+ if(ConfigValueStr(alstr_get_cstr(devname), NULL, "hrtf-paths", &pathlist))
{
- while(isspace(*fnamelist) || *fnamelist == ',')
- fnamelist++;
- if(*fnamelist != '\0')
+ al_string pname = AL_STRING_INIT_STATIC();
+ while(pathlist && *pathlist)
{
const char *next, *end;
- next = strchr(fnamelist, ',');
- if(!next)
- end = fnamelist + strlen(fnamelist);
- else
+ while(isspace(*pathlist) || *pathlist == ',')
+ pathlist++;
+ if(*pathlist == '\0')
+ continue;
+
+ next = strchr(pathlist, ',');
+ if(next)
end = next++;
+ else
+ {
+ end = pathlist + strlen(pathlist);
+ usedefaults = false;
+ }
- while(end != fnamelist && isspace(*(end-1)))
+ while(end != pathlist && isspace(*(end-1)))
--end;
- if(end != fnamelist)
+ if(end != pathlist)
{
- al_string fname = AL_STRING_INIT_STATIC();
vector_al_string flist;
+ size_t i;
- al_string_append_range(&fname, fnamelist, end);
+ alstr_copy_range(&pname, pathlist, end);
- flist = SearchDataFiles(al_string_get_cstr(fname), "openal/hrtf");
- VECTOR_FOR_EACH_PARAMS(al_string, flist, AddFileEntry, &list);
+ flist = SearchDataFiles(".mhr", alstr_get_cstr(pname));
+ for(i = 0;i < VECTOR_SIZE(flist);i++)
+ AddFileEntry(&list, VECTOR_ELEM(flist, i));
+ VECTOR_FOR_EACH(al_string, flist, alstr_reset);
VECTOR_DEINIT(flist);
-
- al_string_deinit(&fname);
}
- fnamelist = next;
+ pathlist = next;
+ }
+
+ alstr_reset(&pname);
+ }
+ else if(ConfigValueExists(alstr_get_cstr(devname), NULL, "hrtf_tables"))
+ ERR("The hrtf_tables option is deprecated, please use hrtf-paths instead.\n");
+
+ if(usedefaults)
+ {
+ al_string ename = AL_STRING_INIT_STATIC();
+ vector_al_string flist;
+ const ALubyte *rdata;
+ size_t rsize, i;
+
+ flist = SearchDataFiles(".mhr", "openal/hrtf");
+ for(i = 0;i < VECTOR_SIZE(flist);i++)
+ AddFileEntry(&list, VECTOR_ELEM(flist, i));
+ VECTOR_FOR_EACH(al_string, flist, alstr_reset);
+ VECTOR_DEINIT(flist);
+
+ rdata = GetResource(IDR_DEFAULT_44100_MHR, &rsize);
+ if(rdata != NULL && rsize > 0)
+ {
+ alstr_copy_cstr(&ename, "Built-In 44100hz");
+ AddBuiltInEntry(&list, ename, IDR_DEFAULT_44100_MHR);
+ }
+
+ rdata = GetResource(IDR_DEFAULT_48000_MHR, &rsize);
+ if(rdata != NULL && rsize > 0)
+ {
+ alstr_copy_cstr(&ename, "Built-In 48000hz");
+ AddBuiltInEntry(&list, ename, IDR_DEFAULT_48000_MHR);
+ }
+ alstr_reset(&ename);
+ }
+
+ if(VECTOR_SIZE(list) > 1 && ConfigValueStr(alstr_get_cstr(devname), NULL, "default-hrtf", &defaulthrtf))
+ {
+ const EnumeratedHrtf *iter;
+ /* Find the preferred HRTF and move it to the front of the list. */
+#define FIND_ENTRY(i) (alstr_cmp_cstr((i)->name, defaulthrtf) == 0)
+ VECTOR_FIND_IF(iter, const EnumeratedHrtf, list, FIND_ENTRY);
+#undef FIND_ENTRY
+ if(iter == VECTOR_END(list))
+ WARN("Failed to find default HRTF \"%s\"\n", defaulthrtf);
+ else if(iter != VECTOR_BEGIN(list))
+ {
+ EnumeratedHrtf entry = *iter;
+ memmove(&VECTOR_ELEM(list,1), &VECTOR_ELEM(list,0),
+ (iter-VECTOR_BEGIN(list))*sizeof(EnumeratedHrtf));
+ VECTOR_ELEM(list,0) = entry;
}
}
return list;
}
-void FreeHrtfList(vector_HrtfEntry *list)
+void FreeHrtfList(vector_EnumeratedHrtf *list)
{
-#define CLEAR_ENTRY(i) do { \
- al_string_deinit(&(i)->name); \
- al_string_deinit(&(i)->filename); \
-} while(0)
- VECTOR_FOR_EACH(HrtfEntry, *list, CLEAR_ENTRY);
+#define CLEAR_ENTRY(i) alstr_reset(&(i)->name)
+ VECTOR_FOR_EACH(EnumeratedHrtf, *list, CLEAR_ENTRY);
VECTOR_DEINIT(*list);
#undef CLEAR_ENTRY
}
+struct Hrtf *GetLoadedHrtf(struct HrtfEntry *entry)
+{
+ struct Hrtf *hrtf = NULL;
+ struct FileMapping fmap;
+ const ALubyte *rdata;
+ const char *name;
+ ALuint residx;
+ size_t rsize;
+ char ch;
+
+ while(ATOMIC_FLAG_TEST_AND_SET(&LoadedHrtfLock, almemory_order_seq_cst))
+ althrd_yield();
+
+ if(entry->handle)
+ {
+ hrtf = entry->handle;
+ Hrtf_IncRef(hrtf);
+ goto done;
+ }
+
+ fmap.ptr = NULL;
+ fmap.len = 0;
+ if(sscanf(entry->filename, "!%u%c", &residx, &ch) == 2 && ch == '_')
+ {
+ name = strchr(entry->filename, ch)+1;
+
+ TRACE("Loading %s...\n", name);
+ rdata = GetResource(residx, &rsize);
+ if(rdata == NULL || rsize == 0)
+ {
+ ERR("Could not get resource %u, %s\n", residx, name);
+ goto done;
+ }
+ }
+ else
+ {
+ name = entry->filename;
+
+ TRACE("Loading %s...\n", entry->filename);
+ fmap = MapFileToMem(entry->filename);
+ if(fmap.ptr == NULL)
+ {
+ ERR("Could not open %s\n", entry->filename);
+ goto done;
+ }
-ALuint GetHrtfSampleRate(const struct Hrtf *Hrtf)
+ rdata = fmap.ptr;
+ rsize = fmap.len;
+ }
+
+ if(rsize < sizeof(magicMarker02))
+ ERR("%s data is too short ("SZFMT" bytes)\n", name, rsize);
+ else if(memcmp(rdata, magicMarker02, sizeof(magicMarker02)) == 0)
+ {
+ TRACE("Detected data set format v2\n");
+ hrtf = LoadHrtf02(rdata+sizeof(magicMarker02),
+ rsize-sizeof(magicMarker02), name
+ );
+ }
+ else if(memcmp(rdata, magicMarker01, sizeof(magicMarker01)) == 0)
+ {
+ TRACE("Detected data set format v1\n");
+ hrtf = LoadHrtf01(rdata+sizeof(magicMarker01),
+ rsize-sizeof(magicMarker01), name
+ );
+ }
+ else if(memcmp(rdata, magicMarker00, sizeof(magicMarker00)) == 0)
+ {
+ TRACE("Detected data set format v0\n");
+ hrtf = LoadHrtf00(rdata+sizeof(magicMarker00),
+ rsize-sizeof(magicMarker00), name
+ );
+ }
+ else
+ ERR("Invalid header in %s: \"%.8s\"\n", name, (const char*)rdata);
+ if(fmap.ptr)
+ UnmapFileMem(&fmap);
+
+ if(!hrtf)
+ {
+ ERR("Failed to load %s\n", name);
+ goto done;
+ }
+ entry->handle = hrtf;
+ Hrtf_IncRef(hrtf);
+
+ TRACE("Loaded HRTF support for format: %s %uhz\n",
+ DevFmtChannelsString(DevFmtStereo), hrtf->sampleRate);
+
+done:
+ ATOMIC_FLAG_CLEAR(&LoadedHrtfLock, almemory_order_seq_cst);
+ return hrtf;
+}
+
+
+void Hrtf_IncRef(struct Hrtf *hrtf)
{
- return Hrtf->sampleRate;
+ uint ref = IncrementRef(&hrtf->ref);
+ TRACEREF("%p increasing refcount to %u\n", hrtf, ref);
}
-ALuint GetHrtfIrSize(const struct Hrtf *Hrtf)
+void Hrtf_DecRef(struct Hrtf *hrtf)
{
- return Hrtf->irSize;
+ struct HrtfEntry *Hrtf;
+ uint ref = DecrementRef(&hrtf->ref);
+ TRACEREF("%p decreasing refcount to %u\n", hrtf, ref);
+ if(ref == 0)
+ {
+ while(ATOMIC_FLAG_TEST_AND_SET(&LoadedHrtfLock, almemory_order_seq_cst))
+ althrd_yield();
+
+ Hrtf = LoadedHrtfs;
+ while(Hrtf != NULL)
+ {
+ /* Need to double-check that it's still unused, as another device
+ * could've reacquired this HRTF after its reference went to 0 and
+ * before the lock was taken.
+ */
+ if(hrtf == Hrtf->handle && ReadRef(&hrtf->ref) == 0)
+ {
+ al_free(Hrtf->handle);
+ Hrtf->handle = NULL;
+ TRACE("Unloaded unused HRTF %s\n", Hrtf->filename);
+ }
+ Hrtf = Hrtf->next;
+ }
+
+ ATOMIC_FLAG_CLEAR(&LoadedHrtfLock, almemory_order_seq_cst);
+ }
}
void FreeHrtfs(void)
{
- struct Hrtf *Hrtf = NULL;
+ struct HrtfEntry *Hrtf = LoadedHrtfs;
+ LoadedHrtfs = NULL;
- while((Hrtf=LoadedHrtfs) != NULL)
+ while(Hrtf != NULL)
{
- LoadedHrtfs = Hrtf->next;
- free((void*)Hrtf->azCount);
- free((void*)Hrtf->evOffset);
- free((void*)Hrtf->coeffs);
- free((void*)Hrtf->delays);
- al_string_deinit(&Hrtf->filename);
- free(Hrtf);
+ struct HrtfEntry *next = Hrtf->next;
+ al_free(Hrtf->handle);
+ al_free(Hrtf);
+ Hrtf = next;
}
}
diff --git a/Alc/hrtf.h b/Alc/hrtf.h
index 6dcd6948..ab68929b 100644
--- a/Alc/hrtf.h
+++ b/Alc/hrtf.h
@@ -4,37 +4,81 @@
#include "AL/al.h"
#include "AL/alc.h"
+#include "alMain.h"
#include "alstring.h"
+#include "atomic.h"
-enum DevFmtChannels;
-struct Hrtf;
-
-typedef struct HrtfEntry {
- al_string name;
- al_string filename;
-
- const struct Hrtf *hrtf;
-} HrtfEntry;
-TYPEDEF_VECTOR(HrtfEntry, vector_HrtfEntry)
+#define HRTF_HISTORY_BITS (6)
+#define HRTF_HISTORY_LENGTH (1<<HRTF_HISTORY_BITS)
+#define HRTF_HISTORY_MASK (HRTF_HISTORY_LENGTH-1)
#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)
+
+
+struct HrtfEntry;
+
+struct Hrtf {
+ RefCount ref;
+
+ ALuint sampleRate;
+ ALsizei irSize;
+
+ ALfloat distance;
+ ALubyte evCount;
+
+ const ALubyte *azCount;
+ const ALushort *evOffset;
+ const ALfloat (*coeffs)[2];
+ const ALubyte (*delays)[2];
+};
+
+
+typedef struct HrtfState {
+ alignas(16) ALfloat History[HRTF_HISTORY_LENGTH];
+ alignas(16) ALfloat Values[HRIR_LENGTH][2];
+} HrtfState;
+
+typedef struct HrtfParams {
+ alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
+ ALsizei Delay[2];
+ ALfloat Gain;
+} HrtfParams;
+
+typedef struct DirectHrtfState {
+ /* HRTF filter state for dry buffer content */
+ ALsizei Offset;
+ ALsizei IrSize;
+ struct {
+ alignas(16) ALfloat Values[HRIR_LENGTH][2];
+ alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
+ } Chan[];
+} DirectHrtfState;
+
+struct AngularPoint {
+ ALfloat Elev;
+ ALfloat Azim;
+};
+
void FreeHrtfs(void);
-vector_HrtfEntry EnumerateHrtf(const_al_string devname);
-void FreeHrtfList(vector_HrtfEntry *list);
+vector_EnumeratedHrtf EnumerateHrtf(const_al_string devname);
+void FreeHrtfList(vector_EnumeratedHrtf *list);
+struct Hrtf *GetLoadedHrtf(struct HrtfEntry *entry);
+void Hrtf_IncRef(struct Hrtf *hrtf);
+void Hrtf_DecRef(struct Hrtf *hrtf);
-ALuint GetHrtfSampleRate(const struct Hrtf *Hrtf);
-ALuint GetHrtfIrSize(const struct Hrtf *Hrtf);
+void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread, ALfloat (*coeffs)[2], ALsizei *delays);
-void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat dirfact, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays);
-ALuint GetMovingHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat dirfact, ALfloat gain, ALfloat delta, ALint counter, ALfloat (*coeffs)[2], ALuint *delays, ALfloat (*coeffStep)[2], ALint *delayStep);
-void GetBFormatHrtfCoeffs(const struct Hrtf *Hrtf, const ALuint num_chans, ALfloat (**coeffs_list)[2], ALuint **delay_list);
+/**
+ * Produces HRTF filter coefficients for decoding B-Format, given a set of
+ * virtual speaker positions, a matching decoding matrix, and per-order high-
+ * frequency gains for the decoder. The calculated impulse responses are
+ * ordered and scaled according to the matrix input.
+ */
+void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei NumChannels, const struct AngularPoint *AmbiPoints, const ALfloat (*restrict AmbiMatrix)[MAX_AMBI_COEFFS], ALsizei AmbiCount, const ALfloat *restrict AmbiOrderHFGain);
#endif /* ALC_HRTF_H */
diff --git a/Alc/inprogext.h b/Alc/inprogext.h
new file mode 100644
index 00000000..3025abe2
--- /dev/null
+++ b/Alc/inprogext.h
@@ -0,0 +1,87 @@
+#ifndef INPROGEXT_H
+#define INPROGEXT_H
+
+#include "AL/al.h"
+#include "AL/alc.h"
+#include "AL/alext.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef ALC_SOFT_loopback2
+#define ALC_SOFT_loopback2 1
+#define ALC_AMBISONIC_LAYOUT_SOFT 0xfff0
+#define ALC_AMBISONIC_SCALING_SOFT 0xfff1
+#define ALC_AMBISONIC_ORDER_SOFT 0xfff2
+#define ALC_MAX_AMBISONIC_ORDER_SOFT 0xfff3
+
+#define ALC_BFORMAT3D_SOFT 0x1508
+
+/* Ambisonic layouts */
+#define ALC_ACN_SOFT 0xfff4
+#define ALC_FUMA_SOFT 0xfff5
+
+/* Ambisonic scalings (normalization) */
+/*#define ALC_FUMA_SOFT*/
+#define ALC_SN3D_SOFT 0xfff6
+#define ALC_N3D_SOFT 0xfff7
+#endif
+
+#ifndef AL_SOFT_map_buffer
+#define AL_SOFT_map_buffer 1
+typedef unsigned int ALbitfieldSOFT;
+#define AL_MAP_READ_BIT_SOFT 0x00000001
+#define AL_MAP_WRITE_BIT_SOFT 0x00000002
+#define AL_MAP_PERSISTENT_BIT_SOFT 0x00000004
+#define AL_PRESERVE_DATA_BIT_SOFT 0x00000008
+typedef void (AL_APIENTRY*LPALBUFFERSTORAGESOFT)(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq, ALbitfieldSOFT flags);
+typedef void* (AL_APIENTRY*LPALMAPBUFFERSOFT)(ALuint buffer, ALsizei offset, ALsizei length, ALbitfieldSOFT access);
+typedef void (AL_APIENTRY*LPALUNMAPBUFFERSOFT)(ALuint buffer);
+typedef void (AL_APIENTRY*LPALFLUSHMAPPEDBUFFERSOFT)(ALuint buffer, ALsizei offset, ALsizei length);
+#ifdef AL_ALEXT_PROTOTYPES
+AL_API void AL_APIENTRY alBufferStorageSOFT(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq, ALbitfieldSOFT flags);
+AL_API void* AL_APIENTRY alMapBufferSOFT(ALuint buffer, ALsizei offset, ALsizei length, ALbitfieldSOFT access);
+AL_API void AL_APIENTRY alUnmapBufferSOFT(ALuint buffer);
+AL_API void AL_APIENTRY alFlushMappedBufferSOFT(ALuint buffer, ALsizei offset, ALsizei length);
+#endif
+#endif
+
+#ifndef AL_SOFT_events
+#define AL_SOFT_events 1
+#define AL_EVENT_CALLBACK_FUNCTION_SOFT 0x1220
+#define AL_EVENT_CALLBACK_USER_PARAM_SOFT 0x1221
+#define AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT 0x1222
+#define AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT 0x1223
+#define AL_EVENT_TYPE_ERROR_SOFT 0x1224
+#define AL_EVENT_TYPE_PERFORMANCE_SOFT 0x1225
+#define AL_EVENT_TYPE_DEPRECATED_SOFT 0x1226
+#define AL_EVENT_TYPE_DISCONNECTED_SOFT 0x1227
+typedef void (AL_APIENTRY*ALEVENTPROCSOFT)(ALenum eventType, ALuint object, ALuint param,
+ ALsizei length, const ALchar *message,
+ void *userParam);
+typedef void (AL_APIENTRY*LPALEVENTCONTROLSOFT)(ALsizei count, const ALenum *types, ALboolean enable);
+typedef void (AL_APIENTRY*LPALEVENTCALLBACKSOFT)(ALEVENTPROCSOFT callback, void *userParam);
+typedef void* (AL_APIENTRY*LPALGETPOINTERSOFT)(ALenum pname);
+typedef void (AL_APIENTRY*LPALGETPOINTERVSOFT)(ALenum pname, void **values);
+#ifdef AL_ALEXT_PROTOTYPES
+AL_API void AL_APIENTRY alEventControlSOFT(ALsizei count, const ALenum *types, ALboolean enable);
+AL_API void AL_APIENTRY alEventCallbackSOFT(ALEVENTPROCSOFT callback, void *userParam);
+AL_API void* AL_APIENTRY alGetPointerSOFT(ALenum pname);
+AL_API void AL_APIENTRY alGetPointervSOFT(ALenum pname, void **values);
+#endif
+#endif
+
+#ifndef AL_SOFT_buffer_layers
+#define AL_SOFT_buffer_layers
+typedef void (AL_APIENTRY*LPALSOURCEQUEUEBUFFERLAYERSSOFT)(ALuint src, ALsizei nb, const ALuint *buffers);
+#ifdef AL_ALEXT_PROTOTYPES
+AL_API void AL_APIENTRY alSourceQueueBufferLayersSOFT(ALuint src, ALsizei nb, const ALuint *buffers);
+#endif
+#endif
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* INPROGEXT_H */
diff --git a/Alc/logging.h b/Alc/logging.h
new file mode 100644
index 00000000..785771c8
--- /dev/null
+++ b/Alc/logging.h
@@ -0,0 +1,69 @@
+#ifndef LOGGING_H
+#define LOGGING_H
+
+#include <stdio.h>
+
+
+#ifdef __GNUC__
+#define DECL_FORMAT(x, y, z) __attribute__((format(x, (y), (z))))
+#else
+#define DECL_FORMAT(x, y, z)
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern FILE *LogFile;
+
+#if defined(__GNUC__) && !defined(_WIN32)
+#define AL_PRINT(T, MSG, ...) fprintf(LogFile, "AL lib: %s %s: "MSG, T, __FUNCTION__ , ## __VA_ARGS__)
+#else
+void al_print(const char *type, const char *func, const char *fmt, ...) DECL_FORMAT(printf, 3,4);
+#define AL_PRINT(T, ...) al_print((T), __FUNCTION__, __VA_ARGS__)
+#endif
+
+#ifdef __ANDROID__
+#include <android/log.h>
+#define LOG_ANDROID(T, MSG, ...) __android_log_print(T, "openal", "AL lib: %s: "MSG, __FUNCTION__ , ## __VA_ARGS__)
+#else
+#define LOG_ANDROID(T, MSG, ...) ((void)0)
+#endif
+
+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__); \
+ LOG_ANDROID(ANDROID_LOG_DEBUG, __VA_ARGS__); \
+} while(0)
+
+#define WARN(...) do { \
+ if(LogLevel >= LogWarning) \
+ AL_PRINT("(WW)", __VA_ARGS__); \
+ LOG_ANDROID(ANDROID_LOG_WARN, __VA_ARGS__); \
+} while(0)
+
+#define ERR(...) do { \
+ if(LogLevel >= LogError) \
+ AL_PRINT("(EE)", __VA_ARGS__); \
+ LOG_ANDROID(ANDROID_LOG_ERROR, __VA_ARGS__); \
+} while(0)
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* LOGGING_H */
diff --git a/Alc/mastering.c b/Alc/mastering.c
new file mode 100644
index 00000000..6745c1c7
--- /dev/null
+++ b/Alc/mastering.c
@@ -0,0 +1,543 @@
+#include "config.h"
+
+#include <math.h>
+
+#include "mastering.h"
+#include "alu.h"
+#include "almalloc.h"
+#include "static_assert.h"
+#include "math_defs.h"
+
+
+/* Early MSVC lacks round/roundf */
+#if defined(_MSC_VER) && _MSC_VER < 1800
+static double round(double val)
+{
+ if(val < 0.0)
+ return ceil(val-0.5);
+ return floor(val+0.5);
+}
+#define roundf(f) ((float)round((float)(f)))
+#endif
+
+
+/* These structures assume BUFFERSIZE is a power of 2. */
+static_assert((BUFFERSIZE & (BUFFERSIZE-1)) == 0, "BUFFERSIZE is not a power of 2");
+
+typedef struct SlidingHold {
+ ALfloat Values[BUFFERSIZE];
+ ALsizei Expiries[BUFFERSIZE];
+ ALsizei LowerIndex;
+ ALsizei UpperIndex;
+ ALsizei Length;
+} SlidingHold;
+
+/* General topology and basic automation was based on the following paper:
+ *
+ * D. Giannoulis, M. Massberg and J. D. Reiss,
+ * "Parameter Automation in a Dynamic Range Compressor,"
+ * Journal of the Audio Engineering Society, v61 (10), Oct. 2013
+ *
+ * Available (along with supplemental reading) at:
+ *
+ * http://c4dm.eecs.qmul.ac.uk/audioengineering/compressors/
+ */
+typedef struct Compressor {
+ ALsizei NumChans;
+ ALuint SampleRate;
+
+ struct {
+ ALuint Knee : 1;
+ ALuint Attack : 1;
+ ALuint Release : 1;
+ ALuint PostGain : 1;
+ ALuint Declip : 1;
+ } Auto;
+
+ ALsizei LookAhead;
+
+ ALfloat PreGain;
+ ALfloat PostGain;
+
+ ALfloat Threshold;
+ ALfloat Slope;
+ ALfloat Knee;
+
+ ALfloat Attack;
+ ALfloat Release;
+
+ alignas(16) ALfloat SideChain[2*BUFFERSIZE];
+ alignas(16) ALfloat CrestFactor[BUFFERSIZE];
+
+ SlidingHold *Hold;
+ ALfloat (*Delay)[BUFFERSIZE];
+ ALsizei DelayIndex;
+
+ ALfloat CrestCoeff;
+ ALfloat GainEstimate;
+ ALfloat AdaptCoeff;
+
+ ALfloat LastPeakSq;
+ ALfloat LastRmsSq;
+ ALfloat LastRelease;
+ ALfloat LastAttack;
+ ALfloat LastGainDev;
+} Compressor;
+
+
+/* This sliding hold follows the input level with an instant attack and a
+ * fixed duration hold before an instant release to the next highest level.
+ * It is a sliding window maximum (descending maxima) implementation based on
+ * Richard Harter's ascending minima algorithm available at:
+ *
+ * http://www.richardhartersworld.com/cri/2001/slidingmin.html
+ */
+static ALfloat UpdateSlidingHold(SlidingHold *Hold, const ALsizei i, const ALfloat in)
+{
+ const ALsizei mask = BUFFERSIZE - 1;
+ const ALsizei length = Hold->Length;
+ ALfloat *restrict values = Hold->Values;
+ ALsizei *restrict expiries = Hold->Expiries;
+ ALsizei lowerIndex = Hold->LowerIndex;
+ ALsizei upperIndex = Hold->UpperIndex;
+
+ if(i >= expiries[upperIndex])
+ upperIndex = (upperIndex + 1) & mask;
+
+ if(in >= values[upperIndex])
+ {
+ values[upperIndex] = in;
+ expiries[upperIndex] = i + length;
+ lowerIndex = upperIndex;
+ }
+ else
+ {
+ do {
+ do {
+ if(!(in >= values[lowerIndex]))
+ goto found_place;
+ } while(lowerIndex--);
+ lowerIndex = mask;
+ } while(1);
+ found_place:
+
+ lowerIndex = (lowerIndex + 1) & mask;
+ values[lowerIndex] = in;
+ expiries[lowerIndex] = i + length;
+ }
+
+ Hold->LowerIndex = lowerIndex;
+ Hold->UpperIndex = upperIndex;
+
+ return values[upperIndex];
+}
+
+static void ShiftSlidingHold(SlidingHold *Hold, const ALsizei n)
+{
+ const ALsizei lowerIndex = Hold->LowerIndex;
+ ALsizei *restrict expiries = Hold->Expiries;
+ ALsizei i = Hold->UpperIndex;
+
+ if(lowerIndex < i)
+ {
+ for(;i < BUFFERSIZE;i++)
+ expiries[i] -= n;
+ i = 0;
+ }
+ for(;i < lowerIndex;i++)
+ expiries[i] -= n;
+
+ expiries[i] -= n;
+}
+
+/* Multichannel compression is linked via the absolute maximum of all
+ * channels.
+ */
+static void LinkChannels(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*restrict OutBuffer)[BUFFERSIZE])
+{
+ const ALsizei index = Comp->LookAhead;
+ const ALsizei numChans = Comp->NumChans;
+ ALfloat *restrict sideChain = Comp->SideChain;
+ ALsizei c, i;
+
+ ASSUME(SamplesToDo > 0);
+ ASSUME(numChans > 0);
+
+ for(i = 0;i < SamplesToDo;i++)
+ sideChain[index + i] = 0.0f;
+
+ for(c = 0;c < numChans;c++)
+ {
+ ALsizei offset = index;
+ for(i = 0;i < SamplesToDo;i++)
+ {
+ sideChain[offset] = maxf(sideChain[offset], fabsf(OutBuffer[c][i]));
+ ++offset;
+ }
+ }
+}
+
+/* This calculates the squared crest factor of the control signal for the
+ * basic automation of the attack/release times. As suggested by the paper,
+ * it uses an instantaneous squared peak detector and a squared RMS detector
+ * both with 200ms release times.
+ */
+static void CrestDetector(Compressor *Comp, const ALsizei SamplesToDo)
+{
+ const ALfloat a_crest = Comp->CrestCoeff;
+ const ALsizei index = Comp->LookAhead;
+ const ALfloat *restrict sideChain = Comp->SideChain;
+ ALfloat *restrict crestFactor = Comp->CrestFactor;
+ ALfloat y2_peak = Comp->LastPeakSq;
+ ALfloat y2_rms = Comp->LastRmsSq;
+ ALsizei i;
+
+ ASSUME(SamplesToDo > 0);
+
+ for(i = 0;i < SamplesToDo;i++)
+ {
+ ALfloat x_abs = sideChain[index + i];
+ ALfloat x2 = maxf(0.000001f, x_abs * x_abs);
+
+ y2_peak = maxf(x2, lerp(x2, y2_peak, a_crest));
+ y2_rms = lerp(x2, y2_rms, a_crest);
+ crestFactor[i] = y2_peak / y2_rms;
+ }
+
+ Comp->LastPeakSq = y2_peak;
+ Comp->LastRmsSq = y2_rms;
+}
+
+/* The side-chain starts with a simple peak detector (based on the absolute
+ * value of the incoming signal) and performs most of its operations in the
+ * log domain.
+ */
+static void PeakDetector(Compressor *Comp, const ALsizei SamplesToDo)
+{
+ const ALsizei index = Comp->LookAhead;
+ ALfloat *restrict sideChain = Comp->SideChain;
+ ALsizei i;
+
+ ASSUME(SamplesToDo > 0);
+
+ for(i = 0;i < SamplesToDo;i++)
+ {
+ const ALuint offset = index + i;
+ const ALfloat x_abs = sideChain[offset];
+
+ sideChain[offset] = logf(maxf(0.000001f, x_abs));
+ }
+}
+
+/* An optional hold can be used to extend the peak detector so it can more
+ * solidly detect fast transients. This is best used when operating as a
+ * limiter.
+ */
+static void PeakHoldDetector(Compressor *Comp, const ALsizei SamplesToDo)
+{
+ const ALsizei index = Comp->LookAhead;
+ ALfloat *restrict sideChain = Comp->SideChain;
+ SlidingHold *hold = Comp->Hold;
+ ALsizei i;
+
+ ASSUME(SamplesToDo > 0);
+
+ for(i = 0;i < SamplesToDo;i++)
+ {
+ const ALsizei offset = index + i;
+ const ALfloat x_abs = sideChain[offset];
+ const ALfloat x_G = logf(maxf(0.000001f, x_abs));
+
+ sideChain[offset] = UpdateSlidingHold(hold, i, x_G);
+ }
+
+ ShiftSlidingHold(hold, SamplesToDo);
+}
+
+/* This is the heart of the feed-forward compressor. It operates in the log
+ * domain (to better match human hearing) and can apply some basic automation
+ * to knee width, attack/release times, make-up/post gain, and clipping
+ * reduction.
+ */
+static void GainCompressor(Compressor *Comp, const ALsizei SamplesToDo)
+{
+ const bool autoKnee = Comp->Auto.Knee;
+ const bool autoAttack = Comp->Auto.Attack;
+ const bool autoRelease = Comp->Auto.Release;
+ const bool autoPostGain = Comp->Auto.PostGain;
+ const bool autoDeclip = Comp->Auto.Declip;
+ const ALsizei lookAhead = Comp->LookAhead;
+ const ALfloat threshold = Comp->Threshold;
+ const ALfloat slope = Comp->Slope;
+ const ALfloat attack = Comp->Attack;
+ const ALfloat release = Comp->Release;
+ const ALfloat c_est = Comp->GainEstimate;
+ const ALfloat a_adp = Comp->AdaptCoeff;
+ const ALfloat *restrict crestFactor = Comp->CrestFactor;
+ ALfloat *restrict sideChain = Comp->SideChain;
+ ALfloat postGain = Comp->PostGain;
+ ALfloat knee = Comp->Knee;
+ ALfloat t_att = attack;
+ ALfloat t_rel = release - attack;
+ ALfloat a_att = expf(-1.0f / t_att);
+ ALfloat a_rel = expf(-1.0f / t_rel);
+ ALfloat y_1 = Comp->LastRelease;
+ ALfloat y_L = Comp->LastAttack;
+ ALfloat c_dev = Comp->LastGainDev;
+ ALsizei i;
+
+ ASSUME(SamplesToDo > 0);
+
+ for(i = 0;i < SamplesToDo;i++)
+ {
+ const ALfloat y2_crest = crestFactor[i];
+ const ALfloat x_G = sideChain[lookAhead + i];
+ const ALfloat x_over = x_G - threshold;
+ ALfloat knee_h;
+ ALfloat y_G;
+ ALfloat x_L;
+
+ if(autoKnee)
+ knee = maxf(0.0f, 2.5f * (c_dev + c_est));
+ knee_h = 0.5f * knee;
+
+ /* This is the gain computer. It applies a static compression curve
+ * to the control signal.
+ */
+ if(x_over <= -knee_h)
+ y_G = 0.0f;
+ else if(fabsf(x_over) < knee_h)
+ y_G = (x_over + knee_h) * (x_over + knee_h) / (2.0f * knee);
+ else
+ y_G = x_over;
+
+ x_L = -slope * y_G;
+
+ if(autoAttack)
+ {
+ t_att = 2.0f * attack / y2_crest;
+ a_att = expf(-1.0f / t_att);
+ }
+
+ if(autoRelease)
+ {
+ t_rel = 2.0f * release / y2_crest - t_att;
+ a_rel = expf(-1.0f / t_rel);
+ }
+
+ /* Gain smoothing (ballistics) is done via a smooth decoupled peak
+ * detector. The attack time is subtracted from the release time
+ * above to compensate for the chained operating mode.
+ */
+ y_1 = maxf(x_L, lerp(x_L, y_1, a_rel));
+ y_L = lerp(y_1, y_L, a_att);
+
+ /* Knee width and make-up gain automation make use of a smoothed
+ * measurement of deviation between the control signal and estimate.
+ * The estimate is also used to bias the measurement to hot-start its
+ * average.
+ */
+ c_dev = lerp(-y_L - c_est, c_dev, a_adp);
+
+ if(autoPostGain)
+ {
+ /* Clipping reduction is only viable when make-up gain is being
+ * automated. It modifies the deviation to further attenuate the
+ * control signal when clipping is detected. The adaptation
+ * time is sufficiently long enough to suppress further clipping
+ * at the same output level.
+ */
+ if(autoDeclip)
+ c_dev = maxf(c_dev, sideChain[i] - y_L - threshold - c_est);
+
+ postGain = -(c_dev + c_est);
+ }
+
+ sideChain[i] = expf(postGain - y_L);
+ }
+
+ Comp->LastRelease = y_1;
+ Comp->LastAttack = y_L;
+ Comp->LastGainDev = c_dev;
+}
+
+/* Combined with the hold time, a look-ahead delay can improve handling of
+ * fast transients by allowing the envelope time to converge prior to
+ * reaching the offending impulse. This is best used when operating as a
+ * limiter.
+ */
+static void SignalDelay(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*restrict OutBuffer)[BUFFERSIZE])
+{
+ const ALsizei mask = BUFFERSIZE - 1;
+ const ALsizei numChans = Comp->NumChans;
+ const ALsizei indexIn = Comp->DelayIndex;
+ const ALsizei indexOut = Comp->DelayIndex - Comp->LookAhead;
+ ALfloat (*restrict delay)[BUFFERSIZE] = Comp->Delay;
+ ALsizei c, i;
+
+ ASSUME(SamplesToDo > 0);
+ ASSUME(numChans > 0);
+
+ for(c = 0;c < numChans;c++)
+ {
+ for(i = 0;i < SamplesToDo;i++)
+ {
+ ALfloat sig = OutBuffer[c][i];
+
+ OutBuffer[c][i] = delay[c][(indexOut + i) & mask];
+ delay[c][(indexIn + i) & mask] = sig;
+ }
+ }
+
+ Comp->DelayIndex = (indexIn + SamplesToDo) & mask;
+}
+
+/* The compressor is initialized with the following settings:
+ *
+ * NumChans - Number of channels to process.
+ * SampleRate - Sample rate to process.
+ * AutoKnee - Whether to automate the knee width parameter.
+ * AutoAttack - Whether to automate the attack time parameter.
+ * AutoRelease - Whether to automate the release time parameter.
+ * AutoPostGain - Whether to automate the make-up (post) gain parameter.
+ * AutoDeclip - Whether to automate clipping reduction. Ignored when
+ * not automating make-up gain.
+ * LookAheadTime - Look-ahead time (in seconds).
+ * HoldTime - Peak hold-time (in seconds).
+ * PreGainDb - Gain applied before detection (in dB).
+ * PostGainDb - Make-up gain applied after compression (in dB).
+ * ThresholdDb - Triggering threshold (in dB).
+ * Ratio - Compression ratio (x:1). Set to INFINITY for true
+ * limiting. Ignored when automating knee width.
+ * KneeDb - Knee width (in dB). Ignored when automating knee
+ * width.
+ * AttackTimeMin - Attack time (in seconds). Acts as a maximum when
+ * automating attack time.
+ * ReleaseTimeMin - Release time (in seconds). Acts as a maximum when
+ * automating release time.
+ */
+Compressor* CompressorInit(const ALsizei NumChans, const ALuint SampleRate,
+ const ALboolean AutoKnee, const ALboolean AutoAttack,
+ const ALboolean AutoRelease, const ALboolean AutoPostGain,
+ const ALboolean AutoDeclip, const ALfloat LookAheadTime,
+ const ALfloat HoldTime, const ALfloat PreGainDb,
+ const ALfloat PostGainDb, const ALfloat ThresholdDb,
+ const ALfloat Ratio, const ALfloat KneeDb,
+ const ALfloat AttackTime, const ALfloat ReleaseTime)
+{
+ Compressor *Comp;
+ ALsizei lookAhead;
+ ALsizei hold;
+ size_t size;
+
+ lookAhead = (ALsizei)clampf(roundf(LookAheadTime*SampleRate), 0.0f, BUFFERSIZE-1);
+ hold = (ALsizei)clampf(roundf(HoldTime*SampleRate), 0.0f, BUFFERSIZE-1);
+ /* The sliding hold implementation doesn't handle a length of 1. A 1-sample
+ * hold is useless anyway, it would only ever give back what was just given
+ * to it.
+ */
+ if(hold == 1)
+ hold = 0;
+
+ size = sizeof(*Comp);
+ if(lookAhead > 0)
+ {
+ size += sizeof(*Comp->Delay) * NumChans;
+ if(hold > 0)
+ size += sizeof(*Comp->Hold);
+ }
+
+ Comp = al_calloc(16, size);
+ Comp->NumChans = NumChans;
+ Comp->SampleRate = SampleRate;
+ Comp->Auto.Knee = AutoKnee;
+ Comp->Auto.Attack = AutoAttack;
+ Comp->Auto.Release = AutoRelease;
+ Comp->Auto.PostGain = AutoPostGain;
+ Comp->Auto.Declip = AutoPostGain && AutoDeclip;
+ Comp->LookAhead = lookAhead;
+ Comp->PreGain = powf(10.0f, PreGainDb / 20.0f);
+ Comp->PostGain = PostGainDb * logf(10.0f) / 20.0f;
+ Comp->Threshold = ThresholdDb * logf(10.0f) / 20.0f;
+ Comp->Slope = 1.0f / maxf(1.0f, Ratio) - 1.0f;
+ Comp->Knee = maxf(0.0f, KneeDb * logf(10.0f) / 20.0f);
+ Comp->Attack = maxf(1.0f, AttackTime * SampleRate);
+ Comp->Release = maxf(1.0f, ReleaseTime * SampleRate);
+
+ /* Knee width automation actually treats the compressor as a limiter. By
+ * varying the knee width, it can effectively be seen as applying
+ * compression over a wide range of ratios.
+ */
+ if(AutoKnee)
+ Comp->Slope = -1.0f;
+
+ if(lookAhead > 0)
+ {
+ if(hold > 0)
+ {
+ Comp->Hold = (SlidingHold*)(Comp + 1);
+ Comp->Hold->Values[0] = -HUGE_VALF;
+ Comp->Hold->Expiries[0] = hold;
+ Comp->Hold->Length = hold;
+ Comp->Delay = (ALfloat(*)[BUFFERSIZE])(Comp->Hold + 1);
+ }
+ else
+ {
+ Comp->Delay = (ALfloat(*)[BUFFERSIZE])(Comp + 1);
+ }
+ }
+
+ Comp->CrestCoeff = expf(-1.0f / (0.200f * SampleRate)); // 200ms
+ Comp->GainEstimate = Comp->Threshold * -0.5f * Comp->Slope;
+ Comp->AdaptCoeff = expf(-1.0f / (2.0f * SampleRate)); // 2s
+
+ return Comp;
+}
+
+void ApplyCompression(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*restrict OutBuffer)[BUFFERSIZE])
+{
+ const ALsizei numChans = Comp->NumChans;
+ const ALfloat preGain = Comp->PreGain;
+ ALfloat *restrict sideChain;
+ ALsizei c, i;
+
+ ASSUME(SamplesToDo > 0);
+ ASSUME(numChans > 0);
+
+ if(preGain != 1.0f)
+ {
+ for(c = 0;c < numChans;c++)
+ {
+ for(i = 0;i < SamplesToDo;i++)
+ OutBuffer[c][i] *= preGain;
+ }
+ }
+
+ LinkChannels(Comp, SamplesToDo, OutBuffer);
+
+ if(Comp->Auto.Attack || Comp->Auto.Release)
+ CrestDetector(Comp, SamplesToDo);
+
+ if(Comp->Hold)
+ PeakHoldDetector(Comp, SamplesToDo);
+ else
+ PeakDetector(Comp, SamplesToDo);
+
+ GainCompressor(Comp, SamplesToDo);
+
+ if(Comp->Delay)
+ SignalDelay(Comp, SamplesToDo, OutBuffer);
+
+ sideChain = Comp->SideChain;
+ for(c = 0;c < numChans;c++)
+ {
+ for(i = 0;i < SamplesToDo;i++)
+ OutBuffer[c][i] *= sideChain[i];
+ }
+
+ memmove(sideChain, sideChain+SamplesToDo, Comp->LookAhead*sizeof(ALfloat));
+}
+
+
+ALsizei GetCompressorLookAhead(const Compressor *Comp)
+{ return Comp->LookAhead; }
diff --git a/Alc/mastering.h b/Alc/mastering.h
new file mode 100644
index 00000000..b68b0de1
--- /dev/null
+++ b/Alc/mastering.h
@@ -0,0 +1,49 @@
+#ifndef MASTERING_H
+#define MASTERING_H
+
+#include "AL/al.h"
+
+/* For BUFFERSIZE. */
+#include "alMain.h"
+
+struct Compressor;
+
+/* The compressor is initialized with the following settings:
+ *
+ * NumChans - Number of channels to process.
+ * SampleRate - Sample rate to process.
+ * AutoKnee - Whether to automate the knee width parameter.
+ * AutoAttack - Whether to automate the attack time parameter.
+ * AutoRelease - Whether to automate the release time parameter.
+ * AutoPostGain - Whether to automate the make-up (post) gain parameter.
+ * AutoDeclip - Whether to automate clipping reduction. Ignored when
+ * not automating make-up gain.
+ * LookAheadTime - Look-ahead time (in seconds).
+ * HoldTime - Peak hold-time (in seconds).
+ * PreGainDb - Gain applied before detection (in dB).
+ * PostGainDb - Make-up gain applied after compression (in dB).
+ * ThresholdDb - Triggering threshold (in dB).
+ * Ratio - Compression ratio (x:1). Set to INFINIFTY for true
+ * limiting. Ignored when automating knee width.
+ * KneeDb - Knee width (in dB). Ignored when automating knee
+ * width.
+ * AttackTimeMin - Attack time (in seconds). Acts as a maximum when
+ * automating attack time.
+ * ReleaseTimeMin - Release time (in seconds). Acts as a maximum when
+ * automating release time.
+ */
+struct Compressor* CompressorInit(const ALsizei NumChans, const ALuint SampleRate,
+ const ALboolean AutoKnee, const ALboolean AutoAttack,
+ const ALboolean AutoRelease, const ALboolean AutoPostGain,
+ const ALboolean AutoDeclip, const ALfloat LookAheadTime,
+ const ALfloat HoldTime, const ALfloat PreGainDb,
+ const ALfloat PostGainDb, const ALfloat ThresholdDb,
+ const ALfloat Ratio, const ALfloat KneeDb,
+ const ALfloat AttackTime, const ALfloat ReleaseTime);
+
+void ApplyCompression(struct Compressor *Comp, const ALsizei SamplesToDo,
+ ALfloat (*restrict OutBuffer)[BUFFERSIZE]);
+
+ALsizei GetCompressorLookAhead(const struct Compressor *Comp);
+
+#endif /* MASTERING_H */
diff --git a/Alc/mixer.c b/Alc/mixer.c
deleted file mode 100644
index 712075f1..00000000
--- a/Alc/mixer.c
+++ /dev/null
@@ -1,638 +0,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.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- * Or go to http://www.gnu.org/copyleft/lgpl.html
- */
-
-#include "config.h"
-
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <assert.h>
-
-#include "alMain.h"
-#include "AL/al.h"
-#include "AL/alc.h"
-#include "alSource.h"
-#include "alBuffer.h"
-#include "alListener.h"
-#include "alAuxEffectSlot.h"
-#include "alu.h"
-
-#include "mixer_defs.h"
-
-
-static_assert((INT_MAX>>FRACTIONBITS)/MAX_PITCH > BUFFERSIZE,
- "MAX_PITCH and/or BUFFERSIZE are too large for FRACTIONBITS!");
-
-extern inline void InitiatePositionArrays(ALuint frac, ALuint increment, ALuint *frac_arr, ALuint *pos_arr, ALuint size);
-
-alignas(16) union ResamplerCoeffs ResampleCoeffs;
-
-
-enum Resampler {
- PointResampler,
- LinearResampler,
- FIR4Resampler,
- FIR8Resampler,
- BSincResampler,
-
- ResamplerDefault = LinearResampler
-};
-
-/* FIR8 requires 3 extra samples before the current position, and 4 after. */
-static_assert(MAX_PRE_SAMPLES >= 3, "MAX_PRE_SAMPLES must be at least 3!");
-static_assert(MAX_POST_SAMPLES >= 4, "MAX_POST_SAMPLES must be at least 4!");
-
-
-static HrtfMixerFunc MixHrtfSamples = MixHrtf_C;
-static MixerFunc MixSamples = Mix_C;
-static ResamplerFunc ResampleSamples = Resample_point32_C;
-
-static inline HrtfMixerFunc SelectHrtfMixer(void)
-{
-#ifdef HAVE_SSE
- if((CPUCapFlags&CPU_CAP_SSE))
- return MixHrtf_SSE;
-#endif
-#ifdef HAVE_NEON
- if((CPUCapFlags&CPU_CAP_NEON))
- return MixHrtf_Neon;
-#endif
-
- return MixHrtf_C;
-}
-
-static inline MixerFunc SelectMixer(void)
-{
-#ifdef HAVE_SSE
- if((CPUCapFlags&CPU_CAP_SSE))
- return Mix_SSE;
-#endif
-#ifdef HAVE_NEON
- if((CPUCapFlags&CPU_CAP_NEON))
- return Mix_Neon;
-#endif
-
- return Mix_C;
-}
-
-static inline ResamplerFunc SelectResampler(enum Resampler resampler)
-{
- switch(resampler)
- {
- case PointResampler:
- return Resample_point32_C;
- case LinearResampler:
-#ifdef HAVE_SSE4_1
- if((CPUCapFlags&CPU_CAP_SSE4_1))
- return Resample_lerp32_SSE41;
-#endif
-#ifdef HAVE_SSE2
- if((CPUCapFlags&CPU_CAP_SSE2))
- return Resample_lerp32_SSE2;
-#endif
- return Resample_lerp32_C;
- case FIR4Resampler:
-#ifdef HAVE_SSE4_1
- if((CPUCapFlags&CPU_CAP_SSE4_1))
- return Resample_fir4_32_SSE41;
-#endif
-#ifdef HAVE_SSE3
- if((CPUCapFlags&CPU_CAP_SSE3))
- return Resample_fir4_32_SSE3;
-#endif
- return Resample_fir4_32_C;
- case FIR8Resampler:
-#ifdef HAVE_SSE4_1
- if((CPUCapFlags&CPU_CAP_SSE4_1))
- return Resample_fir8_32_SSE41;
-#endif
-#ifdef HAVE_SSE3
- if((CPUCapFlags&CPU_CAP_SSE3))
- return Resample_fir8_32_SSE3;
-#endif
- return Resample_fir8_32_C;
- case BSincResampler:
-#ifdef HAVE_SSE
- if((CPUCapFlags&CPU_CAP_SSE))
- return Resample_bsinc32_SSE;
-#endif
- return Resample_bsinc32_C;
- }
-
- return Resample_point32_C;
-}
-
-
-/* The sinc resampler makes use of a Kaiser window to limit the needed sample
- * points to 4 and 8, respectively.
- */
-
-#ifndef M_PI
-#define M_PI (3.14159265358979323846)
-#endif
-static inline double Sinc(double x)
-{
- if(x == 0.0) return 1.0;
- return sin(x*M_PI) / (x*M_PI);
-}
-
-/* The zero-order modified Bessel function of the first kind, used for the
- * Kaiser window.
- *
- * I_0(x) = sum_{k=0}^inf (1 / k!)^2 (x / 2)^(2 k)
- * = sum_{k=0}^inf ((x / 2)^k / k!)^2
- */
-static double BesselI_0(double x)
-{
- double term, sum, x2, y, last_sum;
- int k;
-
- /* Start at k=1 since k=0 is trivial. */
- term = 1.0;
- sum = 1.0;
- x2 = x / 2.0;
- k = 1;
-
- /* Let the integration converge until the term of the sum is no longer
- * significant.
- */
- do {
- y = x2 / k;
- k ++;
- last_sum = sum;
- term *= y * y;
- sum += term;
- } while(sum != last_sum);
- return sum;
-}
-
-/* Calculate a Kaiser window from the given beta value and a normalized k
- * [-1, 1].
- *
- * w(k) = { I_0(B sqrt(1 - k^2)) / I_0(B), -1 <= k <= 1
- * { 0, elsewhere.
- *
- * Where k can be calculated as:
- *
- * k = i / l, where -l <= i <= l.
- *
- * or:
- *
- * k = 2 i / M - 1, where 0 <= i <= M.
- */
-static inline double Kaiser(double b, double k)
-{
- if(k <= -1.0 || k >= 1.0) return 0.0;
- return BesselI_0(b * sqrt(1.0 - (k*k))) / BesselI_0(b);
-}
-
-static inline double CalcKaiserBeta(double rejection)
-{
- if(rejection > 50.0)
- return 0.1102 * (rejection - 8.7);
- if(rejection >= 21.0)
- return (0.5842 * pow(rejection - 21.0, 0.4)) +
- (0.07886 * (rejection - 21.0));
- return 0.0;
-}
-
-static float SincKaiser(double r, double x)
-{
- /* Limit rippling to -60dB. */
- return (float)(Kaiser(CalcKaiserBeta(60.0), x / r) * Sinc(x));
-}
-
-
-void aluInitMixer(void)
-{
- enum Resampler resampler = ResamplerDefault;
- const char *str;
- ALuint i;
-
- if(ConfigValueStr(NULL, NULL, "resampler", &str))
- {
- if(strcasecmp(str, "point") == 0 || strcasecmp(str, "none") == 0)
- resampler = PointResampler;
- else if(strcasecmp(str, "linear") == 0)
- resampler = LinearResampler;
- else if(strcasecmp(str, "sinc4") == 0)
- resampler = FIR4Resampler;
- else if(strcasecmp(str, "sinc8") == 0)
- resampler = FIR8Resampler;
- else if(strcasecmp(str, "bsinc") == 0)
- resampler = BSincResampler;
- else if(strcasecmp(str, "cubic") == 0)
- {
- WARN("Resampler option \"cubic\" is deprecated, using sinc4\n");
- resampler = FIR4Resampler;
- }
- else
- {
- char *end;
- long n = strtol(str, &end, 0);
- if(*end == '\0' && (n == PointResampler || n == LinearResampler || n == FIR4Resampler))
- resampler = n;
- else
- WARN("Invalid resampler: %s\n", str);
- }
- }
-
- if(resampler == FIR8Resampler)
- for(i = 0;i < FRACTIONONE;i++)
- {
- ALdouble mu = (ALdouble)i / FRACTIONONE;
- ResampleCoeffs.FIR8[i][0] = SincKaiser(4.0, mu - -3.0);
- ResampleCoeffs.FIR8[i][1] = SincKaiser(4.0, mu - -2.0);
- ResampleCoeffs.FIR8[i][2] = SincKaiser(4.0, mu - -1.0);
- ResampleCoeffs.FIR8[i][3] = SincKaiser(4.0, mu - 0.0);
- ResampleCoeffs.FIR8[i][4] = SincKaiser(4.0, mu - 1.0);
- ResampleCoeffs.FIR8[i][5] = SincKaiser(4.0, mu - 2.0);
- ResampleCoeffs.FIR8[i][6] = SincKaiser(4.0, mu - 3.0);
- ResampleCoeffs.FIR8[i][7] = SincKaiser(4.0, mu - 4.0);
- }
- else if(resampler == FIR4Resampler)
- for(i = 0;i < FRACTIONONE;i++)
- {
- ALdouble mu = (ALdouble)i / FRACTIONONE;
- ResampleCoeffs.FIR4[i][0] = SincKaiser(2.0, mu - -1.0);
- ResampleCoeffs.FIR4[i][1] = SincKaiser(2.0, mu - 0.0);
- ResampleCoeffs.FIR4[i][2] = SincKaiser(2.0, mu - 1.0);
- ResampleCoeffs.FIR4[i][3] = SincKaiser(2.0, mu - 2.0);
- }
-
- MixHrtfSamples = SelectHrtfMixer();
- MixSamples = SelectMixer();
- ResampleSamples = SelectResampler(resampler);
-}
-
-
-static inline ALfloat Sample_ALbyte(ALbyte val)
-{ return val * (1.0f/127.0f); }
-
-static inline ALfloat Sample_ALshort(ALshort val)
-{ return val * (1.0f/32767.0f); }
-
-static inline ALfloat Sample_ALfloat(ALfloat val)
-{ return val; }
-
-#define DECL_TEMPLATE(T) \
-static inline void Load_##T(ALfloat *dst, const T *src, ALuint srcstep, ALuint samples)\
-{ \
- ALuint i; \
- for(i = 0;i < samples;i++) \
- dst[i] = Sample_##T(src[i*srcstep]); \
-}
-
-DECL_TEMPLATE(ALbyte)
-DECL_TEMPLATE(ALshort)
-DECL_TEMPLATE(ALfloat)
-
-#undef DECL_TEMPLATE
-
-static void LoadSamples(ALfloat *dst, const ALvoid *src, ALuint srcstep, enum FmtType srctype, ALuint samples)
-{
- switch(srctype)
- {
- case FmtByte:
- Load_ALbyte(dst, src, srcstep, samples);
- break;
- case FmtShort:
- Load_ALshort(dst, src, srcstep, samples);
- break;
- case FmtFloat:
- Load_ALfloat(dst, src, srcstep, samples);
- break;
- }
-}
-
-static inline void SilenceSamples(ALfloat *dst, ALuint samples)
-{
- ALuint i;
- for(i = 0;i < samples;i++)
- dst[i] = 0.0f;
-}
-
-
-static const ALfloat *DoFilters(ALfilterState *lpfilter, ALfilterState *hpfilter,
- ALfloat *restrict dst, const ALfloat *restrict src,
- ALuint numsamples, enum ActiveFilters type)
-{
- ALuint i;
- switch(type)
- {
- case AF_None:
- ALfilterState_processPassthru(lpfilter, src, numsamples);
- ALfilterState_processPassthru(hpfilter, src, numsamples);
- break;
-
- case AF_LowPass:
- ALfilterState_process(lpfilter, dst, src, numsamples);
- ALfilterState_processPassthru(hpfilter, dst, numsamples);
- return dst;
- case AF_HighPass:
- ALfilterState_processPassthru(lpfilter, src, numsamples);
- ALfilterState_process(hpfilter, dst, src, numsamples);
- return dst;
-
- case AF_BandPass:
- for(i = 0;i < numsamples;)
- {
- ALfloat temp[256];
- ALuint todo = minu(256, numsamples-i);
-
- ALfilterState_process(lpfilter, temp, src+i, todo);
- ALfilterState_process(hpfilter, dst+i, temp, todo);
- i += todo;
- }
- return dst;
- }
- return src;
-}
-
-
-ALvoid MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALuint SamplesToDo)
-{
- ResamplerFunc Resample;
- ALbufferlistitem *BufferListItem;
- ALuint DataPosInt, DataPosFrac;
- ALboolean Looping;
- ALuint increment;
- ALenum State;
- ALuint OutPos;
- ALuint NumChannels;
- ALuint SampleSize;
- ALint64 DataSize64;
- ALuint IrSize;
- ALuint chan, j;
-
- /* Get source info */
- State = Source->state;
- BufferListItem = ATOMIC_LOAD(&Source->current_buffer);
- DataPosInt = Source->position;
- DataPosFrac = Source->position_fraction;
- Looping = Source->Looping;
- NumChannels = Source->NumChannels;
- SampleSize = Source->SampleSize;
- increment = voice->Step;
-
- IrSize = (Device->Hrtf ? GetHrtfIrSize(Device->Hrtf) : 0);
-
- Resample = ((increment == FRACTIONONE && DataPosFrac == 0) ?
- Resample_copy32_C : ResampleSamples);
-
- OutPos = 0;
- do {
- ALuint SrcBufferSize, DstBufferSize;
-
- /* Figure out how many buffer samples will be needed */
- DataSize64 = SamplesToDo-OutPos;
- DataSize64 *= increment;
- DataSize64 += DataPosFrac+FRACTIONMASK;
- DataSize64 >>= FRACTIONBITS;
- DataSize64 += MAX_POST_SAMPLES+MAX_PRE_SAMPLES;
-
- SrcBufferSize = (ALuint)mini64(DataSize64, BUFFERSIZE);
-
- /* Figure out how many samples we can actually mix from this. */
- DataSize64 = SrcBufferSize;
- DataSize64 -= MAX_POST_SAMPLES+MAX_PRE_SAMPLES;
- DataSize64 <<= FRACTIONBITS;
- DataSize64 -= DataPosFrac;
-
- DstBufferSize = (ALuint)((DataSize64+(increment-1)) / increment);
- DstBufferSize = minu(DstBufferSize, (SamplesToDo-OutPos));
-
- /* Some mixers like having a multiple of 4, so try to give that unless
- * this is the last update. */
- if(OutPos+DstBufferSize < SamplesToDo)
- DstBufferSize &= ~3;
-
- for(chan = 0;chan < NumChannels;chan++)
- {
- const ALfloat *ResampledData;
- ALfloat *SrcData = Device->SourceData;
- ALuint SrcDataSize;
-
- /* Load the previous samples into the source data first. */
- memcpy(SrcData, voice->PrevSamples[chan], MAX_PRE_SAMPLES*sizeof(ALfloat));
- SrcDataSize = MAX_PRE_SAMPLES;
-
- if(Source->SourceType == AL_STATIC)
- {
- const ALbuffer *ALBuffer = BufferListItem->buffer;
- const ALubyte *Data = ALBuffer->data;
- ALuint DataSize;
- ALuint pos;
-
- /* Offset buffer data to current channel */
- Data += chan*SampleSize;
-
- /* If current pos is beyond the loop range, do not loop */
- if(Looping == AL_FALSE || DataPosInt >= (ALuint)ALBuffer->LoopEnd)
- {
- Looping = AL_FALSE;
-
- /* Load what's left to play from the source buffer, and
- * clear the rest of the temp buffer */
- pos = DataPosInt;
- DataSize = minu(SrcBufferSize - SrcDataSize, ALBuffer->SampleLen - pos);
-
- LoadSamples(&SrcData[SrcDataSize], &Data[pos * NumChannels*SampleSize],
- NumChannels, ALBuffer->FmtType, DataSize);
- SrcDataSize += DataSize;
-
- SilenceSamples(&SrcData[SrcDataSize], SrcBufferSize - SrcDataSize);
- SrcDataSize += SrcBufferSize - SrcDataSize;
- }
- else
- {
- ALuint LoopStart = ALBuffer->LoopStart;
- ALuint LoopEnd = ALBuffer->LoopEnd;
-
- /* Load what's left of this loop iteration, then load
- * repeats of the loop section */
- pos = DataPosInt;
- DataSize = LoopEnd - pos;
- DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
-
- LoadSamples(&SrcData[SrcDataSize], &Data[pos * NumChannels*SampleSize],
- NumChannels, ALBuffer->FmtType, DataSize);
- SrcDataSize += DataSize;
-
- DataSize = LoopEnd-LoopStart;
- while(SrcBufferSize > SrcDataSize)
- {
- DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
-
- LoadSamples(&SrcData[SrcDataSize], &Data[LoopStart * NumChannels*SampleSize],
- NumChannels, ALBuffer->FmtType, DataSize);
- SrcDataSize += DataSize;
- }
- }
- }
- else
- {
- /* Crawl the buffer queue to fill in the temp buffer */
- ALbufferlistitem *tmpiter = BufferListItem;
- ALuint pos = DataPosInt;
-
- while(tmpiter && SrcBufferSize > SrcDataSize)
- {
- const ALbuffer *ALBuffer;
- if((ALBuffer=tmpiter->buffer) != NULL)
- {
- const ALubyte *Data = ALBuffer->data;
- ALuint DataSize = ALBuffer->SampleLen;
-
- /* Skip the data already played */
- if(DataSize <= pos)
- pos -= DataSize;
- else
- {
- Data += (pos*NumChannels + chan)*SampleSize;
- DataSize -= pos;
- pos -= pos;
-
- DataSize = minu(SrcBufferSize - SrcDataSize, DataSize);
- LoadSamples(&SrcData[SrcDataSize], Data, NumChannels,
- ALBuffer->FmtType, DataSize);
- SrcDataSize += DataSize;
- }
- }
- tmpiter = tmpiter->next;
- if(!tmpiter && Looping)
- tmpiter = ATOMIC_LOAD(&Source->queue);
- else if(!tmpiter)
- {
- SilenceSamples(&SrcData[SrcDataSize], SrcBufferSize - SrcDataSize);
- SrcDataSize += SrcBufferSize - SrcDataSize;
- }
- }
- }
-
- /* Store the last source samples used for next time. */
- memcpy(voice->PrevSamples[chan],
- &SrcData[(increment*DstBufferSize + DataPosFrac)>>FRACTIONBITS],
- MAX_PRE_SAMPLES*sizeof(ALfloat)
- );
-
- /* Now resample, then filter and mix to the appropriate outputs. */
- ResampledData = Resample(&voice->SincState,
- &SrcData[MAX_PRE_SAMPLES], DataPosFrac, increment,
- Device->ResampledData, DstBufferSize
- );
- {
- DirectParams *parms = &voice->Direct;
- const ALfloat *samples;
-
- samples = DoFilters(
- &parms->Filters[chan].LowPass, &parms->Filters[chan].HighPass,
- Device->FilteredData, ResampledData, DstBufferSize,
- parms->Filters[chan].ActiveType
- );
- if(!voice->IsHrtf)
- MixSamples(samples, parms->OutChannels, parms->OutBuffer, parms->Gains[chan],
- parms->Counter, OutPos, DstBufferSize);
- else
- MixHrtfSamples(parms->OutBuffer, samples, parms->Counter, voice->Offset,
- OutPos, IrSize, &parms->Hrtf[chan].Params,
- &parms->Hrtf[chan].State, DstBufferSize);
- }
-
- for(j = 0;j < Device->NumAuxSends;j++)
- {
- SendParams *parms = &voice->Send[j];
- const ALfloat *samples;
-
- if(!parms->OutBuffer)
- continue;
-
- samples = DoFilters(
- &parms->Filters[chan].LowPass, &parms->Filters[chan].HighPass,
- Device->FilteredData, ResampledData, DstBufferSize,
- parms->Filters[chan].ActiveType
- );
- MixSamples(samples, 1, parms->OutBuffer, &parms->Gains[chan],
- parms->Counter, OutPos, DstBufferSize);
- }
- }
- /* Update positions */
- DataPosFrac += increment*DstBufferSize;
- DataPosInt += DataPosFrac>>FRACTIONBITS;
- DataPosFrac &= FRACTIONMASK;
-
- OutPos += DstBufferSize;
- voice->Offset += DstBufferSize;
- voice->Direct.Counter = maxu(voice->Direct.Counter, DstBufferSize) - DstBufferSize;
- for(j = 0;j < Device->NumAuxSends;j++)
- voice->Send[j].Counter = maxu(voice->Send[j].Counter, DstBufferSize) - DstBufferSize;
-
- /* Handle looping sources */
- while(1)
- {
- const ALbuffer *ALBuffer;
- ALuint DataSize = 0;
- ALuint LoopStart = 0;
- ALuint LoopEnd = 0;
-
- if((ALBuffer=BufferListItem->buffer) != NULL)
- {
- DataSize = ALBuffer->SampleLen;
- LoopStart = ALBuffer->LoopStart;
- LoopEnd = ALBuffer->LoopEnd;
- if(LoopEnd > DataPosInt)
- break;
- }
-
- if(Looping && Source->SourceType == AL_STATIC)
- {
- assert(LoopEnd > LoopStart);
- DataPosInt = ((DataPosInt-LoopStart)%(LoopEnd-LoopStart)) + LoopStart;
- break;
- }
-
- if(DataSize > DataPosInt)
- break;
-
- if(!(BufferListItem=BufferListItem->next))
- {
- if(Looping)
- BufferListItem = ATOMIC_LOAD(&Source->queue);
- else
- {
- State = AL_STOPPED;
- BufferListItem = NULL;
- DataPosInt = 0;
- DataPosFrac = 0;
- break;
- }
- }
-
- DataPosInt -= DataSize;
- }
- } while(State == AL_PLAYING && OutPos < SamplesToDo);
-
- /* Update source info */
- Source->state = State;
- ATOMIC_STORE(&Source->current_buffer, BufferListItem);
- Source->position = DataPosInt;
- Source->position_fraction = DataPosFrac;
-}
diff --git a/Alc/mixer/defs.h b/Alc/mixer/defs.h
new file mode 100644
index 00000000..8f6e3755
--- /dev/null
+++ b/Alc/mixer/defs.h
@@ -0,0 +1,119 @@
+#ifndef MIXER_DEFS_H
+#define MIXER_DEFS_H
+
+#include "AL/alc.h"
+#include "AL/al.h"
+#include "alMain.h"
+#include "alu.h"
+
+struct MixGains;
+
+struct MixHrtfParams;
+struct HrtfState;
+
+/* C resamplers */
+const ALfloat *Resample_copy_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen);
+const ALfloat *Resample_point_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen);
+const ALfloat *Resample_lerp_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen);
+const ALfloat *Resample_cubic_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen);
+const ALfloat *Resample_bsinc_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen);
+
+
+/* C mixers */
+void MixHrtf_C(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, struct MixHrtfParams *hrtfparams,
+ struct HrtfState *hrtfstate, ALsizei BufferSize);
+void MixHrtfBlend_C(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, const HrtfParams *oldparams,
+ MixHrtfParams *newparams, HrtfState *hrtfstate,
+ ALsizei BufferSize);
+void MixDirectHrtf_C(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2], ALfloat (*restrict Values)[2],
+ ALsizei BufferSize);
+void Mix_C(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
+ ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
+ ALsizei BufferSize);
+void MixRow_C(ALfloat *OutBuffer, const ALfloat *Gains,
+ const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans,
+ ALsizei InPos, ALsizei BufferSize);
+
+/* SSE mixers */
+void MixHrtf_SSE(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, struct MixHrtfParams *hrtfparams,
+ struct HrtfState *hrtfstate, ALsizei BufferSize);
+void MixHrtfBlend_SSE(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, const HrtfParams *oldparams,
+ MixHrtfParams *newparams, HrtfState *hrtfstate,
+ ALsizei BufferSize);
+void MixDirectHrtf_SSE(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2], ALfloat (*restrict Values)[2],
+ ALsizei BufferSize);
+void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
+ ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
+ ALsizei BufferSize);
+void MixRow_SSE(ALfloat *OutBuffer, const ALfloat *Gains,
+ const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans,
+ ALsizei InPos, ALsizei BufferSize);
+
+/* SSE resamplers */
+inline void InitiatePositionArrays(ALsizei frac, ALint increment, ALsizei *restrict frac_arr, ALsizei *restrict pos_arr, ALsizei size)
+{
+ ALsizei i;
+
+ pos_arr[0] = 0;
+ frac_arr[0] = frac;
+ for(i = 1;i < size;i++)
+ {
+ ALint frac_tmp = frac_arr[i-1] + increment;
+ pos_arr[i] = pos_arr[i-1] + (frac_tmp>>FRACTIONBITS);
+ frac_arr[i] = frac_tmp&FRACTIONMASK;
+ }
+}
+
+const ALfloat *Resample_lerp_SSE2(const InterpState *state, const ALfloat *restrict src,
+ ALsizei frac, ALint increment, ALfloat *restrict dst,
+ ALsizei numsamples);
+const ALfloat *Resample_lerp_SSE41(const InterpState *state, const ALfloat *restrict src,
+ ALsizei frac, ALint increment, ALfloat *restrict dst,
+ ALsizei numsamples);
+
+const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *restrict src,
+ ALsizei frac, ALint increment, ALfloat *restrict dst,
+ ALsizei dstlen);
+
+/* Neon mixers */
+void MixHrtf_Neon(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, struct MixHrtfParams *hrtfparams,
+ struct HrtfState *hrtfstate, ALsizei BufferSize);
+void MixHrtfBlend_Neon(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, const HrtfParams *oldparams,
+ MixHrtfParams *newparams, HrtfState *hrtfstate,
+ ALsizei BufferSize);
+void MixDirectHrtf_Neon(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2], ALfloat (*restrict Values)[2],
+ ALsizei BufferSize);
+void Mix_Neon(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
+ ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
+ ALsizei BufferSize);
+void MixRow_Neon(ALfloat *OutBuffer, const ALfloat *Gains,
+ const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans,
+ ALsizei InPos, ALsizei BufferSize);
+
+/* Neon resamplers */
+const ALfloat *Resample_lerp_Neon(const InterpState *state, const ALfloat *restrict src,
+ ALsizei frac, ALint increment, ALfloat *restrict dst,
+ ALsizei numsamples);
+const ALfloat *Resample_bsinc_Neon(const InterpState *state, const ALfloat *restrict src,
+ ALsizei frac, ALint increment, ALfloat *restrict dst,
+ ALsizei dstlen);
+
+#endif /* MIXER_DEFS_H */
diff --git a/Alc/mixer/hrtf_inc.c b/Alc/mixer/hrtf_inc.c
new file mode 100644
index 00000000..3ef22f24
--- /dev/null
+++ b/Alc/mixer/hrtf_inc.c
@@ -0,0 +1,128 @@
+#include "config.h"
+
+#include "alMain.h"
+#include "alSource.h"
+
+#include "hrtf.h"
+#include "align.h"
+#include "alu.h"
+#include "defs.h"
+
+
+static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2],
+ const ALsizei irSize,
+ const ALfloat (*restrict Coeffs)[2],
+ ALfloat left, ALfloat right);
+
+
+void MixHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, MixHrtfParams *hrtfparams, HrtfState *hrtfstate,
+ ALsizei BufferSize)
+{
+ const ALfloat (*Coeffs)[2] = ASSUME_ALIGNED(hrtfparams->Coeffs, 16);
+ const ALsizei Delay[2] = { hrtfparams->Delay[0], hrtfparams->Delay[1] };
+ const ALfloat gainstep = hrtfparams->GainStep;
+ const ALfloat gain = hrtfparams->Gain;
+ ALfloat g, stepcount = 0.0f;
+ ALfloat left, right;
+ ALsizei i;
+
+ ASSUME(IrSize >= 4);
+ ASSUME(BufferSize > 0);
+
+ LeftOut += OutPos;
+ RightOut += OutPos;
+ for(i = 0;i < BufferSize;i++)
+ {
+ hrtfstate->History[Offset&HRTF_HISTORY_MASK] = *(data++);
+
+ g = gain + gainstep*stepcount;
+ left = hrtfstate->History[(Offset-Delay[0])&HRTF_HISTORY_MASK]*g;
+ right = hrtfstate->History[(Offset-Delay[1])&HRTF_HISTORY_MASK]*g;
+
+ hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][0] = 0.0f;
+ hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][1] = 0.0f;
+
+ ApplyCoeffs(Offset, hrtfstate->Values, IrSize, Coeffs, left, right);
+ *(LeftOut++) += hrtfstate->Values[Offset&HRIR_MASK][0];
+ *(RightOut++) += hrtfstate->Values[Offset&HRIR_MASK][1];
+
+ stepcount += 1.0f;
+ Offset++;
+ }
+ hrtfparams->Gain = gain + gainstep*stepcount;
+}
+
+void MixHrtfBlend(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, const HrtfParams *oldparams,
+ MixHrtfParams *newparams, HrtfState *hrtfstate,
+ ALsizei BufferSize)
+{
+ const ALfloat (*OldCoeffs)[2] = ASSUME_ALIGNED(oldparams->Coeffs, 16);
+ const ALsizei OldDelay[2] = { oldparams->Delay[0], oldparams->Delay[1] };
+ const ALfloat oldGain = oldparams->Gain;
+ const ALfloat oldGainStep = -oldGain / (ALfloat)BufferSize;
+ const ALfloat (*NewCoeffs)[2] = ASSUME_ALIGNED(newparams->Coeffs, 16);
+ const ALsizei NewDelay[2] = { newparams->Delay[0], newparams->Delay[1] };
+ const ALfloat newGain = newparams->Gain;
+ const ALfloat newGainStep = newparams->GainStep;
+ ALfloat g, stepcount = 0.0f;
+ ALfloat left, right;
+ ALsizei i;
+
+ ASSUME(IrSize >= 4);
+ ASSUME(BufferSize > 0);
+
+ LeftOut += OutPos;
+ RightOut += OutPos;
+ for(i = 0;i < BufferSize;i++)
+ {
+ hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][0] = 0.0f;
+ hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][1] = 0.0f;
+
+ hrtfstate->History[Offset&HRTF_HISTORY_MASK] = *(data++);
+
+ g = oldGain + oldGainStep*stepcount;
+ left = hrtfstate->History[(Offset-OldDelay[0])&HRTF_HISTORY_MASK]*g;
+ right = hrtfstate->History[(Offset-OldDelay[1])&HRTF_HISTORY_MASK]*g;
+ ApplyCoeffs(Offset, hrtfstate->Values, IrSize, OldCoeffs, left, right);
+
+ g = newGain + newGainStep*stepcount;
+ left = hrtfstate->History[(Offset-NewDelay[0])&HRTF_HISTORY_MASK]*g;
+ right = hrtfstate->History[(Offset-NewDelay[1])&HRTF_HISTORY_MASK]*g;
+ ApplyCoeffs(Offset, hrtfstate->Values, IrSize, NewCoeffs, left, right);
+
+ *(LeftOut++) += hrtfstate->Values[Offset&HRIR_MASK][0];
+ *(RightOut++) += hrtfstate->Values[Offset&HRIR_MASK][1];
+
+ stepcount += 1.0f;
+ Offset++;
+ }
+ newparams->Gain = newGain + newGainStep*stepcount;
+}
+
+void MixDirectHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2], ALfloat (*restrict Values)[2],
+ ALsizei BufferSize)
+{
+ ALfloat insample;
+ ALsizei i;
+
+ ASSUME(IrSize >= 4);
+ ASSUME(BufferSize > 0);
+
+ for(i = 0;i < BufferSize;i++)
+ {
+ Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
+ Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
+ Offset++;
+
+ insample = *(data++);
+ ApplyCoeffs(Offset, Values, IrSize, Coeffs, insample, insample);
+ *(LeftOut++) += Values[Offset&HRIR_MASK][0];
+ *(RightOut++) += Values[Offset&HRIR_MASK][1];
+ }
+}
diff --git a/Alc/mixer/mixer_c.c b/Alc/mixer/mixer_c.c
new file mode 100644
index 00000000..14d7c669
--- /dev/null
+++ b/Alc/mixer/mixer_c.c
@@ -0,0 +1,169 @@
+#include "config.h"
+
+#include <assert.h>
+
+#include "alMain.h"
+#include "alu.h"
+#include "alSource.h"
+#include "alAuxEffectSlot.h"
+#include "defs.h"
+
+
+static inline ALfloat do_point(const InterpState* UNUSED(state), const ALfloat *restrict vals, ALsizei UNUSED(frac))
+{ return vals[0]; }
+static inline ALfloat do_lerp(const InterpState* UNUSED(state), const ALfloat *restrict vals, ALsizei frac)
+{ return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); }
+static inline ALfloat do_cubic(const InterpState* UNUSED(state), const ALfloat *restrict vals, ALsizei frac)
+{ return cubic(vals[0], vals[1], vals[2], vals[3], frac * (1.0f/FRACTIONONE)); }
+static inline ALfloat do_bsinc(const InterpState *state, const ALfloat *restrict vals, ALsizei frac)
+{
+ const ALfloat *fil, *scd, *phd, *spd;
+ ALsizei j_f, pi;
+ ALfloat pf, r;
+
+ ASSUME(state->bsinc.m > 0);
+
+ // Calculate the phase index and factor.
+#define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS)
+ pi = frac >> FRAC_PHASE_BITDIFF;
+ pf = (frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF));
+#undef FRAC_PHASE_BITDIFF
+
+ fil = ASSUME_ALIGNED(state->bsinc.filter + state->bsinc.m*pi*4, 16);
+ scd = ASSUME_ALIGNED(fil + state->bsinc.m, 16);
+ phd = ASSUME_ALIGNED(scd + state->bsinc.m, 16);
+ spd = ASSUME_ALIGNED(phd + state->bsinc.m, 16);
+
+ // Apply the scale and phase interpolated filter.
+ r = 0.0f;
+ for(j_f = 0;j_f < state->bsinc.m;j_f++)
+ r += (fil[j_f] + state->bsinc.sf*scd[j_f] + pf*(phd[j_f] + state->bsinc.sf*spd[j_f])) * vals[j_f];
+ return r;
+}
+
+const ALfloat *Resample_copy_C(const InterpState* UNUSED(state),
+ const ALfloat *restrict src, ALsizei UNUSED(frac), ALint UNUSED(increment),
+ ALfloat *restrict dst, ALsizei numsamples)
+{
+#if defined(HAVE_SSE) || defined(HAVE_NEON)
+ /* Avoid copying the source data if it's aligned like the destination. */
+ if((((intptr_t)src)&15) == (((intptr_t)dst)&15))
+ return src;
+#endif
+ memcpy(dst, src, numsamples*sizeof(ALfloat));
+ return dst;
+}
+
+#define DECL_TEMPLATE(Tag, Sampler, O) \
+const ALfloat *Resample_##Tag##_C(const InterpState *state, \
+ const ALfloat *restrict src, ALsizei frac, ALint increment, \
+ ALfloat *restrict dst, ALsizei numsamples) \
+{ \
+ const InterpState istate = *state; \
+ ALsizei i; \
+ \
+ ASSUME(numsamples > 0); \
+ \
+ src -= O; \
+ for(i = 0;i < numsamples;i++) \
+ { \
+ dst[i] = Sampler(&istate, src, frac); \
+ \
+ frac += increment; \
+ src += frac>>FRACTIONBITS; \
+ frac &= FRACTIONMASK; \
+ } \
+ return dst; \
+}
+
+DECL_TEMPLATE(point, do_point, 0)
+DECL_TEMPLATE(lerp, do_lerp, 0)
+DECL_TEMPLATE(cubic, do_cubic, 1)
+DECL_TEMPLATE(bsinc, do_bsinc, istate.bsinc.l)
+
+#undef DECL_TEMPLATE
+
+
+static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2],
+ const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2],
+ ALfloat left, ALfloat right)
+{
+ ALsizei c;
+ for(c = 0;c < IrSize;c++)
+ {
+ const ALsizei off = (Offset+c)&HRIR_MASK;
+ Values[off][0] += Coeffs[c][0] * left;
+ Values[off][1] += Coeffs[c][1] * right;
+ }
+}
+
+#define MixHrtf MixHrtf_C
+#define MixHrtfBlend MixHrtfBlend_C
+#define MixDirectHrtf MixDirectHrtf_C
+#include "hrtf_inc.c"
+
+
+void Mix_C(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
+ ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
+ ALsizei BufferSize)
+{
+ const ALfloat delta = (Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f;
+ ALsizei c;
+
+ ASSUME(OutChans > 0);
+ ASSUME(BufferSize > 0);
+
+ for(c = 0;c < OutChans;c++)
+ {
+ ALsizei pos = 0;
+ ALfloat gain = CurrentGains[c];
+ const ALfloat diff = TargetGains[c] - gain;
+
+ if(fabsf(diff) > FLT_EPSILON)
+ {
+ ALsizei minsize = mini(BufferSize, Counter);
+ const ALfloat step = diff * delta;
+ ALfloat step_count = 0.0f;
+ for(;pos < minsize;pos++)
+ {
+ OutBuffer[c][OutPos+pos] += data[pos] * (gain + step*step_count);
+ step_count += 1.0f;
+ }
+ if(pos == Counter)
+ gain = TargetGains[c];
+ else
+ gain += step*step_count;
+ CurrentGains[c] = gain;
+ }
+
+ if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+ for(;pos < BufferSize;pos++)
+ OutBuffer[c][OutPos+pos] += data[pos]*gain;
+ }
+}
+
+/* Basically the inverse of the above. Rather than one input going to multiple
+ * outputs (each with its own gain), it's multiple inputs (each with its own
+ * gain) going to one output. This applies one row (vs one column) of a matrix
+ * transform. And as the matrices are more or less static once set up, no
+ * stepping is necessary.
+ */
+void MixRow_C(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize)
+{
+ ALsizei c, i;
+
+ ASSUME(InChans > 0);
+ ASSUME(BufferSize > 0);
+
+ for(c = 0;c < InChans;c++)
+ {
+ const ALfloat gain = Gains[c];
+ if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+
+ for(i = 0;i < BufferSize;i++)
+ OutBuffer[i] += data[c][InPos+i] * gain;
+ }
+}
diff --git a/Alc/mixer/mixer_neon.c b/Alc/mixer/mixer_neon.c
new file mode 100644
index 00000000..9bf5521a
--- /dev/null
+++ b/Alc/mixer/mixer_neon.c
@@ -0,0 +1,283 @@
+#include "config.h"
+
+#include <arm_neon.h>
+
+#include "AL/al.h"
+#include "AL/alc.h"
+#include "alMain.h"
+#include "alu.h"
+#include "hrtf.h"
+#include "defs.h"
+
+
+const ALfloat *Resample_lerp_Neon(const InterpState* UNUSED(state),
+ const ALfloat *restrict src, ALsizei frac, ALint increment,
+ ALfloat *restrict dst, ALsizei numsamples)
+{
+ const int32x4_t increment4 = vdupq_n_s32(increment*4);
+ const float32x4_t fracOne4 = vdupq_n_f32(1.0f/FRACTIONONE);
+ const int32x4_t fracMask4 = vdupq_n_s32(FRACTIONMASK);
+ alignas(16) ALsizei pos_[4], frac_[4];
+ int32x4_t pos4, frac4;
+ ALsizei todo, pos, i;
+
+ ASSUME(numsamples > 0);
+
+ InitiatePositionArrays(frac, increment, frac_, pos_, 4);
+ frac4 = vld1q_s32(frac_);
+ pos4 = vld1q_s32(pos_);
+
+ todo = numsamples & ~3;
+ for(i = 0;i < todo;i += 4)
+ {
+ const int pos0 = vgetq_lane_s32(pos4, 0);
+ const int pos1 = vgetq_lane_s32(pos4, 1);
+ const int pos2 = vgetq_lane_s32(pos4, 2);
+ const int pos3 = vgetq_lane_s32(pos4, 3);
+ const float32x4_t val1 = (float32x4_t){src[pos0], src[pos1], src[pos2], src[pos3]};
+ const float32x4_t val2 = (float32x4_t){src[pos0+1], src[pos1+1], src[pos2+1], src[pos3+1]};
+
+ /* val1 + (val2-val1)*mu */
+ const float32x4_t r0 = vsubq_f32(val2, val1);
+ const float32x4_t mu = vmulq_f32(vcvtq_f32_s32(frac4), fracOne4);
+ const float32x4_t out = vmlaq_f32(val1, mu, r0);
+
+ vst1q_f32(&dst[i], out);
+
+ frac4 = vaddq_s32(frac4, increment4);
+ pos4 = vaddq_s32(pos4, vshrq_n_s32(frac4, FRACTIONBITS));
+ frac4 = vandq_s32(frac4, fracMask4);
+ }
+
+ /* NOTE: These four elements represent the position *after* the last four
+ * samples, so the lowest element is the next position to resample.
+ */
+ pos = vgetq_lane_s32(pos4, 0);
+ frac = vgetq_lane_s32(frac4, 0);
+
+ for(;i < numsamples;++i)
+ {
+ dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE));
+
+ frac += increment;
+ pos += frac>>FRACTIONBITS;
+ frac &= FRACTIONMASK;
+ }
+ return dst;
+}
+
+const ALfloat *Resample_bsinc_Neon(const InterpState *state,
+ const ALfloat *restrict src, ALsizei frac, ALint increment,
+ ALfloat *restrict dst, ALsizei dstlen)
+{
+ const ALfloat *const filter = state->bsinc.filter;
+ const float32x4_t sf4 = vdupq_n_f32(state->bsinc.sf);
+ const ALsizei m = state->bsinc.m;
+ const float32x4_t *fil, *scd, *phd, *spd;
+ ALsizei pi, i, j, offset;
+ float32x4_t r4;
+ ALfloat pf;
+
+ ASSUME(m > 0);
+ ASSUME(dstlen > 0);
+
+ src -= state->bsinc.l;
+ for(i = 0;i < dstlen;i++)
+ {
+ // Calculate the phase index and factor.
+#define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS)
+ pi = frac >> FRAC_PHASE_BITDIFF;
+ pf = (frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF));
+#undef FRAC_PHASE_BITDIFF
+
+ offset = m*pi*4;
+ fil = ASSUME_ALIGNED(filter + offset, 16); offset += m;
+ scd = ASSUME_ALIGNED(filter + offset, 16); offset += m;
+ phd = ASSUME_ALIGNED(filter + offset, 16); offset += m;
+ spd = ASSUME_ALIGNED(filter + offset, 16);
+
+ // Apply the scale and phase interpolated filter.
+ r4 = vdupq_n_f32(0.0f);
+ {
+ const ALsizei count = m >> 2;
+ const float32x4_t pf4 = vdupq_n_f32(pf);
+
+ ASSUME(count > 0);
+
+ for(j = 0;j < count;j++)
+ {
+ /* f = ((fil + sf*scd) + pf*(phd + sf*spd)) */
+ const float32x4_t f4 = vmlaq_f32(
+ vmlaq_f32(fil[j], sf4, scd[j]),
+ pf4, vmlaq_f32(phd[j], sf4, spd[j])
+ );
+ /* r += f*src */
+ r4 = vmlaq_f32(r4, f4, vld1q_f32(&src[j*4]));
+ }
+ }
+ r4 = vaddq_f32(r4, vcombine_f32(vrev64_f32(vget_high_f32(r4)),
+ vrev64_f32(vget_low_f32(r4))));
+ dst[i] = vget_lane_f32(vadd_f32(vget_low_f32(r4), vget_high_f32(r4)), 0);
+
+ frac += increment;
+ src += frac>>FRACTIONBITS;
+ frac &= FRACTIONMASK;
+ }
+ return dst;
+}
+
+
+static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2],
+ const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2],
+ ALfloat left, ALfloat right)
+{
+ ALsizei c;
+ float32x4_t leftright4;
+ {
+ float32x2_t leftright2 = vdup_n_f32(0.0);
+ leftright2 = vset_lane_f32(left, leftright2, 0);
+ leftright2 = vset_lane_f32(right, leftright2, 1);
+ leftright4 = vcombine_f32(leftright2, leftright2);
+ }
+ Values = ASSUME_ALIGNED(Values, 16);
+ Coeffs = ASSUME_ALIGNED(Coeffs, 16);
+ for(c = 0;c < IrSize;c += 2)
+ {
+ const ALsizei o0 = (Offset+c)&HRIR_MASK;
+ const ALsizei o1 = (o0+1)&HRIR_MASK;
+ float32x4_t vals = vcombine_f32(vld1_f32((float32_t*)&Values[o0][0]),
+ vld1_f32((float32_t*)&Values[o1][0]));
+ float32x4_t coefs = vld1q_f32((float32_t*)&Coeffs[c][0]);
+
+ vals = vmlaq_f32(vals, coefs, leftright4);
+
+ vst1_f32((float32_t*)&Values[o0][0], vget_low_f32(vals));
+ vst1_f32((float32_t*)&Values[o1][0], vget_high_f32(vals));
+ }
+}
+
+#define MixHrtf MixHrtf_Neon
+#define MixHrtfBlend MixHrtfBlend_Neon
+#define MixDirectHrtf MixDirectHrtf_Neon
+#include "hrtf_inc.c"
+
+
+void Mix_Neon(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
+ ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
+ ALsizei BufferSize)
+{
+ const ALfloat delta = (Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f;
+ ALsizei c;
+
+ ASSUME(OutChans > 0);
+ ASSUME(BufferSize > 0);
+ data = ASSUME_ALIGNED(data, 16);
+ OutBuffer = ASSUME_ALIGNED(OutBuffer, 16);
+
+ for(c = 0;c < OutChans;c++)
+ {
+ ALsizei pos = 0;
+ ALfloat gain = CurrentGains[c];
+ const ALfloat diff = TargetGains[c] - gain;
+
+ if(fabsf(diff) > FLT_EPSILON)
+ {
+ ALsizei minsize = mini(BufferSize, Counter);
+ const ALfloat step = diff * delta;
+ ALfloat step_count = 0.0f;
+ /* Mix with applying gain steps in aligned multiples of 4. */
+ if(LIKELY(minsize > 3))
+ {
+ const float32x4_t four4 = vdupq_n_f32(4.0f);
+ const float32x4_t step4 = vdupq_n_f32(step);
+ const float32x4_t gain4 = vdupq_n_f32(gain);
+ float32x4_t step_count4 = vsetq_lane_f32(0.0f,
+ vsetq_lane_f32(1.0f,
+ vsetq_lane_f32(2.0f,
+ vsetq_lane_f32(3.0f, vdupq_n_f32(0.0f), 3),
+ 2), 1), 0
+ );
+ ALsizei todo = minsize >> 2;
+
+ do {
+ const float32x4_t val4 = vld1q_f32(&data[pos]);
+ float32x4_t dry4 = vld1q_f32(&OutBuffer[c][OutPos+pos]);
+ dry4 = vmlaq_f32(dry4, val4, vmlaq_f32(gain4, step4, step_count4));
+ step_count4 = vaddq_f32(step_count4, four4);
+ vst1q_f32(&OutBuffer[c][OutPos+pos], dry4);
+ pos += 4;
+ } while(--todo);
+ /* NOTE: step_count4 now represents the next four counts after
+ * the last four mixed samples, so the lowest element
+ * represents the next step count to apply.
+ */
+ step_count = vgetq_lane_f32(step_count4, 0);
+ }
+ /* Mix with applying left over gain steps that aren't aligned multiples of 4. */
+ for(;pos < minsize;pos++)
+ {
+ OutBuffer[c][OutPos+pos] += data[pos]*(gain + step*step_count);
+ step_count += 1.0f;
+ }
+ if(pos == Counter)
+ gain = TargetGains[c];
+ else
+ gain += step*step_count;
+ CurrentGains[c] = gain;
+
+ /* Mix until pos is aligned with 4 or the mix is done. */
+ minsize = mini(BufferSize, (pos+3)&~3);
+ for(;pos < minsize;pos++)
+ OutBuffer[c][OutPos+pos] += data[pos]*gain;
+ }
+
+ if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+ if(LIKELY(BufferSize-pos > 3))
+ {
+ ALsizei todo = (BufferSize-pos) >> 2;
+ const float32x4_t gain4 = vdupq_n_f32(gain);
+ do {
+ const float32x4_t val4 = vld1q_f32(&data[pos]);
+ float32x4_t dry4 = vld1q_f32(&OutBuffer[c][OutPos+pos]);
+ dry4 = vmlaq_f32(dry4, val4, gain4);
+ vst1q_f32(&OutBuffer[c][OutPos+pos], dry4);
+ pos += 4;
+ } while(--todo);
+ }
+ for(;pos < BufferSize;pos++)
+ OutBuffer[c][OutPos+pos] += data[pos]*gain;
+ }
+}
+
+void MixRow_Neon(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize)
+{
+ ALsizei c;
+
+ ASSUME(InChans > 0);
+ ASSUME(BufferSize > 0);
+
+ for(c = 0;c < InChans;c++)
+ {
+ ALsizei pos = 0;
+ const ALfloat gain = Gains[c];
+ if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+
+ if(LIKELY(BufferSize > 3))
+ {
+ ALsizei todo = BufferSize >> 2;
+ float32x4_t gain4 = vdupq_n_f32(gain);
+ do {
+ const float32x4_t val4 = vld1q_f32(&data[c][InPos+pos]);
+ float32x4_t dry4 = vld1q_f32(&OutBuffer[pos]);
+ dry4 = vmlaq_f32(dry4, val4, gain4);
+ vst1q_f32(&OutBuffer[pos], dry4);
+ pos += 4;
+ } while(--todo);
+ }
+ for(;pos < BufferSize;pos++)
+ OutBuffer[pos] += data[c][InPos+pos]*gain;
+ }
+}
diff --git a/Alc/mixer/mixer_sse.c b/Alc/mixer/mixer_sse.c
new file mode 100644
index 00000000..725a5ebc
--- /dev/null
+++ b/Alc/mixer/mixer_sse.c
@@ -0,0 +1,250 @@
+#include "config.h"
+
+#include <xmmintrin.h>
+
+#include "AL/al.h"
+#include "AL/alc.h"
+#include "alMain.h"
+#include "alu.h"
+
+#include "alSource.h"
+#include "alAuxEffectSlot.h"
+#include "defs.h"
+
+
+const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *restrict src,
+ ALsizei frac, ALint increment, ALfloat *restrict dst,
+ ALsizei dstlen)
+{
+ const ALfloat *const filter = state->bsinc.filter;
+ const __m128 sf4 = _mm_set1_ps(state->bsinc.sf);
+ const ALsizei m = state->bsinc.m;
+ const __m128 *fil, *scd, *phd, *spd;
+ ALsizei pi, i, j, offset;
+ ALfloat pf;
+ __m128 r4;
+
+ ASSUME(m > 0);
+ ASSUME(dstlen > 0);
+
+ src -= state->bsinc.l;
+ for(i = 0;i < dstlen;i++)
+ {
+ // Calculate the phase index and factor.
+#define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS)
+ pi = frac >> FRAC_PHASE_BITDIFF;
+ pf = (frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF));
+#undef FRAC_PHASE_BITDIFF
+
+ offset = m*pi*4;
+ fil = (const __m128*)ASSUME_ALIGNED(filter + offset, 16); offset += m;
+ scd = (const __m128*)ASSUME_ALIGNED(filter + offset, 16); offset += m;
+ phd = (const __m128*)ASSUME_ALIGNED(filter + offset, 16); offset += m;
+ spd = (const __m128*)ASSUME_ALIGNED(filter + offset, 16);
+
+ // Apply the scale and phase interpolated filter.
+ r4 = _mm_setzero_ps();
+ {
+ const ALsizei count = m >> 2;
+ const __m128 pf4 = _mm_set1_ps(pf);
+
+ ASSUME(count > 0);
+
+#define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z))
+ for(j = 0;j < count;j++)
+ {
+ /* f = ((fil + sf*scd) + pf*(phd + sf*spd)) */
+ const __m128 f4 = MLA4(
+ MLA4(fil[j], sf4, scd[j]),
+ pf4, MLA4(phd[j], sf4, spd[j])
+ );
+ /* r += f*src */
+ r4 = MLA4(r4, f4, _mm_loadu_ps(&src[j*4]));
+ }
+#undef MLA4
+ }
+ r4 = _mm_add_ps(r4, _mm_shuffle_ps(r4, r4, _MM_SHUFFLE(0, 1, 2, 3)));
+ r4 = _mm_add_ps(r4, _mm_movehl_ps(r4, r4));
+ dst[i] = _mm_cvtss_f32(r4);
+
+ frac += increment;
+ src += frac>>FRACTIONBITS;
+ frac &= FRACTIONMASK;
+ }
+ return dst;
+}
+
+
+static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2],
+ const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2],
+ ALfloat left, ALfloat right)
+{
+ const __m128 lrlr = _mm_setr_ps(left, right, left, right);
+ __m128 vals = _mm_setzero_ps();
+ __m128 coeffs;
+ ALsizei i;
+
+ Values = ASSUME_ALIGNED(Values, 16);
+ Coeffs = ASSUME_ALIGNED(Coeffs, 16);
+ if((Offset&1))
+ {
+ const ALsizei o0 = Offset&HRIR_MASK;
+ const ALsizei o1 = (Offset+IrSize-1)&HRIR_MASK;
+ __m128 imp0, imp1;
+
+ coeffs = _mm_load_ps(&Coeffs[0][0]);
+ vals = _mm_loadl_pi(vals, (__m64*)&Values[o0][0]);
+ imp0 = _mm_mul_ps(lrlr, coeffs);
+ vals = _mm_add_ps(imp0, vals);
+ _mm_storel_pi((__m64*)&Values[o0][0], vals);
+ for(i = 1;i < IrSize-1;i += 2)
+ {
+ const ALsizei o2 = (Offset+i)&HRIR_MASK;
+
+ coeffs = _mm_load_ps(&Coeffs[i+1][0]);
+ vals = _mm_load_ps(&Values[o2][0]);
+ imp1 = _mm_mul_ps(lrlr, coeffs);
+ imp0 = _mm_shuffle_ps(imp0, imp1, _MM_SHUFFLE(1, 0, 3, 2));
+ vals = _mm_add_ps(imp0, vals);
+ _mm_store_ps(&Values[o2][0], vals);
+ imp0 = imp1;
+ }
+ vals = _mm_loadl_pi(vals, (__m64*)&Values[o1][0]);
+ imp0 = _mm_movehl_ps(imp0, imp0);
+ vals = _mm_add_ps(imp0, vals);
+ _mm_storel_pi((__m64*)&Values[o1][0], vals);
+ }
+ else
+ {
+ for(i = 0;i < IrSize;i += 2)
+ {
+ const ALsizei o = (Offset + i)&HRIR_MASK;
+
+ coeffs = _mm_load_ps(&Coeffs[i][0]);
+ vals = _mm_load_ps(&Values[o][0]);
+ vals = _mm_add_ps(vals, _mm_mul_ps(lrlr, coeffs));
+ _mm_store_ps(&Values[o][0], vals);
+ }
+ }
+}
+
+#define MixHrtf MixHrtf_SSE
+#define MixHrtfBlend MixHrtfBlend_SSE
+#define MixDirectHrtf MixDirectHrtf_SSE
+#include "hrtf_inc.c"
+
+
+void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
+ ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
+ ALsizei BufferSize)
+{
+ const ALfloat delta = (Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f;
+ ALsizei c;
+
+ ASSUME(OutChans > 0);
+ ASSUME(BufferSize > 0);
+
+ for(c = 0;c < OutChans;c++)
+ {
+ ALsizei pos = 0;
+ ALfloat gain = CurrentGains[c];
+ const ALfloat diff = TargetGains[c] - gain;
+
+ if(fabsf(diff) > FLT_EPSILON)
+ {
+ ALsizei minsize = mini(BufferSize, Counter);
+ const ALfloat step = diff * delta;
+ ALfloat step_count = 0.0f;
+ /* Mix with applying gain steps in aligned multiples of 4. */
+ if(LIKELY(minsize > 3))
+ {
+ const __m128 four4 = _mm_set1_ps(4.0f);
+ const __m128 step4 = _mm_set1_ps(step);
+ const __m128 gain4 = _mm_set1_ps(gain);
+ __m128 step_count4 = _mm_setr_ps(0.0f, 1.0f, 2.0f, 3.0f);
+ ALsizei todo = minsize >> 2;
+ do {
+ const __m128 val4 = _mm_load_ps(&data[pos]);
+ __m128 dry4 = _mm_load_ps(&OutBuffer[c][OutPos+pos]);
+#define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z))
+ /* dry += val * (gain + step*step_count) */
+ dry4 = MLA4(dry4, val4, MLA4(gain4, step4, step_count4));
+#undef MLA4
+ _mm_store_ps(&OutBuffer[c][OutPos+pos], dry4);
+ step_count4 = _mm_add_ps(step_count4, four4);
+ pos += 4;
+ } while(--todo);
+ /* NOTE: step_count4 now represents the next four counts after
+ * the last four mixed samples, so the lowest element
+ * represents the next step count to apply.
+ */
+ step_count = _mm_cvtss_f32(step_count4);
+ }
+ /* Mix with applying left over gain steps that aren't aligned multiples of 4. */
+ for(;pos < minsize;pos++)
+ {
+ OutBuffer[c][OutPos+pos] += data[pos]*(gain + step*step_count);
+ step_count += 1.0f;
+ }
+ if(pos == Counter)
+ gain = TargetGains[c];
+ else
+ gain += step*step_count;
+ CurrentGains[c] = gain;
+
+ /* Mix until pos is aligned with 4 or the mix is done. */
+ minsize = mini(BufferSize, (pos+3)&~3);
+ for(;pos < minsize;pos++)
+ OutBuffer[c][OutPos+pos] += data[pos]*gain;
+ }
+
+ if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+ if(LIKELY(BufferSize-pos > 3))
+ {
+ ALsizei todo = (BufferSize-pos) >> 2;
+ const __m128 gain4 = _mm_set1_ps(gain);
+ do {
+ const __m128 val4 = _mm_load_ps(&data[pos]);
+ __m128 dry4 = _mm_load_ps(&OutBuffer[c][OutPos+pos]);
+ dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4));
+ _mm_store_ps(&OutBuffer[c][OutPos+pos], dry4);
+ pos += 4;
+ } while(--todo);
+ }
+ for(;pos < BufferSize;pos++)
+ OutBuffer[c][OutPos+pos] += data[pos]*gain;
+ }
+}
+
+void MixRow_SSE(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize)
+{
+ ALsizei c;
+
+ ASSUME(InChans > 0);
+ ASSUME(BufferSize > 0);
+
+ for(c = 0;c < InChans;c++)
+ {
+ ALsizei pos = 0;
+ const ALfloat gain = Gains[c];
+ if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+
+ if(LIKELY(BufferSize > 3))
+ {
+ ALsizei todo = BufferSize >> 2;
+ const __m128 gain4 = _mm_set1_ps(gain);
+ do {
+ const __m128 val4 = _mm_load_ps(&data[c][InPos+pos]);
+ __m128 dry4 = _mm_load_ps(&OutBuffer[pos]);
+ dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4));
+ _mm_store_ps(&OutBuffer[pos], dry4);
+ pos += 4;
+ } while(--todo);
+ }
+ for(;pos < BufferSize;pos++)
+ OutBuffer[pos] += data[c][InPos+pos]*gain;
+ }
+}
diff --git a/Alc/mixer/mixer_sse2.c b/Alc/mixer/mixer_sse2.c
new file mode 100644
index 00000000..9cbaeb0a
--- /dev/null
+++ b/Alc/mixer/mixer_sse2.c
@@ -0,0 +1,84 @@
+/**
+ * OpenAL cross platform audio library
+ * Copyright (C) 2014 by Timothy Arceri <[email protected]>.
+ * 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 <xmmintrin.h>
+#include <emmintrin.h>
+
+#include "alu.h"
+#include "defs.h"
+
+
+const ALfloat *Resample_lerp_SSE2(const InterpState* UNUSED(state),
+ const ALfloat *restrict src, ALsizei frac, ALint increment,
+ ALfloat *restrict dst, ALsizei numsamples)
+{
+ const __m128i increment4 = _mm_set1_epi32(increment*4);
+ const __m128 fracOne4 = _mm_set1_ps(1.0f/FRACTIONONE);
+ const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK);
+ alignas(16) ALsizei pos_[4], frac_[4];
+ __m128i frac4, pos4;
+ ALsizei todo, pos, i;
+
+ ASSUME(numsamples > 0);
+
+ InitiatePositionArrays(frac, increment, frac_, pos_, 4);
+ frac4 = _mm_setr_epi32(frac_[0], frac_[1], frac_[2], frac_[3]);
+ pos4 = _mm_setr_epi32(pos_[0], pos_[1], pos_[2], pos_[3]);
+
+ todo = numsamples & ~3;
+ for(i = 0;i < todo;i += 4)
+ {
+ const int pos0 = _mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(0, 0, 0, 0)));
+ const int pos1 = _mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(1, 1, 1, 1)));
+ const int pos2 = _mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(2, 2, 2, 2)));
+ const int pos3 = _mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(3, 3, 3, 3)));
+ const __m128 val1 = _mm_setr_ps(src[pos0 ], src[pos1 ], src[pos2 ], src[pos3 ]);
+ const __m128 val2 = _mm_setr_ps(src[pos0+1], src[pos1+1], src[pos2+1], src[pos3+1]);
+
+ /* val1 + (val2-val1)*mu */
+ const __m128 r0 = _mm_sub_ps(val2, val1);
+ const __m128 mu = _mm_mul_ps(_mm_cvtepi32_ps(frac4), fracOne4);
+ const __m128 out = _mm_add_ps(val1, _mm_mul_ps(mu, r0));
+
+ _mm_store_ps(&dst[i], out);
+
+ frac4 = _mm_add_epi32(frac4, increment4);
+ pos4 = _mm_add_epi32(pos4, _mm_srli_epi32(frac4, FRACTIONBITS));
+ frac4 = _mm_and_si128(frac4, fracMask4);
+ }
+
+ /* NOTE: These four elements represent the position *after* the last four
+ * samples, so the lowest element is the next position to resample.
+ */
+ pos = _mm_cvtsi128_si32(pos4);
+ frac = _mm_cvtsi128_si32(frac4);
+
+ for(;i < numsamples;++i)
+ {
+ dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE));
+
+ frac += increment;
+ pos += frac>>FRACTIONBITS;
+ frac &= FRACTIONMASK;
+ }
+ return dst;
+}
diff --git a/Alc/mixer/mixer_sse3.c b/Alc/mixer/mixer_sse3.c
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/Alc/mixer/mixer_sse3.c
diff --git a/Alc/mixer_sse2.c b/Alc/mixer/mixer_sse41.c
index 32f29227..e92a3dd0 100644
--- a/Alc/mixer_sse2.c
+++ b/Alc/mixer/mixer_sse41.c
@@ -22,32 +22,38 @@
#include <xmmintrin.h>
#include <emmintrin.h>
+#include <smmintrin.h>
#include "alu.h"
-#include "mixer_defs.h"
+#include "defs.h"
-const ALfloat *Resample_lerp32_SSE2(const BsincState* UNUSED(state), const ALfloat *src, ALuint frac, ALuint increment,
- ALfloat *restrict dst, ALuint numsamples)
+const ALfloat *Resample_lerp_SSE41(const InterpState* UNUSED(state),
+ const ALfloat *restrict src, ALsizei frac, ALint increment,
+ ALfloat *restrict dst, ALsizei numsamples)
{
const __m128i increment4 = _mm_set1_epi32(increment*4);
const __m128 fracOne4 = _mm_set1_ps(1.0f/FRACTIONONE);
const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK);
- alignas(16) union { ALuint i[4]; float f[4]; } pos_;
- alignas(16) union { ALuint i[4]; float f[4]; } frac_;
+ alignas(16) ALsizei pos_[4], frac_[4];
__m128i frac4, pos4;
- ALuint pos;
- ALuint i;
+ ALsizei todo, pos, i;
- InitiatePositionArrays(frac, increment, frac_.i, pos_.i, 4);
+ ASSUME(numsamples > 0);
- frac4 = _mm_castps_si128(_mm_load_ps(frac_.f));
- pos4 = _mm_castps_si128(_mm_load_ps(pos_.f));
+ InitiatePositionArrays(frac, increment, frac_, pos_, 4);
+ frac4 = _mm_setr_epi32(frac_[0], frac_[1], frac_[2], frac_[3]);
+ pos4 = _mm_setr_epi32(pos_[0], pos_[1], pos_[2], pos_[3]);
- for(i = 0;numsamples-i > 3;i += 4)
+ todo = numsamples & ~3;
+ for(i = 0;i < todo;i += 4)
{
- const __m128 val1 = _mm_setr_ps(src[pos_.i[0]], src[pos_.i[1]], src[pos_.i[2]], src[pos_.i[3]]);
- const __m128 val2 = _mm_setr_ps(src[pos_.i[0]+1], src[pos_.i[1]+1], src[pos_.i[2]+1], src[pos_.i[3]+1]);
+ const int pos0 = _mm_extract_epi32(pos4, 0);
+ const int pos1 = _mm_extract_epi32(pos4, 1);
+ const int pos2 = _mm_extract_epi32(pos4, 2);
+ const int pos3 = _mm_extract_epi32(pos4, 3);
+ const __m128 val1 = _mm_setr_ps(src[pos0 ], src[pos1 ], src[pos2 ], src[pos3 ]);
+ const __m128 val2 = _mm_setr_ps(src[pos0+1], src[pos1+1], src[pos2+1], src[pos3+1]);
/* val1 + (val2-val1)*mu */
const __m128 r0 = _mm_sub_ps(val2, val1);
@@ -59,17 +65,15 @@ const ALfloat *Resample_lerp32_SSE2(const BsincState* UNUSED(state), const ALflo
frac4 = _mm_add_epi32(frac4, increment4);
pos4 = _mm_add_epi32(pos4, _mm_srli_epi32(frac4, FRACTIONBITS));
frac4 = _mm_and_si128(frac4, fracMask4);
-
- _mm_store_ps(pos_.f, _mm_castsi128_ps(pos4));
}
/* NOTE: These four elements represent the position *after* the last four
* samples, so the lowest element is the next position to resample.
*/
- pos = pos_.i[0];
+ pos = _mm_cvtsi128_si32(pos4);
frac = _mm_cvtsi128_si32(frac4);
- for(;i < numsamples;i++)
+ for(;i < numsamples;++i)
{
dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE));
diff --git a/Alc/mixer_c.c b/Alc/mixer_c.c
deleted file mode 100644
index ef37b730..00000000
--- a/Alc/mixer_c.c
+++ /dev/null
@@ -1,181 +0,0 @@
-#include "config.h"
-
-#include <assert.h>
-
-#include "alMain.h"
-#include "alu.h"
-#include "alSource.h"
-#include "alAuxEffectSlot.h"
-
-
-static inline ALfloat point32(const ALfloat *vals, ALuint UNUSED(frac))
-{ return vals[0]; }
-static inline ALfloat lerp32(const ALfloat *vals, ALuint frac)
-{ return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); }
-static inline ALfloat fir4_32(const ALfloat *vals, ALuint frac)
-{ return resample_fir4(vals[-1], vals[0], vals[1], vals[2], frac); }
-static inline ALfloat fir8_32(const ALfloat *vals, ALuint frac)
-{ return resample_fir8(vals[-3], vals[-2], vals[-1], vals[0], vals[1], vals[2], vals[3], vals[4], frac); }
-
-
-const ALfloat *Resample_copy32_C(const BsincState* UNUSED(state), const ALfloat *src, ALuint UNUSED(frac),
- ALuint UNUSED(increment), ALfloat *restrict dst, ALuint numsamples)
-{
-#if defined(HAVE_SSE) || defined(HAVE_NEON)
- /* Avoid copying the source data if it's aligned like the destination. */
- if((((intptr_t)src)&15) == (((intptr_t)dst)&15))
- return src;
-#endif
- memcpy(dst, src, numsamples*sizeof(ALfloat));
- return dst;
-}
-
-#define DECL_TEMPLATE(Sampler) \
-const ALfloat *Resample_##Sampler##_C(const BsincState* UNUSED(state), \
- const ALfloat *src, ALuint frac, ALuint increment, \
- ALfloat *restrict dst, ALuint numsamples) \
-{ \
- ALuint i; \
- for(i = 0;i < numsamples;i++) \
- { \
- dst[i] = Sampler(src, frac); \
- \
- frac += increment; \
- src += frac>>FRACTIONBITS; \
- frac &= FRACTIONMASK; \
- } \
- return dst; \
-}
-
-DECL_TEMPLATE(point32)
-DECL_TEMPLATE(lerp32)
-DECL_TEMPLATE(fir4_32)
-DECL_TEMPLATE(fir8_32)
-
-#undef DECL_TEMPLATE
-
-const ALfloat *Resample_bsinc32_C(const BsincState *state, const ALfloat *src, ALuint frac,
- ALuint increment, ALfloat *restrict dst, ALuint dstlen)
-{
- const ALfloat *fil, *scd, *phd, *spd;
- const ALfloat sf = state->sf;
- const ALuint m = state->m;
- const ALint l = state->l;
- ALuint j_f, pi, i;
- ALfloat pf, r;
- ALint j_s;
-
- for(i = 0;i < dstlen;i++)
- {
- // Calculate the phase index and factor.
-#define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS)
- pi = frac >> FRAC_PHASE_BITDIFF;
- pf = (frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF));
-#undef FRAC_PHASE_BITDIFF
-
- fil = state->coeffs[pi].filter;
- scd = state->coeffs[pi].scDelta;
- phd = state->coeffs[pi].phDelta;
- spd = state->coeffs[pi].spDelta;
-
- // Apply the scale and phase interpolated filter.
- r = 0.0f;
- for(j_f = 0,j_s = l;j_f < m;j_f++,j_s++)
- r += (fil[j_f] + sf*scd[j_f] + pf*(phd[j_f] + sf*spd[j_f])) *
- src[j_s];
- dst[i] = r;
-
- frac += increment;
- src += frac>>FRACTIONBITS;
- frac &= FRACTIONMASK;
- }
- return dst;
-}
-
-
-void ALfilterState_processC(ALfilterState *filter, ALfloat *restrict dst, const ALfloat *src, ALuint numsamples)
-{
- ALuint i;
- for(i = 0;i < numsamples;i++)
- *(dst++) = ALfilterState_processSingle(filter, *(src++));
-}
-
-
-static inline void SetupCoeffs(ALfloat (*restrict OutCoeffs)[2],
- const HrtfParams *hrtfparams,
- ALuint IrSize, ALuint Counter)
-{
- ALuint c;
- for(c = 0;c < IrSize;c++)
- {
- OutCoeffs[c][0] = hrtfparams->Coeffs[c][0] - (hrtfparams->CoeffStep[c][0]*Counter);
- OutCoeffs[c][1] = hrtfparams->Coeffs[c][1] - (hrtfparams->CoeffStep[c][1]*Counter);
- }
-}
-
-static inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
- const ALuint IrSize,
- ALfloat (*restrict Coeffs)[2],
- const ALfloat (*restrict CoeffStep)[2],
- ALfloat left, ALfloat right)
-{
- ALuint c;
- for(c = 0;c < IrSize;c++)
- {
- const ALuint off = (Offset+c)&HRIR_MASK;
- Values[off][0] += Coeffs[c][0] * left;
- Values[off][1] += Coeffs[c][1] * right;
- Coeffs[c][0] += CoeffStep[c][0];
- Coeffs[c][1] += CoeffStep[c][1];
- }
-}
-
-static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
- const ALuint IrSize,
- ALfloat (*restrict Coeffs)[2],
- ALfloat left, ALfloat right)
-{
- ALuint c;
- for(c = 0;c < IrSize;c++)
- {
- const ALuint off = (Offset+c)&HRIR_MASK;
- Values[off][0] += Coeffs[c][0] * left;
- Values[off][1] += Coeffs[c][1] * right;
- }
-}
-
-#define MixHrtf MixHrtf_C
-#include "mixer_inc.c"
-#undef MixHrtf
-
-
-void Mix_C(const ALfloat *data, ALuint OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
- MixGains *Gains, ALuint Counter, ALuint OutPos, ALuint BufferSize)
-{
- ALfloat gain, step;
- ALuint c;
-
- for(c = 0;c < OutChans;c++)
- {
- ALuint pos = 0;
- gain = Gains[c].Current;
- step = Gains[c].Step;
- if(step != 0.0f && Counter > 0)
- {
- ALuint minsize = minu(BufferSize, Counter);
- for(;pos < minsize;pos++)
- {
- OutBuffer[c][OutPos+pos] += data[pos]*gain;
- gain += step;
- }
- if(pos == Counter)
- gain = Gains[c].Target;
- Gains[c].Current = gain;
- }
-
- if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
- continue;
- for(;pos < BufferSize;pos++)
- OutBuffer[c][OutPos+pos] += data[pos]*gain;
- }
-}
diff --git a/Alc/mixer_defs.h b/Alc/mixer_defs.h
deleted file mode 100644
index 3c32278b..00000000
--- a/Alc/mixer_defs.h
+++ /dev/null
@@ -1,80 +0,0 @@
-#ifndef MIXER_DEFS_H
-#define MIXER_DEFS_H
-
-#include "AL/alc.h"
-#include "AL/al.h"
-#include "alMain.h"
-#include "alu.h"
-
-struct MixGains;
-
-struct HrtfParams;
-struct HrtfState;
-
-/* C resamplers */
-const ALfloat *Resample_copy32_C(const BsincState *state, const ALfloat *src, ALuint frac, ALuint increment, ALfloat *restrict dst, ALuint dstlen);
-const ALfloat *Resample_point32_C(const BsincState *state, const ALfloat *src, ALuint frac, ALuint increment, ALfloat *restrict dst, ALuint dstlen);
-const ALfloat *Resample_lerp32_C(const BsincState *state, const ALfloat *src, ALuint frac, ALuint increment, ALfloat *restrict dst, ALuint dstlen);
-const ALfloat *Resample_fir4_32_C(const BsincState *state, const ALfloat *src, ALuint frac, ALuint increment, ALfloat *restrict dst, ALuint dstlen);
-const ALfloat *Resample_fir8_32_C(const BsincState *state, const ALfloat *src, ALuint frac, ALuint increment, ALfloat *restrict dst, ALuint dstlen);
-const ALfloat *Resample_bsinc32_C(const BsincState *state, const ALfloat *src, ALuint frac, ALuint increment, ALfloat *restrict dst, ALuint dstlen);
-
-
-/* C mixers */
-void MixHrtf_C(ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat *data,
- ALuint Counter, ALuint Offset, ALuint OutPos, const ALuint IrSize,
- const struct HrtfParams *hrtfparams, struct HrtfState *hrtfstate,
- ALuint BufferSize);
-void Mix_C(const ALfloat *data, ALuint OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
- struct MixGains *Gains, ALuint Counter, ALuint OutPos, ALuint BufferSize);
-
-/* SSE mixers */
-void MixHrtf_SSE(ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat *data,
- ALuint Counter, ALuint Offset, ALuint OutPos, const ALuint IrSize,
- const struct HrtfParams *hrtfparams, struct HrtfState *hrtfstate,
- ALuint BufferSize);
-void Mix_SSE(const ALfloat *data, ALuint OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
- struct MixGains *Gains, ALuint Counter, ALuint OutPos, ALuint BufferSize);
-
-/* SSE resamplers */
-inline void InitiatePositionArrays(ALuint frac, ALuint increment, ALuint *frac_arr, ALuint *pos_arr, ALuint size)
-{
- ALuint i;
-
- pos_arr[0] = 0;
- frac_arr[0] = frac;
- for(i = 1;i < size;i++)
- {
- ALuint frac_tmp = frac_arr[i-1] + increment;
- pos_arr[i] = pos_arr[i-1] + (frac_tmp>>FRACTIONBITS);
- frac_arr[i] = frac_tmp&FRACTIONMASK;
- }
-}
-
-const ALfloat *Resample_bsinc32_SSE(const BsincState *state, const ALfloat *src, ALuint frac,
- ALuint increment, ALfloat *restrict dst, ALuint dstlen);
-
-const ALfloat *Resample_lerp32_SSE2(const BsincState *state, const ALfloat *src, ALuint frac, ALuint increment,
- ALfloat *restrict dst, ALuint numsamples);
-const ALfloat *Resample_lerp32_SSE41(const BsincState *state, const ALfloat *src, ALuint frac, ALuint increment,
- ALfloat *restrict dst, ALuint numsamples);
-
-const ALfloat *Resample_fir4_32_SSE3(const BsincState *state, const ALfloat *src, ALuint frac, ALuint increment,
- ALfloat *restrict dst, ALuint numsamples);
-const ALfloat *Resample_fir4_32_SSE41(const BsincState *state, const ALfloat *src, ALuint frac, ALuint increment,
- ALfloat *restrict dst, ALuint numsamples);
-
-const ALfloat *Resample_fir8_32_SSE3(const BsincState *state, const ALfloat *src, ALuint frac, ALuint increment,
- ALfloat *restrict dst, ALuint numsamples);
-const ALfloat *Resample_fir8_32_SSE41(const BsincState *state, const ALfloat *src, ALuint frac, ALuint increment,
- ALfloat *restrict dst, ALuint numsamples);
-
-/* Neon mixers */
-void MixHrtf_Neon(ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat *data,
- ALuint Counter, ALuint Offset, ALuint OutPos, const ALuint IrSize,
- const struct HrtfParams *hrtfparams, struct HrtfState *hrtfstate,
- ALuint BufferSize);
-void Mix_Neon(const ALfloat *data, ALuint OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
- struct MixGains *Gains, ALuint Counter, ALuint OutPos, ALuint BufferSize);
-
-#endif /* MIXER_DEFS_H */
diff --git a/Alc/mixer_inc.c b/Alc/mixer_inc.c
deleted file mode 100644
index a82930cc..00000000
--- a/Alc/mixer_inc.c
+++ /dev/null
@@ -1,79 +0,0 @@
-#include "config.h"
-
-#include "alMain.h"
-#include "alSource.h"
-
-#include "hrtf.h"
-#include "mixer_defs.h"
-#include "align.h"
-
-
-static inline void SetupCoeffs(ALfloat (*restrict OutCoeffs)[2],
- const HrtfParams *hrtfparams,
- ALuint IrSize, ALuint Counter);
-static inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
- const ALuint irSize,
- ALfloat (*restrict Coeffs)[2],
- const ALfloat (*restrict CoeffStep)[2],
- ALfloat left, ALfloat right);
-static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
- const ALuint irSize,
- ALfloat (*restrict Coeffs)[2],
- ALfloat left, ALfloat right);
-
-
-void MixHrtf(ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat *data,
- ALuint Counter, ALuint Offset, ALuint OutPos, const ALuint IrSize,
- const HrtfParams *hrtfparams, HrtfState *hrtfstate, ALuint BufferSize)
-{
- alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
- ALuint Delay[2];
- ALfloat left, right;
- ALuint pos;
-
- SetupCoeffs(Coeffs, hrtfparams, IrSize, Counter);
- Delay[0] = hrtfparams->Delay[0] - (hrtfparams->DelayStep[0]*Counter);
- Delay[1] = hrtfparams->Delay[1] - (hrtfparams->DelayStep[1]*Counter);
-
- pos = 0;
- for(;pos < BufferSize && pos < Counter;pos++)
- {
- hrtfstate->History[Offset&HRTF_HISTORY_MASK] = data[pos];
- left = lerp(hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS))&HRTF_HISTORY_MASK],
- hrtfstate->History[(Offset-(Delay[0]>>HRTFDELAY_BITS)-1)&HRTF_HISTORY_MASK],
- (Delay[0]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
- right = lerp(hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS))&HRTF_HISTORY_MASK],
- hrtfstate->History[(Offset-(Delay[1]>>HRTFDELAY_BITS)-1)&HRTF_HISTORY_MASK],
- (Delay[1]&HRTFDELAY_MASK)*(1.0f/HRTFDELAY_FRACONE));
-
- Delay[0] += hrtfparams->DelayStep[0];
- Delay[1] += hrtfparams->DelayStep[1];
-
- hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
- hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
- Offset++;
-
- ApplyCoeffsStep(Offset, hrtfstate->Values, IrSize, Coeffs, hrtfparams->CoeffStep, left, right);
- OutBuffer[0][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][0];
- OutBuffer[1][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][1];
- OutPos++;
- }
-
- Delay[0] >>= HRTFDELAY_BITS;
- Delay[1] >>= HRTFDELAY_BITS;
- for(;pos < BufferSize;pos++)
- {
- hrtfstate->History[Offset&HRTF_HISTORY_MASK] = data[pos];
- left = hrtfstate->History[(Offset-Delay[0])&HRTF_HISTORY_MASK];
- right = hrtfstate->History[(Offset-Delay[1])&HRTF_HISTORY_MASK];
-
- hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
- hrtfstate->Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
- Offset++;
-
- ApplyCoeffs(Offset, hrtfstate->Values, IrSize, Coeffs, left, right);
- OutBuffer[0][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][0];
- OutBuffer[1][OutPos] += hrtfstate->Values[Offset&HRIR_MASK][1];
- OutPos++;
- }
-}
diff --git a/Alc/mixer_neon.c b/Alc/mixer_neon.c
deleted file mode 100644
index a89caeae..00000000
--- a/Alc/mixer_neon.c
+++ /dev/null
@@ -1,139 +0,0 @@
-#include "config.h"
-
-#include <arm_neon.h>
-
-#include "AL/al.h"
-#include "AL/alc.h"
-#include "alMain.h"
-#include "alu.h"
-#include "hrtf.h"
-
-
-static inline void SetupCoeffs(ALfloat (*restrict OutCoeffs)[2],
- const HrtfParams *hrtfparams,
- ALuint IrSize, ALuint Counter)
-{
- ALuint c;
- float32x4_t counter4;
- {
- float32x2_t counter2 = vdup_n_f32(-(float)Counter);
- counter4 = vcombine_f32(counter2, counter2);
- }
- for(c = 0;c < IrSize;c += 2)
- {
- float32x4_t step4 = vld1q_f32((float32_t*)hrtfparams->CoeffStep[c]);
- float32x4_t coeffs = vld1q_f32((float32_t*)hrtfparams->Coeffs[c]);
- coeffs = vmlaq_f32(coeffs, step4, counter4);
- vst1q_f32((float32_t*)OutCoeffs[c], coeffs);
- }
-}
-
-static inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
- const ALuint IrSize,
- ALfloat (*restrict Coeffs)[2],
- const ALfloat (*restrict CoeffStep)[2],
- ALfloat left, ALfloat right)
-{
- ALuint c;
- float32x4_t leftright4;
- {
- float32x2_t leftright2 = vdup_n_f32(0.0);
- leftright2 = vset_lane_f32(left, leftright2, 0);
- leftright2 = vset_lane_f32(right, leftright2, 1);
- leftright4 = vcombine_f32(leftright2, leftright2);
- }
- for(c = 0;c < IrSize;c += 2)
- {
- const ALuint o0 = (Offset+c)&HRIR_MASK;
- const ALuint o1 = (o0+1)&HRIR_MASK;
- float32x4_t vals = vcombine_f32(vld1_f32((float32_t*)&Values[o0][0]),
- vld1_f32((float32_t*)&Values[o1][0]));
- float32x4_t coefs = vld1q_f32((float32_t*)&Coeffs[c][0]);
- float32x4_t deltas = vld1q_f32(&CoeffStep[c][0]);
-
- vals = vmlaq_f32(vals, coefs, leftright4);
- coefs = vaddq_f32(coefs, deltas);
-
- vst1_f32((float32_t*)&Values[o0][0], vget_low_f32(vals));
- vst1_f32((float32_t*)&Values[o1][0], vget_high_f32(vals));
- vst1q_f32(&Coeffs[c][0], coefs);
- }
-}
-
-static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
- const ALuint IrSize,
- ALfloat (*restrict Coeffs)[2],
- ALfloat left, ALfloat right)
-{
- ALuint c;
- float32x4_t leftright4;
- {
- float32x2_t leftright2 = vdup_n_f32(0.0);
- leftright2 = vset_lane_f32(left, leftright2, 0);
- leftright2 = vset_lane_f32(right, leftright2, 1);
- leftright4 = vcombine_f32(leftright2, leftright2);
- }
- for(c = 0;c < IrSize;c += 2)
- {
- const ALuint o0 = (Offset+c)&HRIR_MASK;
- const ALuint o1 = (o0+1)&HRIR_MASK;
- float32x4_t vals = vcombine_f32(vld1_f32((float32_t*)&Values[o0][0]),
- vld1_f32((float32_t*)&Values[o1][0]));
- float32x4_t coefs = vld1q_f32((float32_t*)&Coeffs[c][0]);
-
- vals = vmlaq_f32(vals, coefs, leftright4);
-
- vst1_f32((float32_t*)&Values[o0][0], vget_low_f32(vals));
- vst1_f32((float32_t*)&Values[o1][0], vget_high_f32(vals));
- }
-}
-
-#define MixHrtf MixHrtf_Neon
-#include "mixer_inc.c"
-#undef MixHrtf
-
-
-void Mix_Neon(const ALfloat *data, ALuint OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
- MixGains *Gains, ALuint Counter, ALuint OutPos, ALuint BufferSize)
-{
- ALfloat gain, step;
- float32x4_t gain4;
- ALuint c;
-
- for(c = 0;c < OutChans;c++)
- {
- ALuint pos = 0;
- gain = Gains[c].Current;
- step = Gains[c].Step;
- if(step != 0.0f && Counter > 0)
- {
- ALuint minsize = minu(BufferSize, Counter);
- for(;pos < minsize;pos++)
- {
- OutBuffer[c][OutPos+pos] += data[pos]*gain;
- gain += step;
- }
- if(pos == Counter)
- gain = Gains[c].Target;
- Gains[c].Current = gain;
-
- /* Mix until pos is aligned with 4 or the mix is done. */
- minsize = minu(BufferSize, (pos+3)&~3);
- for(;pos < minsize;pos++)
- OutBuffer[c][OutPos+pos] += data[pos]*gain;
- }
-
- if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
- continue;
- gain4 = vdupq_n_f32(gain);
- for(;BufferSize-pos > 3;pos += 4)
- {
- const float32x4_t val4 = vld1q_f32(&data[pos]);
- float32x4_t dry4 = vld1q_f32(&OutBuffer[c][OutPos+pos]);
- dry4 = vmlaq_f32(dry4, val4, gain4);
- vst1q_f32(&OutBuffer[c][OutPos+pos], dry4);
- }
- for(;pos < BufferSize;pos++)
- OutBuffer[c][OutPos+pos] += data[pos]*gain;
- }
-}
diff --git a/Alc/mixer_sse.c b/Alc/mixer_sse.c
deleted file mode 100644
index 090b7a5a..00000000
--- a/Alc/mixer_sse.c
+++ /dev/null
@@ -1,279 +0,0 @@
-#include "config.h"
-
-#include <xmmintrin.h>
-
-#include "AL/al.h"
-#include "AL/alc.h"
-#include "alMain.h"
-#include "alu.h"
-
-#include "alSource.h"
-#include "alAuxEffectSlot.h"
-#include "mixer_defs.h"
-
-
-const ALfloat *Resample_bsinc32_SSE(const BsincState *state, const ALfloat *src, ALuint frac,
- ALuint increment, ALfloat *restrict dst, ALuint dstlen)
-{
- const __m128 sf4 = _mm_set1_ps(state->sf);
- const ALuint m = state->m;
- const ALint l = state->l;
- const ALfloat *fil, *scd, *phd, *spd;
- ALuint pi, j_f, i;
- ALfloat pf;
- ALint j_s;
- __m128 r4;
-
- for(i = 0;i < dstlen;i++)
- {
- // Calculate the phase index and factor.
-#define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS)
- pi = frac >> FRAC_PHASE_BITDIFF;
- pf = (frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF));
-#undef FRAC_PHASE_BITDIFF
-
- fil = state->coeffs[pi].filter;
- scd = state->coeffs[pi].scDelta;
- phd = state->coeffs[pi].phDelta;
- spd = state->coeffs[pi].spDelta;
-
- // Apply the scale and phase interpolated filter.
- r4 = _mm_setzero_ps();
- {
- const __m128 pf4 = _mm_set1_ps(pf);
- for(j_f = 0,j_s = l;j_f < m;j_f+=4,j_s+=4)
- {
- const __m128 f4 = _mm_add_ps(
- _mm_add_ps(
- _mm_load_ps(&fil[j_f]),
- _mm_mul_ps(sf4, _mm_load_ps(&scd[j_f]))
- ),
- _mm_mul_ps(
- pf4,
- _mm_add_ps(
- _mm_load_ps(&phd[j_f]),
- _mm_mul_ps(sf4, _mm_load_ps(&spd[j_f]))
- )
- )
- );
- r4 = _mm_add_ps(r4, _mm_mul_ps(f4, _mm_loadu_ps(&src[j_s])));
- }
- }
- r4 = _mm_add_ps(r4, _mm_shuffle_ps(r4, r4, _MM_SHUFFLE(0, 1, 2, 3)));
- r4 = _mm_add_ps(r4, _mm_movehl_ps(r4, r4));
- dst[i] = _mm_cvtss_f32(r4);
-
- frac += increment;
- src += frac>>FRACTIONBITS;
- frac &= FRACTIONMASK;
- }
- return dst;
-}
-
-
-static inline void SetupCoeffs(ALfloat (*restrict OutCoeffs)[2],
- const HrtfParams *hrtfparams,
- ALuint IrSize, ALuint Counter)
-{
- const __m128 counter4 = _mm_set1_ps((float)Counter);
- __m128 coeffs, step4;
- ALuint i;
-
- for(i = 0;i < IrSize;i += 2)
- {
- step4 = _mm_load_ps(&hrtfparams->CoeffStep[i][0]);
- coeffs = _mm_load_ps(&hrtfparams->Coeffs[i][0]);
- coeffs = _mm_sub_ps(coeffs, _mm_mul_ps(step4, counter4));
- _mm_store_ps(&OutCoeffs[i][0], coeffs);
- }
-}
-
-static inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
- const ALuint IrSize,
- ALfloat (*restrict Coeffs)[2],
- const ALfloat (*restrict CoeffStep)[2],
- ALfloat left, ALfloat right)
-{
- const __m128 lrlr = _mm_setr_ps(left, right, left, right);
- __m128 coeffs, deltas, imp0, imp1;
- __m128 vals = _mm_setzero_ps();
- ALuint i;
-
- if((Offset&1))
- {
- const ALuint o0 = Offset&HRIR_MASK;
- const ALuint o1 = (Offset+IrSize-1)&HRIR_MASK;
-
- coeffs = _mm_load_ps(&Coeffs[0][0]);
- deltas = _mm_load_ps(&CoeffStep[0][0]);
- vals = _mm_loadl_pi(vals, (__m64*)&Values[o0][0]);
- imp0 = _mm_mul_ps(lrlr, coeffs);
- coeffs = _mm_add_ps(coeffs, deltas);
- vals = _mm_add_ps(imp0, vals);
- _mm_store_ps(&Coeffs[0][0], coeffs);
- _mm_storel_pi((__m64*)&Values[o0][0], vals);
- for(i = 1;i < IrSize-1;i += 2)
- {
- const ALuint o2 = (Offset+i)&HRIR_MASK;
-
- coeffs = _mm_load_ps(&Coeffs[i+1][0]);
- deltas = _mm_load_ps(&CoeffStep[i+1][0]);
- vals = _mm_load_ps(&Values[o2][0]);
- imp1 = _mm_mul_ps(lrlr, coeffs);
- coeffs = _mm_add_ps(coeffs, deltas);
- imp0 = _mm_shuffle_ps(imp0, imp1, _MM_SHUFFLE(1, 0, 3, 2));
- vals = _mm_add_ps(imp0, vals);
- _mm_store_ps(&Coeffs[i+1][0], coeffs);
- _mm_store_ps(&Values[o2][0], vals);
- imp0 = imp1;
- }
- vals = _mm_loadl_pi(vals, (__m64*)&Values[o1][0]);
- imp0 = _mm_movehl_ps(imp0, imp0);
- vals = _mm_add_ps(imp0, vals);
- _mm_storel_pi((__m64*)&Values[o1][0], vals);
- }
- else
- {
- for(i = 0;i < IrSize;i += 2)
- {
- const ALuint o = (Offset + i)&HRIR_MASK;
-
- coeffs = _mm_load_ps(&Coeffs[i][0]);
- deltas = _mm_load_ps(&CoeffStep[i][0]);
- vals = _mm_load_ps(&Values[o][0]);
- imp0 = _mm_mul_ps(lrlr, coeffs);
- coeffs = _mm_add_ps(coeffs, deltas);
- vals = _mm_add_ps(imp0, vals);
- _mm_store_ps(&Coeffs[i][0], coeffs);
- _mm_store_ps(&Values[o][0], vals);
- }
- }
-}
-
-static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
- const ALuint IrSize,
- ALfloat (*restrict Coeffs)[2],
- ALfloat left, ALfloat right)
-{
- const __m128 lrlr = _mm_setr_ps(left, right, left, right);
- __m128 vals = _mm_setzero_ps();
- __m128 coeffs;
- ALuint i;
-
- if((Offset&1))
- {
- const ALuint o0 = Offset&HRIR_MASK;
- const ALuint o1 = (Offset+IrSize-1)&HRIR_MASK;
- __m128 imp0, imp1;
-
- coeffs = _mm_load_ps(&Coeffs[0][0]);
- vals = _mm_loadl_pi(vals, (__m64*)&Values[o0][0]);
- imp0 = _mm_mul_ps(lrlr, coeffs);
- vals = _mm_add_ps(imp0, vals);
- _mm_storel_pi((__m64*)&Values[o0][0], vals);
- for(i = 1;i < IrSize-1;i += 2)
- {
- const ALuint o2 = (Offset+i)&HRIR_MASK;
-
- coeffs = _mm_load_ps(&Coeffs[i+1][0]);
- vals = _mm_load_ps(&Values[o2][0]);
- imp1 = _mm_mul_ps(lrlr, coeffs);
- imp0 = _mm_shuffle_ps(imp0, imp1, _MM_SHUFFLE(1, 0, 3, 2));
- vals = _mm_add_ps(imp0, vals);
- _mm_store_ps(&Values[o2][0], vals);
- imp0 = imp1;
- }
- vals = _mm_loadl_pi(vals, (__m64*)&Values[o1][0]);
- imp0 = _mm_movehl_ps(imp0, imp0);
- vals = _mm_add_ps(imp0, vals);
- _mm_storel_pi((__m64*)&Values[o1][0], vals);
- }
- else
- {
- for(i = 0;i < IrSize;i += 2)
- {
- const ALuint o = (Offset + i)&HRIR_MASK;
-
- coeffs = _mm_load_ps(&Coeffs[i][0]);
- vals = _mm_load_ps(&Values[o][0]);
- vals = _mm_add_ps(vals, _mm_mul_ps(lrlr, coeffs));
- _mm_store_ps(&Values[o][0], vals);
- }
- }
-}
-
-#define MixHrtf MixHrtf_SSE
-#include "mixer_inc.c"
-#undef MixHrtf
-
-
-void Mix_SSE(const ALfloat *data, ALuint OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
- MixGains *Gains, ALuint Counter, ALuint OutPos, ALuint BufferSize)
-{
- ALfloat gain, step;
- __m128 gain4;
- ALuint c;
-
- for(c = 0;c < OutChans;c++)
- {
- ALuint pos = 0;
- gain = Gains[c].Current;
- step = Gains[c].Step;
- if(step != 0.0f && Counter > 0)
- {
- ALuint minsize = minu(BufferSize, Counter);
- /* Mix with applying gain steps in aligned multiples of 4. */
- if(minsize-pos > 3)
- {
- __m128 step4;
- gain4 = _mm_setr_ps(
- gain,
- gain + step,
- gain + step + step,
- gain + step + step + step
- );
- step4 = _mm_set1_ps(step + step + step + step);
- do {
- const __m128 val4 = _mm_load_ps(&data[pos]);
- __m128 dry4 = _mm_load_ps(&OutBuffer[c][OutPos+pos]);
- dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4));
- gain4 = _mm_add_ps(gain4, step4);
- _mm_store_ps(&OutBuffer[c][OutPos+pos], dry4);
- pos += 4;
- } while(minsize-pos > 3);
- /* NOTE: gain4 now represents the next four gains after the
- * last four mixed samples, so the lowest element represents
- * the next gain to apply.
- */
- gain = _mm_cvtss_f32(gain4);
- }
- /* Mix with applying left over gain steps that aren't aligned multiples of 4. */
- for(;pos < minsize;pos++)
- {
- OutBuffer[c][OutPos+pos] += data[pos]*gain;
- gain += step;
- }
- if(pos == Counter)
- gain = Gains[c].Target;
- Gains[c].Current = gain;
-
- /* Mix until pos is aligned with 4 or the mix is done. */
- minsize = minu(BufferSize, (pos+3)&~3);
- for(;pos < minsize;pos++)
- OutBuffer[c][OutPos+pos] += data[pos]*gain;
- }
-
- if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
- continue;
- gain4 = _mm_set1_ps(gain);
- for(;BufferSize-pos > 3;pos += 4)
- {
- const __m128 val4 = _mm_load_ps(&data[pos]);
- __m128 dry4 = _mm_load_ps(&OutBuffer[c][OutPos+pos]);
- dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4));
- _mm_store_ps(&OutBuffer[c][OutPos+pos], dry4);
- }
- for(;pos < BufferSize;pos++)
- OutBuffer[c][OutPos+pos] += data[pos]*gain;
- }
-}
diff --git a/Alc/mixer_sse3.c b/Alc/mixer_sse3.c
deleted file mode 100644
index 7085c537..00000000
--- a/Alc/mixer_sse3.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/**
- * OpenAL cross platform audio library, SSE3 mixer functions
- *
- * Copyright (C) 2014 by Timothy Arceri <[email protected]>.
- * Copyright (C) 2015 by Chris Robinson <[email protected]>.
- *
- * 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 <xmmintrin.h>
-#include <emmintrin.h>
-#include <pmmintrin.h>
-
-#include "alu.h"
-#include "mixer_defs.h"
-
-
-const ALfloat *Resample_fir4_32_SSE3(const BsincState* UNUSED(state), const ALfloat *src, ALuint frac, ALuint increment,
- ALfloat *restrict dst, ALuint numsamples)
-{
- const __m128i increment4 = _mm_set1_epi32(increment*4);
- const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK);
- alignas(16) union { ALuint i[4]; float f[4]; } pos_;
- alignas(16) union { ALuint i[4]; float f[4]; } frac_;
- __m128i frac4, pos4;
- ALuint pos;
- ALuint i;
-
- InitiatePositionArrays(frac, increment, frac_.i, pos_.i, 4);
-
- frac4 = _mm_castps_si128(_mm_load_ps(frac_.f));
- pos4 = _mm_castps_si128(_mm_load_ps(pos_.f));
-
- --src;
- for(i = 0;numsamples-i > 3;i += 4)
- {
- const __m128 val0 = _mm_loadu_ps(&src[pos_.i[0]]);
- const __m128 val1 = _mm_loadu_ps(&src[pos_.i[1]]);
- const __m128 val2 = _mm_loadu_ps(&src[pos_.i[2]]);
- const __m128 val3 = _mm_loadu_ps(&src[pos_.i[3]]);
- __m128 k0 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[0]]);
- __m128 k1 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[1]]);
- __m128 k2 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[2]]);
- __m128 k3 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[3]]);
- __m128 out;
-
- k0 = _mm_mul_ps(k0, val0);
- k1 = _mm_mul_ps(k1, val1);
- k2 = _mm_mul_ps(k2, val2);
- k3 = _mm_mul_ps(k3, val3);
- k0 = _mm_hadd_ps(k0, k1);
- k2 = _mm_hadd_ps(k2, k3);
- out = _mm_hadd_ps(k0, k2);
-
- _mm_store_ps(&dst[i], out);
-
- frac4 = _mm_add_epi32(frac4, increment4);
- pos4 = _mm_add_epi32(pos4, _mm_srli_epi32(frac4, FRACTIONBITS));
- frac4 = _mm_and_si128(frac4, fracMask4);
-
- _mm_store_ps(pos_.f, _mm_castsi128_ps(pos4));
- _mm_store_ps(frac_.f, _mm_castsi128_ps(frac4));
- }
-
- /* NOTE: These four elements represent the position *after* the last four
- * samples, so the lowest element is the next position to resample.
- */
- pos = pos_.i[0];
- frac = frac_.i[0];
-
- for(;i < numsamples;i++)
- {
- dst[i] = resample_fir4(src[pos], src[pos+1], src[pos+2], src[pos+3], frac);
-
- frac += increment;
- pos += frac>>FRACTIONBITS;
- frac &= FRACTIONMASK;
- }
- return dst;
-}
-
-const ALfloat *Resample_fir8_32_SSE3(const BsincState* UNUSED(state), const ALfloat *src, ALuint frac, ALuint increment,
- ALfloat *restrict dst, ALuint numsamples)
-{
- const __m128i increment4 = _mm_set1_epi32(increment*4);
- const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK);
- alignas(16) union { ALuint i[4]; float f[4]; } pos_;
- alignas(16) union { ALuint i[4]; float f[4]; } frac_;
- __m128i frac4, pos4;
- ALuint pos;
- ALuint i, j;
-
- InitiatePositionArrays(frac, increment, frac_.i, pos_.i, 4);
-
- frac4 = _mm_castps_si128(_mm_load_ps(frac_.f));
- pos4 = _mm_castps_si128(_mm_load_ps(pos_.f));
-
- src -= 3;
- for(i = 0;numsamples-i > 3;i += 4)
- {
- __m128 out[2];
- for(j = 0;j < 8;j+=4)
- {
- const __m128 val0 = _mm_loadu_ps(&src[pos_.i[0]+j]);
- const __m128 val1 = _mm_loadu_ps(&src[pos_.i[1]+j]);
- const __m128 val2 = _mm_loadu_ps(&src[pos_.i[2]+j]);
- const __m128 val3 = _mm_loadu_ps(&src[pos_.i[3]+j]);
- __m128 k0 = _mm_load_ps(&ResampleCoeffs.FIR8[frac_.i[0]][j]);
- __m128 k1 = _mm_load_ps(&ResampleCoeffs.FIR8[frac_.i[1]][j]);
- __m128 k2 = _mm_load_ps(&ResampleCoeffs.FIR8[frac_.i[2]][j]);
- __m128 k3 = _mm_load_ps(&ResampleCoeffs.FIR8[frac_.i[3]][j]);
-
- k0 = _mm_mul_ps(k0, val0);
- k1 = _mm_mul_ps(k1, val1);
- k2 = _mm_mul_ps(k2, val2);
- k3 = _mm_mul_ps(k3, val3);
- k0 = _mm_hadd_ps(k0, k1);
- k2 = _mm_hadd_ps(k2, k3);
- out[j>>2] = _mm_hadd_ps(k0, k2);
- }
-
- out[0] = _mm_add_ps(out[0], out[1]);
- _mm_store_ps(&dst[i], out[0]);
-
- frac4 = _mm_add_epi32(frac4, increment4);
- pos4 = _mm_add_epi32(pos4, _mm_srli_epi32(frac4, FRACTIONBITS));
- frac4 = _mm_and_si128(frac4, fracMask4);
-
- _mm_store_ps(pos_.f, _mm_castsi128_ps(pos4));
- _mm_store_ps(frac_.f, _mm_castsi128_ps(frac4));
- }
-
- pos = pos_.i[0];
- frac = frac_.i[0];
-
- for(;i < numsamples;i++)
- {
- dst[i] = resample_fir8(src[pos ], src[pos+1], src[pos+2], src[pos+3],
- src[pos+4], src[pos+5], src[pos+6], src[pos+7], frac);
-
- frac += increment;
- pos += frac>>FRACTIONBITS;
- frac &= FRACTIONMASK;
- }
- return dst;
-}
diff --git a/Alc/mixer_sse41.c b/Alc/mixer_sse41.c
deleted file mode 100644
index e832e5df..00000000
--- a/Alc/mixer_sse41.c
+++ /dev/null
@@ -1,224 +0,0 @@
-/**
- * OpenAL cross platform audio library
- * Copyright (C) 2014 by Timothy Arceri <[email protected]>.
- * 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 <xmmintrin.h>
-#include <emmintrin.h>
-#include <smmintrin.h>
-
-#include "alu.h"
-#include "mixer_defs.h"
-
-
-const ALfloat *Resample_lerp32_SSE41(const BsincState* UNUSED(state), const ALfloat *src, ALuint frac, ALuint increment,
- ALfloat *restrict dst, ALuint numsamples)
-{
- const __m128i increment4 = _mm_set1_epi32(increment*4);
- const __m128 fracOne4 = _mm_set1_ps(1.0f/FRACTIONONE);
- const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK);
- alignas(16) union { ALuint i[4]; float f[4]; } pos_;
- alignas(16) union { ALuint i[4]; float f[4]; } frac_;
- __m128i frac4, pos4;
- ALuint pos;
- ALuint i;
-
- InitiatePositionArrays(frac, increment, frac_.i, pos_.i, 4);
-
- frac4 = _mm_castps_si128(_mm_load_ps(frac_.f));
- pos4 = _mm_castps_si128(_mm_load_ps(pos_.f));
-
- for(i = 0;numsamples-i > 3;i += 4)
- {
- const __m128 val1 = _mm_setr_ps(src[pos_.i[0]], src[pos_.i[1]], src[pos_.i[2]], src[pos_.i[3]]);
- const __m128 val2 = _mm_setr_ps(src[pos_.i[0]+1], src[pos_.i[1]+1], src[pos_.i[2]+1], src[pos_.i[3]+1]);
-
- /* val1 + (val2-val1)*mu */
- const __m128 r0 = _mm_sub_ps(val2, val1);
- const __m128 mu = _mm_mul_ps(_mm_cvtepi32_ps(frac4), fracOne4);
- const __m128 out = _mm_add_ps(val1, _mm_mul_ps(mu, r0));
-
- _mm_store_ps(&dst[i], out);
-
- frac4 = _mm_add_epi32(frac4, increment4);
- pos4 = _mm_add_epi32(pos4, _mm_srli_epi32(frac4, FRACTIONBITS));
- frac4 = _mm_and_si128(frac4, fracMask4);
-
- pos_.i[0] = _mm_extract_epi32(pos4, 0);
- pos_.i[1] = _mm_extract_epi32(pos4, 1);
- pos_.i[2] = _mm_extract_epi32(pos4, 2);
- pos_.i[3] = _mm_extract_epi32(pos4, 3);
- }
-
- /* NOTE: These four elements represent the position *after* the last four
- * samples, so the lowest element is the next position to resample.
- */
- pos = pos_.i[0];
- frac = _mm_cvtsi128_si32(frac4);
-
- for(;i < numsamples;i++)
- {
- dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE));
-
- frac += increment;
- pos += frac>>FRACTIONBITS;
- frac &= FRACTIONMASK;
- }
- return dst;
-}
-
-const ALfloat *Resample_fir4_32_SSE41(const BsincState* UNUSED(state), const ALfloat *src, ALuint frac, ALuint increment,
- ALfloat *restrict dst, ALuint numsamples)
-{
- const __m128i increment4 = _mm_set1_epi32(increment*4);
- const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK);
- alignas(16) union { ALuint i[4]; float f[4]; } pos_;
- alignas(16) union { ALuint i[4]; float f[4]; } frac_;
- __m128i frac4, pos4;
- ALuint pos;
- ALuint i;
-
- InitiatePositionArrays(frac, increment, frac_.i, pos_.i, 4);
-
- frac4 = _mm_castps_si128(_mm_load_ps(frac_.f));
- pos4 = _mm_castps_si128(_mm_load_ps(pos_.f));
-
- --src;
- for(i = 0;numsamples-i > 3;i += 4)
- {
- const __m128 val0 = _mm_loadu_ps(&src[pos_.i[0]]);
- const __m128 val1 = _mm_loadu_ps(&src[pos_.i[1]]);
- const __m128 val2 = _mm_loadu_ps(&src[pos_.i[2]]);
- const __m128 val3 = _mm_loadu_ps(&src[pos_.i[3]]);
- __m128 k0 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[0]]);
- __m128 k1 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[1]]);
- __m128 k2 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[2]]);
- __m128 k3 = _mm_load_ps(ResampleCoeffs.FIR4[frac_.i[3]]);
- __m128 out;
-
- k0 = _mm_mul_ps(k0, val0);
- k1 = _mm_mul_ps(k1, val1);
- k2 = _mm_mul_ps(k2, val2);
- k3 = _mm_mul_ps(k3, val3);
- k0 = _mm_hadd_ps(k0, k1);
- k2 = _mm_hadd_ps(k2, k3);
- out = _mm_hadd_ps(k0, k2);
-
- _mm_store_ps(&dst[i], out);
-
- frac4 = _mm_add_epi32(frac4, increment4);
- pos4 = _mm_add_epi32(pos4, _mm_srli_epi32(frac4, FRACTIONBITS));
- frac4 = _mm_and_si128(frac4, fracMask4);
-
- pos_.i[0] = _mm_extract_epi32(pos4, 0);
- pos_.i[1] = _mm_extract_epi32(pos4, 1);
- pos_.i[2] = _mm_extract_epi32(pos4, 2);
- pos_.i[3] = _mm_extract_epi32(pos4, 3);
- frac_.i[0] = _mm_extract_epi32(frac4, 0);
- frac_.i[1] = _mm_extract_epi32(frac4, 1);
- frac_.i[2] = _mm_extract_epi32(frac4, 2);
- frac_.i[3] = _mm_extract_epi32(frac4, 3);
- }
-
- pos = pos_.i[0];
- frac = frac_.i[0];
-
- for(;i < numsamples;i++)
- {
- dst[i] = resample_fir4(src[pos], src[pos+1], src[pos+2], src[pos+3], frac);
-
- frac += increment;
- pos += frac>>FRACTIONBITS;
- frac &= FRACTIONMASK;
- }
- return dst;
-}
-
-const ALfloat *Resample_fir8_32_SSE41(const BsincState* UNUSED(state), const ALfloat *src, ALuint frac, ALuint increment,
- ALfloat *restrict dst, ALuint numsamples)
-{
- const __m128i increment4 = _mm_set1_epi32(increment*4);
- const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK);
- alignas(16) union { ALuint i[4]; float f[4]; } pos_;
- alignas(16) union { ALuint i[4]; float f[4]; } frac_;
- __m128i frac4, pos4;
- ALuint pos;
- ALuint i, j;
-
- InitiatePositionArrays(frac, increment, frac_.i, pos_.i, 4);
-
- frac4 = _mm_castps_si128(_mm_load_ps(frac_.f));
- pos4 = _mm_castps_si128(_mm_load_ps(pos_.f));
-
- src -= 3;
- for(i = 0;numsamples-i > 3;i += 4)
- {
- __m128 out[2];
- for(j = 0;j < 8;j+=4)
- {
- const __m128 val0 = _mm_loadu_ps(&src[pos_.i[0]+j]);
- const __m128 val1 = _mm_loadu_ps(&src[pos_.i[1]+j]);
- const __m128 val2 = _mm_loadu_ps(&src[pos_.i[2]+j]);
- const __m128 val3 = _mm_loadu_ps(&src[pos_.i[3]+j]);
- __m128 k0 = _mm_load_ps(&ResampleCoeffs.FIR8[frac_.i[0]][j]);
- __m128 k1 = _mm_load_ps(&ResampleCoeffs.FIR8[frac_.i[1]][j]);
- __m128 k2 = _mm_load_ps(&ResampleCoeffs.FIR8[frac_.i[2]][j]);
- __m128 k3 = _mm_load_ps(&ResampleCoeffs.FIR8[frac_.i[3]][j]);
-
- k0 = _mm_mul_ps(k0, val0);
- k1 = _mm_mul_ps(k1, val1);
- k2 = _mm_mul_ps(k2, val2);
- k3 = _mm_mul_ps(k3, val3);
- k0 = _mm_hadd_ps(k0, k1);
- k2 = _mm_hadd_ps(k2, k3);
- out[j>>2] = _mm_hadd_ps(k0, k2);
- }
-
- out[0] = _mm_add_ps(out[0], out[1]);
- _mm_store_ps(&dst[i], out[0]);
-
- frac4 = _mm_add_epi32(frac4, increment4);
- pos4 = _mm_add_epi32(pos4, _mm_srli_epi32(frac4, FRACTIONBITS));
- frac4 = _mm_and_si128(frac4, fracMask4);
-
- pos_.i[0] = _mm_extract_epi32(pos4, 0);
- pos_.i[1] = _mm_extract_epi32(pos4, 1);
- pos_.i[2] = _mm_extract_epi32(pos4, 2);
- pos_.i[3] = _mm_extract_epi32(pos4, 3);
- frac_.i[0] = _mm_extract_epi32(frac4, 0);
- frac_.i[1] = _mm_extract_epi32(frac4, 1);
- frac_.i[2] = _mm_extract_epi32(frac4, 2);
- frac_.i[3] = _mm_extract_epi32(frac4, 3);
- }
-
- pos = pos_.i[0];
- frac = frac_.i[0];
-
- for(;i < numsamples;i++)
- {
- dst[i] = resample_fir8(src[pos ], src[pos+1], src[pos+2], src[pos+3],
- src[pos+4], src[pos+5], src[pos+6], src[pos+7], frac);
-
- frac += increment;
- pos += frac>>FRACTIONBITS;
- frac &= FRACTIONMASK;
- }
- return dst;
-}
diff --git a/Alc/mixvoice.c b/Alc/mixvoice.c
new file mode 100644
index 00000000..d019b898
--- /dev/null
+++ b/Alc/mixvoice.c
@@ -0,0 +1,762 @@
+/**
+ * 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 <math.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <assert.h>
+
+#include "alMain.h"
+#include "AL/al.h"
+#include "AL/alc.h"
+#include "alSource.h"
+#include "alBuffer.h"
+#include "alListener.h"
+#include "alAuxEffectSlot.h"
+#include "sample_cvt.h"
+#include "alu.h"
+#include "alconfig.h"
+#include "ringbuffer.h"
+
+#include "cpu_caps.h"
+#include "mixer/defs.h"
+
+
+static_assert((INT_MAX>>FRACTIONBITS)/MAX_PITCH > BUFFERSIZE,
+ "MAX_PITCH and/or BUFFERSIZE are too large for FRACTIONBITS!");
+
+extern inline void InitiatePositionArrays(ALsizei frac, ALint increment, ALsizei *restrict frac_arr, ALsizei *restrict pos_arr, ALsizei size);
+
+
+/* BSinc24 requires up to 23 extra samples before the current position, and 24 after. */
+static_assert(MAX_RESAMPLE_PADDING >= 24, "MAX_RESAMPLE_PADDING must be at least 24!");
+
+
+enum Resampler ResamplerDefault = LinearResampler;
+
+MixerFunc MixSamples = Mix_C;
+RowMixerFunc MixRowSamples = MixRow_C;
+static HrtfMixerFunc MixHrtfSamples = MixHrtf_C;
+static HrtfMixerBlendFunc MixHrtfBlendSamples = MixHrtfBlend_C;
+
+static MixerFunc SelectMixer(void)
+{
+#ifdef HAVE_NEON
+ if((CPUCapFlags&CPU_CAP_NEON))
+ return Mix_Neon;
+#endif
+#ifdef HAVE_SSE
+ if((CPUCapFlags&CPU_CAP_SSE))
+ return Mix_SSE;
+#endif
+ return Mix_C;
+}
+
+static RowMixerFunc SelectRowMixer(void)
+{
+#ifdef HAVE_NEON
+ if((CPUCapFlags&CPU_CAP_NEON))
+ return MixRow_Neon;
+#endif
+#ifdef HAVE_SSE
+ if((CPUCapFlags&CPU_CAP_SSE))
+ return MixRow_SSE;
+#endif
+ return MixRow_C;
+}
+
+static inline HrtfMixerFunc SelectHrtfMixer(void)
+{
+#ifdef HAVE_NEON
+ if((CPUCapFlags&CPU_CAP_NEON))
+ return MixHrtf_Neon;
+#endif
+#ifdef HAVE_SSE
+ if((CPUCapFlags&CPU_CAP_SSE))
+ return MixHrtf_SSE;
+#endif
+ return MixHrtf_C;
+}
+
+static inline HrtfMixerBlendFunc SelectHrtfBlendMixer(void)
+{
+#ifdef HAVE_NEON
+ if((CPUCapFlags&CPU_CAP_NEON))
+ return MixHrtfBlend_Neon;
+#endif
+#ifdef HAVE_SSE
+ if((CPUCapFlags&CPU_CAP_SSE))
+ return MixHrtfBlend_SSE;
+#endif
+ return MixHrtfBlend_C;
+}
+
+ResamplerFunc SelectResampler(enum Resampler resampler)
+{
+ switch(resampler)
+ {
+ case PointResampler:
+ return Resample_point_C;
+ case LinearResampler:
+#ifdef HAVE_NEON
+ if((CPUCapFlags&CPU_CAP_NEON))
+ return Resample_lerp_Neon;
+#endif
+#ifdef HAVE_SSE4_1
+ if((CPUCapFlags&CPU_CAP_SSE4_1))
+ return Resample_lerp_SSE41;
+#endif
+#ifdef HAVE_SSE2
+ if((CPUCapFlags&CPU_CAP_SSE2))
+ return Resample_lerp_SSE2;
+#endif
+ return Resample_lerp_C;
+ case FIR4Resampler:
+ return Resample_cubic_C;
+ case BSinc12Resampler:
+ case BSinc24Resampler:
+#ifdef HAVE_NEON
+ if((CPUCapFlags&CPU_CAP_NEON))
+ return Resample_bsinc_Neon;
+#endif
+#ifdef HAVE_SSE
+ if((CPUCapFlags&CPU_CAP_SSE))
+ return Resample_bsinc_SSE;
+#endif
+ return Resample_bsinc_C;
+ }
+
+ return Resample_point_C;
+}
+
+
+void aluInitMixer(void)
+{
+ const char *str;
+
+ if(ConfigValueStr(NULL, NULL, "resampler", &str))
+ {
+ if(strcasecmp(str, "point") == 0 || strcasecmp(str, "none") == 0)
+ ResamplerDefault = PointResampler;
+ else if(strcasecmp(str, "linear") == 0)
+ ResamplerDefault = LinearResampler;
+ else if(strcasecmp(str, "cubic") == 0)
+ ResamplerDefault = FIR4Resampler;
+ else if(strcasecmp(str, "bsinc12") == 0)
+ ResamplerDefault = BSinc12Resampler;
+ else if(strcasecmp(str, "bsinc24") == 0)
+ ResamplerDefault = BSinc24Resampler;
+ else if(strcasecmp(str, "bsinc") == 0)
+ {
+ WARN("Resampler option \"%s\" is deprecated, using bsinc12\n", str);
+ ResamplerDefault = BSinc12Resampler;
+ }
+ else if(strcasecmp(str, "sinc4") == 0 || strcasecmp(str, "sinc8") == 0)
+ {
+ WARN("Resampler option \"%s\" is deprecated, using cubic\n", str);
+ ResamplerDefault = FIR4Resampler;
+ }
+ else
+ {
+ char *end;
+ long n = strtol(str, &end, 0);
+ if(*end == '\0' && (n == PointResampler || n == LinearResampler || n == FIR4Resampler))
+ ResamplerDefault = n;
+ else
+ WARN("Invalid resampler: %s\n", str);
+ }
+ }
+
+ MixHrtfBlendSamples = SelectHrtfBlendMixer();
+ MixHrtfSamples = SelectHrtfMixer();
+ MixSamples = SelectMixer();
+ MixRowSamples = SelectRowMixer();
+}
+
+
+static void SendAsyncEvent(ALCcontext *context, ALuint enumtype, ALenum type,
+ ALuint objid, ALuint param, const char *msg)
+{
+ AsyncEvent evt = ASYNC_EVENT(enumtype);
+ evt.u.user.type = type;
+ evt.u.user.id = objid;
+ evt.u.user.param = param;
+ strcpy(evt.u.user.msg, msg);
+ if(ll_ringbuffer_write(context->AsyncEvents, (const char*)&evt, 1) == 1)
+ alsem_post(&context->EventSem);
+}
+
+
+static inline ALfloat Sample_ALubyte(ALubyte val)
+{ return (val-128) * (1.0f/128.0f); }
+
+static inline ALfloat Sample_ALshort(ALshort val)
+{ return val * (1.0f/32768.0f); }
+
+static inline ALfloat Sample_ALfloat(ALfloat val)
+{ return val; }
+
+static inline ALfloat Sample_ALdouble(ALdouble val)
+{ return (ALfloat)val; }
+
+typedef ALubyte ALmulaw;
+static inline ALfloat Sample_ALmulaw(ALmulaw val)
+{ return muLawDecompressionTable[val] * (1.0f/32768.0f); }
+
+typedef ALubyte ALalaw;
+static inline ALfloat Sample_ALalaw(ALalaw val)
+{ return aLawDecompressionTable[val] * (1.0f/32768.0f); }
+
+#define DECL_TEMPLATE(T) \
+static inline void Load_##T(ALfloat *restrict dst, const T *restrict src, \
+ ALint srcstep, ALsizei samples) \
+{ \
+ ALsizei i; \
+ for(i = 0;i < samples;i++) \
+ dst[i] += Sample_##T(src[i*srcstep]); \
+}
+
+DECL_TEMPLATE(ALubyte)
+DECL_TEMPLATE(ALshort)
+DECL_TEMPLATE(ALfloat)
+DECL_TEMPLATE(ALdouble)
+DECL_TEMPLATE(ALmulaw)
+DECL_TEMPLATE(ALalaw)
+
+#undef DECL_TEMPLATE
+
+static void LoadSamples(ALfloat *restrict dst, const ALvoid *restrict src, ALint srcstep,
+ enum FmtType srctype, ALsizei samples)
+{
+#define HANDLE_FMT(ET, ST) case ET: Load_##ST(dst, src, srcstep, samples); break
+ switch(srctype)
+ {
+ HANDLE_FMT(FmtUByte, ALubyte);
+ HANDLE_FMT(FmtShort, ALshort);
+ HANDLE_FMT(FmtFloat, ALfloat);
+ HANDLE_FMT(FmtDouble, ALdouble);
+ HANDLE_FMT(FmtMulaw, ALmulaw);
+ HANDLE_FMT(FmtAlaw, ALalaw);
+ }
+#undef HANDLE_FMT
+}
+
+
+static const ALfloat *DoFilters(BiquadFilter *lpfilter, BiquadFilter *hpfilter,
+ ALfloat *restrict dst, const ALfloat *restrict src,
+ ALsizei numsamples, enum ActiveFilters type)
+{
+ ALsizei i;
+ switch(type)
+ {
+ case AF_None:
+ BiquadFilter_passthru(lpfilter, numsamples);
+ BiquadFilter_passthru(hpfilter, numsamples);
+ break;
+
+ case AF_LowPass:
+ BiquadFilter_process(lpfilter, dst, src, numsamples);
+ BiquadFilter_passthru(hpfilter, numsamples);
+ return dst;
+ case AF_HighPass:
+ BiquadFilter_passthru(lpfilter, numsamples);
+ BiquadFilter_process(hpfilter, dst, src, numsamples);
+ return dst;
+
+ case AF_BandPass:
+ for(i = 0;i < numsamples;)
+ {
+ ALfloat temp[256];
+ ALsizei todo = mini(256, numsamples-i);
+
+ BiquadFilter_process(lpfilter, temp, src+i, todo);
+ BiquadFilter_process(hpfilter, dst+i, temp, todo);
+ i += todo;
+ }
+ return dst;
+ }
+ return src;
+}
+
+
+/* This function uses these device temp buffers. */
+#define SOURCE_DATA_BUF 0
+#define RESAMPLED_BUF 1
+#define FILTERED_BUF 2
+#define NFC_DATA_BUF 3
+ALboolean MixSource(ALvoice *voice, ALuint SourceID, ALCcontext *Context, ALsizei SamplesToDo)
+{
+ ALCdevice *Device = Context->Device;
+ ALbufferlistitem *BufferListItem;
+ ALbufferlistitem *BufferLoopItem;
+ ALsizei NumChannels, SampleSize;
+ ALbitfieldSOFT enabledevt;
+ ALsizei buffers_done = 0;
+ ResamplerFunc Resample;
+ ALsizei DataPosInt;
+ ALsizei DataPosFrac;
+ ALint64 DataSize64;
+ ALint increment;
+ ALsizei Counter;
+ ALsizei OutPos;
+ ALsizei IrSize;
+ bool isplaying;
+ bool firstpass;
+ bool isstatic;
+ ALsizei chan;
+ ALsizei send;
+
+ /* Get source info */
+ isplaying = true; /* Will only be called while playing. */
+ isstatic = !!(voice->Flags&VOICE_IS_STATIC);
+ DataPosInt = ATOMIC_LOAD(&voice->position, almemory_order_acquire);
+ DataPosFrac = ATOMIC_LOAD(&voice->position_fraction, almemory_order_relaxed);
+ BufferListItem = ATOMIC_LOAD(&voice->current_buffer, almemory_order_relaxed);
+ BufferLoopItem = ATOMIC_LOAD(&voice->loop_buffer, almemory_order_relaxed);
+ NumChannels = voice->NumChannels;
+ SampleSize = voice->SampleSize;
+ increment = voice->Step;
+
+ IrSize = (Device->HrtfHandle ? Device->HrtfHandle->irSize : 0);
+
+ Resample = ((increment == FRACTIONONE && DataPosFrac == 0) ?
+ Resample_copy_C : voice->Resampler);
+
+ Counter = (voice->Flags&VOICE_IS_FADING) ? SamplesToDo : 0;
+ firstpass = true;
+ OutPos = 0;
+
+ do {
+ ALsizei SrcBufferSize, DstBufferSize;
+
+ /* Figure out how many buffer samples will be needed */
+ DataSize64 = SamplesToDo-OutPos;
+ DataSize64 *= increment;
+ DataSize64 += DataPosFrac+FRACTIONMASK;
+ DataSize64 >>= FRACTIONBITS;
+ DataSize64 += MAX_RESAMPLE_PADDING*2;
+ SrcBufferSize = (ALsizei)mini64(DataSize64, BUFFERSIZE);
+
+ /* Figure out how many samples we can actually mix from this. */
+ DataSize64 = SrcBufferSize;
+ DataSize64 -= MAX_RESAMPLE_PADDING*2;
+ DataSize64 <<= FRACTIONBITS;
+ DataSize64 -= DataPosFrac;
+ DstBufferSize = (ALsizei)mini64((DataSize64+(increment-1)) / increment,
+ SamplesToDo - OutPos);
+
+ /* Some mixers like having a multiple of 4, so try to give that unless
+ * this is the last update. */
+ if(DstBufferSize < SamplesToDo-OutPos)
+ DstBufferSize &= ~3;
+
+ /* It's impossible to have a buffer list item with no entries. */
+ assert(BufferListItem->num_buffers > 0);
+
+ for(chan = 0;chan < NumChannels;chan++)
+ {
+ const ALfloat *ResampledData;
+ ALfloat *SrcData = Device->TempBuffer[SOURCE_DATA_BUF];
+ ALsizei FilledAmt;
+
+ /* Load the previous samples into the source data first, and clear the rest. */
+ memcpy(SrcData, voice->PrevSamples[chan], MAX_RESAMPLE_PADDING*sizeof(ALfloat));
+ memset(SrcData+MAX_RESAMPLE_PADDING, 0, (BUFFERSIZE-MAX_RESAMPLE_PADDING)*
+ sizeof(ALfloat));
+ FilledAmt = MAX_RESAMPLE_PADDING;
+
+ if(isstatic)
+ {
+ /* TODO: For static sources, loop points are taken from the
+ * first buffer (should be adjusted by any buffer offset, to
+ * possibly be added later).
+ */
+ const ALbuffer *Buffer0 = BufferListItem->buffers[0];
+ const ALsizei LoopStart = Buffer0->LoopStart;
+ const ALsizei LoopEnd = Buffer0->LoopEnd;
+ const ALsizei LoopSize = LoopEnd - LoopStart;
+
+ /* If current pos is beyond the loop range, do not loop */
+ if(!BufferLoopItem || DataPosInt >= LoopEnd)
+ {
+ ALsizei SizeToDo = SrcBufferSize - FilledAmt;
+ ALsizei CompLen = 0;
+ ALsizei i;
+
+ BufferLoopItem = NULL;
+
+ for(i = 0;i < BufferListItem->num_buffers;i++)
+ {
+ const ALbuffer *buffer = BufferListItem->buffers[i];
+ const ALubyte *Data = buffer->data;
+ ALsizei DataSize;
+
+ if(DataPosInt >= buffer->SampleLen)
+ continue;
+
+ /* Load what's left to play from the buffer */
+ DataSize = mini(SizeToDo, buffer->SampleLen - DataPosInt);
+ CompLen = maxi(CompLen, DataSize);
+
+ LoadSamples(&SrcData[FilledAmt],
+ &Data[(DataPosInt*NumChannels + chan)*SampleSize],
+ NumChannels, buffer->FmtType, DataSize
+ );
+ }
+ FilledAmt += CompLen;
+ }
+ else
+ {
+ ALsizei SizeToDo = mini(SrcBufferSize - FilledAmt, LoopEnd - DataPosInt);
+ ALsizei CompLen = 0;
+ ALsizei i;
+
+ for(i = 0;i < BufferListItem->num_buffers;i++)
+ {
+ const ALbuffer *buffer = BufferListItem->buffers[i];
+ const ALubyte *Data = buffer->data;
+ ALsizei DataSize;
+
+ if(DataPosInt >= buffer->SampleLen)
+ continue;
+
+ /* Load what's left of this loop iteration */
+ DataSize = mini(SizeToDo, buffer->SampleLen - DataPosInt);
+ CompLen = maxi(CompLen, DataSize);
+
+ LoadSamples(&SrcData[FilledAmt],
+ &Data[(DataPosInt*NumChannels + chan)*SampleSize],
+ NumChannels, buffer->FmtType, DataSize
+ );
+ }
+ FilledAmt += CompLen;
+
+ while(SrcBufferSize > FilledAmt)
+ {
+ const ALsizei SizeToDo = mini(SrcBufferSize - FilledAmt, LoopSize);
+
+ CompLen = 0;
+ for(i = 0;i < BufferListItem->num_buffers;i++)
+ {
+ const ALbuffer *buffer = BufferListItem->buffers[i];
+ const ALubyte *Data = buffer->data;
+ ALsizei DataSize;
+
+ if(LoopStart >= buffer->SampleLen)
+ continue;
+
+ DataSize = mini(SizeToDo, buffer->SampleLen - LoopStart);
+ CompLen = maxi(CompLen, DataSize);
+
+ LoadSamples(&SrcData[FilledAmt],
+ &Data[(LoopStart*NumChannels + chan)*SampleSize],
+ NumChannels, buffer->FmtType, DataSize
+ );
+ }
+ FilledAmt += CompLen;
+ }
+ }
+ }
+ else
+ {
+ /* Crawl the buffer queue to fill in the temp buffer */
+ ALbufferlistitem *tmpiter = BufferListItem;
+ ALsizei pos = DataPosInt;
+
+ while(tmpiter && SrcBufferSize > FilledAmt)
+ {
+ ALsizei SizeToDo = SrcBufferSize - FilledAmt;
+ ALsizei CompLen = 0;
+ ALsizei i;
+
+ for(i = 0;i < tmpiter->num_buffers;i++)
+ {
+ const ALbuffer *ALBuffer = tmpiter->buffers[i];
+ ALsizei DataSize = ALBuffer ? ALBuffer->SampleLen : 0;
+
+ if(DataSize > pos)
+ {
+ const ALubyte *Data = ALBuffer->data;
+ Data += (pos*NumChannels + chan)*SampleSize;
+
+ DataSize = mini(SizeToDo, DataSize - pos);
+ CompLen = maxi(CompLen, DataSize);
+
+ LoadSamples(&SrcData[FilledAmt], Data, NumChannels,
+ ALBuffer->FmtType, DataSize);
+ }
+ }
+ if(UNLIKELY(!CompLen))
+ pos -= tmpiter->max_samples;
+ else
+ {
+ FilledAmt += CompLen;
+ if(SrcBufferSize <= FilledAmt)
+ break;
+ pos = 0;
+ }
+ tmpiter = ATOMIC_LOAD(&tmpiter->next, almemory_order_acquire);
+ if(!tmpiter) tmpiter = BufferLoopItem;
+ }
+ }
+
+ /* Store the last source samples used for next time. */
+ memcpy(voice->PrevSamples[chan],
+ &SrcData[(increment*DstBufferSize + DataPosFrac)>>FRACTIONBITS],
+ MAX_RESAMPLE_PADDING*sizeof(ALfloat)
+ );
+
+ /* Now resample, then filter and mix to the appropriate outputs. */
+ ResampledData = Resample(&voice->ResampleState,
+ &SrcData[MAX_RESAMPLE_PADDING], DataPosFrac, increment,
+ Device->TempBuffer[RESAMPLED_BUF], DstBufferSize
+ );
+ {
+ DirectParams *parms = &voice->Direct.Params[chan];
+ const ALfloat *samples;
+
+ samples = DoFilters(
+ &parms->LowPass, &parms->HighPass, Device->TempBuffer[FILTERED_BUF],
+ ResampledData, DstBufferSize, voice->Direct.FilterType
+ );
+ if(!(voice->Flags&VOICE_HAS_HRTF))
+ {
+ if(!Counter)
+ memcpy(parms->Gains.Current, parms->Gains.Target,
+ sizeof(parms->Gains.Current));
+ if(!(voice->Flags&VOICE_HAS_NFC))
+ MixSamples(samples, voice->Direct.Channels, voice->Direct.Buffer,
+ parms->Gains.Current, parms->Gains.Target, Counter, OutPos,
+ DstBufferSize
+ );
+ else
+ {
+ ALfloat *nfcsamples = Device->TempBuffer[NFC_DATA_BUF];
+ ALsizei chanoffset = 0;
+
+ MixSamples(samples,
+ voice->Direct.ChannelsPerOrder[0], voice->Direct.Buffer,
+ parms->Gains.Current, parms->Gains.Target, Counter, OutPos,
+ DstBufferSize
+ );
+ chanoffset += voice->Direct.ChannelsPerOrder[0];
+#define APPLY_NFC_MIX(order) \
+ if(voice->Direct.ChannelsPerOrder[order] > 0) \
+ { \
+ NfcFilterProcess##order(&parms->NFCtrlFilter, nfcsamples, samples, \
+ DstBufferSize); \
+ MixSamples(nfcsamples, voice->Direct.ChannelsPerOrder[order], \
+ voice->Direct.Buffer+chanoffset, parms->Gains.Current+chanoffset, \
+ parms->Gains.Target+chanoffset, Counter, OutPos, DstBufferSize \
+ ); \
+ chanoffset += voice->Direct.ChannelsPerOrder[order]; \
+ }
+ APPLY_NFC_MIX(1)
+ APPLY_NFC_MIX(2)
+ APPLY_NFC_MIX(3)
+#undef APPLY_NFC_MIX
+ }
+ }
+ else
+ {
+ MixHrtfParams hrtfparams;
+ ALsizei fademix = 0;
+ int lidx, ridx;
+
+ lidx = GetChannelIdxByName(&Device->RealOut, FrontLeft);
+ ridx = GetChannelIdxByName(&Device->RealOut, FrontRight);
+ assert(lidx != -1 && ridx != -1);
+
+ if(!Counter)
+ {
+ /* No fading, just overwrite the old HRTF params. */
+ parms->Hrtf.Old = parms->Hrtf.Target;
+ }
+ else if(!(parms->Hrtf.Old.Gain > GAIN_SILENCE_THRESHOLD))
+ {
+ /* The old HRTF params are silent, so overwrite the old
+ * coefficients with the new, and reset the old gain to
+ * 0. The future mix will then fade from silence.
+ */
+ parms->Hrtf.Old = parms->Hrtf.Target;
+ parms->Hrtf.Old.Gain = 0.0f;
+ }
+ else if(firstpass)
+ {
+ ALfloat gain;
+
+ /* Fade between the coefficients over 128 samples. */
+ fademix = mini(DstBufferSize, 128);
+
+ /* The new coefficients need to fade in completely
+ * since they're replacing the old ones. To keep the
+ * gain fading consistent, interpolate between the old
+ * and new target gains given how much of the fade time
+ * this mix handles.
+ */
+ gain = lerp(parms->Hrtf.Old.Gain, parms->Hrtf.Target.Gain,
+ minf(1.0f, (ALfloat)fademix/Counter));
+ hrtfparams.Coeffs = parms->Hrtf.Target.Coeffs;
+ hrtfparams.Delay[0] = parms->Hrtf.Target.Delay[0];
+ hrtfparams.Delay[1] = parms->Hrtf.Target.Delay[1];
+ hrtfparams.Gain = 0.0f;
+ hrtfparams.GainStep = gain / (ALfloat)fademix;
+
+ MixHrtfBlendSamples(
+ voice->Direct.Buffer[lidx], voice->Direct.Buffer[ridx],
+ samples, voice->Offset, OutPos, IrSize, &parms->Hrtf.Old,
+ &hrtfparams, &parms->Hrtf.State, fademix
+ );
+ /* Update the old parameters with the result. */
+ parms->Hrtf.Old = parms->Hrtf.Target;
+ if(fademix < Counter)
+ parms->Hrtf.Old.Gain = hrtfparams.Gain;
+ }
+
+ if(fademix < DstBufferSize)
+ {
+ ALsizei todo = DstBufferSize - fademix;
+ ALfloat gain = parms->Hrtf.Target.Gain;
+
+ /* Interpolate the target gain if the gain fading lasts
+ * longer than this mix.
+ */
+ if(Counter > DstBufferSize)
+ gain = lerp(parms->Hrtf.Old.Gain, gain,
+ (ALfloat)todo/(Counter-fademix));
+
+ hrtfparams.Coeffs = parms->Hrtf.Target.Coeffs;
+ hrtfparams.Delay[0] = parms->Hrtf.Target.Delay[0];
+ hrtfparams.Delay[1] = parms->Hrtf.Target.Delay[1];
+ hrtfparams.Gain = parms->Hrtf.Old.Gain;
+ hrtfparams.GainStep = (gain - parms->Hrtf.Old.Gain) / (ALfloat)todo;
+ MixHrtfSamples(
+ voice->Direct.Buffer[lidx], voice->Direct.Buffer[ridx],
+ samples+fademix, voice->Offset+fademix, OutPos+fademix, IrSize,
+ &hrtfparams, &parms->Hrtf.State, todo
+ );
+ /* Store the interpolated gain or the final target gain
+ * depending if the fade is done.
+ */
+ if(DstBufferSize < Counter)
+ parms->Hrtf.Old.Gain = gain;
+ else
+ parms->Hrtf.Old.Gain = parms->Hrtf.Target.Gain;
+ }
+ }
+ }
+
+ for(send = 0;send < Device->NumAuxSends;send++)
+ {
+ SendParams *parms = &voice->Send[send].Params[chan];
+ const ALfloat *samples;
+
+ if(!voice->Send[send].Buffer)
+ continue;
+
+ samples = DoFilters(
+ &parms->LowPass, &parms->HighPass, Device->TempBuffer[FILTERED_BUF],
+ ResampledData, DstBufferSize, voice->Send[send].FilterType
+ );
+
+ if(!Counter)
+ memcpy(parms->Gains.Current, parms->Gains.Target,
+ sizeof(parms->Gains.Current));
+ MixSamples(samples, voice->Send[send].Channels, voice->Send[send].Buffer,
+ parms->Gains.Current, parms->Gains.Target, Counter, OutPos, DstBufferSize
+ );
+ }
+ }
+ /* Update positions */
+ DataPosFrac += increment*DstBufferSize;
+ DataPosInt += DataPosFrac>>FRACTIONBITS;
+ DataPosFrac &= FRACTIONMASK;
+
+ OutPos += DstBufferSize;
+ voice->Offset += DstBufferSize;
+ Counter = maxi(DstBufferSize, Counter) - DstBufferSize;
+ firstpass = false;
+
+ if(isstatic)
+ {
+ if(BufferLoopItem)
+ {
+ /* Handle looping static source */
+ const ALbuffer *Buffer = BufferListItem->buffers[0];
+ ALsizei LoopStart = Buffer->LoopStart;
+ ALsizei LoopEnd = Buffer->LoopEnd;
+ if(DataPosInt >= LoopEnd)
+ {
+ assert(LoopEnd > LoopStart);
+ DataPosInt = ((DataPosInt-LoopStart)%(LoopEnd-LoopStart)) + LoopStart;
+ }
+ }
+ else
+ {
+ /* Handle non-looping static source */
+ if(DataPosInt >= BufferListItem->max_samples)
+ {
+ isplaying = false;
+ BufferListItem = NULL;
+ DataPosInt = 0;
+ DataPosFrac = 0;
+ break;
+ }
+ }
+ }
+ else while(1)
+ {
+ /* Handle streaming source */
+ if(BufferListItem->max_samples > DataPosInt)
+ break;
+
+ DataPosInt -= BufferListItem->max_samples;
+
+ buffers_done += BufferListItem->num_buffers;
+ BufferListItem = ATOMIC_LOAD(&BufferListItem->next, almemory_order_relaxed);
+ if(!BufferListItem && !(BufferListItem=BufferLoopItem))
+ {
+ isplaying = false;
+ DataPosInt = 0;
+ DataPosFrac = 0;
+ break;
+ }
+ }
+ } while(isplaying && OutPos < SamplesToDo);
+
+ voice->Flags |= VOICE_IS_FADING;
+
+ /* Update source info */
+ ATOMIC_STORE(&voice->position, DataPosInt, almemory_order_relaxed);
+ ATOMIC_STORE(&voice->position_fraction, DataPosFrac, almemory_order_relaxed);
+ ATOMIC_STORE(&voice->current_buffer, BufferListItem, almemory_order_release);
+
+ /* Send any events now, after the position/buffer info was updated. */
+ enabledevt = ATOMIC_LOAD(&Context->EnabledEvts, almemory_order_acquire);
+ if(buffers_done > 0 && (enabledevt&EventType_BufferCompleted))
+ SendAsyncEvent(Context, EventType_BufferCompleted,
+ AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT, SourceID, buffers_done, "Buffer completed"
+ );
+
+ return isplaying;
+}
diff --git a/Alc/panning.c b/Alc/panning.c
index 6305bff7..2c0f3bf2 100644
--- a/Alc/panning.c
+++ b/Alc/panning.c
@@ -27,19 +27,24 @@
#include <assert.h>
#include "alMain.h"
-#include "AL/al.h"
-#include "AL/alc.h"
+#include "alAuxEffectSlot.h"
#include "alu.h"
+#include "alconfig.h"
#include "bool.h"
+#include "ambdec.h"
+#include "bformatdec.h"
+#include "filters/splitter.h"
+#include "uhjfilter.h"
+#include "bs2b.h"
-#define ZERO_ORDER_SCALE 0.0f
-#define FIRST_ORDER_SCALE 1.0f
-#define SECOND_ORDER_SCALE (1.0f / 1.22474f)
-#define THIRD_ORDER_SCALE (1.0f / 1.30657f)
+extern inline void CalcDirectionCoeffs(const ALfloat dir[3], ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS]);
+extern inline void CalcAngleCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS]);
+extern inline float ScaleAzimuthFront(float azimuth, float scale);
+extern inline void ComputePanGains(const MixParams *dry, const ALfloat*restrict coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
-static const ALuint FuMa2ACN[MAX_AMBI_COEFFS] = {
+static const ALsizei FuMa2ACN[MAX_AMBI_COEFFS] = {
0, /* W */
3, /* X */
1, /* Y */
@@ -57,71 +62,21 @@ static const ALuint FuMa2ACN[MAX_AMBI_COEFFS] = {
15, /* P */
9, /* Q */
};
-
-/* NOTE: These are scale factors as applied to Ambisonics content. FuMa
- * decoder coefficients should be divided by these values to get N3D decoder
- * coefficients.
- */
-static const ALfloat FuMa2N3DScale[MAX_AMBI_COEFFS] = {
- 1.414213562f, /* ACN 0 (W), sqrt(2) */
- 1.732050808f, /* ACN 1 (Y), sqrt(3) */
- 1.732050808f, /* ACN 2 (Z), sqrt(3) */
- 1.732050808f, /* ACN 3 (X), sqrt(3) */
- 1.936491673f, /* ACN 4 (V), sqrt(15)/2 */
- 1.936491673f, /* ACN 5 (T), sqrt(15)/2 */
- 2.236067978f, /* ACN 6 (R), sqrt(5) */
- 1.936491673f, /* ACN 7 (S), sqrt(15)/2 */
- 1.936491673f, /* ACN 8 (U), sqrt(15)/2 */
- 2.091650066f, /* ACN 9 (Q), sqrt(35/8) */
- 1.972026594f, /* ACN 10 (O), sqrt(35)/3 */
- 2.231093404f, /* ACN 11 (M), sqrt(224/45) */
- 2.645751311f, /* ACN 12 (K), sqrt(7) */
- 2.231093404f, /* ACN 13 (L), sqrt(224/45) */
- 1.972026594f, /* ACN 14 (N), sqrt(35)/3 */
- 2.091650066f, /* ACN 15 (P), sqrt(35/8) */
+static const ALsizei ACN2ACN[MAX_AMBI_COEFFS] = {
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15
};
-void ComputeAmbientGains(const ALCdevice *device, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
-{
- ALuint i;
-
- for(i = 0;i < device->NumChannels;i++)
- {
- // The W coefficients are based on a mathematical average of the
- // output. The square root of the base average provides for a more
- // perceptual average volume, better suited to non-directional gains.
- gains[i] = sqrtf(device->AmbiCoeffs[i][0]) * ingain;
- }
- for(;i < MAX_OUTPUT_CHANNELS;i++)
- gains[i] = 0.0f;
-}
-
-void ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat elevation, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
+void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALfloat spread,
+ ALfloat coeffs[MAX_AMBI_COEFFS])
{
- ALfloat dir[3] = {
- sinf(angle) * cosf(elevation),
- sinf(elevation),
- -cosf(angle) * cosf(elevation)
- };
- ComputeDirectionalGains(device, dir, ingain, gains);
-}
-
-void ComputeDirectionalGains(const ALCdevice *device, const ALfloat dir[3], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
-{
- ALfloat coeffs[MAX_AMBI_COEFFS];
- ALuint i, j;
- /* Convert from OpenAL coords to Ambisonics. */
- ALfloat x = -dir[2];
- ALfloat y = -dir[0];
- ALfloat z = dir[1];
-
/* Zeroth-order */
coeffs[0] = 1.0f; /* ACN 0 = 1 */
/* First-order */
- coeffs[1] = 1.732050808f * y; /* ACN 1 = sqrt(3) * Y */
- coeffs[2] = 1.732050808f * z; /* ACN 2 = sqrt(3) * Z */
- coeffs[3] = 1.732050808f * x; /* ACN 3 = sqrt(3) * X */
+ coeffs[1] = SQRTF_3 * y; /* ACN 1 = sqrt(3) * Y */
+ coeffs[2] = SQRTF_3 * z; /* ACN 2 = sqrt(3) * Z */
+ coeffs[3] = SQRTF_3 * x; /* ACN 3 = sqrt(3) * X */
/* Second-order */
coeffs[4] = 3.872983346f * x * y; /* ACN 4 = sqrt(15) * X * Y */
coeffs[5] = 3.872983346f * y * z; /* ACN 5 = sqrt(15) * Y * Z */
@@ -137,34 +92,92 @@ void ComputeDirectionalGains(const ALCdevice *device, const ALfloat dir[3], ALfl
coeffs[14] = 5.123475383f * z * (x*x - y*y); /* ACN 14 = sqrt(105)/2 * Z * (X*X - Y*Y) */
coeffs[15] = 2.091650066f * x * (x*x - 3.0f*y*y); /* ACN 15 = sqrt(35/8) * X * (X*X - 3*Y*Y) */
- for(i = 0;i < device->NumChannels;i++)
+ if(spread > 0.0f)
{
- float gain = 0.0f;
- for(j = 0;j < MAX_AMBI_COEFFS;j++)
- gain += device->AmbiCoeffs[i][j]*coeffs[j];
- gains[i] = gain * ingain;
+ /* Implement the spread by using a spherical source that subtends the
+ * angle spread. See:
+ * http://www.ppsloan.org/publications/StupidSH36.pdf - Appendix A3
+ *
+ * When adjusted for N3D normalization instead of SN3D, these
+ * calculations are:
+ *
+ * ZH0 = -sqrt(pi) * (-1+ca);
+ * ZH1 = 0.5*sqrt(pi) * sa*sa;
+ * ZH2 = -0.5*sqrt(pi) * ca*(-1+ca)*(ca+1);
+ * ZH3 = -0.125*sqrt(pi) * (-1+ca)*(ca+1)*(5*ca*ca - 1);
+ * ZH4 = -0.125*sqrt(pi) * ca*(-1+ca)*(ca+1)*(7*ca*ca - 3);
+ * ZH5 = -0.0625*sqrt(pi) * (-1+ca)*(ca+1)*(21*ca*ca*ca*ca - 14*ca*ca + 1);
+ *
+ * The gain of the source is compensated for size, so that the
+ * loundness doesn't depend on the spread. Thus:
+ *
+ * ZH0 = 1.0f;
+ * ZH1 = 0.5f * (ca+1.0f);
+ * ZH2 = 0.5f * (ca+1.0f)*ca;
+ * ZH3 = 0.125f * (ca+1.0f)*(5.0f*ca*ca - 1.0f);
+ * ZH4 = 0.125f * (ca+1.0f)*(7.0f*ca*ca - 3.0f)*ca;
+ * ZH5 = 0.0625f * (ca+1.0f)*(21.0f*ca*ca*ca*ca - 14.0f*ca*ca + 1.0f);
+ */
+ ALfloat ca = cosf(spread * 0.5f);
+ /* Increase the source volume by up to +3dB for a full spread. */
+ ALfloat scale = sqrtf(1.0f + spread/F_TAU);
+
+ ALfloat ZH0_norm = scale;
+ ALfloat ZH1_norm = 0.5f * (ca+1.f) * scale;
+ ALfloat ZH2_norm = 0.5f * (ca+1.f)*ca * scale;
+ ALfloat ZH3_norm = 0.125f * (ca+1.f)*(5.f*ca*ca-1.f) * scale;
+
+ /* Zeroth-order */
+ coeffs[0] *= ZH0_norm;
+ /* First-order */
+ coeffs[1] *= ZH1_norm;
+ coeffs[2] *= ZH1_norm;
+ coeffs[3] *= ZH1_norm;
+ /* Second-order */
+ coeffs[4] *= ZH2_norm;
+ coeffs[5] *= ZH2_norm;
+ coeffs[6] *= ZH2_norm;
+ coeffs[7] *= ZH2_norm;
+ coeffs[8] *= ZH2_norm;
+ /* Third-order */
+ coeffs[9] *= ZH3_norm;
+ coeffs[10] *= ZH3_norm;
+ coeffs[11] *= ZH3_norm;
+ coeffs[12] *= ZH3_norm;
+ coeffs[13] *= ZH3_norm;
+ coeffs[14] *= ZH3_norm;
+ coeffs[15] *= ZH3_norm;
}
- for(;i < MAX_OUTPUT_CHANNELS;i++)
- gains[i] = 0.0f;
}
-void ComputeBFormatGains(const ALCdevice *device, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
+
+void ComputePanningGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, ALsizei numcoeffs, const ALfloat*restrict coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
{
- ALuint i, j;
+ ALsizei i, j;
- for(i = 0;i < device->NumChannels;i++)
+ for(i = 0;i < numchans;i++)
{
float gain = 0.0f;
- for(j = 0;j < 4;j++)
- gain += device->AmbiCoeffs[i][j] * mtx[j];
- gains[i] = gain * ingain;
+ for(j = 0;j < numcoeffs;j++)
+ gain += chancoeffs[i][j]*coeffs[j];
+ gains[i] = clampf(gain, 0.0f, 1.0f) * ingain;
}
for(;i < MAX_OUTPUT_CHANNELS;i++)
gains[i] = 0.0f;
}
+void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, const ALfloat*restrict coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
+{
+ ALsizei i;
+
+ for(i = 0;i < numchans;i++)
+ gains[i] = chanmap[i].Scale * coeffs[chanmap[i].Index] * ingain;
+ for(;i < MAX_OUTPUT_CHANNELS;i++)
+ gains[i] = 0.0f;
+}
+
-DECL_CONST static inline const char *GetLabelFromChannel(enum Channel channel)
+static inline const char *GetLabelFromChannel(enum Channel channel)
{
switch(channel)
{
@@ -178,10 +191,31 @@ DECL_CONST static inline const char *GetLabelFromChannel(enum Channel channel)
case SideLeft: return "side-left";
case SideRight: return "side-right";
- case BFormatW: return "bformat-w";
- case BFormatX: return "bformat-x";
- case BFormatY: return "bformat-y";
- case BFormatZ: return "bformat-z";
+ case UpperFrontLeft: return "upper-front-left";
+ case UpperFrontRight: return "upper-front-right";
+ case UpperBackLeft: return "upper-back-left";
+ case UpperBackRight: return "upper-back-right";
+ case LowerFrontLeft: return "lower-front-left";
+ case LowerFrontRight: return "lower-front-right";
+ case LowerBackLeft: return "lower-back-left";
+ case LowerBackRight: return "lower-back-right";
+
+ case Aux0: return "aux-0";
+ case Aux1: return "aux-1";
+ case Aux2: return "aux-2";
+ case Aux3: return "aux-3";
+ case Aux4: return "aux-4";
+ case Aux5: return "aux-5";
+ case Aux6: return "aux-6";
+ case Aux7: return "aux-7";
+ case Aux8: return "aux-8";
+ case Aux9: return "aux-9";
+ case Aux10: return "aux-10";
+ case Aux11: return "aux-11";
+ case Aux12: return "aux-12";
+ case Aux13: return "aux-13";
+ case Aux14: return "aux-14";
+ case Aux15: return "aux-15";
case InvalidChannel: break;
}
@@ -194,364 +228,1012 @@ typedef struct ChannelMap {
ChannelConfig Config;
} ChannelMap;
-static void SetChannelMap(ALCdevice *device, const ChannelMap *chanmap, size_t count, ALfloat ambiscale, ALboolean isfuma)
+static void SetChannelMap(const enum Channel devchans[MAX_OUTPUT_CHANNELS],
+ ChannelConfig *ambicoeffs, const ChannelMap *chanmap,
+ ALsizei count, ALsizei *outcount)
{
- size_t j, k;
- ALuint i;
+ ALsizei maxchans = 0;
+ ALsizei i, j;
- device->AmbiScale = ambiscale;
- for(i = 0;i < MAX_OUTPUT_CHANNELS && device->ChannelName[i] != InvalidChannel;i++)
+ for(i = 0;i < count;i++)
{
- if(device->ChannelName[i] == LFE)
+ ALint idx = GetChannelIndex(devchans, chanmap[i].ChanName);
+ if(idx < 0)
{
- for(j = 0;j < MAX_AMBI_COEFFS;j++)
- device->AmbiCoeffs[i][j] = 0.0f;
+ ERR("Failed to find %s channel in device\n",
+ GetLabelFromChannel(chanmap[i].ChanName));
continue;
}
- for(j = 0;j < count;j++)
+ maxchans = maxi(maxchans, idx+1);
+ for(j = 0;j < MAX_AMBI_COEFFS;j++)
+ ambicoeffs[idx][j] = chanmap[i].Config[j];
+ }
+ *outcount = mini(maxchans, MAX_OUTPUT_CHANNELS);
+}
+
+static bool MakeSpeakerMap(ALCdevice *device, const AmbDecConf *conf, ALsizei speakermap[MAX_OUTPUT_CHANNELS])
+{
+ ALsizei i;
+
+ for(i = 0;i < conf->NumSpeakers;i++)
+ {
+ enum Channel ch;
+ int chidx = -1;
+
+ /* NOTE: AmbDec does not define any standard speaker names, however
+ * for this to work we have to by able to find the output channel
+ * the speaker definition corresponds to. Therefore, OpenAL Soft
+ * requires these channel labels to be recognized:
+ *
+ * LF = Front left
+ * RF = Front right
+ * LS = Side left
+ * RS = Side right
+ * LB = Back left
+ * RB = Back right
+ * CE = Front center
+ * CB = Back center
+ *
+ * Additionally, surround51 will acknowledge back speakers for side
+ * channels, and surround51rear will acknowledge side speakers for
+ * back channels, to avoid issues with an ambdec expecting 5.1 to
+ * use the side channels when the device is configured for back,
+ * and vice-versa.
+ */
+ if(alstr_cmp_cstr(conf->Speakers[i].Name, "LF") == 0)
+ ch = FrontLeft;
+ else if(alstr_cmp_cstr(conf->Speakers[i].Name, "RF") == 0)
+ ch = FrontRight;
+ else if(alstr_cmp_cstr(conf->Speakers[i].Name, "CE") == 0)
+ ch = FrontCenter;
+ else if(alstr_cmp_cstr(conf->Speakers[i].Name, "LS") == 0)
+ {
+ if(device->FmtChans == DevFmtX51Rear)
+ ch = BackLeft;
+ else
+ ch = SideLeft;
+ }
+ else if(alstr_cmp_cstr(conf->Speakers[i].Name, "RS") == 0)
+ {
+ if(device->FmtChans == DevFmtX51Rear)
+ ch = BackRight;
+ else
+ ch = SideRight;
+ }
+ else if(alstr_cmp_cstr(conf->Speakers[i].Name, "LB") == 0)
+ {
+ if(device->FmtChans == DevFmtX51)
+ ch = SideLeft;
+ else
+ ch = BackLeft;
+ }
+ else if(alstr_cmp_cstr(conf->Speakers[i].Name, "RB") == 0)
+ {
+ if(device->FmtChans == DevFmtX51)
+ ch = SideRight;
+ else
+ ch = BackRight;
+ }
+ else if(alstr_cmp_cstr(conf->Speakers[i].Name, "CB") == 0)
+ ch = BackCenter;
+ else
{
- if(device->ChannelName[i] == chanmap[j].ChanName)
+ const char *name = alstr_get_cstr(conf->Speakers[i].Name);
+ unsigned int n;
+ char c;
+
+ if(sscanf(name, "AUX%u%c", &n, &c) == 1 && n < 16)
+ ch = Aux0+n;
+ else
{
- if(isfuma)
- {
- /* Reformat FuMa -> ACN/N3D */
- for(k = 0;k < MAX_AMBI_COEFFS;++k)
- {
- ALuint acn = FuMa2ACN[k];
- device->AmbiCoeffs[i][acn] = chanmap[j].Config[k] / FuMa2N3DScale[acn];
- }
- }
- else
- {
- for(k = 0;k < MAX_AMBI_COEFFS;++k)
- device->AmbiCoeffs[i][k] = chanmap[j].Config[k];
- }
- break;
+ ERR("AmbDec speaker label \"%s\" not recognized\n", name);
+ return false;
}
}
- if(j == count)
- ERR("Failed to match %s channel (%u) in config\n", GetLabelFromChannel(device->ChannelName[i]), i);
+ chidx = GetChannelIdxByName(&device->RealOut, ch);
+ if(chidx == -1)
+ {
+ ERR("Failed to lookup AmbDec speaker label %s\n",
+ alstr_get_cstr(conf->Speakers[i].Name));
+ return false;
+ }
+ speakermap[i] = chidx;
}
- device->NumChannels = i;
+
+ return true;
}
-static bool LoadChannelSetup(ALCdevice *device)
+
+static const ChannelMap MonoCfg[1] = {
+ { FrontCenter, { 1.0f } },
+}, StereoCfg[2] = {
+ { FrontLeft, { 5.00000000e-1f, 2.88675135e-1f, 0.0f, 5.52305643e-2f } },
+ { FrontRight, { 5.00000000e-1f, -2.88675135e-1f, 0.0f, 5.52305643e-2f } },
+}, QuadCfg[4] = {
+ { BackLeft, { 3.53553391e-1f, 2.04124145e-1f, 0.0f, -2.04124145e-1f } },
+ { FrontLeft, { 3.53553391e-1f, 2.04124145e-1f, 0.0f, 2.04124145e-1f } },
+ { FrontRight, { 3.53553391e-1f, -2.04124145e-1f, 0.0f, 2.04124145e-1f } },
+ { BackRight, { 3.53553391e-1f, -2.04124145e-1f, 0.0f, -2.04124145e-1f } },
+}, X51SideCfg[4] = {
+ { SideLeft, { 3.33000782e-1f, 1.89084803e-1f, 0.0f, -2.00042375e-1f, -2.12307769e-2f, 0.0f, 0.0f, 0.0f, -1.14579885e-2f } },
+ { FrontLeft, { 1.88542860e-1f, 1.27709292e-1f, 0.0f, 1.66295695e-1f, 7.30571517e-2f, 0.0f, 0.0f, 0.0f, 2.10901184e-2f } },
+ { FrontRight, { 1.88542860e-1f, -1.27709292e-1f, 0.0f, 1.66295695e-1f, -7.30571517e-2f, 0.0f, 0.0f, 0.0f, 2.10901184e-2f } },
+ { SideRight, { 3.33000782e-1f, -1.89084803e-1f, 0.0f, -2.00042375e-1f, 2.12307769e-2f, 0.0f, 0.0f, 0.0f, -1.14579885e-2f } },
+}, X51RearCfg[4] = {
+ { BackLeft, { 3.33000782e-1f, 1.89084803e-1f, 0.0f, -2.00042375e-1f, -2.12307769e-2f, 0.0f, 0.0f, 0.0f, -1.14579885e-2f } },
+ { FrontLeft, { 1.88542860e-1f, 1.27709292e-1f, 0.0f, 1.66295695e-1f, 7.30571517e-2f, 0.0f, 0.0f, 0.0f, 2.10901184e-2f } },
+ { FrontRight, { 1.88542860e-1f, -1.27709292e-1f, 0.0f, 1.66295695e-1f, -7.30571517e-2f, 0.0f, 0.0f, 0.0f, 2.10901184e-2f } },
+ { BackRight, { 3.33000782e-1f, -1.89084803e-1f, 0.0f, -2.00042375e-1f, 2.12307769e-2f, 0.0f, 0.0f, 0.0f, -1.14579885e-2f } },
+}, X61Cfg[6] = {
+ { SideLeft, { 2.04460341e-1f, 2.17177926e-1f, 0.0f, -4.39996780e-2f, -2.60790269e-2f, 0.0f, 0.0f, 0.0f, -6.87239792e-2f } },
+ { FrontLeft, { 1.58923161e-1f, 9.21772680e-2f, 0.0f, 1.59658796e-1f, 6.66278083e-2f, 0.0f, 0.0f, 0.0f, 3.84686854e-2f } },
+ { FrontRight, { 1.58923161e-1f, -9.21772680e-2f, 0.0f, 1.59658796e-1f, -6.66278083e-2f, 0.0f, 0.0f, 0.0f, 3.84686854e-2f } },
+ { SideRight, { 2.04460341e-1f, -2.17177926e-1f, 0.0f, -4.39996780e-2f, 2.60790269e-2f, 0.0f, 0.0f, 0.0f, -6.87239792e-2f } },
+ { BackCenter, { 2.50001688e-1f, 0.00000000e+0f, 0.0f, -2.50000094e-1f, 0.00000000e+0f, 0.0f, 0.0f, 0.0f, 6.05133395e-2f } },
+}, X71Cfg[6] = {
+ { BackLeft, { 2.04124145e-1f, 1.08880247e-1f, 0.0f, -1.88586120e-1f, -1.29099444e-1f, 0.0f, 0.0f, 0.0f, 7.45355993e-2f, 3.73460789e-2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.00000000e+0f } },
+ { SideLeft, { 2.04124145e-1f, 2.17760495e-1f, 0.0f, 0.00000000e+0f, 0.00000000e+0f, 0.0f, 0.0f, 0.0f, -1.49071198e-1f, -3.73460789e-2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.00000000e+0f } },
+ { FrontLeft, { 2.04124145e-1f, 1.08880247e-1f, 0.0f, 1.88586120e-1f, 1.29099444e-1f, 0.0f, 0.0f, 0.0f, 7.45355993e-2f, 3.73460789e-2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.00000000e+0f } },
+ { FrontRight, { 2.04124145e-1f, -1.08880247e-1f, 0.0f, 1.88586120e-1f, -1.29099444e-1f, 0.0f, 0.0f, 0.0f, 7.45355993e-2f, -3.73460789e-2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.00000000e+0f } },
+ { SideRight, { 2.04124145e-1f, -2.17760495e-1f, 0.0f, 0.00000000e+0f, 0.00000000e+0f, 0.0f, 0.0f, 0.0f, -1.49071198e-1f, 3.73460789e-2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.00000000e+0f } },
+ { BackRight, { 2.04124145e-1f, -1.08880247e-1f, 0.0f, -1.88586120e-1f, 1.29099444e-1f, 0.0f, 0.0f, 0.0f, 7.45355993e-2f, -3.73460789e-2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.00000000e+0f } },
+};
+
+static void InitNearFieldCtrl(ALCdevice *device, ALfloat ctrl_dist, ALsizei order,
+ const ALsizei *restrict chans_per_order)
{
- static const enum Channel mono_chans[1] = {
- FrontCenter
- }, stereo_chans[2] = {
- FrontLeft, FrontRight
- }, quad_chans[4] = {
- FrontLeft, FrontRight,
- BackLeft, BackRight
- }, surround51_chans[5] = {
- FrontLeft, FrontRight, FrontCenter,
- SideLeft, SideRight
- }, surround51rear_chans[5] = {
- FrontLeft, FrontRight, FrontCenter,
- BackLeft, BackRight
- }, surround61_chans[6] = {
- FrontLeft, FrontRight,
- FrontCenter, BackCenter,
- SideLeft, SideRight
- }, surround71_chans[7] = {
- FrontLeft, FrontRight, FrontCenter,
- BackLeft, BackRight,
- SideLeft, SideRight
- };
- ChannelMap chanmap[MAX_OUTPUT_CHANNELS];
- const enum Channel *channels = NULL;
- const char *layout = NULL;
- ALfloat ambiscale = 1.0f;
- size_t count = 0;
- int isfuma;
- int order;
- size_t i;
+ const char *devname = alstr_get_cstr(device->DeviceName);
+ ALsizei i;
+
+ if(GetConfigValueBool(devname, "decoder", "nfc", 1) && ctrl_dist > 0.0f)
+ {
+ /* NFC is only used when AvgSpeakerDist is greater than 0, and can only
+ * be used when rendering to an ambisonic buffer.
+ */
+ device->AvgSpeakerDist = minf(ctrl_dist, 10.0f);
+ TRACE("Using near-field reference distance: %.2f meters\n", device->AvgSpeakerDist);
+
+ for(i = 0;i < order+1;i++)
+ device->NumChannelsPerOrder[i] = chans_per_order[i];
+ for(;i < MAX_AMBI_ORDER+1;i++)
+ device->NumChannelsPerOrder[i] = 0;
+ }
+}
+
+static void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf, const ALsizei speakermap[MAX_OUTPUT_CHANNELS])
+{
+ const char *devname = alstr_get_cstr(device->DeviceName);
+ ALfloat maxdist = 0.0f;
+ size_t total = 0;
+ ALsizei i;
+
+ for(i = 0;i < conf->NumSpeakers;i++)
+ maxdist = maxf(maxdist, conf->Speakers[i].Distance);
+
+ if(GetConfigValueBool(devname, "decoder", "distance-comp", 1) && maxdist > 0.0f)
+ {
+ ALfloat srate = (ALfloat)device->Frequency;
+ for(i = 0;i < conf->NumSpeakers;i++)
+ {
+ ALsizei chan = speakermap[i];
+ ALfloat delay;
+
+ /* Distance compensation only delays in steps of the sample rate.
+ * This is a bit less accurate since the delay time falls to the
+ * nearest sample time, but it's far simpler as it doesn't have to
+ * deal with phase offsets. This means at 48khz, for instance, the
+ * distance delay will be in steps of about 7 millimeters.
+ */
+ delay = floorf((maxdist-conf->Speakers[i].Distance) / SPEEDOFSOUNDMETRESPERSEC *
+ srate + 0.5f);
+ if(delay >= (ALfloat)MAX_DELAY_LENGTH)
+ ERR("Delay for speaker \"%s\" exceeds buffer length (%f >= %u)\n",
+ alstr_get_cstr(conf->Speakers[i].Name), delay, MAX_DELAY_LENGTH);
+
+ device->ChannelDelay[chan].Length = (ALsizei)clampf(
+ delay, 0.0f, (ALfloat)(MAX_DELAY_LENGTH-1)
+ );
+ device->ChannelDelay[chan].Gain = conf->Speakers[i].Distance / maxdist;
+ TRACE("Channel %u \"%s\" distance compensation: %d samples, %f gain\n", chan,
+ alstr_get_cstr(conf->Speakers[i].Name), device->ChannelDelay[chan].Length,
+ device->ChannelDelay[chan].Gain
+ );
+
+ /* Round up to the next 4th sample, so each channel buffer starts
+ * 16-byte aligned.
+ */
+ total += RoundUp(device->ChannelDelay[chan].Length, 4);
+ }
+ }
+
+ if(total > 0)
+ {
+ device->ChannelDelay[0].Buffer = al_calloc(16, total * sizeof(ALfloat));
+ for(i = 1;i < MAX_OUTPUT_CHANNELS;i++)
+ {
+ size_t len = RoundUp(device->ChannelDelay[i-1].Length, 4);
+ device->ChannelDelay[i].Buffer = device->ChannelDelay[i-1].Buffer + len;
+ }
+ }
+}
+
+static void InitPanning(ALCdevice *device)
+{
+ const ChannelMap *chanmap = NULL;
+ ALsizei coeffcount = 0;
+ ALsizei count = 0;
+ ALsizei i, j;
switch(device->FmtChans)
{
case DevFmtMono:
- layout = "mono";
- channels = mono_chans;
- count = COUNTOF(mono_chans);
+ count = COUNTOF(MonoCfg);
+ chanmap = MonoCfg;
+ coeffcount = 1;
break;
+
case DevFmtStereo:
- layout = "stereo";
- channels = stereo_chans;
- count = COUNTOF(stereo_chans);
+ count = COUNTOF(StereoCfg);
+ chanmap = StereoCfg;
+ coeffcount = 4;
break;
+
case DevFmtQuad:
- layout = "quad";
- channels = quad_chans;
- count = COUNTOF(quad_chans);
+ count = COUNTOF(QuadCfg);
+ chanmap = QuadCfg;
+ coeffcount = 4;
break;
+
case DevFmtX51:
- layout = "surround51";
- channels = surround51_chans;
- count = COUNTOF(surround51_chans);
+ count = COUNTOF(X51SideCfg);
+ chanmap = X51SideCfg;
+ coeffcount = 9;
break;
+
case DevFmtX51Rear:
- layout = "surround51rear";
- channels = surround51rear_chans;
- count = COUNTOF(surround51rear_chans);
+ count = COUNTOF(X51RearCfg);
+ chanmap = X51RearCfg;
+ coeffcount = 9;
break;
+
case DevFmtX61:
- layout = "surround61";
- channels = surround61_chans;
- count = COUNTOF(surround61_chans);
+ count = COUNTOF(X61Cfg);
+ chanmap = X61Cfg;
+ coeffcount = 9;
break;
+
case DevFmtX71:
- layout = "surround71";
- channels = surround71_chans;
- count = COUNTOF(surround71_chans);
+ count = COUNTOF(X71Cfg);
+ chanmap = X71Cfg;
+ coeffcount = 16;
break;
- case DevFmtBFormat3D:
+
+ case DevFmtAmbi3D:
break;
}
- if(!layout)
- return false;
- else
+ if(device->FmtChans == DevFmtAmbi3D)
{
- char name[32] = {0};
- const char *type;
- char eol;
-
- snprintf(name, sizeof(name), "%s/type", layout);
- if(!ConfigValueStr(al_string_get_cstr(device->DeviceName), "layouts", name, &type))
- return false;
+ const char *devname = alstr_get_cstr(device->DeviceName);
+ const ALsizei *acnmap = (device->AmbiLayout == AmbiLayout_FuMa) ? FuMa2ACN : ACN2ACN;
+ const ALfloat *n3dscale = (device->AmbiScale == AmbiNorm_FuMa) ? FuMa2N3DScale :
+ (device->AmbiScale == AmbiNorm_SN3D) ? SN3D2N3DScale :
+ /*(device->AmbiScale == AmbiNorm_N3D) ?*/ N3D2N3DScale;
+ ALfloat nfc_delay = 0.0f;
- if(sscanf(type, " %31[^: ] : %d%c", name, &order, &eol) != 2)
+ count = (device->AmbiOrder == 3) ? 16 :
+ (device->AmbiOrder == 2) ? 9 :
+ (device->AmbiOrder == 1) ? 4 : 1;
+ for(i = 0;i < count;i++)
{
- ERR("Invalid type value '%s' (expected name:order) for layout %s\n", type, layout);
- return false;
+ ALsizei acn = acnmap[i];
+ device->Dry.Ambi.Map[i].Scale = 1.0f/n3dscale[acn];
+ device->Dry.Ambi.Map[i].Index = acn;
}
+ device->Dry.CoeffCount = 0;
+ device->Dry.NumChannels = count;
- if(strcasecmp(name, "fuma") == 0)
- isfuma = 1;
- else if(strcasecmp(name, "n3d") == 0)
- isfuma = 0;
+ if(device->AmbiOrder < 2)
+ {
+ device->FOAOut.Ambi = device->Dry.Ambi;
+ device->FOAOut.CoeffCount = device->Dry.CoeffCount;
+ device->FOAOut.NumChannels = 0;
+ }
else
{
- ERR("Unhandled type name '%s' (expected FuMa or N3D) for layout %s\n", name, layout);
- return false;
+ ALfloat w_scale=1.0f, xyz_scale=1.0f;
+
+ /* FOA output is always ACN+N3D for higher-order ambisonic output.
+ * The upsampler expects this and will convert it for output.
+ */
+ memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
+ for(i = 0;i < 4;i++)
+ {
+ device->FOAOut.Ambi.Map[i].Scale = 1.0f;
+ device->FOAOut.Ambi.Map[i].Index = i;
+ }
+ device->FOAOut.CoeffCount = 0;
+ device->FOAOut.NumChannels = 4;
+
+ if(device->AmbiOrder >= 3)
+ {
+ w_scale = W_SCALE_3H3P;
+ xyz_scale = XYZ_SCALE_3H3P;
+ }
+ else
+ {
+ w_scale = W_SCALE_2H2P;
+ xyz_scale = XYZ_SCALE_2H2P;
+ }
+ ambiup_reset(device->AmbiUp, device, w_scale, xyz_scale);
}
- if(order == 3)
- ambiscale = THIRD_ORDER_SCALE;
- else if(order == 2)
- ambiscale = SECOND_ORDER_SCALE;
- else if(order == 1)
- ambiscale = FIRST_ORDER_SCALE;
- else if(order == 0)
- ambiscale = ZERO_ORDER_SCALE;
- else
+ if(ConfigValueFloat(devname, "decoder", "nfc-ref-delay", &nfc_delay) && nfc_delay > 0.0f)
{
- ERR("Unhandled type order %d (expected 0, 1, 2, or 3) for layout %s\n", order, layout);
- return false;
+ static const ALsizei chans_per_order[MAX_AMBI_ORDER+1] = {
+ 1, 3, 5, 7
+ };
+ nfc_delay = clampf(nfc_delay, 0.001f, 1000.0f);
+ InitNearFieldCtrl(device, nfc_delay * SPEEDOFSOUNDMETRESPERSEC,
+ device->AmbiOrder, chans_per_order);
}
}
+ else
+ {
+ ALfloat w_scale, xyz_scale;
- for(i = 0;i < count;i++)
+ SetChannelMap(device->RealOut.ChannelName, device->Dry.Ambi.Coeffs,
+ chanmap, count, &device->Dry.NumChannels);
+ device->Dry.CoeffCount = coeffcount;
+
+ w_scale = (device->Dry.CoeffCount > 9) ? W_SCALE_3H0P :
+ (device->Dry.CoeffCount > 4) ? W_SCALE_2H0P : 1.0f;
+ xyz_scale = (device->Dry.CoeffCount > 9) ? XYZ_SCALE_3H0P :
+ (device->Dry.CoeffCount > 4) ? XYZ_SCALE_2H0P : 1.0f;
+
+ memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
+ for(i = 0;i < device->Dry.NumChannels;i++)
+ {
+ device->FOAOut.Ambi.Coeffs[i][0] = device->Dry.Ambi.Coeffs[i][0] * w_scale;
+ for(j = 1;j < 4;j++)
+ device->FOAOut.Ambi.Coeffs[i][j] = device->Dry.Ambi.Coeffs[i][j] * xyz_scale;
+ }
+ device->FOAOut.CoeffCount = 4;
+ device->FOAOut.NumChannels = 0;
+ }
+ device->RealOut.NumChannels = 0;
+}
+
+static void InitCustomPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei speakermap[MAX_OUTPUT_CHANNELS])
+{
+ ChannelMap chanmap[MAX_OUTPUT_CHANNELS];
+ const ALfloat *coeff_scale = N3D2N3DScale;
+ ALfloat w_scale = 1.0f;
+ ALfloat xyz_scale = 1.0f;
+ ALsizei i, j;
+
+ if(conf->FreqBands != 1)
+ ERR("Basic renderer uses the high-frequency matrix as single-band (xover_freq = %.0fhz)\n",
+ conf->XOverFreq);
+
+ if((conf->ChanMask&AMBI_PERIPHONIC_MASK))
+ {
+ if(conf->ChanMask > 0x1ff)
+ {
+ w_scale = W_SCALE_3H3P;
+ xyz_scale = XYZ_SCALE_3H3P;
+ }
+ else if(conf->ChanMask > 0xf)
+ {
+ w_scale = W_SCALE_2H2P;
+ xyz_scale = XYZ_SCALE_2H2P;
+ }
+ }
+ else
+ {
+ if(conf->ChanMask > 0x1ff)
+ {
+ w_scale = W_SCALE_3H0P;
+ xyz_scale = XYZ_SCALE_3H0P;
+ }
+ else if(conf->ChanMask > 0xf)
+ {
+ w_scale = W_SCALE_2H0P;
+ xyz_scale = XYZ_SCALE_2H0P;
+ }
+ }
+
+ if(conf->CoeffScale == ADS_SN3D)
+ coeff_scale = SN3D2N3DScale;
+ else if(conf->CoeffScale == ADS_FuMa)
+ coeff_scale = FuMa2N3DScale;
+
+ for(i = 0;i < conf->NumSpeakers;i++)
{
- float coeffs[MAX_AMBI_COEFFS] = {0.0f};
- const char *channame;
- char chanlayout[32];
- const char *value;
- int props = 0;
- char eol = 0;
- int j;
+ ALsizei chan = speakermap[i];
+ ALfloat gain;
+ ALsizei k = 0;
- chanmap[i].ChanName = channels[i];
- channame = GetLabelFromChannel(channels[i]);
+ for(j = 0;j < MAX_AMBI_COEFFS;j++)
+ chanmap[i].Config[j] = 0.0f;
- snprintf(chanlayout, sizeof(chanlayout), "%s/%s", layout, channame);
- if(!ConfigValueStr(al_string_get_cstr(device->DeviceName), "layouts", chanlayout, &value))
+ chanmap[i].ChanName = device->RealOut.ChannelName[chan];
+ for(j = 0;j < MAX_AMBI_COEFFS;j++)
{
- ERR("Missing channel %s\n", channame);
- return false;
+ if(j == 0) gain = conf->HFOrderGain[0];
+ else if(j == 1) gain = conf->HFOrderGain[1];
+ else if(j == 4) gain = conf->HFOrderGain[2];
+ else if(j == 9) gain = conf->HFOrderGain[3];
+ if((conf->ChanMask&(1<<j)))
+ chanmap[i].Config[j] = conf->HFMatrix[i][k++] / coeff_scale[j] * gain;
}
- if(order == 3)
- props = sscanf(value, " %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %c",
- &coeffs[0], &coeffs[1], &coeffs[2], &coeffs[3],
- &coeffs[4], &coeffs[5], &coeffs[6], &coeffs[7],
- &coeffs[8], &coeffs[9], &coeffs[10], &coeffs[11],
- &coeffs[12], &coeffs[13], &coeffs[14], &coeffs[15],
- &eol
- );
- else if(order == 2)
- props = sscanf(value, " %f %f %f %f %f %f %f %f %f %c",
- &coeffs[0], &coeffs[1], &coeffs[2],
- &coeffs[3], &coeffs[4], &coeffs[5],
- &coeffs[6], &coeffs[7], &coeffs[8],
- &eol
- );
- else if(order == 1)
- props = sscanf(value, " %f %f %f %f %c",
- &coeffs[0], &coeffs[1],
- &coeffs[2], &coeffs[3],
- &eol
- );
- else if(order == 0)
- props = sscanf(value, " %f %c", &coeffs[0], &eol);
- if(props == 0)
+ }
+
+ SetChannelMap(device->RealOut.ChannelName, device->Dry.Ambi.Coeffs, chanmap,
+ conf->NumSpeakers, &device->Dry.NumChannels);
+ device->Dry.CoeffCount = (conf->ChanMask > 0x1ff) ? 16 :
+ (conf->ChanMask > 0xf) ? 9 : 4;
+
+ memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
+ for(i = 0;i < device->Dry.NumChannels;i++)
+ {
+ device->FOAOut.Ambi.Coeffs[i][0] = device->Dry.Ambi.Coeffs[i][0] * w_scale;
+ for(j = 1;j < 4;j++)
+ device->FOAOut.Ambi.Coeffs[i][j] = device->Dry.Ambi.Coeffs[i][j] * xyz_scale;
+ }
+ device->FOAOut.CoeffCount = 4;
+ device->FOAOut.NumChannels = 0;
+
+ device->RealOut.NumChannels = 0;
+
+ InitDistanceComp(device, conf, speakermap);
+}
+
+static void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei speakermap[MAX_OUTPUT_CHANNELS])
+{
+ static const ALsizei chans_per_order2d[MAX_AMBI_ORDER+1] = { 1, 2, 2, 2 };
+ static const ALsizei chans_per_order3d[MAX_AMBI_ORDER+1] = { 1, 3, 5, 7 };
+ ALfloat avg_dist;
+ ALsizei count;
+ ALsizei i;
+
+ if((conf->ChanMask&AMBI_PERIPHONIC_MASK))
+ {
+ count = (conf->ChanMask > 0x1ff) ? 16 :
+ (conf->ChanMask > 0xf) ? 9 : 4;
+ for(i = 0;i < count;i++)
{
- ERR("Failed to parse option %s properties\n", chanlayout);
- return false;
+ device->Dry.Ambi.Map[i].Scale = 1.0f;
+ device->Dry.Ambi.Map[i].Index = i;
}
+ }
+ else
+ {
+ static const int map[MAX_AMBI2D_COEFFS] = { 0, 1, 3, 4, 8, 9, 15 };
- if(props > (order+1)*(order+1))
+ count = (conf->ChanMask > 0x1ff) ? 7 :
+ (conf->ChanMask > 0xf) ? 5 : 3;
+ for(i = 0;i < count;i++)
{
- ERR("Excess elements in option %s (expected %d)\n", chanlayout, (order+1)*(order+1));
- return false;
+ device->Dry.Ambi.Map[i].Scale = 1.0f;
+ device->Dry.Ambi.Map[i].Index = map[i];
}
+ }
+ device->Dry.CoeffCount = 0;
+ device->Dry.NumChannels = count;
+
+ TRACE("Enabling %s-band %s-order%s ambisonic decoder\n",
+ (conf->FreqBands == 1) ? "single" : "dual",
+ (conf->ChanMask > 0xf) ? (conf->ChanMask > 0x1ff) ? "third" : "second" : "first",
+ (conf->ChanMask&AMBI_PERIPHONIC_MASK) ? " periphonic" : ""
+ );
+ bformatdec_reset(device->AmbiDecoder, conf, count, device->Frequency, speakermap);
- for(j = 0;j < MAX_AMBI_COEFFS;++j)
- chanmap[i].Config[j] = coeffs[j];
+ if(!(conf->ChanMask > 0xf))
+ {
+ device->FOAOut.Ambi = device->Dry.Ambi;
+ device->FOAOut.CoeffCount = device->Dry.CoeffCount;
+ device->FOAOut.NumChannels = 0;
}
- SetChannelMap(device, chanmap, count, ambiscale, isfuma);
- return true;
+ else
+ {
+ memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
+ if((conf->ChanMask&AMBI_PERIPHONIC_MASK))
+ {
+ count = 4;
+ for(i = 0;i < count;i++)
+ {
+ device->FOAOut.Ambi.Map[i].Scale = 1.0f;
+ device->FOAOut.Ambi.Map[i].Index = i;
+ }
+ }
+ else
+ {
+ static const int map[3] = { 0, 1, 3 };
+ count = 3;
+ for(i = 0;i < count;i++)
+ {
+ device->FOAOut.Ambi.Map[i].Scale = 1.0f;
+ device->FOAOut.Ambi.Map[i].Index = map[i];
+ }
+ }
+ device->FOAOut.CoeffCount = 0;
+ device->FOAOut.NumChannels = count;
+ }
+
+ device->RealOut.NumChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
+
+ avg_dist = 0.0f;
+ for(i = 0;i < conf->NumSpeakers;i++)
+ avg_dist += conf->Speakers[i].Distance;
+ avg_dist /= (ALfloat)conf->NumSpeakers;
+ InitNearFieldCtrl(device, avg_dist,
+ (conf->ChanMask > 0x1ff) ? 3 : (conf->ChanMask > 0xf) ? 2 : 1,
+ (conf->ChanMask&AMBI_PERIPHONIC_MASK) ? chans_per_order3d : chans_per_order2d
+ );
+
+ InitDistanceComp(device, conf, speakermap);
}
-ALvoid aluInitPanning(ALCdevice *device)
+static void InitHrtfPanning(ALCdevice *device)
{
- /* NOTE: These decoder coefficients are using FuMa channel ordering and
- * normalization, since that's what was produced by the Ambisonic Decoder
- * Toolbox. SetChannelMap will convert them to N3D.
- */
- static const ChannelMap MonoCfg[1] = {
- { FrontCenter, { 1.414213562f } },
- }, StereoCfg[2] = {
- { FrontLeft, { 0.707106781f, 0.0f, 0.5f, 0.0f } },
- { FrontRight, { 0.707106781f, 0.0f, -0.5f, 0.0f } },
- }, QuadCfg[4] = {
- { FrontLeft, { 0.353553f, 0.306184f, 0.306184f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, 0.117186f } },
- { FrontRight, { 0.353553f, 0.306184f, -0.306184f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, -0.117186f } },
- { BackLeft, { 0.353553f, -0.306184f, 0.306184f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, -0.117186f } },
- { BackRight, { 0.353553f, -0.306184f, -0.306184f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, 0.117186f } },
- }, X51SideCfg[5] = {
- { FrontLeft, { 0.208954f, 0.212846f, 0.238350f, 0.0f, 0.0f, 0.0f, 0.0f, -0.017738f, 0.204014f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.051023f, 0.047490f } },
- { FrontRight, { 0.208954f, 0.212846f, -0.238350f, 0.0f, 0.0f, 0.0f, 0.0f, -0.017738f, -0.204014f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.051023f, -0.047490f } },
- { FrontCenter, { 0.109403f, 0.179490f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.142031f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.072024f, 0.000000f } },
- { SideLeft, { 0.470936f, -0.369626f, 0.349386f, 0.0f, 0.0f, 0.0f, 0.0f, -0.031375f, -0.058144f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.007119f, -0.043968f } },
- { SideRight, { 0.470936f, -0.369626f, -0.349386f, 0.0f, 0.0f, 0.0f, 0.0f, -0.031375f, 0.058144f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.007119f, 0.043968f } },
- }, X51RearCfg[5] = {
- { FrontLeft, { 0.208954f, 0.212846f, 0.238350f, 0.0f, 0.0f, 0.0f, 0.0f, -0.017738f, 0.204014f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.051023f, 0.047490f } },
- { FrontRight, { 0.208954f, 0.212846f, -0.238350f, 0.0f, 0.0f, 0.0f, 0.0f, -0.017738f, -0.204014f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.051023f, -0.047490f } },
- { FrontCenter, { 0.109403f, 0.179490f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.142031f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.072024f, 0.000000f } },
- { BackLeft, { 0.470936f, -0.369626f, 0.349386f, 0.0f, 0.0f, 0.0f, 0.0f, -0.031375f, -0.058144f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.007119f, -0.043968f } },
- { BackRight, { 0.470936f, -0.369626f, -0.349386f, 0.0f, 0.0f, 0.0f, 0.0f, -0.031375f, 0.058144f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.007119f, 0.043968f } },
- }, X61Cfg[6] = {
- { FrontLeft, { 0.167065f, 0.200583f, 0.172695f, 0.0f, 0.0f, 0.0f, 0.0f, 0.029855f, 0.186407f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.039241f, 0.068910f } },
- { FrontRight, { 0.167065f, 0.200583f, -0.172695f, 0.0f, 0.0f, 0.0f, 0.0f, 0.029855f, -0.186407f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.039241f, -0.068910f } },
- { FrontCenter, { 0.109403f, 0.179490f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.142031f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.072024f, 0.000000f } },
- { BackCenter, { 0.353556f, -0.461940f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.165723f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, 0.000000f } },
- { SideLeft, { 0.289151f, -0.081301f, 0.401292f, 0.0f, 0.0f, 0.0f, 0.0f, -0.188208f, -0.071420f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.010099f, -0.032897f } },
- { SideRight, { 0.289151f, -0.081301f, -0.401292f, 0.0f, 0.0f, 0.0f, 0.0f, -0.188208f, 0.071420f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.010099f, 0.032897f } },
- }, X71Cfg[7] = {
- { FrontLeft, { 0.167065f, 0.200583f, 0.172695f, 0.0f, 0.0f, 0.0f, 0.0f, 0.029855f, 0.186407f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.039241f, 0.068910f } },
- { FrontRight, { 0.167065f, 0.200583f, -0.172695f, 0.0f, 0.0f, 0.0f, 0.0f, 0.029855f, -0.186407f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.039241f, -0.068910f } },
- { FrontCenter, { 0.109403f, 0.179490f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.142031f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.072024f, 0.000000f } },
- { BackLeft, { 0.224752f, -0.295009f, 0.170325f, 0.0f, 0.0f, 0.0f, 0.0f, 0.105349f, -0.182473f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, 0.065799f } },
- { BackRight, { 0.224752f, -0.295009f, -0.170325f, 0.0f, 0.0f, 0.0f, 0.0f, 0.105349f, 0.182473f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, -0.065799f } },
- { SideLeft, { 0.224739f, 0.000000f, 0.340644f, 0.0f, 0.0f, 0.0f, 0.0f, -0.210697f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, -0.065795f } },
- { SideRight, { 0.224739f, 0.000000f, -0.340644f, 0.0f, 0.0f, 0.0f, 0.0f, -0.210697f, 0.000000f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.000000f, 0.065795f } },
- }, BFormat3D[4] = {
- { BFormatW, { 1.0f, 0.0f, 0.0f, 0.0f } },
- { BFormatX, { 0.0f, 1.0f, 0.0f, 0.0f } },
- { BFormatY, { 0.0f, 0.0f, 1.0f, 0.0f } },
- { BFormatZ, { 0.0f, 0.0f, 0.0f, 1.0f } },
+ /* NOTE: azimuth goes clockwise. */
+ static const struct AngularPoint AmbiPoints[] = {
+ { DEG2RAD( 90.0f), DEG2RAD( 0.0f) },
+ { DEG2RAD( 35.2643897f), DEG2RAD( 45.0f) },
+ { DEG2RAD( 35.2643897f), DEG2RAD( 135.0f) },
+ { DEG2RAD( 35.2643897f), DEG2RAD(-135.0f) },
+ { DEG2RAD( 35.2643897f), DEG2RAD( -45.0f) },
+ { DEG2RAD( 0.0f), DEG2RAD( 0.0f) },
+ { DEG2RAD( 0.0f), DEG2RAD( 45.0f) },
+ { DEG2RAD( 0.0f), DEG2RAD( 90.0f) },
+ { DEG2RAD( 0.0f), DEG2RAD( 135.0f) },
+ { DEG2RAD( 0.0f), DEG2RAD( 180.0f) },
+ { DEG2RAD( 0.0f), DEG2RAD(-135.0f) },
+ { DEG2RAD( 0.0f), DEG2RAD( -90.0f) },
+ { DEG2RAD( 0.0f), DEG2RAD( -45.0f) },
+ { DEG2RAD(-35.2643897f), DEG2RAD( 45.0f) },
+ { DEG2RAD(-35.2643897f), DEG2RAD( 135.0f) },
+ { DEG2RAD(-35.2643897f), DEG2RAD(-135.0f) },
+ { DEG2RAD(-35.2643897f), DEG2RAD( -45.0f) },
+ { DEG2RAD(-90.0f), DEG2RAD( 0.0f) },
};
- const ChannelMap *chanmap = NULL;
- ALfloat ambiscale = 1.0f;
- size_t count = 0;
+ static const ALfloat AmbiMatrixFOA[][MAX_AMBI_COEFFS] = {
+ { 5.55555556e-02f, 0.00000000e+00f, 1.23717915e-01f, 0.00000000e+00f },
+ { 5.55555556e-02f, -5.00000000e-02f, 7.14285715e-02f, 5.00000000e-02f },
+ { 5.55555556e-02f, -5.00000000e-02f, 7.14285715e-02f, -5.00000000e-02f },
+ { 5.55555556e-02f, 5.00000000e-02f, 7.14285715e-02f, -5.00000000e-02f },
+ { 5.55555556e-02f, 5.00000000e-02f, 7.14285715e-02f, 5.00000000e-02f },
+ { 5.55555556e-02f, 0.00000000e+00f, 0.00000000e+00f, 8.66025404e-02f },
+ { 5.55555556e-02f, -6.12372435e-02f, 0.00000000e+00f, 6.12372435e-02f },
+ { 5.55555556e-02f, -8.66025404e-02f, 0.00000000e+00f, 0.00000000e+00f },
+ { 5.55555556e-02f, -6.12372435e-02f, 0.00000000e+00f, -6.12372435e-02f },
+ { 5.55555556e-02f, 0.00000000e+00f, 0.00000000e+00f, -8.66025404e-02f },
+ { 5.55555556e-02f, 6.12372435e-02f, 0.00000000e+00f, -6.12372435e-02f },
+ { 5.55555556e-02f, 8.66025404e-02f, 0.00000000e+00f, 0.00000000e+00f },
+ { 5.55555556e-02f, 6.12372435e-02f, 0.00000000e+00f, 6.12372435e-02f },
+ { 5.55555556e-02f, -5.00000000e-02f, -7.14285715e-02f, 5.00000000e-02f },
+ { 5.55555556e-02f, -5.00000000e-02f, -7.14285715e-02f, -5.00000000e-02f },
+ { 5.55555556e-02f, 5.00000000e-02f, -7.14285715e-02f, -5.00000000e-02f },
+ { 5.55555556e-02f, 5.00000000e-02f, -7.14285715e-02f, 5.00000000e-02f },
+ { 5.55555556e-02f, 0.00000000e+00f, -1.23717915e-01f, 0.00000000e+00f },
+ }, AmbiMatrixHOA[][MAX_AMBI_COEFFS] = {
+ { 5.55555556e-02f, 0.00000000e+00f, 1.23717915e-01f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f },
+ { 5.55555556e-02f, -5.00000000e-02f, 7.14285715e-02f, 5.00000000e-02f, -4.55645099e-02f, 0.00000000e+00f },
+ { 5.55555556e-02f, -5.00000000e-02f, 7.14285715e-02f, -5.00000000e-02f, 4.55645099e-02f, 0.00000000e+00f },
+ { 5.55555556e-02f, 5.00000000e-02f, 7.14285715e-02f, -5.00000000e-02f, -4.55645099e-02f, 0.00000000e+00f },
+ { 5.55555556e-02f, 5.00000000e-02f, 7.14285715e-02f, 5.00000000e-02f, 4.55645099e-02f, 0.00000000e+00f },
+ { 5.55555556e-02f, 0.00000000e+00f, 0.00000000e+00f, 8.66025404e-02f, 0.00000000e+00f, 1.29099445e-01f },
+ { 5.55555556e-02f, -6.12372435e-02f, 0.00000000e+00f, 6.12372435e-02f, -6.83467648e-02f, 0.00000000e+00f },
+ { 5.55555556e-02f, -8.66025404e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, -1.29099445e-01f },
+ { 5.55555556e-02f, -6.12372435e-02f, 0.00000000e+00f, -6.12372435e-02f, 6.83467648e-02f, 0.00000000e+00f },
+ { 5.55555556e-02f, 0.00000000e+00f, 0.00000000e+00f, -8.66025404e-02f, 0.00000000e+00f, 1.29099445e-01f },
+ { 5.55555556e-02f, 6.12372435e-02f, 0.00000000e+00f, -6.12372435e-02f, -6.83467648e-02f, 0.00000000e+00f },
+ { 5.55555556e-02f, 8.66025404e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, -1.29099445e-01f },
+ { 5.55555556e-02f, 6.12372435e-02f, 0.00000000e+00f, 6.12372435e-02f, 6.83467648e-02f, 0.00000000e+00f },
+ { 5.55555556e-02f, -5.00000000e-02f, -7.14285715e-02f, 5.00000000e-02f, -4.55645099e-02f, 0.00000000e+00f },
+ { 5.55555556e-02f, -5.00000000e-02f, -7.14285715e-02f, -5.00000000e-02f, 4.55645099e-02f, 0.00000000e+00f },
+ { 5.55555556e-02f, 5.00000000e-02f, -7.14285715e-02f, -5.00000000e-02f, -4.55645099e-02f, 0.00000000e+00f },
+ { 5.55555556e-02f, 5.00000000e-02f, -7.14285715e-02f, 5.00000000e-02f, 4.55645099e-02f, 0.00000000e+00f },
+ { 5.55555556e-02f, 0.00000000e+00f, -1.23717915e-01f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f },
+ };
+ static const ALfloat AmbiOrderHFGainFOA[MAX_AMBI_ORDER+1] = {
+ 3.00000000e+00f, 1.73205081e+00f
+ }, AmbiOrderHFGainHOA[MAX_AMBI_ORDER+1] = {
+ 2.40192231e+00f, 1.86052102e+00f, 9.60768923e-01f
+ };
+ static const ALsizei IndexMap[6] = { 0, 1, 2, 3, 4, 8 };
+ static const ALsizei ChansPerOrder[MAX_AMBI_ORDER+1] = { 1, 3, 2, 0 };
+ const ALfloat (*restrict AmbiMatrix)[MAX_AMBI_COEFFS] = AmbiMatrixFOA;
+ const ALfloat *restrict AmbiOrderHFGain = AmbiOrderHFGainFOA;
+ ALsizei count = 4;
+ ALsizei i;
- device->AmbiScale = 1.0f;
- memset(device->AmbiCoeffs, 0, sizeof(device->AmbiCoeffs));
- device->NumChannels = 0;
+ static_assert(COUNTOF(AmbiPoints) == COUNTOF(AmbiMatrixFOA), "FOA Ambisonic HRTF mismatch");
+ static_assert(COUNTOF(AmbiPoints) == COUNTOF(AmbiMatrixHOA), "HOA Ambisonic HRTF mismatch");
- if(device->Hrtf)
+ if(device->AmbiUp)
{
- ALfloat (*coeffs_list[4])[2];
- ALuint *delay_list[4];
- ALuint i;
+ AmbiMatrix = AmbiMatrixHOA;
+ AmbiOrderHFGain = AmbiOrderHFGainHOA;
+ count = COUNTOF(IndexMap);
+ }
- count = COUNTOF(BFormat3D);
- chanmap = BFormat3D;
- ambiscale = 1.0f;
+ device->Hrtf = al_calloc(16, FAM_SIZE(DirectHrtfState, Chan, count));
- for(i = 0;i < count;i++)
- device->ChannelName[i] = chanmap[i].ChanName;
- for(;i < MAX_OUTPUT_CHANNELS;i++)
- device->ChannelName[i] = InvalidChannel;
- SetChannelMap(device, chanmap, count, ambiscale, AL_TRUE);
+ for(i = 0;i < count;i++)
+ {
+ device->Dry.Ambi.Map[i].Scale = 1.0f;
+ device->Dry.Ambi.Map[i].Index = IndexMap[i];
+ }
+ device->Dry.CoeffCount = 0;
+ device->Dry.NumChannels = count;
- for(i = 0;i < 4;++i)
+ if(device->AmbiUp)
+ {
+ memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
+ for(i = 0;i < 4;i++)
{
- static const enum Channel inputs[4] = { BFormatW, BFormatX, BFormatY, BFormatZ };
- int chan = GetChannelIdxByName(device, inputs[i]);
- coeffs_list[i] = device->Hrtf_Params[chan].Coeffs;
- delay_list[i] = device->Hrtf_Params[chan].Delay;
+ device->FOAOut.Ambi.Map[i].Scale = 1.0f;
+ device->FOAOut.Ambi.Map[i].Index = i;
}
- GetBFormatHrtfCoeffs(device->Hrtf, 4, coeffs_list, delay_list);
+ device->FOAOut.CoeffCount = 0;
+ device->FOAOut.NumChannels = 4;
- return;
+ ambiup_reset(device->AmbiUp, device, AmbiOrderHFGainFOA[0] / AmbiOrderHFGain[0],
+ AmbiOrderHFGainFOA[1] / AmbiOrderHFGain[1]);
+ }
+ else
+ {
+ device->FOAOut.Ambi = device->Dry.Ambi;
+ device->FOAOut.CoeffCount = device->Dry.CoeffCount;
+ device->FOAOut.NumChannels = 0;
}
- if(LoadChannelSetup(device))
- return;
+ device->RealOut.NumChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
- switch(device->FmtChans)
+ BuildBFormatHrtf(device->HrtfHandle,
+ device->Hrtf, device->Dry.NumChannels, AmbiPoints, AmbiMatrix, COUNTOF(AmbiPoints),
+ AmbiOrderHFGain
+ );
+
+ InitNearFieldCtrl(device, device->HrtfHandle->distance, device->AmbiUp ? 2 : 1,
+ ChansPerOrder);
+}
+
+static void InitUhjPanning(ALCdevice *device)
+{
+ ALsizei count = 3;
+ ALsizei i;
+
+ for(i = 0;i < count;i++)
{
- case DevFmtMono:
- count = COUNTOF(MonoCfg);
- chanmap = MonoCfg;
- ambiscale = ZERO_ORDER_SCALE;
- break;
+ ALsizei acn = FuMa2ACN[i];
+ device->Dry.Ambi.Map[i].Scale = 1.0f/FuMa2N3DScale[acn];
+ device->Dry.Ambi.Map[i].Index = acn;
+ }
+ device->Dry.CoeffCount = 0;
+ device->Dry.NumChannels = count;
- case DevFmtStereo:
- count = COUNTOF(StereoCfg);
- chanmap = StereoCfg;
- ambiscale = FIRST_ORDER_SCALE;
- break;
+ device->FOAOut.Ambi = device->Dry.Ambi;
+ device->FOAOut.CoeffCount = device->Dry.CoeffCount;
+ device->FOAOut.NumChannels = 0;
- case DevFmtQuad:
- count = COUNTOF(QuadCfg);
- chanmap = QuadCfg;
- ambiscale = SECOND_ORDER_SCALE;
- break;
+ device->RealOut.NumChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
+}
- case DevFmtX51:
- count = COUNTOF(X51SideCfg);
- chanmap = X51SideCfg;
- ambiscale = THIRD_ORDER_SCALE;
- break;
+void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf_appreq, enum HrtfRequestMode hrtf_userreq)
+{
+ /* Hold the HRTF the device last used, in case it's used again. */
+ struct Hrtf *old_hrtf = device->HrtfHandle;
+ const char *mode;
+ bool headphones;
+ int bs2blevel;
+ size_t i;
- case DevFmtX51Rear:
- count = COUNTOF(X51RearCfg);
- chanmap = X51RearCfg;
- ambiscale = THIRD_ORDER_SCALE;
- break;
+ al_free(device->Hrtf);
+ device->Hrtf = NULL;
+ device->HrtfHandle = NULL;
+ alstr_clear(&device->HrtfName);
+ device->Render_Mode = NormalRender;
- case DevFmtX61:
- count = COUNTOF(X61Cfg);
- chanmap = X61Cfg;
- ambiscale = THIRD_ORDER_SCALE;
- break;
+ memset(&device->Dry.Ambi, 0, sizeof(device->Dry.Ambi));
+ device->Dry.CoeffCount = 0;
+ device->Dry.NumChannels = 0;
+ for(i = 0;i < MAX_AMBI_ORDER+1;i++)
+ device->NumChannelsPerOrder[i] = 0;
+
+ device->AvgSpeakerDist = 0.0f;
+ memset(device->ChannelDelay, 0, sizeof(device->ChannelDelay));
+ for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
+ {
+ device->ChannelDelay[i].Gain = 1.0f;
+ device->ChannelDelay[i].Length = 0;
+ }
+
+ al_free(device->Stablizer);
+ device->Stablizer = NULL;
+
+ if(device->FmtChans != DevFmtStereo)
+ {
+ ALsizei speakermap[MAX_OUTPUT_CHANNELS];
+ const char *devname, *layout = NULL;
+ AmbDecConf conf, *pconf = NULL;
+
+ if(old_hrtf)
+ Hrtf_DecRef(old_hrtf);
+ old_hrtf = NULL;
+ if(hrtf_appreq == Hrtf_Enable)
+ device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
+
+ ambdec_init(&conf);
+
+ devname = alstr_get_cstr(device->DeviceName);
+ switch(device->FmtChans)
+ {
+ case DevFmtQuad: layout = "quad"; break;
+ case DevFmtX51: /* fall-through */
+ case DevFmtX51Rear: layout = "surround51"; break;
+ case DevFmtX61: layout = "surround61"; break;
+ case DevFmtX71: layout = "surround71"; break;
+ /* Mono, Stereo, and Ambisonics output don't use custom decoders. */
+ case DevFmtMono:
+ case DevFmtStereo:
+ case DevFmtAmbi3D:
+ break;
+ }
+ if(layout)
+ {
+ const char *fname;
+ if(ConfigValueStr(devname, "decoder", layout, &fname))
+ {
+ if(!ambdec_load(&conf, fname))
+ ERR("Failed to load layout file %s\n", fname);
+ else
+ {
+ if(conf.ChanMask > 0xffff)
+ ERR("Unsupported channel mask 0x%04x (max 0xffff)\n", conf.ChanMask);
+ else
+ {
+ if(MakeSpeakerMap(device, &conf, speakermap))
+ pconf = &conf;
+ }
+ }
+ }
+ }
+ if(pconf && GetConfigValueBool(devname, "decoder", "hq-mode", 0))
+ {
+ ambiup_free(&device->AmbiUp);
+ if(!device->AmbiDecoder)
+ device->AmbiDecoder = bformatdec_alloc();
+ }
+ else
+ {
+ bformatdec_free(&device->AmbiDecoder);
+ if(device->FmtChans != DevFmtAmbi3D || device->AmbiOrder < 2)
+ ambiup_free(&device->AmbiUp);
+ else
+ {
+ if(!device->AmbiUp)
+ device->AmbiUp = ambiup_alloc();
+ }
+ }
+
+ if(!pconf)
+ InitPanning(device);
+ else if(device->AmbiDecoder)
+ InitHQPanning(device, pconf, speakermap);
+ else
+ InitCustomPanning(device, pconf, speakermap);
+
+ /* Enable the stablizer only for formats that have front-left, front-
+ * right, and front-center outputs.
+ */
+ switch(device->FmtChans)
+ {
+ case DevFmtX51:
+ case DevFmtX51Rear:
+ case DevFmtX61:
case DevFmtX71:
- count = COUNTOF(X71Cfg);
- chanmap = X71Cfg;
- ambiscale = THIRD_ORDER_SCALE;
- break;
+ if(GetConfigValueBool(devname, NULL, "front-stablizer", 0))
+ {
+ /* Initialize band-splitting filters for the front-left and
+ * front-right channels, with a crossover at 5khz (could be
+ * higher).
+ */
+ ALfloat scale = (ALfloat)(5000.0 / device->Frequency);
+ FrontStablizer *stablizer = al_calloc(16, sizeof(*stablizer));
- case DevFmtBFormat3D:
- count = COUNTOF(BFormat3D);
- chanmap = BFormat3D;
- ambiscale = 1.0f;
+ bandsplit_init(&stablizer->LFilter, scale);
+ stablizer->RFilter = stablizer->LFilter;
+
+ /* Initialize all-pass filters for all other channels. */
+ splitterap_init(&stablizer->APFilter[0], scale);
+ for(i = 1;i < (size_t)device->RealOut.NumChannels;i++)
+ stablizer->APFilter[i] = stablizer->APFilter[0];
+
+ device->Stablizer = stablizer;
+ }
+ break;
+ case DevFmtMono:
+ case DevFmtStereo:
+ case DevFmtQuad:
+ case DevFmtAmbi3D:
break;
+ }
+ TRACE("Front stablizer %s\n", device->Stablizer ? "enabled" : "disabled");
+
+ ambdec_deinit(&conf);
+ return;
+ }
+
+ bformatdec_free(&device->AmbiDecoder);
+
+ headphones = device->IsHeadphones;
+ if(device->Type != Loopback)
+ {
+ const char *mode;
+ if(ConfigValueStr(alstr_get_cstr(device->DeviceName), NULL, "stereo-mode", &mode))
+ {
+ if(strcasecmp(mode, "headphones") == 0)
+ headphones = true;
+ else if(strcasecmp(mode, "speakers") == 0)
+ headphones = false;
+ else if(strcasecmp(mode, "auto") != 0)
+ ERR("Unexpected stereo-mode: %s\n", mode);
+ }
+ }
+
+ if(hrtf_userreq == Hrtf_Default)
+ {
+ bool usehrtf = (headphones && hrtf_appreq != Hrtf_Disable) ||
+ (hrtf_appreq == Hrtf_Enable);
+ if(!usehrtf) goto no_hrtf;
+
+ device->HrtfStatus = ALC_HRTF_ENABLED_SOFT;
+ if(headphones && hrtf_appreq != Hrtf_Disable)
+ device->HrtfStatus = ALC_HRTF_HEADPHONES_DETECTED_SOFT;
+ }
+ else
+ {
+ if(hrtf_userreq != Hrtf_Enable)
+ {
+ if(hrtf_appreq == Hrtf_Enable)
+ device->HrtfStatus = ALC_HRTF_DENIED_SOFT;
+ goto no_hrtf;
+ }
+ device->HrtfStatus = ALC_HRTF_REQUIRED_SOFT;
+ }
+
+ if(VECTOR_SIZE(device->HrtfList) == 0)
+ {
+ VECTOR_DEINIT(device->HrtfList);
+ device->HrtfList = EnumerateHrtf(device->DeviceName);
}
- SetChannelMap(device, chanmap, count, ambiscale, AL_TRUE);
+ if(hrtf_id >= 0 && (size_t)hrtf_id < VECTOR_SIZE(device->HrtfList))
+ {
+ const EnumeratedHrtf *entry = &VECTOR_ELEM(device->HrtfList, hrtf_id);
+ struct Hrtf *hrtf = GetLoadedHrtf(entry->hrtf);
+ if(hrtf && hrtf->sampleRate == device->Frequency)
+ {
+ device->HrtfHandle = hrtf;
+ alstr_copy(&device->HrtfName, entry->name);
+ }
+ else if(hrtf)
+ Hrtf_DecRef(hrtf);
+ }
+
+ for(i = 0;!device->HrtfHandle && i < VECTOR_SIZE(device->HrtfList);i++)
+ {
+ const EnumeratedHrtf *entry = &VECTOR_ELEM(device->HrtfList, i);
+ struct Hrtf *hrtf = GetLoadedHrtf(entry->hrtf);
+ if(hrtf && hrtf->sampleRate == device->Frequency)
+ {
+ device->HrtfHandle = hrtf;
+ alstr_copy(&device->HrtfName, entry->name);
+ }
+ else if(hrtf)
+ Hrtf_DecRef(hrtf);
+ }
+
+ if(device->HrtfHandle)
+ {
+ if(old_hrtf)
+ Hrtf_DecRef(old_hrtf);
+ old_hrtf = NULL;
+
+ device->Render_Mode = HrtfRender;
+ if(ConfigValueStr(alstr_get_cstr(device->DeviceName), NULL, "hrtf-mode", &mode))
+ {
+ if(strcasecmp(mode, "full") == 0)
+ device->Render_Mode = HrtfRender;
+ else if(strcasecmp(mode, "basic") == 0)
+ device->Render_Mode = NormalRender;
+ else
+ ERR("Unexpected hrtf-mode: %s\n", mode);
+ }
+
+ if(device->Render_Mode == HrtfRender)
+ {
+ /* Don't bother with HOA when using full HRTF rendering. Nothing
+ * needs it, and it eases the CPU/memory load.
+ */
+ ambiup_free(&device->AmbiUp);
+ }
+ else
+ {
+ if(!device->AmbiUp)
+ device->AmbiUp = ambiup_alloc();
+ }
+
+ TRACE("%s HRTF rendering enabled, using \"%s\"\n",
+ ((device->Render_Mode == HrtfRender) ? "Full" : "Basic"),
+ alstr_get_cstr(device->HrtfName)
+ );
+ InitHrtfPanning(device);
+ return;
+ }
+ device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
+
+no_hrtf:
+ if(old_hrtf)
+ Hrtf_DecRef(old_hrtf);
+ old_hrtf = NULL;
+ TRACE("HRTF disabled\n");
+
+ device->Render_Mode = StereoPair;
+
+ ambiup_free(&device->AmbiUp);
+
+ bs2blevel = ((headphones && hrtf_appreq != Hrtf_Disable) ||
+ (hrtf_appreq == Hrtf_Enable)) ? 5 : 0;
+ if(device->Type != Loopback)
+ ConfigValueInt(alstr_get_cstr(device->DeviceName), NULL, "cf_level", &bs2blevel);
+ if(bs2blevel > 0 && bs2blevel <= 6)
+ {
+ device->Bs2b = al_calloc(16, sizeof(*device->Bs2b));
+ bs2b_set_params(device->Bs2b, bs2blevel, device->Frequency);
+ TRACE("BS2B enabled\n");
+ InitPanning(device);
+ return;
+ }
+
+ TRACE("BS2B disabled\n");
+
+ if(ConfigValueStr(alstr_get_cstr(device->DeviceName), NULL, "stereo-encoding", &mode))
+ {
+ if(strcasecmp(mode, "uhj") == 0)
+ device->Render_Mode = NormalRender;
+ else if(strcasecmp(mode, "panpot") != 0)
+ ERR("Unexpected stereo-encoding: %s\n", mode);
+ }
+ if(device->Render_Mode == NormalRender)
+ {
+ device->Uhj_Encoder = al_calloc(16, sizeof(Uhj2Encoder));
+ TRACE("UHJ enabled\n");
+ InitUhjPanning(device);
+ return;
+ }
+
+ TRACE("UHJ disabled\n");
+ InitPanning(device);
+}
+
+
+void aluInitEffectPanning(ALeffectslot *slot)
+{
+ ALsizei i;
+
+ memset(slot->ChanMap, 0, sizeof(slot->ChanMap));
+ slot->NumChannels = 0;
+
+ for(i = 0;i < MAX_EFFECT_CHANNELS;i++)
+ {
+ slot->ChanMap[i].Scale = 1.0f;
+ slot->ChanMap[i].Index = i;
+ }
+ slot->NumChannels = i;
}
diff --git a/Alc/polymorphism.h b/Alc/polymorphism.h
new file mode 100644
index 00000000..fa31fad2
--- /dev/null
+++ b/Alc/polymorphism.h
@@ -0,0 +1,105 @@
+#ifndef POLYMORPHISM_H
+#define POLYMORPHISM_H
+
+/* Macros to declare inheriting types, and to (down-)cast and up-cast. */
+#define DERIVE_FROM_TYPE(t) t t##_parent
+#define STATIC_CAST(to, obj) (&(obj)->to##_parent)
+#ifdef __GNUC__
+#define STATIC_UPCAST(to, from, obj) __extension__({ \
+ static_assert(__builtin_types_compatible_p(from, __typeof(*(obj))), \
+ "Invalid upcast object from type"); \
+ (to*)((char*)(obj) - offsetof(to, from##_parent)); \
+})
+#else
+#define STATIC_UPCAST(to, from, obj) ((to*)((char*)(obj) - offsetof(to, from##_parent)))
+#endif
+
+/* Defines method forwards, which call the given parent's (T2's) implementation. */
+#define DECLARE_FORWARD(T1, T2, rettype, func) \
+rettype T1##_##func(T1 *obj) \
+{ return T2##_##func(STATIC_CAST(T2, obj)); }
+
+#define DECLARE_FORWARD1(T1, T2, rettype, func, argtype1) \
+rettype T1##_##func(T1 *obj, argtype1 a) \
+{ return T2##_##func(STATIC_CAST(T2, obj), a); }
+
+#define DECLARE_FORWARD2(T1, T2, rettype, func, argtype1, argtype2) \
+rettype T1##_##func(T1 *obj, argtype1 a, argtype2 b) \
+{ return T2##_##func(STATIC_CAST(T2, obj), a, b); }
+
+#define DECLARE_FORWARD3(T1, T2, rettype, func, argtype1, argtype2, argtype3) \
+rettype T1##_##func(T1 *obj, argtype1 a, argtype2 b, argtype3 c) \
+{ return T2##_##func(STATIC_CAST(T2, obj), a, b, c); }
+
+/* Defines method thunks, functions that call to the child's method. */
+#define DECLARE_THUNK(T1, T2, rettype, func) \
+static rettype T1##_##T2##_##func(T2 *obj) \
+{ return T1##_##func(STATIC_UPCAST(T1, T2, obj)); }
+
+#define DECLARE_THUNK1(T1, T2, rettype, func, argtype1) \
+static rettype T1##_##T2##_##func(T2 *obj, argtype1 a) \
+{ return T1##_##func(STATIC_UPCAST(T1, T2, obj), a); }
+
+#define DECLARE_THUNK2(T1, T2, rettype, func, argtype1, argtype2) \
+static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b) \
+{ return T1##_##func(STATIC_UPCAST(T1, T2, obj), a, b); }
+
+#define DECLARE_THUNK3(T1, T2, rettype, func, argtype1, argtype2, argtype3) \
+static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b, argtype3 c) \
+{ return T1##_##func(STATIC_UPCAST(T1, T2, obj), a, b, c); }
+
+#define DECLARE_THUNK4(T1, T2, rettype, func, argtype1, argtype2, argtype3, argtype4) \
+static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b, argtype3 c, argtype4 d) \
+{ return T1##_##func(STATIC_UPCAST(T1, T2, obj), a, b, c, d); }
+
+/* Defines the default functions used to (de)allocate a polymorphic object. */
+#define DECLARE_DEFAULT_ALLOCATORS(T) \
+static void* T##_New(size_t size) { return al_malloc(16, size); } \
+static void T##_Delete(void *ptr) { al_free(ptr); }
+
+
+/* Helper to extract an argument list for virtual method calls. */
+#define EXTRACT_VCALL_ARGS(...) __VA_ARGS__))
+
+/* Call a "virtual" method on an object, with arguments. */
+#define V(obj, func) ((obj)->vtbl->func((obj), EXTRACT_VCALL_ARGS
+/* Call a "virtual" method on an object, with no arguments. */
+#define V0(obj, func) ((obj)->vtbl->func((obj) EXTRACT_VCALL_ARGS
+
+
+/* Helper to extract an argument list for NEW_OBJ calls. */
+#define EXTRACT_NEW_ARGS(...) __VA_ARGS__); \
+ } \
+} while(0)
+
+/* Allocate and construct an object, with arguments. */
+#define NEW_OBJ(_res, T) do { \
+ _res = T##_New(sizeof(T)); \
+ if(_res) \
+ { \
+ memset(_res, 0, sizeof(T)); \
+ T##_Construct(_res, EXTRACT_NEW_ARGS
+/* Allocate and construct an object, with no arguments. */
+#define NEW_OBJ0(_res, T) do { \
+ _res = T##_New(sizeof(T)); \
+ if(_res) \
+ { \
+ memset(_res, 0, sizeof(T)); \
+ T##_Construct(_res EXTRACT_NEW_ARGS
+
+/* Destructs and deallocate an object. */
+#define DELETE_OBJ(obj) do { \
+ if((obj) != NULL) \
+ { \
+ V0((obj),Destruct)(); \
+ V0((obj),Delete)(); \
+ } \
+} while(0)
+
+
+/* Helper to get a type's vtable thunk for a child type. */
+#define GET_VTABLE2(T1, T2) (&(T1##_##T2##_vtable))
+/* Helper to set an object's vtable thunk for a child type. Used when constructing an object. */
+#define SET_VTABLE2(T1, T2, obj) (STATIC_CAST(T2, obj)->vtbl = GET_VTABLE2(T1, T2))
+
+#endif /* POLYMORPHISM_H */
diff --git a/Alc/ringbuffer.c b/Alc/ringbuffer.c
new file mode 100644
index 00000000..6c419cf8
--- /dev/null
+++ b/Alc/ringbuffer.c
@@ -0,0 +1,295 @@
+/**
+ * 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 <limits.h>
+
+#include "ringbuffer.h"
+#include "align.h"
+#include "atomic.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 {
+ ATOMIC(size_t) write_ptr;
+ ATOMIC(size_t) read_ptr;
+ size_t size;
+ size_t size_mask;
+ size_t elem_size;
+
+ alignas(16) char buf[];
+};
+
+ll_ringbuffer_t *ll_ringbuffer_create(size_t sz, size_t elem_sz, int limit_writes)
+{
+ ll_ringbuffer_t *rb;
+ size_t power_of_two = 0;
+
+ if(sz > 0)
+ {
+ power_of_two = sz;
+ power_of_two |= power_of_two>>1;
+ power_of_two |= power_of_two>>2;
+ power_of_two |= power_of_two>>4;
+ power_of_two |= power_of_two>>8;
+ power_of_two |= power_of_two>>16;
+#if SIZE_MAX > UINT_MAX
+ power_of_two |= power_of_two>>32;
+#endif
+ }
+ power_of_two++;
+ if(power_of_two < sz) return NULL;
+
+ rb = al_malloc(16, sizeof(*rb) + power_of_two*elem_sz);
+ if(!rb) return NULL;
+
+ ATOMIC_INIT(&rb->write_ptr, 0);
+ ATOMIC_INIT(&rb->read_ptr, 0);
+ rb->size = limit_writes ? sz : power_of_two;
+ rb->size_mask = power_of_two - 1;
+ rb->elem_size = elem_sz;
+ return rb;
+}
+
+void ll_ringbuffer_free(ll_ringbuffer_t *rb)
+{
+ al_free(rb);
+}
+
+void ll_ringbuffer_reset(ll_ringbuffer_t *rb)
+{
+ ATOMIC_STORE(&rb->write_ptr, 0, almemory_order_release);
+ ATOMIC_STORE(&rb->read_ptr, 0, almemory_order_release);
+ memset(rb->buf, 0, (rb->size_mask+1)*rb->elem_size);
+}
+
+
+size_t ll_ringbuffer_read_space(const ll_ringbuffer_t *rb)
+{
+ size_t w = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->write_ptr, almemory_order_acquire);
+ size_t r = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->read_ptr, almemory_order_acquire);
+ return (w-r) & rb->size_mask;
+}
+
+size_t ll_ringbuffer_write_space(const ll_ringbuffer_t *rb)
+{
+ size_t w = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->write_ptr, almemory_order_acquire);
+ size_t r = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->read_ptr, almemory_order_acquire);
+ w = (r-w-1) & rb->size_mask;
+ return (w > rb->size) ? rb->size : w;
+}
+
+
+size_t ll_ringbuffer_read(ll_ringbuffer_t *rb, char *dest, size_t cnt)
+{
+ size_t read_ptr;
+ 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;
+ read_ptr = ATOMIC_LOAD(&rb->read_ptr, almemory_order_relaxed) & rb->size_mask;
+
+ cnt2 = read_ptr + to_read;
+ if(cnt2 > rb->size_mask+1)
+ {
+ n1 = rb->size_mask+1 - read_ptr;
+ n2 = cnt2 & rb->size_mask;
+ }
+ else
+ {
+ n1 = to_read;
+ n2 = 0;
+ }
+
+ memcpy(dest, &rb->buf[read_ptr*rb->elem_size], n1*rb->elem_size);
+ read_ptr += n1;
+ if(n2)
+ {
+ memcpy(dest + n1*rb->elem_size, &rb->buf[(read_ptr&rb->size_mask)*rb->elem_size],
+ n2*rb->elem_size);
+ read_ptr += n2;
+ }
+ ATOMIC_STORE(&rb->read_ptr, read_ptr, almemory_order_release);
+ return to_read;
+}
+
+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 read_ptr;
+
+ free_cnt = ll_ringbuffer_read_space(rb);
+ if(free_cnt == 0) return 0;
+
+ to_read = (cnt > free_cnt) ? free_cnt : cnt;
+ read_ptr = ATOMIC_LOAD(&rb->read_ptr, almemory_order_relaxed) & rb->size_mask;
+
+ cnt2 = read_ptr + to_read;
+ if(cnt2 > rb->size_mask+1)
+ {
+ n1 = rb->size_mask+1 - read_ptr;
+ n2 = cnt2 & rb->size_mask;
+ }
+ else
+ {
+ n1 = to_read;
+ n2 = 0;
+ }
+
+ memcpy(dest, &rb->buf[read_ptr*rb->elem_size], n1*rb->elem_size);
+ if(n2)
+ {
+ read_ptr += n1;
+ memcpy(dest + n1*rb->elem_size, &rb->buf[(read_ptr&rb->size_mask)*rb->elem_size],
+ n2*rb->elem_size);
+ }
+ return to_read;
+}
+
+size_t ll_ringbuffer_write(ll_ringbuffer_t *rb, const char *src, size_t cnt)
+{
+ size_t write_ptr;
+ 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;
+ write_ptr = ATOMIC_LOAD(&rb->write_ptr, almemory_order_relaxed) & rb->size_mask;
+
+ cnt2 = write_ptr + to_write;
+ if(cnt2 > rb->size_mask+1)
+ {
+ n1 = rb->size_mask+1 - write_ptr;
+ n2 = cnt2 & rb->size_mask;
+ }
+ else
+ {
+ n1 = to_write;
+ n2 = 0;
+ }
+
+ memcpy(&rb->buf[write_ptr*rb->elem_size], src, n1*rb->elem_size);
+ write_ptr += n1;
+ if(n2)
+ {
+ memcpy(&rb->buf[(write_ptr&rb->size_mask)*rb->elem_size], src + n1*rb->elem_size,
+ n2*rb->elem_size);
+ write_ptr += n2;
+ }
+ ATOMIC_STORE(&rb->write_ptr, write_ptr, almemory_order_release);
+ return to_write;
+}
+
+
+void ll_ringbuffer_read_advance(ll_ringbuffer_t *rb, size_t cnt)
+{
+ ATOMIC_ADD(&rb->read_ptr, cnt, almemory_order_acq_rel);
+}
+
+void ll_ringbuffer_write_advance(ll_ringbuffer_t *rb, size_t cnt)
+{
+ ATOMIC_ADD(&rb->write_ptr, cnt, almemory_order_acq_rel);
+}
+
+
+void ll_ringbuffer_get_read_vector(const ll_ringbuffer_t *rb, ll_ringbuffer_data_t vec[2])
+{
+ size_t free_cnt;
+ size_t cnt2;
+ size_t w, r;
+
+ w = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->write_ptr, almemory_order_acquire);
+ r = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->read_ptr, almemory_order_acquire);
+ w &= rb->size_mask;
+ r &= rb->size_mask;
+ free_cnt = (w-r) & rb->size_mask;
+
+ cnt2 = r + free_cnt;
+ if(cnt2 > rb->size_mask+1)
+ {
+ /* 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_mask+1 - 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;
+ }
+}
+
+void ll_ringbuffer_get_write_vector(const ll_ringbuffer_t *rb, ll_ringbuffer_data_t vec[2])
+{
+ size_t free_cnt;
+ size_t cnt2;
+ size_t w, r;
+
+ w = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->write_ptr, almemory_order_acquire);
+ r = ATOMIC_LOAD(&CONST_CAST(ll_ringbuffer_t*,rb)->read_ptr, almemory_order_acquire);
+ w &= rb->size_mask;
+ r &= rb->size_mask;
+ free_cnt = (r-w-1) & rb->size_mask;
+ if(free_cnt > rb->size) free_cnt = rb->size;
+
+ cnt2 = w + free_cnt;
+ if(cnt2 > rb->size_mask+1)
+ {
+ /* 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_mask+1 - 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;
+ }
+}
diff --git a/Alc/ringbuffer.h b/Alc/ringbuffer.h
new file mode 100644
index 00000000..0d05ec84
--- /dev/null
+++ b/Alc/ringbuffer.h
@@ -0,0 +1,77 @@
+#ifndef RINGBUFFER_H
+#define RINGBUFFER_H
+
+#include <stddef.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct ll_ringbuffer ll_ringbuffer_t;
+typedef struct ll_ringbuffer_data {
+ char *buf;
+ size_t len;
+} ll_ringbuffer_data_t;
+
+
+/**
+ * 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 (even if it is
+ * already a power of two, to ensure the requested amount can be written).
+ */
+ll_ringbuffer_t *ll_ringbuffer_create(size_t sz, size_t elem_sz, int limit_writes);
+/** Free all data associated with the ringbuffer `rb'. */
+void ll_ringbuffer_free(ll_ringbuffer_t *rb);
+/** Reset the read and write pointers to zero. This is not thread safe. */
+void ll_ringbuffer_reset(ll_ringbuffer_t *rb);
+
+/**
+ * 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[2]);
+/**
+ * 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[2]);
+
+/**
+ * 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);
+/**
+ * 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);
+/**
+ * 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);
+/** Advance the read pointer `cnt' places. */
+void ll_ringbuffer_read_advance(ll_ringbuffer_t *rb, size_t cnt);
+
+/**
+ * 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);
+/**
+ * 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);
+/** Advance the write pointer `cnt' places. */
+void ll_ringbuffer_write_advance(ll_ringbuffer_t *rb, size_t cnt);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* RINGBUFFER_H */
diff --git a/Alc/uhjfilter.c b/Alc/uhjfilter.c
new file mode 100644
index 00000000..42b0bc40
--- /dev/null
+++ b/Alc/uhjfilter.c
@@ -0,0 +1,120 @@
+
+#include "config.h"
+
+#include "alu.h"
+#include "uhjfilter.h"
+
+/* This is the maximum number of samples processed for each inner loop
+ * iteration. */
+#define MAX_UPDATE_SAMPLES 128
+
+
+static const ALfloat Filter1CoeffSqr[4] = {
+ 0.479400865589f, 0.876218493539f, 0.976597589508f, 0.997499255936f
+};
+static const ALfloat Filter2CoeffSqr[4] = {
+ 0.161758498368f, 0.733028932341f, 0.945349700329f, 0.990599156685f
+};
+
+static void allpass_process(AllPassState *state, ALfloat *restrict dst, const ALfloat *restrict src, const ALfloat aa, ALsizei todo)
+{
+ ALfloat z1 = state->z[0];
+ ALfloat z2 = state->z[1];
+ ALsizei i;
+
+ for(i = 0;i < todo;i++)
+ {
+ ALfloat input = src[i];
+ ALfloat output = input*aa + z1;
+ z1 = z2; z2 = output*aa - input;
+ dst[i] = output;
+ }
+
+ state->z[0] = z1;
+ state->z[1] = z2;
+}
+
+
+/* NOTE: There seems to be a bit of an inconsistency in how this encoding is
+ * supposed to work. Some references, such as
+ *
+ * http://members.tripod.com/martin_leese/Ambisonic/UHJ_file_format.html
+ *
+ * specify a pre-scaling of sqrt(2) on the W channel input, while other
+ * references, such as
+ *
+ * https://en.wikipedia.org/wiki/Ambisonic_UHJ_format#Encoding.5B1.5D
+ * and
+ * https://wiki.xiph.org/Ambisonics#UHJ_format
+ *
+ * do not. The sqrt(2) scaling is in line with B-Format decoder coefficients
+ * which include such a scaling for the W channel input, however the original
+ * source for this equation is a 1985 paper by Michael Gerzon, which does not
+ * apparently include the scaling. Applying the extra scaling creates a louder
+ * result with a narrower stereo image compared to not scaling, and I don't
+ * know which is the intended result.
+ */
+
+void EncodeUhj2(Uhj2Encoder *enc, ALfloat *restrict LeftOut, ALfloat *restrict RightOut, ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo)
+{
+ ALfloat D[MAX_UPDATE_SAMPLES], S[MAX_UPDATE_SAMPLES];
+ ALfloat temp[2][MAX_UPDATE_SAMPLES];
+ ALsizei base, i;
+
+ ASSUME(SamplesToDo > 0);
+
+ for(base = 0;base < SamplesToDo;)
+ {
+ ALsizei todo = mini(SamplesToDo - base, MAX_UPDATE_SAMPLES);
+ ASSUME(todo > 0);
+
+ /* D = 0.6554516*Y */
+ for(i = 0;i < todo;i++)
+ temp[0][i] = 0.6554516f*InSamples[2][base+i];
+ allpass_process(&enc->Filter1_Y[0], temp[1], temp[0], Filter1CoeffSqr[0], todo);
+ allpass_process(&enc->Filter1_Y[1], temp[0], temp[1], Filter1CoeffSqr[1], todo);
+ allpass_process(&enc->Filter1_Y[2], temp[1], temp[0], Filter1CoeffSqr[2], todo);
+ allpass_process(&enc->Filter1_Y[3], temp[0], temp[1], Filter1CoeffSqr[3], todo);
+ /* NOTE: Filter1 requires a 1 sample delay for the final output, so
+ * take the last processed sample from the previous run as the first
+ * output sample.
+ */
+ D[0] = enc->LastY;
+ for(i = 1;i < todo;i++)
+ D[i] = temp[0][i-1];
+ enc->LastY = temp[0][i-1];
+
+ /* D += j(-0.3420201*W + 0.5098604*X) */
+ for(i = 0;i < todo;i++)
+ temp[0][i] = -0.3420201f*InSamples[0][base+i] +
+ 0.5098604f*InSamples[1][base+i];
+ allpass_process(&enc->Filter2_WX[0], temp[1], temp[0], Filter2CoeffSqr[0], todo);
+ allpass_process(&enc->Filter2_WX[1], temp[0], temp[1], Filter2CoeffSqr[1], todo);
+ allpass_process(&enc->Filter2_WX[2], temp[1], temp[0], Filter2CoeffSqr[2], todo);
+ allpass_process(&enc->Filter2_WX[3], temp[0], temp[1], Filter2CoeffSqr[3], todo);
+ for(i = 0;i < todo;i++)
+ D[i] += temp[0][i];
+
+ /* S = 0.9396926*W + 0.1855740*X */
+ for(i = 0;i < todo;i++)
+ temp[0][i] = 0.9396926f*InSamples[0][base+i] +
+ 0.1855740f*InSamples[1][base+i];
+ allpass_process(&enc->Filter1_WX[0], temp[1], temp[0], Filter1CoeffSqr[0], todo);
+ allpass_process(&enc->Filter1_WX[1], temp[0], temp[1], Filter1CoeffSqr[1], todo);
+ allpass_process(&enc->Filter1_WX[2], temp[1], temp[0], Filter1CoeffSqr[2], todo);
+ allpass_process(&enc->Filter1_WX[3], temp[0], temp[1], Filter1CoeffSqr[3], todo);
+ S[0] = enc->LastWX;
+ for(i = 1;i < todo;i++)
+ S[i] = temp[0][i-1];
+ enc->LastWX = temp[0][i-1];
+
+ /* Left = (S + D)/2.0 */
+ for(i = 0;i < todo;i++)
+ *(LeftOut++) += (S[i] + D[i]) * 0.5f;
+ /* Right = (S - D)/2.0 */
+ for(i = 0;i < todo;i++)
+ *(RightOut++) += (S[i] - D[i]) * 0.5f;
+
+ base += todo;
+ }
+}
diff --git a/Alc/uhjfilter.h b/Alc/uhjfilter.h
new file mode 100644
index 00000000..e773e0a7
--- /dev/null
+++ b/Alc/uhjfilter.h
@@ -0,0 +1,49 @@
+#ifndef UHJFILTER_H
+#define UHJFILTER_H
+
+#include "AL/al.h"
+
+#include "alMain.h"
+
+typedef struct AllPassState {
+ ALfloat z[2];
+} AllPassState;
+
+/* Encoding 2-channel UHJ from B-Format is done as:
+ *
+ * S = 0.9396926*W + 0.1855740*X
+ * D = j(-0.3420201*W + 0.5098604*X) + 0.6554516*Y
+ *
+ * Left = (S + D)/2.0
+ * Right = (S - D)/2.0
+ *
+ * where j is a wide-band +90 degree phase shift.
+ *
+ * The phase shift is done using a Hilbert transform, described here:
+ * https://web.archive.org/web/20060708031958/http://www.biochem.oulu.fi/~oniemita/dsp/hilbert/
+ * It works using 2 sets of 4 chained filters. The first filter chain produces
+ * a phase shift of varying magnitude over a wide range of frequencies, while
+ * the second filter chain produces a phase shift 90 degrees ahead of the
+ * first over the same range.
+ *
+ * Combining these two stages requires the use of three filter chains. S-
+ * channel output uses a Filter1 chain on the W and X channel mix, while the D-
+ * channel output uses a Filter1 chain on the Y channel plus a Filter2 chain on
+ * the W and X channel mix. This results in the W and X input mix on the D-
+ * channel output having the required +90 degree phase shift relative to the
+ * other inputs.
+ */
+
+typedef struct Uhj2Encoder {
+ AllPassState Filter1_Y[4];
+ AllPassState Filter2_WX[4];
+ AllPassState Filter1_WX[4];
+ ALfloat LastY, LastWX;
+} Uhj2Encoder;
+
+/* Encodes a 2-channel UHJ (stereo-compatible) signal from a B-Format input
+ * signal. The input must use FuMa channel ordering and scaling.
+ */
+void EncodeUhj2(Uhj2Encoder *enc, ALfloat *restrict LeftOut, ALfloat *restrict RightOut, ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo);
+
+#endif /* UHJFILTER_H */
diff --git a/Alc/vector.h b/Alc/vector.h
index c1fc925d..ed9acfb0 100644
--- a/Alc/vector.h
+++ b/Alc/vector.h
@@ -5,11 +5,8 @@
#include <AL/al.h>
-/* "Base" vector type, designed to alias with the actual vector types. */
-typedef struct vector__s {
- size_t Capacity;
- size_t Size;
-} *vector_;
+#include "almalloc.h"
+
#define TYPEDEF_VECTOR(T, N) typedef struct { \
size_t Capacity; \
@@ -27,38 +24,48 @@ typedef const _##N* const_##N;
#define VECTOR_INIT(_x) do { (_x) = NULL; } while(0)
#define VECTOR_INIT_STATIC() NULL
-#define VECTOR_DEINIT(_x) do { free((_x)); (_x) = NULL; } while(0)
-
-/* Helper to increase a vector's reserve. Do not call directly. */
-ALboolean vector_reserve(char *ptr, size_t base_size, size_t obj_size, size_t obj_count, ALboolean exact);
-#define VECTOR_RESERVE(_x, _c) (vector_reserve((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_c), AL_TRUE))
-
-ALboolean vector_resize(char *ptr, size_t base_size, size_t obj_size, size_t obj_count);
-#define VECTOR_RESIZE(_x, _c) (vector_resize((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_c)))
+#define VECTOR_DEINIT(_x) do { al_free((_x)); (_x) = NULL; } while(0)
+
+#define VECTOR_RESIZE(_x, _s, _c) do { \
+ size_t _size = (_s); \
+ size_t _cap = (_c); \
+ if(_size > _cap) \
+ _cap = _size; \
+ \
+ if(!(_x) && _cap == 0) \
+ break; \
+ \
+ if(((_x) ? (_x)->Capacity : 0) < _cap) \
+ { \
+ ptrdiff_t data_offset = (_x) ? (char*)((_x)->Data) - (char*)(_x) : \
+ sizeof(*(_x)); \
+ size_t old_size = ((_x) ? (_x)->Size : 0); \
+ void *temp; \
+ \
+ temp = al_calloc(16, data_offset + sizeof((_x)->Data[0])*_cap); \
+ assert(temp != NULL); \
+ if((_x)) \
+ memcpy(((char*)temp)+data_offset, (_x)->Data, \
+ sizeof((_x)->Data[0])*old_size); \
+ \
+ al_free((_x)); \
+ (_x) = temp; \
+ (_x)->Capacity = _cap; \
+ } \
+ (_x)->Size = _size; \
+} while(0) \
#define VECTOR_CAPACITY(_x) ((_x) ? (_x)->Capacity : 0)
#define VECTOR_SIZE(_x) ((_x) ? (_x)->Size : 0)
-#define VECTOR_ITER_BEGIN(_x) ((_x) ? (_x)->Data + 0 : NULL)
-#define VECTOR_ITER_END(_x) ((_x) ? (_x)->Data + (_x)->Size : NULL)
-
-ALboolean vector_insert(char *ptr, size_t base_size, size_t obj_size, void *ins_pos, const void *datstart, const void *datend);
-#ifdef __GNUC__
-#define TYPE_CHECK(T1, T2) __builtin_types_compatible_p(T1, T2)
-#define VECTOR_INSERT(_x, _i, _s, _e) __extension__({ \
- ALboolean _r; \
- static_assert(TYPE_CHECK(__typeof((_x)->Data[0]), __typeof(*(_i))), "Incompatible insertion iterator"); \
- static_assert(TYPE_CHECK(__typeof((_x)->Data[0]), __typeof(*(_s))), "Incompatible insertion source type"); \
- static_assert(TYPE_CHECK(__typeof(*(_s)), __typeof(*(_e))), "Incompatible iterator sources"); \
- _r = vector_insert((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i), (_s), (_e)); \
- _r; \
-})
-#else
-#define VECTOR_INSERT(_x, _i, _s, _e) (vector_insert((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), (_i), (_s), (_e)))
-#endif
-
-#define VECTOR_PUSH_BACK(_x, _obj) (vector_reserve((char*)&(_x), sizeof(*(_x)), sizeof((_x)->Data[0]), VECTOR_SIZE(_x)+1, AL_FALSE) && \
- (((_x)->Data[(_x)->Size++] = (_obj)),AL_TRUE))
+#define VECTOR_BEGIN(_x) ((_x) ? (_x)->Data + 0 : NULL)
+#define VECTOR_END(_x) ((_x) ? (_x)->Data + (_x)->Size : NULL)
+
+#define VECTOR_PUSH_BACK(_x, _obj) do { \
+ size_t _pbsize = VECTOR_SIZE(_x)+1; \
+ VECTOR_RESIZE(_x, _pbsize, _pbsize); \
+ (_x)->Data[(_x)->Size-1] = (_obj); \
+} while(0)
#define VECTOR_POP_BACK(_x) ((void)((_x)->Size--))
#define VECTOR_BACK(_x) ((_x)->Data[(_x)->Size-1])
@@ -67,22 +74,15 @@ ALboolean vector_insert(char *ptr, size_t base_size, size_t obj_size, void *ins_
#define VECTOR_ELEM(_x, _o) ((_x)->Data[(_o)])
#define VECTOR_FOR_EACH(_t, _x, _f) do { \
- _t *_iter = VECTOR_ITER_BEGIN((_x)); \
- _t *_end = VECTOR_ITER_END((_x)); \
+ _t *_iter = VECTOR_BEGIN((_x)); \
+ _t *_end = VECTOR_END((_x)); \
for(;_iter != _end;++_iter) \
_f(_iter); \
} while(0)
-#define VECTOR_FOR_EACH_PARAMS(_t, _x, _f, ...) do { \
- _t *_iter = VECTOR_ITER_BEGIN((_x)); \
- _t *_end = VECTOR_ITER_END((_x)); \
- for(;_iter != _end;++_iter) \
- _f(__VA_ARGS__, _iter); \
-} while(0)
-
#define VECTOR_FIND_IF(_i, _t, _x, _f) do { \
- _t *_iter = VECTOR_ITER_BEGIN((_x)); \
- _t *_end = VECTOR_ITER_END((_x)); \
+ _t *_iter = VECTOR_BEGIN((_x)); \
+ _t *_end = VECTOR_END((_x)); \
for(;_iter != _end;++_iter) \
{ \
if(_f(_iter)) \
@@ -91,15 +91,4 @@ ALboolean vector_insert(char *ptr, size_t base_size, size_t obj_size, void *ins_
(_i) = _iter; \
} while(0)
-#define VECTOR_FIND_IF_PARMS(_i, _t, _x, _f, ...) do { \
- _t *_iter = VECTOR_ITER_BEGIN((_x)); \
- _t *_end = VECTOR_ITER_END((_x)); \
- for(;_iter != _end;++_iter) \
- { \
- if(_f(__VA_ARGS__, _iter)) \
- break; \
- } \
- (_i) = _iter; \
-} while(0)
-
#endif /* AL_VECTOR_H */
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ae6586a3..984ec821 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,12 +1,21 @@
# CMake build file list for OpenAL
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+CMAKE_MINIMUM_REQUIRED(VERSION 3.0.2)
PROJECT(OpenAL)
IF(COMMAND CMAKE_POLICY)
- CMAKE_POLICY(SET CMP0003 NEW)
- CMAKE_POLICY(SET CMP0005 NEW)
+ CMAKE_POLICY(SET CMP0003 NEW)
+ CMAKE_POLICY(SET CMP0005 NEW)
+ IF(POLICY CMP0020)
+ CMAKE_POLICY(SET CMP0020 NEW)
+ ENDIF(POLICY CMP0020)
+ IF(POLICY CMP0042)
+ CMAKE_POLICY(SET CMP0042 NEW)
+ ENDIF(POLICY CMP0042)
+ IF(POLICY CMP0054)
+ CMAKE_POLICY(SET CMP0054 NEW)
+ ENDIF(POLICY CMP0054)
ENDIF(COMMAND CMAKE_POLICY)
SET(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
@@ -18,10 +27,12 @@ INCLUDE(CheckIncludeFile)
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckSymbolExists)
INCLUDE(CheckCCompilerFlag)
+INCLUDE(CheckCXXCompilerFlag)
INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckTypeSize)
+include(CheckStructHasMember)
include(CheckFileOffsetBits)
-
+include(GNUInstallDirs)
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
@@ -38,12 +49,29 @@ OPTION(ALSOFT_TESTS "Build and install test programs" ON)
OPTION(ALSOFT_CONFIG "Install alsoft.conf sample configuration file" ON)
OPTION(ALSOFT_HRTF_DEFS "Install HRTF definition files" ON)
+OPTION(ALSOFT_AMBDEC_PRESETS "Install AmbDec preset files" ON)
OPTION(ALSOFT_INSTALL "Install headers and libraries" ON)
+if(DEFINED SHARE_INSTALL_DIR)
+ message(WARNING "SHARE_INSTALL_DIR is deprecated. Use the variables provided by the GNUInstallDirs module instead")
+ set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
+endif()
+
+if(DEFINED LIB_SUFFIX)
+ message(WARNING "LIB_SUFFIX is deprecated. Use the variables provided by the GNUInstallDirs module instead")
+endif()
+
+
+SET(CPP_DEFS ) # C pre-process, not C++
+SET(INC_PATHS )
+SET(C_FLAGS )
+SET(LINKER_FLAGS )
+SET(EXTRA_LIBS )
IF(WIN32)
- SET(LIBNAME OpenAL32)
- ADD_DEFINITIONS("-D_WIN32 -D_WIN32_WINNT=0x0502")
+ SET(CPP_DEFS ${CPP_DEFS} _WIN32 _WIN32_WINNT=0x0502)
+
+ OPTION(ALSOFT_BUILD_ROUTER "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)" OFF)
# This option is mainly for static linking OpenAL Soft into another project
# that already defines the IDs. It is up to that project to ensure all
@@ -60,28 +88,13 @@ IF(WIN32)
ENDIF()
ENDIF()
ENDIF()
-ELSE()
- SET(LIBNAME openal)
-
- # These are needed on non-Windows systems for extra features
- ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700)
- SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_GNU_SOURCE=1 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700")
ENDIF()
-# Set defines for large file support
-CHECK_FILE_OFFSET_BITS()
-IF(_FILE_OFFSET_BITS)
- ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS})
- SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
-ENDIF()
-ADD_DEFINITIONS(-D_LARGEFILE_SOURCE -D_LARGE_FILES)
-SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_LARGEFILE_SOURCE -D_LARGE_FILES")
-
# QNX's gcc do not uses /usr/include and /usr/lib pathes by default
IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
- ADD_DEFINITIONS("-I/usr/include")
- SET(EXTRA_LIBS ${EXTRA_LIBS} -L/usr/lib)
+ SET(INC_PATHS ${INC_PATHS} /usr/include)
+ SET(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
ENDIF()
IF(NOT LIBTYPE)
@@ -89,8 +102,8 @@ IF(NOT LIBTYPE)
ENDIF()
SET(LIB_MAJOR_VERSION "1")
-SET(LIB_MINOR_VERSION "17")
-SET(LIB_REVISION "0")
+SET(LIB_MINOR_VERSION "19")
+SET(LIB_REVISION "1")
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
SET(EXPORT_DECL "")
@@ -114,6 +127,36 @@ ELSE()
ENDIF()
ENDIF()
+CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD_CXX11)
+IF(HAVE_STD_CXX11)
+ SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
+ENDIF()
+
+if(NOT WIN32)
+ # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
+ CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
+ IF(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
+ SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
+ SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
+ CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
+ IF(NOT HAVE_POSIX_MEMALIGN_POSIX)
+ SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
+ ELSE()
+ SET(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
+ ENDIF()
+ ENDIF()
+ UNSET(OLD_REQUIRED_FLAGS)
+ENDIF()
+
+# Set defines for large file support
+CHECK_FILE_OFFSET_BITS()
+IF(_FILE_OFFSET_BITS)
+ SET(CPP_DEFS ${CPP_DEFS} "_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
+ SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
+ENDIF()
+SET(CPP_DEFS ${CPP_DEFS} _LARGEFILE_SOURCE _LARGE_FILES)
+SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_LARGEFILE_SOURCE -D_LARGE_FILES")
+
# MSVC may need workarounds for C99 restrict and inline
IF(MSVC)
# TODO: Once we truly require C99, these restrict and inline checks should go
@@ -121,7 +164,7 @@ IF(MSVC)
CHECK_C_SOURCE_COMPILES("int *restrict foo;
int main() {return 0;}" HAVE_RESTRICT)
IF(NOT HAVE_RESTRICT)
- ADD_DEFINITIONS("-Drestrict=")
+ SET(CPP_DEFS ${CPP_DEFS} "restrict=")
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Drestrict=")
ENDIF()
@@ -134,13 +177,15 @@ IF(MSVC)
MESSAGE(FATAL_ERROR "No inline keyword found, please report!")
ENDIF()
- ADD_DEFINITIONS(-Dinline=__inline)
+ SET(CPP_DEFS ${CPP_DEFS} inline=__inline)
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
ENDIF()
ENDIF()
# Make sure we have C99-style inline semantics with GCC (4.3 or newer).
IF(CMAKE_COMPILER_IS_GNUCC)
+ SET(CMAKE_C_FLAGS "-fno-gnu89-inline ${CMAKE_C_FLAGS}")
+
SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
# Force no inlining for the next test.
SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -fno-inline")
@@ -155,15 +200,36 @@ IF(CMAKE_COMPILER_IS_GNUCC)
SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
ENDIF()
-# Check if we have C99 variable length arrays
-CHECK_C_SOURCE_COMPILES(
-"int main(int argc, char *argv[])
- {
- volatile int tmp[argc];
- tmp[0] = argv[0][0];
- return tmp[0];
- }"
-HAVE_C99_VLA)
+# Check if we have a proper timespec declaration
+CHECK_STRUCT_HAS_MEMBER("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC)
+IF(HAVE_STRUCT_TIMESPEC)
+ # Define it here so we don't have to include config.h for it
+ SET(CPP_DEFS ${CPP_DEFS} HAVE_STRUCT_TIMESPEC)
+ENDIF()
+
+# Some systems may need libatomic for C11 atomic functions to work
+SET(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+SET(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
+CHECK_C_SOURCE_COMPILES("#include <stdatomic.h>
+int _Atomic foo = ATOMIC_VAR_INIT(0);
+int main()
+{
+ return atomic_fetch_add(&foo, 2);
+}"
+HAVE_LIBATOMIC)
+IF(NOT HAVE_LIBATOMIC)
+ SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
+ELSE()
+ SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
+ENDIF()
+UNSET(OLD_REQUIRED_LIBRARIES)
+
+# Include liblog for Android logging
+CHECK_LIBRARY_EXISTS(log __android_log_print "" HAVE_LIBLOG)
+IF(HAVE_LIBLOG)
+ SET(EXTRA_LIBS log ${EXTRA_LIBS})
+ SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
+ENDIF()
# Check if we have C99 bool
CHECK_C_SOURCE_COMPILES(
@@ -196,21 +262,16 @@ HAVE_C11_ALIGNAS)
# Check if we have C11 _Atomic
CHECK_C_SOURCE_COMPILES(
"#include <stdatomic.h>
- const int _Atomic foo = ATOMIC_VAR_INIT(~0);
+ int _Atomic foo = ATOMIC_VAR_INIT(0);
int main()
{
- return atomic_load(&foo);
+ atomic_fetch_add(&foo, 2);
+ return 0;
}"
HAVE_C11_ATOMIC)
# Add definitions, compiler switches, etc.
-INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_BINARY_DIR}")
-IF(CMAKE_VERSION VERSION_LESS "2.8.8")
- INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
- IF(WIN32 AND ALSOFT_NO_UID_DEFS)
- ADD_DEFINITIONS("-DAL_NO_UID_DEFS")
- ENDIF()
-ENDIF()
+INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_SOURCE_DIR}/common" "${OpenAL_BINARY_DIR}")
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
@@ -224,9 +285,8 @@ IF(NOT CMAKE_DEBUG_POSTFIX)
ENDIF()
IF(MSVC)
- ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
- ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
- ADD_DEFINITIONS("/wd4098")
+ SET(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
+ SET(C_FLAGS ${C_FLAGS} /wd4098)
IF(NOT DXSDK_DIR)
STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
@@ -248,25 +308,14 @@ IF(MSVC)
ENDFOREACH(flag_var)
ENDIF()
ELSE()
- ADD_DEFINITIONS(-Winline -Wall)
+ SET(C_FLAGS ${C_FLAGS} -Winline -Wall)
CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
IF(HAVE_W_EXTRA)
- ADD_DEFINITIONS(-Wextra)
+ SET(C_FLAGS ${C_FLAGS} -Wextra)
ENDIF()
IF(ALSOFT_WERROR)
- ADD_DEFINITIONS(-Werror)
- ENDIF()
-
- # Force enable -fPIC for CMake versions before 2.8.9 (later versions have
- # the POSITION_INDEPENDENT_CODE target property). The static common library
- # will be linked into the dynamic openal library, which requires all its
- # code to be position-independent.
- IF(CMAKE_VERSION VERSION_LESS "2.8.9" AND NOT WIN32)
- CHECK_C_COMPILER_FLAG(-fPIC HAVE_FPIC_SWITCH)
- IF(HAVE_FPIC_SWITCH)
- ADD_DEFINITIONS(-fPIC)
- ENDIF()
+ SET(C_FLAGS ${C_FLAGS} -Werror)
ENDIF()
# We want RelWithDebInfo to actually include debug stuff (define _DEBUG
@@ -277,8 +326,32 @@ ELSE()
ENDIF()
ENDFOREACH()
+ CHECK_C_COMPILER_FLAG(-fno-math-errno HAVE_FNO_MATH_ERRNO)
+ IF(HAVE_FNO_MATH_ERRNO)
+ SET(C_FLAGS ${C_FLAGS} -fno-math-errno)
+ ENDIF()
+
CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
+
+ option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
+ if(ALSOFT_STATIC_LIBGCC)
+ set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
+ set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
+ check_c_source_compiles(
+"#include <stdlib.h>
+int main()
+{
+ return 0;
+}"
+ HAVE_STATIC_LIBGCC_SWITCH
+ )
+ if(HAVE_STATIC_LIBGCC_SWITCH)
+ SET(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
+ endif()
+ set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
+ unset(OLD_REQUIRED_LIBRARIES)
+ endif()
ENDIF()
# Set visibility/export options if available
@@ -309,7 +382,7 @@ ELSE()
IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
- ADD_DEFINITIONS(-fvisibility=hidden)
+ SET(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
ENDIF()
ENDIF()
@@ -322,28 +395,88 @@ ELSE()
SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
ENDIF()
+CHECK_C_SOURCE_COMPILES("
+int main()
+{
+ float *ptr;
+ ptr = __builtin_assume_aligned(ptr, 16);
+ return 0;
+}" HAVE___BUILTIN_ASSUME_ALIGNED)
+IF(HAVE___BUILTIN_ASSUME_ALIGNED)
+ SET(ASSUME_ALIGNED_DECL "__builtin_assume_aligned(x, y)")
+ELSE()
+ SET(ASSUME_ALIGNED_DECL "(x)")
+ENDIF()
+
SET(SSE_SWITCH "")
SET(SSE2_SWITCH "")
+SET(SSE3_SWITCH "")
SET(SSE4_1_SWITCH "")
-IF(NOT MSVC)
- CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
- IF(HAVE_MSSE_SWITCH)
- SET(SSE_SWITCH "-msse")
+SET(FPU_NEON_SWITCH "")
+
+CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
+IF(HAVE_MSSE_SWITCH)
+ SET(SSE_SWITCH "-msse")
+ENDIF()
+CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
+IF(HAVE_MSSE2_SWITCH)
+ SET(SSE2_SWITCH "-msse2")
+ENDIF()
+CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
+IF(HAVE_MSSE3_SWITCH)
+ SET(SSE3_SWITCH "-msse3")
+ENDIF()
+CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
+IF(HAVE_MSSE4_1_SWITCH)
+ SET(SSE4_1_SWITCH "-msse4.1")
+ENDIF()
+CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
+IF(HAVE_MFPU_NEON_SWITCH)
+ SET(FPU_NEON_SWITCH "-mfpu=neon")
+ENDIF()
+
+SET(FPMATH_SET "0")
+IF(CMAKE_SIZEOF_VOID_P MATCHES "4")
+ IF(SSE_SWITCH OR MSVC)
+ OPTION(ALSOFT_ENABLE_SSE_CODEGEN "Enable SSE code generation instead of x87 for 32-bit targets." TRUE)
ENDIF()
- CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
- IF(HAVE_MSSE2_SWITCH)
- SET(SSE2_SWITCH "-msse2")
+ IF(SSE2_SWITCH OR MSVC)
+ OPTION(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
ENDIF()
- CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
- IF(HAVE_MSSE3_SWITCH)
- SET(SSE3_SWITCH "-msse3")
+
+ IF(ALSOFT_ENABLE_SSE2_CODEGEN)
+ IF(SSE2_SWITCH)
+ CHECK_C_COMPILER_FLAG("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
+ IF(HAVE_MFPMATH_SSE_2)
+ SET(C_FLAGS ${C_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
+ SET(FPMATH_SET 2)
+ ENDIF()
+ ELSEIF(MSVC)
+ CHECK_C_COMPILER_FLAG("/arch:SSE2" HAVE_ARCH_SSE2)
+ IF(HAVE_ARCH_SSE2)
+ SET(C_FLAGS ${C_FLAGS} "/arch:SSE2")
+ SET(FPMATH_SET 2)
+ ENDIF()
+ ENDIF()
ENDIF()
- CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
- IF(HAVE_MSSE4_1_SWITCH)
- SET(SSE4_1_SWITCH "-msse4.1")
+ IF(ALSOFT_ENABLE_SSE_CODEGEN AND NOT FPMATH_SET)
+ IF(SSE_SWITCH)
+ CHECK_C_COMPILER_FLAG("${SSE_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE)
+ IF(HAVE_MFPMATH_SSE)
+ SET(C_FLAGS ${C_FLAGS} ${SSE_SWITCH} -mfpmath=sse)
+ SET(FPMATH_SET 1)
+ ENDIF()
+ ELSEIF(MSVC)
+ CHECK_C_COMPILER_FLAG("/arch:SSE" HAVE_ARCH_SSE)
+ IF(HAVE_ARCH_SSE)
+ SET(C_FLAGS ${C_FLAGS} "/arch:SSE")
+ SET(FPMATH_SET 1)
+ ENDIF()
+ ENDIF()
ENDIF()
ENDIF()
+
CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
int main() {return 0;}" HAVE_GCC_FORMAT)
@@ -351,7 +484,6 @@ CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
CHECK_INCLUDE_FILE(stdalign.h HAVE_STDALIGN_H)
CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
-CHECK_INCLUDE_FILE(io.h HAVE_IO_H)
CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
@@ -364,6 +496,26 @@ IF(NOT HAVE_GUIDDEF_H)
CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
ENDIF()
+# Some systems need libm for some of the following math functions to work
+SET(MATH_LIB )
+CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
+IF(HAVE_LIBM)
+ SET(MATH_LIB ${MATH_LIB} m)
+ SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
+ENDIF()
+
+# Check for the dlopen API (for dynamicly loading backend libs)
+IF(ALSOFT_DLOPEN)
+ CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
+ IF(HAVE_LIBDL)
+ SET(EXTRA_LIBS dl ${EXTRA_LIBS})
+ SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
+ ENDIF()
+
+ CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
+ENDIF()
+
+# Check for a cpuid intrinsic
IF(HAVE_CPUID_H)
CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
int main()
@@ -372,7 +524,6 @@ IF(HAVE_CPUID_H)
return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
}" HAVE_GCC_GET_CPUID)
ENDIF()
-
IF(HAVE_INTRIN_H)
CHECK_C_SOURCE_COMPILES("#include <intrin.h>
int main()
@@ -381,35 +532,40 @@ IF(HAVE_INTRIN_H)
__cpuid(regs, 0);
return regs[0];
}" HAVE_CPUID_INTRINSIC)
+ CHECK_C_SOURCE_COMPILES("#include <intrin.h>
+ int main()
+ {
+ unsigned long idx = 0;
+ _BitScanForward64(&idx, 1);
+ return idx;
+ }" HAVE_BITSCANFORWARD64_INTRINSIC)
+ CHECK_C_SOURCE_COMPILES("#include <intrin.h>
+ int main()
+ {
+ unsigned long idx = 0;
+ _BitScanForward(&idx, 1);
+ return idx;
+ }" HAVE_BITSCANFORWARD_INTRINSIC)
ENDIF()
-# Some systems need libm for some of the following math functions to work
-CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
-IF(HAVE_LIBM)
- SET(EXTRA_LIBS m ${EXTRA_LIBS})
- SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
-ENDIF()
-
-
+CHECK_SYMBOL_EXISTS(sysconf unistd.h HAVE_SYSCONF)
CHECK_SYMBOL_EXISTS(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
CHECK_SYMBOL_EXISTS(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
+CHECK_SYMBOL_EXISTS(proc_pidpath libproc.h HAVE_PROC_PIDPATH)
CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
CHECK_SYMBOL_EXISTS(modff math.h HAVE_MODFF)
-IF(NOT HAVE_C99_VLA)
- CHECK_SYMBOL_EXISTS(alloca malloc.h HAVE_ALLOCA)
- IF(NOT HAVE_ALLOCA)
- MESSAGE(FATAL_ERROR "No alloca function found, please report!")
- ENDIF()
-ENDIF()
+CHECK_SYMBOL_EXISTS(log2f math.h HAVE_LOG2F)
+CHECK_SYMBOL_EXISTS(cbrtf math.h HAVE_CBRTF)
+CHECK_SYMBOL_EXISTS(copysignf math.h HAVE_COPYSIGNF)
IF(HAVE_FLOAT_H)
CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
ENDIF()
-CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
+CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
IF(NOT HAVE_STRCASECMP)
CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
@@ -417,7 +573,7 @@ IF(NOT HAVE_STRCASECMP)
MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
ENDIF()
- ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
+ SET(CPP_DEFS ${CPP_DEFS} strcasecmp=_stricmp)
ENDIF()
CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
@@ -427,9 +583,10 @@ IF(NOT HAVE_STRNCASECMP)
MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
ENDIF()
- ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
+ SET(CPP_DEFS ${CPP_DEFS} strncasecmp=_strnicmp)
ENDIF()
+CHECK_SYMBOL_EXISTS(strnlen string.h HAVE_STRNLEN)
CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
IF(NOT HAVE_SNPRINTF)
CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
@@ -437,7 +594,7 @@ IF(NOT HAVE_SNPRINTF)
MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
ENDIF()
- ADD_DEFINITIONS(-Dsnprintf=_snprintf)
+ SET(CPP_DEFS ${CPP_DEFS} snprintf=_snprintf)
ENDIF()
CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
@@ -448,9 +605,9 @@ IF(NOT HAVE_ISFINITE)
IF(NOT HAVE__FINITE)
MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
ENDIF()
- ADD_DEFINITIONS(-Disfinite=_finite)
+ SET(CPP_DEFS ${CPP_DEFS} isfinite=_finite)
ELSE()
- ADD_DEFINITIONS(-Disfinite=finite)
+ SET(CPP_DEFS ${CPP_DEFS} isfinite=finite)
ENDIF()
ENDIF()
@@ -461,33 +618,24 @@ IF(NOT HAVE_ISNAN)
MESSAGE(FATAL_ERROR "No isnan function found, please report!")
ENDIF()
- ADD_DEFINITIONS(-Disnan=_isnan)
-ENDIF()
-
-
-# Check for the dlopen API (for dynamicly loading backend libs)
-IF(ALSOFT_DLOPEN)
- CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
- IF(HAVE_DLFCN_H)
- CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
- IF(HAVE_LIBDL)
- SET(EXTRA_LIBS dl ${EXTRA_LIBS})
- ENDIF()
- ENDIF()
+ SET(CPP_DEFS ${CPP_DEFS} isnan=_isnan)
ENDIF()
-# Check if we have Android headers
-CHECK_INCLUDE_FILE(android/api-level.h HAVE_ANDROID_H)
# Check if we have Windows headers
-CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0502)
+SET(OLD_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS})
+SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0502)
+CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
+SET(CMAKE_REQUIRED_DEFINITIONS ${OLD_REQUIRED_DEFINITIONS})
+UNSET(OLD_REQUIRED_DEFINITIONS)
+
IF(NOT HAVE_WINDOWS_H)
- CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
+ CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
IF(NOT HAVE_GETTIMEOFDAY)
MESSAGE(FATAL_ERROR "No timing function found!")
ENDIF()
- CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
+ CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
IF(NOT HAVE_NANOSLEEP)
MESSAGE(FATAL_ERROR "No sleep function found!")
ENDIF()
@@ -503,9 +651,9 @@ IF(NOT HAVE_WINDOWS_H)
CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
IF(NOT HAVE_ANDROID_H)
IF(HAVE_PTHREAD)
- ADD_DEFINITIONS(-pthread)
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
- SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
+ SET(C_FLAGS ${C_FLAGS} -pthread)
+ SET(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
ENDIF()
CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
@@ -523,12 +671,52 @@ IF(NOT HAVE_WINDOWS_H)
CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
IF(NOT HAVE_PTHREAD_SETNAME_NP)
CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
+ ELSE()
+ CHECK_C_SOURCE_COMPILES("
+#include <pthread.h>
+#include <pthread_np.h>
+int main()
+{
+ pthread_setname_np(\"testname\");
+ return 0;
+}"
+ PTHREAD_SETNAME_NP_ONE_PARAM
+ )
+ CHECK_C_SOURCE_COMPILES("
+#include <pthread.h>
+#include <pthread_np.h>
+int main()
+{
+ pthread_setname_np(pthread_self(), \"%s\", \"testname\");
+ return 0;
+}"
+ PTHREAD_SETNAME_NP_THREE_PARAMS
+ )
ENDIF()
CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
ELSE()
CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
IF(NOT HAVE_PTHREAD_SETNAME_NP)
CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
+ ELSE()
+ CHECK_C_SOURCE_COMPILES("
+#include <pthread.h>
+int main()
+{
+ pthread_setname_np(\"testname\");
+ return 0;
+}"
+ PTHREAD_SETNAME_NP_ONE_PARAM
+ )
+ CHECK_C_SOURCE_COMPILES("
+#include <pthread.h>
+int main()
+{
+ pthread_setname_np(pthread_self(), \"%s\", \"testname\");
+ return 0;
+}"
+ PTHREAD_SETNAME_NP_THREE_PARAMS
+ )
ENDIF()
CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
ENDIF()
@@ -541,6 +729,8 @@ IF(NOT HAVE_WINDOWS_H)
ENDIF()
ENDIF()
+CHECK_SYMBOL_EXISTS(getopt unistd.h HAVE_GETOPT)
+
# Check for a 64-bit type
CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
IF(NOT HAVE_STDINT_H)
@@ -560,45 +750,100 @@ IF(NOT HAVE_STDINT_H)
ENDIF()
-SET(COMMON_OBJS common/atomic.c
- common/rwlock.c
- common/threads.c
- common/uintmap.c
+SET(COMMON_OBJS
+ common/alcomplex.c
+ common/alcomplex.h
+ common/align.h
+ common/almalloc.c
+ common/almalloc.h
+ common/atomic.c
+ common/atomic.h
+ common/bool.h
+ common/math_defs.h
+ common/rwlock.c
+ common/rwlock.h
+ common/static_assert.h
+ common/threads.c
+ common/threads.h
+ common/uintmap.c
+ common/uintmap.h
)
-SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
- OpenAL32/alBuffer.c
- OpenAL32/alEffect.c
- OpenAL32/alError.c
- OpenAL32/alExtension.c
- OpenAL32/alFilter.c
- OpenAL32/alListener.c
- OpenAL32/alSource.c
- OpenAL32/alState.c
- OpenAL32/alThunk.c
- OpenAL32/sample_cvt.c
+SET(OPENAL_OBJS
+ OpenAL32/Include/bs2b.h
+ OpenAL32/Include/alMain.h
+ OpenAL32/Include/alu.h
+
+ OpenAL32/Include/alAuxEffectSlot.h
+ OpenAL32/alAuxEffectSlot.c
+ OpenAL32/Include/alBuffer.h
+ OpenAL32/alBuffer.c
+ OpenAL32/Include/alEffect.h
+ OpenAL32/alEffect.c
+ OpenAL32/Include/alError.h
+ OpenAL32/alError.c
+ OpenAL32/alExtension.c
+ OpenAL32/Include/alFilter.h
+ OpenAL32/alFilter.c
+ OpenAL32/Include/alListener.h
+ OpenAL32/alListener.c
+ OpenAL32/Include/alSource.h
+ OpenAL32/alSource.c
+ OpenAL32/alState.c
+ OpenAL32/event.c
+ OpenAL32/Include/sample_cvt.h
+ OpenAL32/sample_cvt.c
)
-SET(ALC_OBJS Alc/ALc.c
- Alc/ALu.c
- Alc/alcConfig.c
- Alc/alcRing.c
- Alc/bs2b.c
- Alc/effects/autowah.c
- Alc/effects/chorus.c
- Alc/effects/compressor.c
- Alc/effects/dedicated.c
- Alc/effects/distortion.c
- Alc/effects/echo.c
- Alc/effects/equalizer.c
- Alc/effects/flanger.c
- Alc/effects/modulator.c
- Alc/effects/null.c
- Alc/effects/reverb.c
- Alc/helpers.c
- Alc/bsinc.c
- Alc/hrtf.c
- Alc/panning.c
- Alc/mixer.c
- Alc/mixer_c.c
+SET(ALC_OBJS
+ Alc/ALc.c
+ Alc/ALu.c
+ Alc/alconfig.c
+ Alc/alconfig.h
+ Alc/bs2b.c
+ Alc/converter.c
+ Alc/converter.h
+ Alc/inprogext.h
+ Alc/mastering.c
+ Alc/mastering.h
+ Alc/ringbuffer.c
+ Alc/ringbuffer.h
+ Alc/effects/autowah.c
+ Alc/effects/chorus.c
+ Alc/effects/compressor.c
+ Alc/effects/dedicated.c
+ Alc/effects/distortion.c
+ Alc/effects/echo.c
+ Alc/effects/equalizer.c
+ Alc/effects/fshifter.c
+ Alc/effects/modulator.c
+ Alc/effects/null.c
+ Alc/effects/pshifter.c
+ Alc/effects/reverb.c
+ Alc/filters/defs.h
+ Alc/filters/filter.c
+ Alc/filters/nfc.c
+ Alc/filters/nfc.h
+ Alc/filters/splitter.c
+ Alc/filters/splitter.h
+ Alc/helpers.c
+ Alc/alstring.h
+ Alc/compat.h
+ Alc/cpu_caps.h
+ Alc/fpu_modes.h
+ Alc/logging.h
+ Alc/vector.h
+ Alc/hrtf.c
+ Alc/hrtf.h
+ Alc/uhjfilter.c
+ Alc/uhjfilter.h
+ Alc/ambdec.c
+ Alc/ambdec.h
+ Alc/bformatdec.c
+ Alc/bformatdec.h
+ Alc/panning.c
+ Alc/polymorphism.h
+ Alc/mixvoice.c
+ Alc/mixer/defs.h
+ Alc/mixer/mixer_c.c
)
@@ -615,13 +860,14 @@ SET(HAVE_SOLARIS 0)
SET(HAVE_SNDIO 0)
SET(HAVE_QSA 0)
SET(HAVE_DSOUND 0)
-SET(HAVE_MMDEVAPI 0)
+SET(HAVE_WASAPI 0)
SET(HAVE_WINMM 0)
SET(HAVE_PORTAUDIO 0)
SET(HAVE_PULSEAUDIO 0)
SET(HAVE_COREAUDIO 0)
SET(HAVE_OPENSL 0)
SET(HAVE_WAVE 0)
+SET(HAVE_SDL2 0)
# Check for SSE support
OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
@@ -631,9 +877,9 @@ IF(HAVE_XMMINTRIN_H)
IF(ALSOFT_CPUEXT_SSE)
IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
SET(HAVE_SSE 1)
- SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse.c)
+ SET(ALC_OBJS ${ALC_OBJS} Alc/mixer/mixer_sse.c)
IF(SSE_SWITCH)
- SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse.c PROPERTIES
+ SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse.c PROPERTIES
COMPILE_FLAGS "${SSE_SWITCH}")
ENDIF()
SET(CPU_EXTS "${CPU_EXTS}, SSE")
@@ -651,9 +897,9 @@ IF(HAVE_EMMINTRIN_H)
IF(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
SET(HAVE_SSE2 1)
- SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse2.c)
+ SET(ALC_OBJS ${ALC_OBJS} Alc/mixer/mixer_sse2.c)
IF(SSE2_SWITCH)
- SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse2.c PROPERTIES
+ SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse2.c PROPERTIES
COMPILE_FLAGS "${SSE2_SWITCH}")
ENDIF()
SET(CPU_EXTS "${CPU_EXTS}, SSE2")
@@ -664,16 +910,16 @@ IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
ENDIF()
-OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE3 support" OFF)
+OPTION(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
IF(HAVE_EMMINTRIN_H)
OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
SET(HAVE_SSE3 1)
- SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse3.c)
+ SET(ALC_OBJS ${ALC_OBJS} Alc/mixer/mixer_sse3.c)
IF(SSE2_SWITCH)
- SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse3.c PROPERTIES
+ SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse3.c PROPERTIES
COMPILE_FLAGS "${SSE3_SWITCH}")
ENDIF()
SET(CPU_EXTS "${CPU_EXTS}, SSE3")
@@ -691,9 +937,9 @@ IF(HAVE_SMMINTRIN_H)
IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE4_1)
IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
SET(HAVE_SSE4_1 1)
- SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_sse41.c)
+ SET(ALC_OBJS ${ALC_OBJS} Alc/mixer/mixer_sse41.c)
IF(SSE4_1_SWITCH)
- SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse41.c PROPERTIES
+ SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse41.c PROPERTIES
COMPILE_FLAGS "${SSE4_1_SWITCH}")
ENDIF()
SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
@@ -706,12 +952,16 @@ ENDIF()
# Check for ARM Neon support
OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
-CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H)
+CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H ${FPU_NEON_SWITCH})
IF(HAVE_ARM_NEON_H)
OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
IF(ALSOFT_CPUEXT_NEON)
SET(HAVE_NEON 1)
- SET(ALC_OBJS ${ALC_OBJS} Alc/mixer_neon.c)
+ SET(ALC_OBJS ${ALC_OBJS} Alc/mixer/mixer_neon.c)
+ IF(FPU_NEON_SWITCH)
+ SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_neon.c PROPERTIES
+ COMPILE_FLAGS "${FPU_NEON_SWITCH}")
+ ENDIF()
SET(CPU_EXTS "${CPU_EXTS}, Neon")
ENDIF()
ENDIF()
@@ -733,10 +983,11 @@ ENDIF()
SET(BACKENDS "")
SET(ALC_OBJS ${ALC_OBJS}
- Alc/backends/base.c
- # Default backends, always available
- Alc/backends/loopback.c
- Alc/backends/null.c
+ Alc/backends/base.c
+ Alc/backends/base.h
+ # Default backends, always available
+ Alc/backends/loopback.c
+ Alc/backends/null.c
)
# Check ALSA backend
@@ -749,9 +1000,7 @@ IF(ALSA_FOUND)
SET(BACKENDS "${BACKENDS} ALSA${IS_LINKED},")
SET(ALC_OBJS ${ALC_OBJS} Alc/backends/alsa.c)
ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
- IF(CMAKE_VERSION VERSION_LESS "2.8.8")
- INCLUDE_DIRECTORIES(${ALSA_INCLUDE_DIRS})
- ENDIF()
+ SET(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
ENDIF()
ENDIF()
IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
@@ -767,9 +1016,10 @@ IF(OSS_FOUND)
SET(HAVE_OSS 1)
SET(BACKENDS "${BACKENDS} OSS,")
SET(ALC_OBJS ${ALC_OBJS} Alc/backends/oss.c)
- IF(CMAKE_VERSION VERSION_LESS "2.8.8")
- INCLUDE_DIRECTORIES(${OSS_INCLUDE_DIRS})
+ IF(OSS_LIBRARIES)
+ SET(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
ENDIF()
+ SET(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
ENDIF()
ENDIF()
IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
@@ -785,9 +1035,7 @@ IF(AUDIOIO_FOUND)
SET(HAVE_SOLARIS 1)
SET(BACKENDS "${BACKENDS} Solaris,")
SET(ALC_OBJS ${ALC_OBJS} Alc/backends/solaris.c)
- IF(CMAKE_VERSION VERSION_LESS "2.8.8")
- INCLUDE_DIRECTORIES(${AUDIOIO_INCLUDE_DIRS})
- ENDIF()
+ SET(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
ENDIF()
ENDIF()
IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
@@ -804,9 +1052,7 @@ IF(SOUNDIO_FOUND)
SET(BACKENDS "${BACKENDS} SndIO (linked),")
SET(ALC_OBJS ${ALC_OBJS} Alc/backends/sndio.c)
SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
- IF(CMAKE_VERSION VERSION_LESS "2.8.8")
- INCLUDE_DIRECTORIES(${SOUNDIO_INCLUDE_DIRS})
- ENDIF()
+ SET(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
ENDIF()
ENDIF()
IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
@@ -823,9 +1069,7 @@ IF(QSA_FOUND)
SET(BACKENDS "${BACKENDS} QSA (linked),")
SET(ALC_OBJS ${ALC_OBJS} Alc/backends/qsa.c)
SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
- IF(CMAKE_VERSION VERSION_LESS "2.8.8")
- INCLUDE_DIRECTORIES(${QSA_INCLUDE_DIRS})
- ENDIF()
+ SET(INC_PATHS ${INC_PATHS} ${QSA_INCLUDE_DIRS})
ENDIF()
ENDIF()
IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
@@ -835,10 +1079,13 @@ ENDIF()
# Check Windows-only backends
OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
-OPTION(ALSOFT_REQUIRE_MMDEVAPI "Require MMDevApi backend" OFF)
+OPTION(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
IF(HAVE_WINDOWS_H)
+ SET(OLD_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS})
+ SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0502)
+
# Check MMSystem backend
- CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0502)
+ CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
IF(HAVE_MMSYSTEM_H)
CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
IF(HAVE_LIBWINMM)
@@ -861,22 +1108,23 @@ IF(HAVE_WINDOWS_H)
SET(BACKENDS "${BACKENDS} DirectSound${IS_LINKED},")
SET(ALC_OBJS ${ALC_OBJS} Alc/backends/dsound.c)
ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
- IF(CMAKE_VERSION VERSION_LESS "2.8.8")
- INCLUDE_DIRECTORIES(${DSOUND_INCLUDE_DIRS})
- ENDIF()
+ SET(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
ENDIF()
ENDIF()
- # Check for MMDevApi backend
+ # Check for WASAPI backend
CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
IF(HAVE_MMDEVICEAPI_H)
- OPTION(ALSOFT_BACKEND_MMDEVAPI "Enable MMDevApi backend" ON)
- IF(ALSOFT_BACKEND_MMDEVAPI)
- SET(HAVE_MMDEVAPI 1)
- SET(BACKENDS "${BACKENDS} MMDevApi,")
- SET(ALC_OBJS ${ALC_OBJS} Alc/backends/mmdevapi.c)
+ OPTION(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
+ IF(ALSOFT_BACKEND_WASAPI)
+ SET(HAVE_WASAPI 1)
+ SET(BACKENDS "${BACKENDS} WASAPI,")
+ SET(ALC_OBJS ${ALC_OBJS} Alc/backends/wasapi.c)
ENDIF()
ENDIF()
+
+ SET(CMAKE_REQUIRED_DEFINITIONS ${OLD_REQUIRED_DEFINITIONS})
+ UNSET(OLD_REQUIRED_DEFINITIONS)
ENDIF()
IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
@@ -884,8 +1132,8 @@ ENDIF()
IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
ENDIF()
-IF(ALSOFT_REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
- MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
+IF(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
+ MESSAGE(FATAL_ERROR "Failed to enabled required WASAPI backend")
ENDIF()
# Check PortAudio backend
@@ -898,9 +1146,7 @@ IF(PORTAUDIO_FOUND)
SET(BACKENDS "${BACKENDS} PortAudio${IS_LINKED},")
SET(ALC_OBJS ${ALC_OBJS} Alc/backends/portaudio.c)
ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
- IF(CMAKE_VERSION VERSION_LESS "2.8.8")
- INCLUDE_DIRECTORIES(${PORTAUDIO_INCLUDE_DIRS})
- ENDIF()
+ SET(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
ENDIF()
ENDIF()
IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
@@ -917,9 +1163,7 @@ IF(PULSEAUDIO_FOUND)
SET(BACKENDS "${BACKENDS} PulseAudio${IS_LINKED},")
SET(ALC_OBJS ${ALC_OBJS} Alc/backends/pulseaudio.c)
ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
- IF(CMAKE_VERSION VERSION_LESS "2.8.8")
- INCLUDE_DIRECTORIES(${PULSEAUDIO_INCLUDE_DIRS})
- ENDIF()
+ SET(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
ENDIF()
ENDIF()
IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
@@ -935,10 +1179,8 @@ IF(JACK_FOUND)
SET(HAVE_JACK 1)
SET(BACKENDS "${BACKENDS} JACK${IS_LINKED},")
SET(ALC_OBJS ${ALC_OBJS} Alc/backends/jack.c)
- ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
- IF(CMAKE_VERSION VERSION_LESS "2.8.8")
- INCLUDE_DIRECTORIES(${JACK_INCLUDE_DIRS})
- ENDIF()
+ ADD_BACKEND_LIBS(${JACK_LIBRARIES})
+ SET(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
ENDIF()
ENDIF()
IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
@@ -997,6 +1239,24 @@ IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
ENDIF()
+# Check for SDL2 backend
+OPTION(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
+FIND_PACKAGE(SDL2)
+IF(SDL2_FOUND)
+ # Off by default, since it adds a runtime dependency
+ OPTION(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
+ IF(ALSOFT_BACKEND_SDL2)
+ SET(HAVE_SDL2 1)
+ SET(ALC_OBJS ${ALC_OBJS} Alc/backends/sdl2.c)
+ SET(BACKENDS "${BACKENDS} SDL2,")
+ SET(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
+ SET(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
+ ENDIF()
+ENDIF()
+IF(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
+ MESSAGE(FATAL_ERROR "Failed to enabled required SDL2 backend")
+ENDIF()
+
# Optionally enable the Wave Writer backend
OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
IF(ALSOFT_BACKEND_WAVE)
@@ -1008,35 +1268,114 @@ ENDIF()
# This is always available
SET(BACKENDS "${BACKENDS} Null")
+
+FIND_PACKAGE(Git)
+IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
+ # Get the current working branch and its latest abbreviated commit hash
+ ADD_CUSTOM_TARGET(build_version
+ ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
+ -D LIB_VERSION=${LIB_VERSION}
+ -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
+ -D DST=${OpenAL_BINARY_DIR}/version.h
+ -P ${OpenAL_SOURCE_DIR}/version.cmake
+ WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
+ VERBATIM
+ )
+ELSE()
+ SET(GIT_BRANCH "UNKNOWN")
+ SET(GIT_COMMIT_HASH "unknown")
+ CONFIGURE_FILE(
+ "${OpenAL_SOURCE_DIR}/version.h.in"
+ "${OpenAL_BINARY_DIR}/version.h")
+ENDIF()
+
+SET(NATIVE_SRC_DIR "${OpenAL_SOURCE_DIR}/native-tools/")
+SET(NATIVE_BIN_DIR "${OpenAL_BINARY_DIR}/native-tools/")
+FILE(MAKE_DIRECTORY "${NATIVE_BIN_DIR}")
+
+SET(BIN2H_COMMAND "${NATIVE_BIN_DIR}bin2h")
+SET(BSINCGEN_COMMAND "${NATIVE_BIN_DIR}bsincgen")
+ADD_CUSTOM_COMMAND(OUTPUT "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
+ COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${NATIVE_SRC_DIR}"
+ COMMAND ${CMAKE_COMMAND} -E remove "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
+ COMMAND ${CMAKE_COMMAND} --build . --config "Release"
+ WORKING_DIRECTORY "${NATIVE_BIN_DIR}"
+ DEPENDS "${NATIVE_SRC_DIR}CMakeLists.txt"
+ IMPLICIT_DEPENDS C "${NATIVE_SRC_DIR}bin2h.c"
+ C "${NATIVE_SRC_DIR}bsincgen.c"
+ VERBATIM
+)
+ADD_CUSTOM_TARGET(native-tools
+ DEPENDS "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
+ VERBATIM
+)
+
+option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
+if(ALSOFT_EMBED_HRTF_DATA)
+ MACRO(make_hrtf_header FILENAME VARNAME)
+ SET(infile "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
+ SET(outfile "${OpenAL_BINARY_DIR}/${FILENAME}.h")
+
+ ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
+ COMMAND "${BIN2H_COMMAND}" "${infile}" "${outfile}" ${VARNAME}
+ DEPENDS native-tools "${infile}"
+ VERBATIM
+ )
+ SET(ALC_OBJS ${ALC_OBJS} "${outfile}")
+ ENDMACRO()
+
+ make_hrtf_header(default-44100.mhr "hrtf_default_44100")
+ make_hrtf_header(default-48000.mhr "hrtf_default_48000")
+endif()
+
+ADD_CUSTOM_COMMAND(OUTPUT "${OpenAL_BINARY_DIR}/bsinc_inc.h"
+ COMMAND "${BSINCGEN_COMMAND}" "${OpenAL_BINARY_DIR}/bsinc_inc.h"
+ DEPENDS native-tools "${NATIVE_SRC_DIR}bsincgen.c"
+ VERBATIM
+)
+SET(ALC_OBJS ${ALC_OBJS} "${OpenAL_BINARY_DIR}/bsinc_inc.h")
+
+
IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
add_subdirectory(utils/alsoft-config)
ENDIF()
IF(ALSOFT_EXAMPLES)
- FIND_PACKAGE(SDL2)
+ IF(NOT SDL2_FOUND)
+ FIND_PACKAGE(SDL2)
+ ENDIF()
IF(SDL2_FOUND)
FIND_PACKAGE(SDL_sound)
- IF(SDL_SOUND_FOUND AND CMAKE_VERSION VERSION_LESS "2.8.8")
- INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
- ENDIF()
FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
- IF(FFMPEG_FOUND AND CMAKE_VERSION VERSION_LESS "2.8.8")
- INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIRS})
- ENDIF()
ENDIF()
ENDIF()
-IF(LIBTYPE STREQUAL "STATIC")
- ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
- SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
+IF(NOT WIN32)
+ SET(LIBNAME "openal")
+ELSE()
+ SET(LIBNAME "OpenAL32")
ENDIF()
# Needed for openal.pc.in
SET(prefix ${CMAKE_INSTALL_PREFIX})
SET(exec_prefix "\${prefix}")
-SET(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
-SET(bindir "\${exec_prefix}/bin")
-SET(includedir "\${prefix}/include")
+SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
+SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
+SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
SET(PACKAGE_VERSION "${LIB_VERSION}")
+SET(PKG_CONFIG_CFLAGS )
+SET(PKG_CONFIG_PRIVATE_LIBS )
+IF(LIBTYPE STREQUAL "STATIC")
+ SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
+ FOREACH(FLAG ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
+ # If this is already a linker flag, or is a full path+file, add it
+ # as-is. Otherwise, it's a name intended to be dressed as -lname.
+ IF(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
+ SET(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
+ ELSE()
+ SET(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
+ ENDIF()
+ ENDFOREACH()
+ENDIF()
# End configuration
CONFIGURE_FILE(
@@ -1047,100 +1386,136 @@ CONFIGURE_FILE(
"${OpenAL_BINARY_DIR}/openal.pc"
@ONLY)
-# Build a common library with reusable helpers
+
+# Add a static library with common functions used by multiple targets
ADD_LIBRARY(common STATIC ${COMMON_OBJS})
-IF(NOT LIBTYPE STREQUAL "STATIC")
- SET_PROPERTY(TARGET common PROPERTY POSITION_INDEPENDENT_CODE TRUE)
-ENDIF()
+TARGET_COMPILE_DEFINITIONS(common PRIVATE ${CPP_DEFS})
+TARGET_COMPILE_OPTIONS(common PRIVATE ${C_FLAGS})
+
+
+UNSET(HAS_ROUTER)
+SET(IMPL_TARGET OpenAL)
+SET(COMMON_LIB )
+SET(SUBSYS_FLAG )
# Build main library
IF(LIBTYPE STREQUAL "STATIC")
- ADD_LIBRARY(${LIBNAME} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
+ SET(CPP_DEFS ${CPP_DEFS} AL_LIBTYPE_STATIC)
+ IF(WIN32 AND ALSOFT_NO_UID_DEFS)
+ SET(CPP_DEFS ${CPP_DEFS} AL_NO_UID_DEFS)
+ ENDIF()
+ ADD_LIBRARY(OpenAL STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
ELSE()
- ADD_LIBRARY(${LIBNAME} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
-ENDIF()
-SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_DEFINITIONS AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES)
-IF(WIN32 AND ALSOFT_NO_UID_DEFS)
- SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_DEFINITIONS AL_NO_UID_DEFS)
-ENDIF()
-SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
-IF(HAVE_ALSA)
- SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${ALSA_INCLUDE_DIRS})
-ENDIF()
-IF(HAVE_OSS)
- SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${OSS_INCLUDE_DIRS})
-ENDIF()
-IF(HAVE_SOLARIS)
- SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${AUDIOIO_INCLUDE_DIRS})
-ENDIF()
-IF(HAVE_SNDIO)
- SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${SOUNDIO_INCLUDE_DIRS})
-ENDIF()
-IF(HAVE_QSA)
- SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${QSA_INCLUDE_DIRS})
-ENDIF()
-IF(HAVE_DSOUND)
- SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${DSOUND_INCLUDE_DIRS})
-ENDIF()
-IF(HAVE_PORTAUDIO)
- SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${PORTAUDIO_INCLUDE_DIRS})
-ENDIF()
-IF(HAVE_PULSEAUDIO)
- SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${PULSEAUDIO_INCLUDE_DIRS})
-ENDIF()
-IF(HAVE_JACK)
- SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${JACK_INCLUDE_DIRS})
-ENDIF()
-SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
- SOVERSION ${LIB_MAJOR_VERSION})
-IF(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
- SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
+ # Make sure to compile the common code with PIC, since it'll be linked into
+ # shared libs that needs it.
+ SET_PROPERTY(TARGET common PROPERTY POSITION_INDEPENDENT_CODE TRUE)
+ SET(COMMON_LIB common)
- IF(MINGW AND ALSOFT_BUILD_IMPORT_LIB)
- FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
- FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
- IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
- MESSAGE(STATUS "")
- IF(NOT SED_EXECUTABLE)
- MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
- ENDIF()
- IF(NOT DLLTOOL_EXECUTABLE)
- MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
- ENDIF()
- ELSE()
- SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES LINK_FLAGS "-Wl,--output-def,${LIBNAME}.def")
- ADD_CUSTOM_COMMAND(TARGET ${LIBNAME} POST_BUILD
- COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" ${LIBNAME}.def
- COMMAND "${DLLTOOL_EXECUTABLE}" -d ${LIBNAME}.def -l ${LIBNAME}.lib -D ${LIBNAME}.dll
- COMMENT "Stripping ordinals from ${LIBNAME}.def and generating ${LIBNAME}.lib..."
- VERBATIM
- )
+ IF(WIN32)
+ IF(MSVC)
+ SET(SUBSYS_FLAG ${SUBSYS_FLAG} "/SUBSYSTEM:WINDOWS")
+ ELSEIF(CMAKE_COMPILER_IS_GNUCC)
+ SET(SUBSYS_FLAG ${SUBSYS_FLAG} "-mwindows")
ENDIF()
ENDIF()
-ENDIF()
-TARGET_LINK_LIBRARIES(${LIBNAME} common ${EXTRA_LIBS})
+ IF(WIN32 AND ALSOFT_BUILD_ROUTER)
+ ADD_LIBRARY(OpenAL SHARED router/router.c router/router.h router/alc.c router/al.c)
+ TARGET_COMPILE_DEFINITIONS(OpenAL
+ PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
+ TARGET_COMPILE_OPTIONS(OpenAL PRIVATE ${C_FLAGS})
+ TARGET_LINK_LIBRARIES(OpenAL PRIVATE ${LINKER_FLAGS} ${COMMON_LIB})
+ SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
+ SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
+ IF(TARGET build_version)
+ ADD_DEPENDENCIES(OpenAL build_version)
+ ENDIF()
+ SET(HAS_ROUTER 1)
+
+ SET(LIBNAME "soft_oal")
+ SET(IMPL_TARGET soft_oal)
+ ENDIF()
+
+ ADD_LIBRARY(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
+ IF(WIN32)
+ SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES PREFIX "")
+ ENDIF()
+ENDIF()
+SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
+ VERSION ${LIB_VERSION}
+ SOVERSION ${LIB_MAJOR_VERSION}
+)
+TARGET_COMPILE_DEFINITIONS(${IMPL_TARGET}
+ PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
+TARGET_INCLUDE_DIRECTORIES(${IMPL_TARGET}
+ PRIVATE "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc" ${INC_PATHS})
+TARGET_COMPILE_OPTIONS(${IMPL_TARGET} PRIVATE ${C_FLAGS})
+TARGET_LINK_LIBRARIES(${IMPL_TARGET}
+ PRIVATE ${LINKER_FLAGS} ${COMMON_LIB} ${EXTRA_LIBS} ${MATH_LIB})
+IF(TARGET build_version)
+ ADD_DEPENDENCIES(${IMPL_TARGET} build_version)
+ENDIF()
+
+IF(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
+ FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
+ FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
+ IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
+ MESSAGE(STATUS "")
+ IF(NOT SED_EXECUTABLE)
+ MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
+ ENDIF()
+ IF(NOT DLLTOOL_EXECUTABLE)
+ MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
+ ENDIF()
+ ELSE()
+ SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS
+ " -Wl,--output-def,OpenAL32.def")
+ ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
+ COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
+ COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
+ COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
+ VERBATIM
+ )
+ ENDIF()
+ENDIF()
IF(ALSOFT_INSTALL)
- # Add an install target here
- INSTALL(TARGETS ${LIBNAME}
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION "lib${LIB_SUFFIX}"
- ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
+ INSTALL(TARGETS OpenAL EXPORT OpenAL
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL
)
+ EXPORT(TARGETS OpenAL
+ NAMESPACE OpenAL::
+ FILE OpenALConfig.cmake)
+ INSTALL(EXPORT OpenAL
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
+ NAMESPACE OpenAL::
+ FILE OpenALConfig.cmake)
INSTALL(FILES include/AL/al.h
include/AL/alc.h
include/AL/alext.h
include/AL/efx.h
include/AL/efx-creative.h
include/AL/efx-presets.h
- DESTINATION include/AL
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
)
INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
- DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
+ IF(TARGET soft_oal)
+ INSTALL(TARGETS soft_oal
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ )
+ ENDIF()
ENDIF()
+if(HAS_ROUTER)
+ message(STATUS "")
+ message(STATUS "Building DLL router")
+endif()
+
MESSAGE(STATUS "")
MESSAGE(STATUS "Building OpenAL with support for the following backends:")
MESSAGE(STATUS " ${BACKENDS}")
@@ -1148,6 +1523,10 @@ MESSAGE(STATUS "")
MESSAGE(STATUS "Building with support for CPU extensions:")
MESSAGE(STATUS " ${CPU_EXTS}")
MESSAGE(STATUS "")
+IF(FPMATH_SET)
+ MESSAGE(STATUS "Building with SSE${FPMATH_SET} codegen")
+ MESSAGE(STATUS "")
+ENDIF()
IF(WIN32)
IF(NOT HAVE_DSOUND)
@@ -1157,10 +1536,15 @@ IF(WIN32)
ENDIF()
ENDIF()
+if(ALSOFT_EMBED_HRTF_DATA)
+ message(STATUS "Embedding HRTF datasets")
+ message(STATUS "")
+endif()
+
# Install alsoft.conf configuration file
IF(ALSOFT_CONFIG)
INSTALL(FILES alsoftrc.sample
- DESTINATION share/openal
+ DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
)
MESSAGE(STATUS "Installing sample configuration")
MESSAGE(STATUS "")
@@ -1170,31 +1554,48 @@ ENDIF()
IF(ALSOFT_HRTF_DEFS)
INSTALL(FILES hrtf/default-44100.mhr
hrtf/default-48000.mhr
- DESTINATION share/openal/hrtf
+ DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
)
MESSAGE(STATUS "Installing HRTF definitions")
MESSAGE(STATUS "")
ENDIF()
+# Install AmbDec presets
+IF(ALSOFT_AMBDEC_PRESETS)
+ INSTALL(FILES presets/3D7.1.ambdec
+ presets/hexagon.ambdec
+ presets/itu5.1.ambdec
+ presets/itu5.1-nocenter.ambdec
+ presets/rectangle.ambdec
+ presets/square.ambdec
+ presets/presets.txt
+ DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
+ )
+ MESSAGE(STATUS "Installing AmbDec presets")
+ MESSAGE(STATUS "")
+ENDIF()
+
IF(ALSOFT_UTILS)
ADD_EXECUTABLE(openal-info utils/openal-info.c)
- TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
+ TARGET_COMPILE_OPTIONS(openal-info PRIVATE ${C_FLAGS})
+ TARGET_LINK_LIBRARIES(openal-info PRIVATE ${LINKER_FLAGS} OpenAL)
- ADD_EXECUTABLE(makehrtf utils/makehrtf.c)
- IF(HAVE_LIBM)
- TARGET_LINK_LIBRARIES(makehrtf m)
+ SET(MAKEHRTF_SRCS utils/makehrtf.c)
+ IF(NOT HAVE_GETOPT)
+ SET(MAKEHRTF_SRCS ${MAKEHRTF_SRCS} utils/getopt.c utils/getopt.h)
ENDIF()
-
- ADD_EXECUTABLE(bsincgen utils/bsincgen.c)
+ ADD_EXECUTABLE(makehrtf ${MAKEHRTF_SRCS})
+ TARGET_COMPILE_DEFINITIONS(makehrtf PRIVATE ${CPP_DEFS})
+ TARGET_COMPILE_OPTIONS(makehrtf PRIVATE ${C_FLAGS})
IF(HAVE_LIBM)
- TARGET_LINK_LIBRARIES(bsincgen m)
+ TARGET_LINK_LIBRARIES(makehrtf PRIVATE ${LINKER_FLAGS} m)
ENDIF()
IF(ALSOFT_INSTALL)
- INSTALL(TARGETS openal-info makehrtf bsincgen
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION "lib${LIB_SUFFIX}"
- ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
+ INSTALL(TARGETS openal-info makehrtf
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
ENDIF()
@@ -1206,103 +1607,164 @@ IF(ALSOFT_UTILS)
ENDIF()
IF(ALSOFT_TESTS)
- ADD_LIBRARY(test-common STATIC examples/common/alhelpers.c)
+ SET(TEST_COMMON_OBJS examples/common/alhelpers.c)
- ADD_EXECUTABLE(altonegen examples/altonegen.c)
- TARGET_LINK_LIBRARIES(altonegen test-common ${LIBNAME})
+ ADD_EXECUTABLE(altonegen examples/altonegen.c ${TEST_COMMON_OBJS})
+ TARGET_COMPILE_DEFINITIONS(altonegen PRIVATE ${CPP_DEFS})
+ TARGET_COMPILE_OPTIONS(altonegen PRIVATE ${C_FLAGS})
+ TARGET_LINK_LIBRARIES(altonegen PRIVATE ${LINKER_FLAGS} common OpenAL ${MATH_LIB})
- IF(ALSOFT_INSTALL)
- INSTALL(TARGETS altonegen
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION "lib${LIB_SUFFIX}"
- ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
- )
- ENDIF()
+ IF(ALSOFT_INSTALL)
+ INSTALL(TARGETS altonegen
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ )
+ ENDIF()
- MESSAGE(STATUS "Building test programs")
- MESSAGE(STATUS "")
+ MESSAGE(STATUS "Building test programs")
+ MESSAGE(STATUS "")
ENDIF()
IF(ALSOFT_EXAMPLES)
- IF(SDL2_FOUND AND SDL_SOUND_FOUND)
- ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c
- examples/common/sdl_sound.c)
- SET_PROPERTY(TARGET ex-common APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
- ${SDL_SOUND_INCLUDE_DIR})
-
- ADD_EXECUTABLE(alstream examples/alstream.c)
- TARGET_LINK_LIBRARIES(alstream ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${LIBNAME})
- SET_PROPERTY(TARGET alstream APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
- ${SDL_SOUND_INCLUDE_DIR})
-
- ADD_EXECUTABLE(alreverb examples/alreverb.c)
- TARGET_LINK_LIBRARIES(alreverb ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${LIBNAME})
- SET_PROPERTY(TARGET alreverb APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
- ${SDL_SOUND_INCLUDE_DIR})
-
- ADD_EXECUTABLE(allatency examples/allatency.c)
- TARGET_LINK_LIBRARIES(allatency ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${LIBNAME})
- SET_PROPERTY(TARGET allatency APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
- ${SDL_SOUND_INCLUDE_DIR})
-
- ADD_EXECUTABLE(alloopback examples/alloopback.c)
- TARGET_LINK_LIBRARIES(alloopback ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${LIBNAME})
- SET_PROPERTY(TARGET alloopback APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
- ${SDL_SOUND_INCLUDE_DIR})
-
- ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
- TARGET_LINK_LIBRARIES(alhrtf ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${LIBNAME})
- SET_PROPERTY(TARGET alhrtf APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
- ${SDL_SOUND_INCLUDE_DIR})
-
- IF(ALSOFT_INSTALL)
- INSTALL(TARGETS alstream alreverb allatency alloopback
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION "lib${LIB_SUFFIX}"
- ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
- )
+ ADD_EXECUTABLE(alrecord examples/alrecord.c)
+ TARGET_COMPILE_DEFINITIONS(alrecord PRIVATE ${CPP_DEFS})
+ TARGET_COMPILE_OPTIONS(alrecord PRIVATE ${C_FLAGS})
+ TARGET_LINK_LIBRARIES(alrecord PRIVATE ${LINKER_FLAGS} common OpenAL)
+
+ IF(ALSOFT_INSTALL)
+ INSTALL(TARGETS alrecord
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ )
+ ENDIF()
+
+ MESSAGE(STATUS "Building example programs")
+
+ IF(SDL2_FOUND)
+ IF(SDL_SOUND_FOUND)
+ # Add a static library with common functions used by multiple targets
+ ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c)
+ TARGET_COMPILE_DEFINITIONS(ex-common PRIVATE ${CPP_DEFS})
+ TARGET_COMPILE_OPTIONS(ex-common PRIVATE ${C_FLAGS})
+
+ ADD_EXECUTABLE(alplay examples/alplay.c)
+ TARGET_COMPILE_DEFINITIONS(alplay PRIVATE ${CPP_DEFS})
+ TARGET_INCLUDE_DIRECTORIES(alplay
+ PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
+ TARGET_COMPILE_OPTIONS(alplay PRIVATE ${C_FLAGS})
+ TARGET_LINK_LIBRARIES(alplay
+ PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
+ OpenAL)
+
+ ADD_EXECUTABLE(alstream examples/alstream.c)
+ TARGET_COMPILE_DEFINITIONS(alstream PRIVATE ${CPP_DEFS})
+ TARGET_INCLUDE_DIRECTORIES(alstream
+ PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
+ TARGET_COMPILE_OPTIONS(alstream PRIVATE ${C_FLAGS})
+ TARGET_LINK_LIBRARIES(alstream
+ PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
+ OpenAL)
+
+ ADD_EXECUTABLE(alreverb examples/alreverb.c)
+ TARGET_COMPILE_DEFINITIONS(alreverb PRIVATE ${CPP_DEFS})
+ TARGET_INCLUDE_DIRECTORIES(alreverb
+ PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
+ TARGET_COMPILE_OPTIONS(alreverb PRIVATE ${C_FLAGS})
+ TARGET_LINK_LIBRARIES(alreverb
+ PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
+ OpenAL)
+
+ ADD_EXECUTABLE(almultireverb examples/almultireverb.c)
+ TARGET_COMPILE_DEFINITIONS(almultireverb PRIVATE ${CPP_DEFS})
+ TARGET_INCLUDE_DIRECTORIES(almultireverb
+ PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
+ TARGET_COMPILE_OPTIONS(almultireverb PRIVATE ${C_FLAGS})
+ TARGET_LINK_LIBRARIES(almultireverb
+ PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
+ OpenAL ${MATH_LIB})
+
+ ADD_EXECUTABLE(allatency examples/allatency.c)
+ TARGET_COMPILE_DEFINITIONS(allatency PRIVATE ${CPP_DEFS})
+ TARGET_INCLUDE_DIRECTORIES(allatency
+ PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
+ TARGET_COMPILE_OPTIONS(allatency PRIVATE ${C_FLAGS})
+ TARGET_LINK_LIBRARIES(allatency
+ PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
+ OpenAL)
+
+ ADD_EXECUTABLE(alloopback examples/alloopback.c)
+ TARGET_COMPILE_DEFINITIONS(alloopback PRIVATE ${CPP_DEFS})
+ TARGET_INCLUDE_DIRECTORIES(alloopback
+ PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
+ TARGET_COMPILE_OPTIONS(alloopback PRIVATE ${C_FLAGS})
+ TARGET_LINK_LIBRARIES(alloopback
+ PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
+ OpenAL ${MATH_LIB})
+
+ ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
+ TARGET_COMPILE_DEFINITIONS(alhrtf PRIVATE ${CPP_DEFS})
+ TARGET_INCLUDE_DIRECTORIES(alhrtf
+ PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
+ TARGET_COMPILE_OPTIONS(alhrtf PRIVATE ${C_FLAGS})
+ TARGET_LINK_LIBRARIES(alhrtf
+ PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
+ OpenAL ${MATH_LIB})
+
+ IF(ALSOFT_INSTALL)
+ INSTALL(TARGETS alplay alstream alreverb almultireverb allatency alloopback alhrtf
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ )
+ ENDIF()
+
+ MESSAGE(STATUS "Building SDL_sound example programs")
ENDIF()
SET(FFVER_OK FALSE)
IF(FFMPEG_FOUND)
SET(FFVER_OK TRUE)
- IF(AVFORMAT_VERSION VERSION_LESS "55.33.100")
- MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 55.33.100)")
+ IF(AVFORMAT_VERSION VERSION_LESS "57.56.101")
+ MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
SET(FFVER_OK FALSE)
ENDIF()
- IF(AVCODEC_VERSION VERSION_LESS "55.52.102")
- MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 55.52.102)")
+ IF(AVCODEC_VERSION VERSION_LESS "57.64.101")
+ MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
SET(FFVER_OK FALSE)
ENDIF()
- IF(AVUTIL_VERSION VERSION_LESS "52.66.100")
- MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 52.66.100)")
+ IF(AVUTIL_VERSION VERSION_LESS "55.34.101")
+ MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
SET(FFVER_OK FALSE)
ENDIF()
- IF(SWSCALE_VERSION VERSION_LESS "2.5.102")
- MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 2.5.102)")
+ IF(SWSCALE_VERSION VERSION_LESS "4.2.100")
+ MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
SET(FFVER_OK FALSE)
ENDIF()
- IF(SWRESAMPLE_VERSION VERSION_LESS "0.18.100")
- MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 0.18.100)")
+ IF(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
+ MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
SET(FFVER_OK FALSE)
ENDIF()
ENDIF()
- IF(FFVER_OK AND NOT MSVC)
- ADD_EXECUTABLE(alffplay examples/alffplay.c)
- TARGET_LINK_LIBRARIES(alffplay common ex-common ${SDL2_LIBRARY} ${LIBNAME} ${FFMPEG_LIBRARIES})
- SET_PROPERTY(TARGET alffplay APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
- ${FFMPEG_INCLUDE_DIRS})
+ IF(FFVER_OK)
+ ADD_EXECUTABLE(alffplay examples/alffplay.cpp)
+ TARGET_COMPILE_DEFINITIONS(alffplay PRIVATE ${CPP_DEFS})
+ TARGET_INCLUDE_DIRECTORIES(alffplay
+ PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
+ TARGET_COMPILE_OPTIONS(alffplay PRIVATE ${C_FLAGS})
+ TARGET_LINK_LIBRARIES(alffplay
+ PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common common
+ OpenAL)
IF(ALSOFT_INSTALL)
INSTALL(TARGETS alffplay
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION "lib${LIB_SUFFIX}"
- ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
ENDIF()
- MESSAGE(STATUS "Building SDL and FFmpeg example programs")
- ELSE()
- MESSAGE(STATUS "Building SDL example programs")
+ MESSAGE(STATUS "Building SDL+FFmpeg example programs")
ENDIF()
MESSAGE(STATUS "")
ENDIF()
diff --git a/COPYING b/COPYING
index 5bc8fb2c..8d5d0000 100644
--- a/COPYING
+++ b/COPYING
@@ -51,7 +51,7 @@ library. If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.
-
+
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
@@ -98,7 +98,7 @@ works together with the library.
Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.
-
+
GNU LIBRARY GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@@ -145,7 +145,7 @@ Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
-
+
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
@@ -203,7 +203,7 @@ instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
-
+
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
@@ -254,7 +254,7 @@ Library will still fall under Section 6.)
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
-
+
6. As an exception to the Sections above, you may also compile or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
@@ -308,7 +308,7 @@ restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
-
+
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
@@ -349,7 +349,7 @@ subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
-
+
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
@@ -401,7 +401,7 @@ conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
-
+
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
@@ -435,47 +435,3 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Libraries
-
- If you develop a new library, and you want it to be of the greatest
-possible use to the public, we recommend making it free software that
-everyone can redistribute and change. You can do so by permitting
-redistribution under these terms (or, alternatively, under the terms of the
-ordinary General Public License).
-
- To apply these terms, attach the following notices to the library. It is
-safest to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least the
-"copyright" line and a pointer to where the full notice is found.
-
- <one line to give the library's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- 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
-
-Also add information on how to contact you by electronic and paper mail.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the library, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the
- library `Frob' (a library for tweaking knobs) written by James Random Hacker.
-
- <signature of Ty Coon>, 1 April 1990
- Ty Coon, President of Vice
-
-That's all there is to it!
diff --git a/ChangeLog b/ChangeLog
index 2f037254..d234c14f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,217 @@
+openal-soft-1.19.1:
+
+ Implemented capture support for the SoundIO backend.
+
+ Fixed source buffer queues potentially not playing properly when a queue
+ entry completes.
+
+ Fixed possible unexpected failures when generating auxiliary effect slots.
+
+ Fixed a crash with certain reverb or device settings.
+
+ Fixed OpenSL capture.
+
+ Improved output limiter response, better ensuring the sample amplitude is
+ clamped for output.
+
+openal-soft-1.19.0:
+
+ Implemented the ALC_SOFT_device_clock extension.
+
+ Implemented the Pitch Shifter, Frequency Shifter, and Autowah effects.
+
+ Fixed compiling on FreeBSD systems that use freebsd-lib 9.1.
+
+ Fixed compiling on NetBSD.
+
+ Fixed the reverb effect's density scale and panning parameters.
+
+ Fixed use of the WASAPI backend with certain games, which caused odd COM
+ initialization errors.
+
+ Increased the number of virtual channels for decoding Ambisonics to HRTF
+ output.
+
+ Changed 32-bit x86 builds to use SSE2 math by default for performance.
+ Build-time options are available to use just SSE1 or x87 instead.
+
+ Replaced the 4-point Sinc resampler with a more efficient cubic resampler.
+
+ Renamed the MMDevAPI backend to WASAPI.
+
+ Added support for 24-bit, dual-ear HRTF data sets. The built-in data set
+ has been updated to 24-bit.
+
+ Added a 24- to 48-point band-limited Sinc resampler.
+
+ Added an SDL2 playback backend. Disabled by default to avoid a dependency
+ on SDL2.
+
+ Improved the performance and quality of the Chorus and Flanger effects.
+
+ Improved the efficiency of the band-limited Sinc resampler.
+
+ Improved the Sinc resampler's transition band to avoid over-attenuating
+ higher frequencies.
+
+ Improved the performance of some filter operations.
+
+ Improved the efficiency of object ID lookups.
+
+ Improved the efficienty of internal voice/source synchronization.
+
+ Improved AL call error logging with contextualized messages.
+
+ Removed the reverb effect's modulation stage. Due to the lack of reference
+ for its intended behavior and strength.
+
+openal-soft-1.18.2:
+
+ Fixed resetting the FPU rounding mode after certain function calls on
+ Windows.
+
+ Fixed use of SSE intrinsics when building with Clang on Windows.
+
+ Fixed a crash with the JACK backend when using JACK1.
+
+ Fixed use of pthread_setnane_np on NetBSD.
+
+ Fixed building on FreeBSD with an older freebsd-lib.
+
+ OSS now links with libossaudio if found at build time (for NetBSD).
+
+openal-soft-1.18.1:
+
+ Fixed an issue where resuming a source might not restart playing it.
+
+ Fixed PulseAudio playback when the configured stream length is much less
+ than the requested length.
+
+ Fixed MMDevAPI capture with sample rates not matching the backing device.
+
+ Fixed int32 output for the Wave Writer.
+
+ Fixed enumeration of OSS devices that are missing device files.
+
+ Added correct retrieval of the executable's path on FreeBSD.
+
+ Added a config option to specify the dithering depth.
+
+ Added a 5.1 decoder preset that excludes front-center output.
+
+openal-soft-1.18.0:
+
+ Implemented the AL_EXT_STEREO_ANGLES and AL_EXT_SOURCE_RADIUS extensions.
+
+ Implemented the AL_SOFT_gain_clamp_ex, AL_SOFT_source_resampler,
+ AL_SOFT_source_spatialize, and ALC_SOFT_output_limiter extensions.
+
+ Implemented 3D processing for some effects. Currently implemented for
+ Reverb, Compressor, Equalizer, and Ring Modulator.
+
+ Implemented 2-channel UHJ output encoding. This needs to be enabled with a
+ config option to be used.
+
+ Implemented dual-band processing for high-quality ambisonic decoding.
+
+ Implemented distance-compensation for surround sound output.
+
+ Implemented near-field emulation and compensation with ambisonic rendering.
+ Currently only applies when using the high-quality ambisonic decoder or
+ ambisonic output, with appropriate config options.
+
+ Implemented an output limiter to reduce the amount of distortion from
+ clipping.
+
+ Implemented dithering for 8-bit and 16-bit output.
+
+ Implemented a config option to select a preferred HRTF.
+
+ Implemented a run-time check for NEON extensions using /proc/cpuinfo.
+
+ Implemented experimental capture support for the OpenSL backend.
+
+ Fixed building on compilers with NEON support but don't default to having
+ NEON enabled.
+
+ Fixed support for JACK on Windows.
+
+ Fixed starting a source while alcSuspendContext is in effect.
+
+ Fixed detection of headsets as headphones, with MMDevAPI.
+
+ Added support for AmbDec config files, for custom ambisonic decoder
+ configurations. Version 3 files only.
+
+ Added backend-specific options to alsoft-config.
+
+ Added first-, second-, and third-order ambisonic output formats. Currently
+ only works with backends that don't rely on channel labels, like JACK,
+ ALSA, and OSS.
+
+ Added a build option to embed the default HRTFs into the lib.
+
+ Added AmbDec presets to enable high-quality ambisonic decoding.
+
+ Added an AmbDec preset for 3D7.1 speaker setups.
+
+ Added documentation regarding Ambisonics, 3D7.1, AmbDec config files, and
+ the provided ambdec presets.
+
+ Added the ability for MMDevAPI to open devices given a Device ID or GUID
+ string.
+
+ Added an option to the example apps to open a specific device.
+
+ Increased the maximum auxiliary send limit to 16 (up from 4). Requires
+ requesting them with the ALC_MAX_AUXILIARY_SENDS context creation
+ attribute.
+
+ Increased the default auxiliary effect slot count to 64 (up from 4).
+
+ Reduced the default period count to 3 (down from 4).
+
+ Slightly improved automatic naming for enumerated HRTFs.
+
+ Improved B-Format decoding with HRTF output.
+
+ Improved internal property handling for better batching behavior.
+
+ Improved performance of certain filter uses.
+
+ Removed support for the AL_SOFT_buffer_samples and AL_SOFT_buffer_sub_data
+ extensions. Due to conflicts with AL_EXT_SOURCE_RADIUS.
+
+openal-soft-1.17.2:
+
+ Implemented device enumeration for OSSv4.
+
+ Fixed building on OSX.
+
+ Fixed building on non-Windows systems without POSIX-2008.
+
+ Fixed Dedicated Dialog and Dedicated LFE effect output.
+
+ Added a build option to override the share install dir.
+
+ Added a build option to static-link libgcc for MinGW.
+
+openal-soft-1.17.1:
+
+ Fixed building with JACK and without PulseAudio.
+
+ Fixed building on FreeBSD.
+
+ Fixed the ALSA backend's allow-resampler option.
+
+ Fixed handling of inexact ALSA period counts.
+
+ Altered device naming scheme on Windows backends to better match other
+ drivers.
+
+ Updated the CoreAudio backend to use the AudioComponent API. This clears up
+ deprecation warnings for OSX 10.11, although requires OSX 10.6 or newer.
+
openal-soft-1.17.0:
Implemented a JACK playback backend.
diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h
index 0f0d3ef8..03ee97d6 100644
--- a/OpenAL32/Include/alAuxEffectSlot.h
+++ b/OpenAL32/Include/alAuxEffectSlot.h
@@ -4,6 +4,7 @@
#include "alMain.h"
#include "alEffect.h"
+#include "atomic.h"
#include "align.h"
#ifdef __cplusplus
@@ -14,24 +15,36 @@ struct ALeffectStateVtable;
struct ALeffectslot;
typedef struct ALeffectState {
+ RefCount Ref;
const struct ALeffectStateVtable *vtbl;
+
+ ALfloat (*OutBuffer)[BUFFERSIZE];
+ ALsizei OutChannels;
} ALeffectState;
+void ALeffectState_Construct(ALeffectState *state);
+void ALeffectState_Destruct(ALeffectState *state);
+
struct ALeffectStateVtable {
void (*const Destruct)(ALeffectState *state);
ALboolean (*const deviceUpdate)(ALeffectState *state, ALCdevice *device);
- void (*const update)(ALeffectState *state, ALCdevice *device, const struct ALeffectslot *slot);
- void (*const process)(ALeffectState *state, ALuint samplesToDo, const ALfloat *restrict samplesIn, ALfloat (*restrict samplesOut)[BUFFERSIZE], ALuint numChannels);
+ void (*const update)(ALeffectState *state, const ALCcontext *context, const struct ALeffectslot *slot, const union ALeffectProps *props);
+ void (*const process)(ALeffectState *state, ALsizei samplesToDo, const ALfloat (*restrict samplesIn)[BUFFERSIZE], ALfloat (*restrict samplesOut)[BUFFERSIZE], ALsizei numChannels);
void (*const Delete)(void *ptr);
};
+/* Small hack to use a pointer-to-array types as a normal argument type.
+ * Shouldn't be used directly.
+ */
+typedef ALfloat ALfloatBUFFERSIZE[BUFFERSIZE];
+
#define DEFINE_ALEFFECTSTATE_VTABLE(T) \
DECLARE_THUNK(T, ALeffectState, void, Destruct) \
DECLARE_THUNK1(T, ALeffectState, ALboolean, deviceUpdate, ALCdevice*) \
-DECLARE_THUNK2(T, ALeffectState, void, update, ALCdevice*, const ALeffectslot*) \
-DECLARE_THUNK4(T, ALeffectState, void, process, ALuint, const ALfloat*restrict, ALfloatBUFFERSIZE*restrict, ALuint) \
+DECLARE_THUNK3(T, ALeffectState, void, update, const ALCcontext*, const ALeffectslot*, const ALeffectProps*) \
+DECLARE_THUNK4(T, ALeffectState, void, process, ALsizei, const ALfloatBUFFERSIZE*restrict, ALfloatBUFFERSIZE*restrict, ALsizei) \
static void T##_ALeffectState_Delete(void *ptr) \
{ return T##_Delete(STATIC_UPCAST(T, ALeffectState, (ALeffectState*)ptr)); } \
\
@@ -46,69 +59,124 @@ static const struct ALeffectStateVtable T##_ALeffectState_vtable = { \
}
-struct ALeffectStateFactoryVtable;
+struct EffectStateFactoryVtable;
-typedef struct ALeffectStateFactory {
- const struct ALeffectStateFactoryVtable *vtbl;
-} ALeffectStateFactory;
+typedef struct EffectStateFactory {
+ const struct EffectStateFactoryVtable *vtab;
+} EffectStateFactory;
-struct ALeffectStateFactoryVtable {
- ALeffectState *(*const create)(ALeffectStateFactory *factory);
+struct EffectStateFactoryVtable {
+ ALeffectState *(*const create)(EffectStateFactory *factory);
};
+#define EffectStateFactory_create(x) ((x)->vtab->create((x)))
-#define DEFINE_ALEFFECTSTATEFACTORY_VTABLE(T) \
-DECLARE_THUNK(T, ALeffectStateFactory, ALeffectState*, create) \
+#define DEFINE_EFFECTSTATEFACTORY_VTABLE(T) \
+DECLARE_THUNK(T, EffectStateFactory, ALeffectState*, create) \
\
-static const struct ALeffectStateFactoryVtable T##_ALeffectStateFactory_vtable = { \
- T##_ALeffectStateFactory_create, \
+static const struct EffectStateFactoryVtable T##_EffectStateFactory_vtable = { \
+ T##_EffectStateFactory_create, \
}
+#define MAX_EFFECT_CHANNELS (4)
+
+
+struct ALeffectslotArray {
+ ALsizei count;
+ struct ALeffectslot *slot[];
+};
+
+
+struct ALeffectslotProps {
+ ALfloat Gain;
+ ALboolean AuxSendAuto;
+
+ ALenum Type;
+ ALeffectProps Props;
+
+ ALeffectState *State;
+
+ ATOMIC(struct ALeffectslotProps*) next;
+};
+
+
typedef struct ALeffectslot {
- ALenum EffectType;
- ALeffectProps EffectProps;
+ ALfloat Gain;
+ ALboolean AuxSendAuto;
- volatile ALfloat Gain;
- volatile ALboolean AuxSendAuto;
+ struct {
+ ALenum Type;
+ ALeffectProps Props;
- ATOMIC(ALenum) NeedsUpdate;
- ALeffectState *EffectState;
+ ALeffectState *State;
+ } Effect;
- alignas(16) ALfloat WetBuffer[1][BUFFERSIZE];
+ ATOMIC_FLAG PropsClean;
RefCount ref;
+ ATOMIC(struct ALeffectslotProps*) Update;
+
+ struct {
+ ALfloat Gain;
+ ALboolean AuxSendAuto;
+
+ ALenum EffectType;
+ ALeffectProps EffectProps;
+ ALeffectState *EffectState;
+
+ ALfloat RoomRolloff; /* Added to the source's room rolloff, not multiplied. */
+ ALfloat DecayTime;
+ ALfloat DecayLFRatio;
+ ALfloat DecayHFRatio;
+ ALboolean DecayHFLimit;
+ ALfloat AirAbsorptionGainHF;
+ } Params;
+
/* Self ID */
ALuint id;
-} ALeffectslot;
-inline struct ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id)
-{ return (struct ALeffectslot*)LookupUIntMapKey(&context->EffectSlotMap, id); }
-inline struct ALeffectslot *RemoveEffectSlot(ALCcontext *context, ALuint id)
-{ return (struct ALeffectslot*)RemoveUIntMapKey(&context->EffectSlotMap, id); }
+ ALsizei NumChannels;
+ BFChannelConfig ChanMap[MAX_EFFECT_CHANNELS];
+ /* Wet buffer configuration is ACN channel order with N3D scaling:
+ * * Channel 0 is the unattenuated mono signal.
+ * * Channel 1 is OpenAL -X * sqrt(3)
+ * * Channel 2 is OpenAL Y * sqrt(3)
+ * * Channel 3 is OpenAL -Z * sqrt(3)
+ * Consequently, effects that only want to work with mono input can use
+ * channel 0 by itself. Effects that want multichannel can process the
+ * ambisonics signal and make a B-Format source pan for first-order device
+ * output (FOAOut).
+ */
+ alignas(16) ALfloat WetBuffer[MAX_EFFECT_CHANNELS][BUFFERSIZE];
+} ALeffectslot;
ALenum InitEffectSlot(ALeffectslot *slot);
+void DeinitEffectSlot(ALeffectslot *slot);
+void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context);
+void UpdateAllEffectSlotProps(ALCcontext *context);
ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context);
-ALeffectStateFactory *ALnullStateFactory_getFactory(void);
-ALeffectStateFactory *ALreverbStateFactory_getFactory(void);
-ALeffectStateFactory *ALautowahStateFactory_getFactory(void);
-ALeffectStateFactory *ALchorusStateFactory_getFactory(void);
-ALeffectStateFactory *ALcompressorStateFactory_getFactory(void);
-ALeffectStateFactory *ALdistortionStateFactory_getFactory(void);
-ALeffectStateFactory *ALechoStateFactory_getFactory(void);
-ALeffectStateFactory *ALequalizerStateFactory_getFactory(void);
-ALeffectStateFactory *ALflangerStateFactory_getFactory(void);
-ALeffectStateFactory *ALmodulatorStateFactory_getFactory(void);
+EffectStateFactory *NullStateFactory_getFactory(void);
+EffectStateFactory *ReverbStateFactory_getFactory(void);
+EffectStateFactory *AutowahStateFactory_getFactory(void);
+EffectStateFactory *ChorusStateFactory_getFactory(void);
+EffectStateFactory *CompressorStateFactory_getFactory(void);
+EffectStateFactory *DistortionStateFactory_getFactory(void);
+EffectStateFactory *EchoStateFactory_getFactory(void);
+EffectStateFactory *EqualizerStateFactory_getFactory(void);
+EffectStateFactory *FlangerStateFactory_getFactory(void);
+EffectStateFactory *FshifterStateFactory_getFactory(void);
+EffectStateFactory *ModulatorStateFactory_getFactory(void);
+EffectStateFactory *PshifterStateFactory_getFactory(void);
-ALeffectStateFactory *ALdedicatedStateFactory_getFactory(void);
+EffectStateFactory *DedicatedStateFactory_getFactory(void);
-ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *effect);
+ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect);
-void InitEffectFactoryMap(void);
-void DeinitEffectFactoryMap(void);
+void ALeffectState_DecRef(ALeffectState *state);
#ifdef __cplusplus
}
diff --git a/OpenAL32/Include/alBuffer.h b/OpenAL32/Include/alBuffer.h
index dd046da8..fbe3e6e5 100644
--- a/OpenAL32/Include/alBuffer.h
+++ b/OpenAL32/Include/alBuffer.h
@@ -1,7 +1,13 @@
#ifndef _AL_BUFFER_H_
#define _AL_BUFFER_H_
-#include "alMain.h"
+#include "AL/alc.h"
+#include "AL/al.h"
+#include "AL/alext.h"
+
+#include "inprogext.h"
+#include "atomic.h"
+#include "rwlock.h"
#ifdef __cplusplus
extern "C" {
@@ -9,36 +15,30 @@ extern "C" {
/* 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,
+ UserFmtUByte,
+ UserFmtShort,
+ UserFmtFloat,
+ UserFmtDouble,
UserFmtMulaw,
UserFmtAlaw,
UserFmtIMA4,
UserFmtMSADPCM,
};
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) */
- UserFmtBFormat2D = 0x10000000, /* WXY */
+ UserFmtMono,
+ UserFmtStereo,
+ UserFmtRear,
+ UserFmtQuad,
+ UserFmtX51, /* (WFX order) */
+ UserFmtX61, /* (WFX order) */
+ UserFmtX71, /* (WFX order) */
+ UserFmtBFormat2D, /* WXY */
UserFmtBFormat3D, /* WXYZ */
};
-ALuint BytesFromUserFmt(enum UserFmtType type) DECL_CONST;
-ALuint ChannelsFromUserFmt(enum UserFmtChannels chans) DECL_CONST;
-inline ALuint FrameSizeFromUserFmt(enum UserFmtChannels chans, enum UserFmtType type)
+ALsizei BytesFromUserFmt(enum UserFmtType type);
+ALsizei ChannelsFromUserFmt(enum UserFmtChannels chans);
+inline ALsizei FrameSizeFromUserFmt(enum UserFmtChannels chans, enum UserFmtType type)
{
return ChannelsFromUserFmt(chans) * BytesFromUserFmt(type);
}
@@ -46,9 +46,12 @@ inline ALuint FrameSizeFromUserFmt(enum UserFmtChannels chans, enum UserFmtType
/* Storable formats */
enum FmtType {
- FmtByte = UserFmtByte,
- FmtShort = UserFmtShort,
- FmtFloat = UserFmtFloat,
+ FmtUByte = UserFmtUByte,
+ FmtShort = UserFmtShort,
+ FmtFloat = UserFmtFloat,
+ FmtDouble = UserFmtDouble,
+ FmtMulaw = UserFmtMulaw,
+ FmtAlaw = UserFmtAlaw,
};
enum FmtChannels {
FmtMono = UserFmtMono,
@@ -63,9 +66,9 @@ enum FmtChannels {
};
#define MAX_INPUT_CHANNELS (8)
-ALuint BytesFromFmt(enum FmtType type) DECL_CONST;
-ALuint ChannelsFromFmt(enum FmtChannels chans) DECL_CONST;
-inline ALuint FrameSizeFromFmt(enum FmtChannels chans, enum FmtType type)
+ALsizei BytesFromFmt(enum FmtType type);
+ALsizei ChannelsFromFmt(enum FmtChannels chans);
+inline ALsizei FrameSizeFromFmt(enum FmtChannels chans, enum FmtType type)
{
return ChannelsFromFmt(chans) * BytesFromFmt(type);
}
@@ -74,43 +77,35 @@ inline ALuint FrameSizeFromFmt(enum FmtChannels chans, enum FmtType type)
typedef struct ALbuffer {
ALvoid *data;
- ALsizei Frequency;
- ALenum Format;
- ALsizei SampleLen;
+ ALsizei Frequency;
+ ALbitfieldSOFT Access;
+ ALsizei SampleLen;
enum FmtChannels FmtChannels;
enum FmtType FmtType;
+ ALsizei BytesAlloc;
- enum UserFmtChannels OriginalChannels;
- enum UserFmtType OriginalType;
- ALsizei OriginalSize;
- ALsizei OriginalAlign;
+ enum UserFmtType OriginalType;
+ ALsizei OriginalSize;
+ ALsizei OriginalAlign;
- ALsizei LoopStart;
- ALsizei LoopEnd;
+ ALsizei LoopStart;
+ ALsizei LoopEnd;
ATOMIC(ALsizei) UnpackAlign;
ATOMIC(ALsizei) PackAlign;
+ ALbitfieldSOFT MappedAccess;
+ ALsizei MappedOffset;
+ ALsizei MappedSize;
+
/* Number of times buffer was attached to a source (deletion can only occur when 0) */
RefCount ref;
- RWLock lock;
-
/* Self ID */
ALuint id;
} ALbuffer;
-ALbuffer *NewBuffer(ALCcontext *context);
-void DeleteBuffer(ALCdevice *device, ALbuffer *buffer);
-
-ALenum LoadData(ALbuffer *buffer, ALuint freq, ALenum NewFormat, ALsizei frames, enum UserFmtChannels SrcChannels, enum UserFmtType SrcType, const ALvoid *data, ALsizei align, ALboolean storesrc);
-
-inline struct ALbuffer *LookupBuffer(ALCdevice *device, ALuint id)
-{ return (struct ALbuffer*)LookupUIntMapKey(&device->BufferMap, id); }
-inline struct ALbuffer *RemoveBuffer(ALCdevice *device, ALuint id)
-{ return (struct ALbuffer*)RemoveUIntMapKey(&device->BufferMap, id); }
-
ALvoid ReleaseALBuffers(ALCdevice *device);
#ifdef __cplusplus
diff --git a/OpenAL32/Include/alEffect.h b/OpenAL32/Include/alEffect.h
index 91ee782f..7b849c0c 100644
--- a/OpenAL32/Include/alEffect.h
+++ b/OpenAL32/Include/alEffect.h
@@ -10,24 +10,34 @@ extern "C" {
struct ALeffect;
enum {
- EAXREVERB = 0,
- REVERB,
- AUTOWAH,
- CHORUS,
- COMPRESSOR,
- DISTORTION,
- ECHO,
- EQUALIZER,
- FLANGER,
- MODULATOR,
- DEDICATED,
+ EAXREVERB_EFFECT = 0,
+ REVERB_EFFECT,
+ AUTOWAH_EFFECT,
+ CHORUS_EFFECT,
+ COMPRESSOR_EFFECT,
+ DISTORTION_EFFECT,
+ ECHO_EFFECT,
+ EQUALIZER_EFFECT,
+ FLANGER_EFFECT,
+ FSHIFTER_EFFECT,
+ MODULATOR_EFFECT,
+ PSHIFTER_EFFECT,
+ DEDICATED_EFFECT,
MAX_EFFECTS
};
extern ALboolean DisabledEffects[MAX_EFFECTS];
extern ALfloat ReverbBoost;
-extern ALboolean EmulateEAXReverb;
+
+struct EffectList {
+ const char name[16];
+ int type;
+ ALenum val;
+};
+#define EFFECTLIST_SIZE 14
+extern const struct EffectList EffectList[EFFECTLIST_SIZE];
+
struct ALeffectVtable {
void (*const setParami)(struct ALeffect *effect, ALCcontext *context, ALenum param, ALint val);
@@ -58,8 +68,10 @@ extern const struct ALeffectVtable ALdistortion_vtable;
extern const struct ALeffectVtable ALecho_vtable;
extern const struct ALeffectVtable ALequalizer_vtable;
extern const struct ALeffectVtable ALflanger_vtable;
+extern const struct ALeffectVtable ALfshifter_vtable;
extern const struct ALeffectVtable ALmodulator_vtable;
extern const struct ALeffectVtable ALnull_vtable;
+extern const struct ALeffectVtable ALpshifter_vtable;
extern const struct ALeffectVtable ALdedicated_vtable;
@@ -96,8 +108,8 @@ typedef union ALeffectProps {
struct {
ALfloat AttackTime;
ALfloat ReleaseTime;
- ALfloat PeakGain;
ALfloat Resonance;
+ ALfloat PeakGain;
} Autowah;
struct {
@@ -107,7 +119,7 @@ typedef union ALeffectProps {
ALfloat Depth;
ALfloat Feedback;
ALfloat Delay;
- } Chorus;
+ } Chorus; /* Also Flanger */
struct {
ALboolean OnOff;
@@ -145,13 +157,10 @@ typedef union ALeffectProps {
} Equalizer;
struct {
- ALint Waveform;
- ALint Phase;
- ALfloat Rate;
- ALfloat Depth;
- ALfloat Feedback;
- ALfloat Delay;
- } Flanger;
+ ALfloat Frequency;
+ ALint LeftDirection;
+ ALint RightDirection;
+ } Fshifter;
struct {
ALfloat Frequency;
@@ -160,6 +169,11 @@ typedef union ALeffectProps {
} Modulator;
struct {
+ ALint CoarseTune;
+ ALint FineTune;
+ } Pshifter;
+
+ struct {
ALfloat Gain;
} Dedicated;
} ALeffectProps;
@@ -170,24 +184,27 @@ typedef struct ALeffect {
ALeffectProps Props;
- const struct ALeffectVtable *vtbl;
+ const struct ALeffectVtable *vtab;
/* Self ID */
ALuint id;
} ALeffect;
-
-inline struct ALeffect *LookupEffect(ALCdevice *device, ALuint id)
-{ return (struct ALeffect*)LookupUIntMapKey(&device->EffectMap, id); }
-inline struct ALeffect *RemoveEffect(ALCdevice *device, ALuint id)
-{ return (struct ALeffect*)RemoveUIntMapKey(&device->EffectMap, id); }
+#define ALeffect_setParami(o, c, p, v) ((o)->vtab->setParami(o, c, p, v))
+#define ALeffect_setParamf(o, c, p, v) ((o)->vtab->setParamf(o, c, p, v))
+#define ALeffect_setParamiv(o, c, p, v) ((o)->vtab->setParamiv(o, c, p, v))
+#define ALeffect_setParamfv(o, c, p, v) ((o)->vtab->setParamfv(o, c, p, v))
+#define ALeffect_getParami(o, c, p, v) ((o)->vtab->getParami(o, c, p, v))
+#define ALeffect_getParamf(o, c, p, v) ((o)->vtab->getParamf(o, c, p, v))
+#define ALeffect_getParamiv(o, c, p, v) ((o)->vtab->getParamiv(o, c, p, v))
+#define ALeffect_getParamfv(o, c, p, v) ((o)->vtab->getParamfv(o, c, p, v))
inline ALboolean IsReverbEffect(ALenum type)
{ return type == AL_EFFECT_REVERB || type == AL_EFFECT_EAXREVERB; }
-ALenum InitEffect(ALeffect *effect);
-ALvoid ReleaseALEffects(ALCdevice *device);
+void InitEffect(ALeffect *effect);
+void ReleaseALEffects(ALCdevice *device);
-ALvoid LoadReverbPreset(const char *name, ALeffect *effect);
+void LoadReverbPreset(const char *name, ALeffect *effect);
#ifdef __cplusplus
}
diff --git a/OpenAL32/Include/alError.h b/OpenAL32/Include/alError.h
index ab91d27b..858f81de 100644
--- a/OpenAL32/Include/alError.h
+++ b/OpenAL32/Include/alError.h
@@ -2,6 +2,7 @@
#define _AL_ERROR_H_
#include "alMain.h"
+#include "logging.h"
#ifdef __cplusplus
extern "C" {
@@ -9,21 +10,16 @@ extern "C" {
extern ALboolean TrapALError;
-ALvoid alSetError(ALCcontext *Context, ALenum errorCode);
+void alSetError(ALCcontext *context, ALenum errorCode, const char *msg, ...) DECL_FORMAT(printf, 3, 4);
-#define SET_ERROR_AND_RETURN(ctx, err) do { \
- alSetError((ctx), (err)); \
- return; \
-} while(0)
-
-#define SET_ERROR_AND_RETURN_VALUE(ctx, err, val) do { \
- alSetError((ctx), (err)); \
- return (val); \
+#define SETERR_GOTO(ctx, err, lbl, ...) do { \
+ alSetError((ctx), (err), __VA_ARGS__); \
+ goto lbl; \
} while(0)
-#define SET_ERROR_AND_GOTO(ctx, err, lbl) do { \
- alSetError((ctx), (err)); \
- goto lbl; \
+#define SETERR_RETURN(ctx, err, retval, ...) do { \
+ alSetError((ctx), (err), __VA_ARGS__); \
+ return retval; \
} while(0)
#ifdef __cplusplus
diff --git a/OpenAL32/Include/alFilter.h b/OpenAL32/Include/alFilter.h
index 3c65fd9f..2634d5e8 100644
--- a/OpenAL32/Include/alFilter.h
+++ b/OpenAL32/Include/alFilter.h
@@ -1,9 +1,8 @@
#ifndef _AL_FILTER_H_
#define _AL_FILTER_H_
-#include "alMain.h"
-
-#include "math_defs.h"
+#include "AL/alc.h"
+#include "AL/al.h"
#ifdef __cplusplus
extern "C" {
@@ -13,86 +12,28 @@ extern "C" {
#define HIGHPASSFREQREF (250.0f)
-/* Filters implementation is based on the "Cookbook formulae for audio
- * EQ biquad filter coefficients" by Robert Bristow-Johnson
- * http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
- */
-/* Implementation note: For the shelf filters, the specified gain is for the
- * reference frequency, which is the centerpoint of the transition band. This
- * better matches EFX filter design. To set the gain for the shelf itself, use
- * the square root of the desired linear gain (or halve the dB gain).
- */
-
-typedef enum ALfilterType {
- /** EFX-style low-pass filter, specifying a gain and reference frequency. */
- ALfilterType_HighShelf,
- /** EFX-style high-pass filter, specifying a gain and reference frequency. */
- ALfilterType_LowShelf,
- /** Peaking filter, specifying a gain and reference frequency. */
- ALfilterType_Peaking,
-
- /** Low-pass cut-off filter, specifying a cut-off frequency. */
- ALfilterType_LowPass,
- /** High-pass cut-off filter, specifying a cut-off frequency. */
- ALfilterType_HighPass,
- /** Band-pass filter, specifying a center frequency. */
- ALfilterType_BandPass,
-} ALfilterType;
-
-typedef struct ALfilterState {
- ALfloat x[2]; /* History of two last input samples */
- ALfloat y[2]; /* History of two last output samples */
- ALfloat a[3]; /* Transfer function coefficients "a" */
- ALfloat b[3]; /* Transfer function coefficients "b" */
-
- void (*process)(struct ALfilterState *self, ALfloat *restrict dst, const ALfloat *src, ALuint numsamples);
-} ALfilterState;
-#define ALfilterState_process(a, ...) ((a)->process((a), __VA_ARGS__))
-
-/* Calculates the rcpQ (i.e. 1/Q) coefficient for shelving filters, using the
- * reference gain and shelf slope parameter.
- * 0 < gain
- * 0 < slope <= 1
- */
-inline ALfloat calc_rcpQ_from_slope(ALfloat gain, ALfloat slope)
-{
- return sqrtf((gain + 1.0f/gain)*(1.0f/slope - 1.0f) + 2.0f);
-}
-/* Calculates the rcpQ (i.e. 1/Q) coefficient for filters, using the frequency
- * multiple (i.e. ref_freq / sampling_freq) and bandwidth.
- * 0 < freq_mult < 0.5.
- */
-inline ALfloat calc_rcpQ_from_bandwidth(ALfloat freq_mult, ALfloat bandwidth)
-{
- ALfloat w0 = F_TAU * freq_mult;
- return 2.0f*sinhf(logf(2.0f)/2.0f*bandwidth*w0/sinf(w0));
-}
-
-void ALfilterState_clear(ALfilterState *filter);
-void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat gain, ALfloat freq_mult, ALfloat rcpQ);
+struct ALfilter;
-inline ALfloat ALfilterState_processSingle(ALfilterState *filter, ALfloat sample)
-{
- ALfloat outsmp;
+typedef struct ALfilterVtable {
+ void (*const setParami)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALint val);
+ void (*const setParamiv)(struct ALfilter *filter, ALCcontext *context, ALenum param, const ALint *vals);
+ void (*const setParamf)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val);
+ void (*const setParamfv)(struct ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals);
- outsmp = filter->b[0] * sample +
- filter->b[1] * filter->x[0] +
- filter->b[2] * filter->x[1] -
- filter->a[1] * filter->y[0] -
- filter->a[2] * filter->y[1];
- filter->x[1] = filter->x[0];
- filter->x[0] = sample;
- filter->y[1] = filter->y[0];
- filter->y[0] = outsmp;
+ void (*const getParami)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALint *val);
+ void (*const getParamiv)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALint *vals);
+ void (*const getParamf)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val);
+ void (*const getParamfv)(struct ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals);
+} ALfilterVtable;
- return outsmp;
+#define DEFINE_ALFILTER_VTABLE(T) \
+const struct ALfilterVtable T##_vtable = { \
+ T##_setParami, T##_setParamiv, \
+ T##_setParamf, T##_setParamfv, \
+ T##_getParami, T##_getParamiv, \
+ T##_getParamf, T##_getParamfv, \
}
-void ALfilterState_processC(ALfilterState *filter, ALfloat *restrict dst, const ALfloat *src, ALuint numsamples);
-
-void ALfilterState_processPassthru(ALfilterState *filter, const ALfloat *src, ALuint numsamples);
-
-
typedef struct ALfilter {
// Filter type (AL_FILTER_NULL, ...)
ALenum type;
@@ -103,36 +44,21 @@ typedef struct ALfilter {
ALfloat GainLF;
ALfloat LFReference;
- 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);
+ const struct ALfilterVtable *vtab;
/* 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)))
-
-inline struct ALfilter *LookupFilter(ALCdevice *device, ALuint id)
-{ return (struct ALfilter*)LookupUIntMapKey(&device->FilterMap, id); }
-inline struct ALfilter *RemoveFilter(ALCdevice *device, ALuint id)
-{ return (struct ALfilter*)RemoveUIntMapKey(&device->FilterMap, id); }
-
-ALvoid ReleaseALFilters(ALCdevice *device);
+#define ALfilter_setParami(o, c, p, v) ((o)->vtab->setParami(o, c, p, v))
+#define ALfilter_setParamf(o, c, p, v) ((o)->vtab->setParamf(o, c, p, v))
+#define ALfilter_setParamiv(o, c, p, v) ((o)->vtab->setParamiv(o, c, p, v))
+#define ALfilter_setParamfv(o, c, p, v) ((o)->vtab->setParamfv(o, c, p, v))
+#define ALfilter_getParami(o, c, p, v) ((o)->vtab->getParami(o, c, p, v))
+#define ALfilter_getParamf(o, c, p, v) ((o)->vtab->getParamf(o, c, p, v))
+#define ALfilter_getParamiv(o, c, p, v) ((o)->vtab->getParamiv(o, c, p, v))
+#define ALfilter_getParamfv(o, c, p, v) ((o)->vtab->getParamfv(o, c, p, v))
+
+void ReleaseALFilters(ALCdevice *device);
#ifdef __cplusplus
}
diff --git a/OpenAL32/Include/alListener.h b/OpenAL32/Include/alListener.h
index c9bd9be0..0d80a8d7 100644
--- a/OpenAL32/Include/alListener.h
+++ b/OpenAL32/Include/alListener.h
@@ -8,20 +8,58 @@
extern "C" {
#endif
+struct ALcontextProps {
+ ALfloat DopplerFactor;
+ ALfloat DopplerVelocity;
+ ALfloat SpeedOfSound;
+ ALboolean SourceDistanceModel;
+ enum DistanceModel DistanceModel;
+ ALfloat MetersPerUnit;
+
+ ATOMIC(struct ALcontextProps*) next;
+};
+
+struct ALlistenerProps {
+ ALfloat Position[3];
+ ALfloat Velocity[3];
+ ALfloat Forward[3];
+ ALfloat Up[3];
+ ALfloat Gain;
+
+ ATOMIC(struct ALlistenerProps*) next;
+};
+
typedef struct ALlistener {
- aluVector Position;
- aluVector Velocity;
- volatile ALfloat Forward[3];
- volatile ALfloat Up[3];
- volatile ALfloat Gain;
- volatile ALfloat MetersPerUnit;
+ alignas(16) ALfloat Position[3];
+ ALfloat Velocity[3];
+ ALfloat Forward[3];
+ ALfloat Up[3];
+ ALfloat Gain;
+
+ ATOMIC_FLAG PropsClean;
+
+ /* Pointer to the most recent property values that are awaiting an update.
+ */
+ ATOMIC(struct ALlistenerProps*) Update;
struct {
- aluMatrixd Matrix;
+ aluMatrixf Matrix;
aluVector Velocity;
+
+ ALfloat Gain;
+ ALfloat MetersPerUnit;
+
+ ALfloat DopplerFactor;
+ ALfloat SpeedOfSound; /* in units per sec! */
+ ALfloat ReverbSpeedOfSound; /* in meters per sec! */
+
+ ALboolean SourceDistanceModel;
+ enum DistanceModel DistanceModel;
} Params;
} ALlistener;
+void UpdateListenerProps(ALCcontext *context);
+
#ifdef __cplusplus
}
#endif
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 8f1fd956..0fd77491 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -3,6 +3,7 @@
#include <string.h>
#include <stdio.h>
+#include <stddef.h>
#include <stdarg.h>
#include <assert.h>
#include <math.h>
@@ -11,15 +12,25 @@
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
-
-#ifdef HAVE_FENV_H
-#include <fenv.h>
+#ifdef HAVE_INTRIN_H
+#include <intrin.h>
#endif
#include "AL/al.h"
#include "AL/alc.h"
#include "AL/alext.h"
+#include "inprogext.h"
+#include "logging.h"
+#include "polymorphism.h"
+#include "static_assert.h"
+#include "align.h"
+#include "atomic.h"
+#include "vector.h"
+#include "alstring.h"
+#include "almalloc.h"
+#include "threads.h"
+
#if defined(_WIN64)
#define SZFMT "%I64u"
@@ -29,38 +40,38 @@
#define SZFMT "%zu"
#endif
-
-#include "static_assert.h"
-#include "align.h"
-#include "atomic.h"
-#include "uintmap.h"
-#include "vector.h"
-#include "alstring.h"
-
-#include "hrtf.h"
-
-#ifndef ALC_SOFT_device_clock
-#define ALC_SOFT_device_clock 1
-typedef int64_t ALCint64SOFT;
-typedef uint64_t ALCuint64SOFT;
-#define ALC_DEVICE_CLOCK_SOFT 0x1600
-typedef void (ALC_APIENTRY*LPALCGETINTEGER64VSOFT)(ALCdevice *device, ALCenum pname, ALsizei size, ALCint64SOFT *values);
-#ifdef AL_ALEXT_PROTOTYPES
-ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname, ALsizei size, ALCint64SOFT *values);
-#endif
+#ifdef __has_builtin
+#define HAS_BUILTIN __has_builtin
+#else
+#define HAS_BUILTIN(x) (0)
#endif
+#ifdef __GNUC__
+/* LIKELY optimizes the case where the condition is true. The condition is not
+ * required to be true, but it can result in more optimal code for the true
+ * path at the expense of a less optimal false path.
+ */
+#define LIKELY(x) __builtin_expect(!!(x), !0)
+/* The opposite of LIKELY, optimizing the case where the condition is false. */
+#define UNLIKELY(x) __builtin_expect(!!(x), 0)
+/* Unlike LIKELY, ASSUME requires the condition to be true or else it invokes
+ * undefined behavior. It's essentially an assert without actually checking the
+ * condition at run-time, allowing for stronger optimizations than LIKELY.
+ */
+#if HAS_BUILTIN(__builtin_assume)
+#define ASSUME __builtin_assume
+#else
+#define ASSUME(x) do { if(!(x)) __builtin_unreachable(); } while(0)
+#endif
-typedef ALint64SOFT ALint64;
-typedef ALuint64SOFT ALuint64;
+#else
-#ifndef U64
-#if defined(_MSC_VER)
-#define U64(x) ((ALuint64)(x##ui64))
-#elif SIZEOF_LONG == 8
-#define U64(x) ((ALuint64)(x##ul))
-#elif SIZEOF_LONG_LONG == 8
-#define U64(x) ((ALuint64)(x##ull))
+#define LIKELY(x) (!!(x))
+#define UNLIKELY(x) (!!(x))
+#ifdef _MSC_VER
+#define ASSUME __assume
+#else
+#define ASSUME(x) ((void)0)
#endif
#endif
@@ -80,141 +91,127 @@ typedef ALuint64SOFT ALuint64;
#endif
#endif
-#ifdef __GNUC__
-#define DECL_CONST __attribute__((const))
-#define DECL_FORMAT(x, y, z) __attribute__((format(x, (y), (z))))
-#else
-#define DECL_CONST
-#define DECL_FORMAT(x, y, z)
-#endif
+/* Calculates the size of a struct with N elements of a flexible array member.
+ * GCC and Clang allow offsetof(Type, fam[N]) for this, but MSVC seems to have
+ * trouble, so a bit more verbose workaround is needed.
+ */
+#define FAM_SIZE(T, M, N) (offsetof(T, M) + sizeof(((T*)NULL)->M[0])*(N))
-#if defined(__GNUC__) && defined(__i386__)
-/* force_align_arg_pointer is required for proper function arguments aligning
- * when SSE code is used. Some systems (Windows, QNX) do not guarantee our
- * thread functions will be properly aligned on the stack, even though GCC may
- * generate code with the assumption that it is. */
-#define FORCE_ALIGN __attribute__((force_align_arg_pointer))
-#else
-#define FORCE_ALIGN
-#endif
-#ifdef HAVE_C99_VLA
-#define DECL_VLA(T, _name, _size) T _name[(_size)]
-#else
-#define DECL_VLA(T, _name, _size) T *_name = alloca((_size) * sizeof(T))
+#ifdef __cplusplus
+extern "C" {
#endif
-#ifndef PATH_MAX
-#ifdef MAX_PATH
-#define PATH_MAX MAX_PATH
-#else
-#define PATH_MAX 4096
+typedef ALint64SOFT ALint64;
+typedef ALuint64SOFT ALuint64;
+
+#ifndef U64
+#if defined(_MSC_VER)
+#define U64(x) ((ALuint64)(x##ui64))
+#elif SIZEOF_LONG == 8
+#define U64(x) ((ALuint64)(x##ul))
+#elif SIZEOF_LONG_LONG == 8
+#define U64(x) ((ALuint64)(x##ull))
#endif
#endif
+#ifndef I64
+#if defined(_MSC_VER)
+#define I64(x) ((ALint64)(x##i64))
+#elif SIZEOF_LONG == 8
+#define I64(x) ((ALint64)(x##l))
+#elif SIZEOF_LONG_LONG == 8
+#define I64(x) ((ALint64)(x##ll))
+#endif
+#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]))
-
-
-#define DERIVE_FROM_TYPE(t) t t##_parent
-#define STATIC_CAST(to, obj) (&(obj)->to##_parent)
+/* Define a CTZ64 macro (count trailing zeros, for 64-bit integers). The result
+ * is *UNDEFINED* if the value is 0.
+ */
#ifdef __GNUC__
-#define STATIC_UPCAST(to, from, obj) __extension__({ \
- static_assert(__builtin_types_compatible_p(from, __typeof(*(obj))), \
- "Invalid upcast object from type"); \
- (to*)((char*)(obj) - offsetof(to, from##_parent)); \
-})
+
+#if SIZEOF_LONG == 8
+#define CTZ64 __builtin_ctzl
#else
-#define STATIC_UPCAST(to, from, obj) ((to*)((char*)(obj) - offsetof(to, from##_parent)))
+#define CTZ64 __builtin_ctzll
#endif
-#define DECLARE_FORWARD(T1, T2, rettype, func) \
-rettype T1##_##func(T1 *obj) \
-{ return T2##_##func(STATIC_CAST(T2, obj)); }
-
-#define DECLARE_FORWARD1(T1, T2, rettype, func, argtype1) \
-rettype T1##_##func(T1 *obj, argtype1 a) \
-{ return T2##_##func(STATIC_CAST(T2, obj), a); }
-
-#define DECLARE_FORWARD2(T1, T2, rettype, func, argtype1, argtype2) \
-rettype T1##_##func(T1 *obj, argtype1 a, argtype2 b) \
-{ return T2##_##func(STATIC_CAST(T2, obj), a, b); }
-
-#define DECLARE_FORWARD3(T1, T2, rettype, func, argtype1, argtype2, argtype3) \
-rettype T1##_##func(T1 *obj, argtype1 a, argtype2 b, argtype3 c) \
-{ return T2##_##func(STATIC_CAST(T2, obj), a, b, c); }
-
-
-#define GET_VTABLE1(T1) (&(T1##_vtable))
-#define GET_VTABLE2(T1, T2) (&(T1##_##T2##_vtable))
-
-#define SET_VTABLE1(T1, obj) ((obj)->vtbl = GET_VTABLE1(T1))
-#define SET_VTABLE2(T1, T2, obj) (STATIC_CAST(T2, obj)->vtbl = GET_VTABLE2(T1, T2))
-
-#define DECLARE_THUNK(T1, T2, rettype, func) \
-static rettype T1##_##T2##_##func(T2 *obj) \
-{ return T1##_##func(STATIC_UPCAST(T1, T2, obj)); }
+#elif defined(HAVE_BITSCANFORWARD64_INTRINSIC)
-#define DECLARE_THUNK1(T1, T2, rettype, func, argtype1) \
-static rettype T1##_##T2##_##func(T2 *obj, argtype1 a) \
-{ return T1##_##func(STATIC_UPCAST(T1, T2, obj), a); }
-
-#define DECLARE_THUNK2(T1, T2, rettype, func, argtype1, argtype2) \
-static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b) \
-{ return T1##_##func(STATIC_UPCAST(T1, T2, obj), a, b); }
-
-#define DECLARE_THUNK3(T1, T2, rettype, func, argtype1, argtype2, argtype3) \
-static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b, argtype3 c) \
-{ return T1##_##func(STATIC_UPCAST(T1, T2, obj), a, b, c); }
-
-#define DECLARE_THUNK4(T1, T2, rettype, func, argtype1, argtype2, argtype3, argtype4) \
-static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b, argtype3 c, argtype4 d) \
-{ return T1##_##func(STATIC_UPCAST(T1, T2, obj), a, b, c, d); }
-
-#define DECLARE_DEFAULT_ALLOCATORS(T) \
-static void* T##_New(size_t size) { return al_malloc(16, size); } \
-static void T##_Delete(void *ptr) { al_free(ptr); }
+inline int msvc64_ctz64(ALuint64 v)
+{
+ unsigned long idx = 64;
+ _BitScanForward64(&idx, v);
+ return (int)idx;
+}
+#define CTZ64 msvc64_ctz64
-/* Helper to extract an argument list for VCALL. Not used directly. */
-#define EXTRACT_VCALL_ARGS(...) __VA_ARGS__))
+#elif defined(HAVE_BITSCANFORWARD_INTRINSIC)
-/* Call a "virtual" method on an object, with arguments. */
-#define V(obj, func) ((obj)->vtbl->func((obj), EXTRACT_VCALL_ARGS
-/* Call a "virtual" method on an object, with no arguments. */
-#define V0(obj, func) ((obj)->vtbl->func((obj) EXTRACT_VCALL_ARGS
+inline int msvc_ctz64(ALuint64 v)
+{
+ unsigned long idx = 64;
+ if(!_BitScanForward(&idx, v&0xffffffff))
+ {
+ if(_BitScanForward(&idx, v>>32))
+ idx += 32;
+ }
+ return (int)idx;
+}
+#define CTZ64 msvc_ctz64
-#define DELETE_OBJ(obj) do { \
- if((obj) != NULL) \
- { \
- V0((obj),Destruct)(); \
- V0((obj),Delete)(); \
- } \
-} while(0)
+#else
+/* There be black magics here. The popcnt64 method is derived from
+ * https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
+ * while the ctz-utilizing-popcnt algorithm is shown here
+ * http://www.hackersdelight.org/hdcodetxt/ntz.c.txt
+ * as the ntz2 variant. These likely aren't the most efficient methods, but
+ * they're good enough if the GCC or MSVC intrinsics aren't available.
+ */
+inline int fallback_popcnt64(ALuint64 v)
+{
+ v = v - ((v >> 1) & U64(0x5555555555555555));
+ v = (v & U64(0x3333333333333333)) + ((v >> 2) & U64(0x3333333333333333));
+ v = (v + (v >> 4)) & U64(0x0f0f0f0f0f0f0f0f);
+ return (int)((v * U64(0x0101010101010101)) >> 56);
+}
-#define EXTRACT_NEW_ARGS(...) __VA_ARGS__); \
- } \
-} while(0)
+inline int fallback_ctz64(ALuint64 value)
+{
+ return fallback_popcnt64(~value & (value - 1));
+}
+#define CTZ64 fallback_ctz64
+#endif
-#define NEW_OBJ(_res, T) do { \
- _res = T##_New(sizeof(T)); \
- if(_res) \
- { \
- memset(_res, 0, sizeof(T)); \
- T##_Construct(_res, EXTRACT_NEW_ARGS
+#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
+#define IS_LITTLE_ENDIAN (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+#else
+static const union {
+ ALuint u;
+ ALubyte b[sizeof(ALuint)];
+} EndianTest = { 1 };
+#define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
+#endif
+#define COUNTOF(x) (sizeof(x) / sizeof(0[x]))
-#ifdef __cplusplus
-extern "C" {
-#endif
+struct ll_ringbuffer;
struct Hrtf;
+struct HrtfEntry;
+struct DirectHrtfState;
+struct FrontStablizer;
+struct Compressor;
+struct ALCbackend;
+struct ALbuffer;
+struct ALeffect;
+struct ALfilter;
+struct ALsource;
+struct ALcontextProps;
+struct ALlistenerProps;
+struct ALvoiceProps;
+struct ALeffectslotProps;
#define DEFAULT_OUTPUT_RATE (44100)
@@ -236,26 +233,138 @@ inline ALuint NextPowerOf2(ALuint value)
return value+1;
}
-/* Fast float-to-int conversion. Assumes the FPU is already in round-to-zero
- * mode. */
+/** Round up a value to the next multiple. */
+inline size_t RoundUp(size_t value, size_t r)
+{
+ value += r-1;
+ return value - (value%r);
+}
+
+/* Fast float-to-int conversion. No particular rounding mode is assumed; the
+ * IEEE-754 default is round-to-nearest with ties-to-even, though an app could
+ * change it on its own threads. On some systems, a truncating conversion may
+ * always be the fastest method.
+ */
inline ALint fastf2i(ALfloat f)
{
-#ifdef HAVE_LRINTF
- return lrintf(f);
-#elif defined(_MSC_VER) && defined(_M_IX86)
+#if defined(HAVE_INTRIN_H) && ((defined(_M_IX86_FP) && (_M_IX86_FP > 0)) || defined(_M_X64))
+ return _mm_cvt_ss2si(_mm_set1_ps(f));
+
+#elif defined(_MSC_VER) && defined(_M_IX86_FP)
+
ALint i;
__asm fld f
__asm fistp i
return i;
+
+#elif (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__))
+
+ ALint i;
+#ifdef __SSE_MATH__
+ __asm__("cvtss2si %1, %0" : "=r"(i) : "x"(f));
#else
+ __asm__ __volatile__("fistpl %0" : "=m"(i) : "t"(f) : "st");
+#endif
+ return i;
+
+ /* On GCC when compiling with -fno-math-errno, lrintf can be inlined to
+ * some simple instructions. Clang does not inline it, always generating a
+ * libc call, while MSVC's implementation is horribly slow, so always fall
+ * back to a normal integer conversion for them.
+ */
+#elif defined(HAVE_LRINTF) && !defined(_MSC_VER) && !defined(__clang__)
+
+ return lrintf(f);
+
+#else
+
return (ALint)f;
#endif
}
-/* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
- * mode. */
-inline ALuint fastf2u(ALfloat f)
-{ return fastf2i(f); }
+/* Converts float-to-int using standard behavior (truncation). */
+inline int float2int(float f)
+{
+#if ((defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__)) && \
+ !defined(__SSE_MATH__)) || (defined(_MSC_VER) && defined(_M_IX86_FP) && _M_IX86_FP == 0)
+ ALint sign, shift, mant;
+ union {
+ ALfloat f;
+ ALint i;
+ } conv;
+
+ conv.f = f;
+ sign = (conv.i>>31) | 1;
+ shift = ((conv.i>>23)&0xff) - (127+23);
+
+ /* Over/underflow */
+ if(UNLIKELY(shift >= 31 || shift < -23))
+ return 0;
+
+ mant = (conv.i&0x7fffff) | 0x800000;
+ if(LIKELY(shift < 0))
+ return (mant >> -shift) * sign;
+ return (mant << shift) * sign;
+
+#else
+
+ return (ALint)f;
+#endif
+}
+
+/* Rounds a float to the nearest integral value, according to the current
+ * rounding mode. This is essentially an inlined version of rintf, although
+ * makes fewer promises (e.g. -0 or -0.25 rounded to 0 may result in +0).
+ */
+inline float fast_roundf(float f)
+{
+#if (defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__)) && \
+ !defined(__SSE_MATH__)
+
+ float out;
+ __asm__ __volatile__("frndint" : "=t"(out) : "0"(f));
+ return out;
+
+#else
+
+ /* Integral limit, where sub-integral precision is not available for
+ * floats.
+ */
+ static const float ilim[2] = {
+ 8388608.0f /* 0x1.0p+23 */,
+ -8388608.0f /* -0x1.0p+23 */
+ };
+ ALuint sign, expo;
+ union {
+ ALfloat f;
+ ALuint i;
+ } conv;
+
+ conv.f = f;
+ sign = (conv.i>>31)&0x01;
+ expo = (conv.i>>23)&0xff;
+
+ if(UNLIKELY(expo >= 150/*+23*/))
+ {
+ /* An exponent (base-2) of 23 or higher is incapable of sub-integral
+ * precision, so it's already an integral value. We don't need to worry
+ * about infinity or NaN here.
+ */
+ return f;
+ }
+ /* Adding the integral limit to the value (with a matching sign) forces a
+ * result that has no sub-integral precision, and is consequently forced to
+ * round to an integral value. Removing the integral limit then restores
+ * the initial value rounded to the integral. The compiler should not
+ * optimize this out because of non-associative rules on floating-point
+ * math (as long as you don't use -fassociative-math,
+ * -funsafe-math-optimizations, -ffast-math, or -Ofast, in which case this
+ * may break).
+ */
+ f += ilim[sign];
+ return f - ilim[sign];
+#endif
+}
enum DevProbe {
@@ -263,36 +372,6 @@ enum DevProbe {
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*);
-} BackendFuncs;
-
-ALCboolean alc_sndio_init(BackendFuncs *func_list);
-void alc_sndio_deinit(void);
-void alc_sndio_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_qsa_init(BackendFuncs *func_list);
-void alc_qsa_deinit(void);
-void alc_qsa_probe(enum DevProbe type);
-
-struct ALCbackend;
-
enum DistanceModel {
InverseDistanceClamped = AL_INVERSE_DISTANCE_CLAMPED,
@@ -317,10 +396,31 @@ enum Channel {
SideLeft,
SideRight,
- BFormatW,
- BFormatX,
- BFormatY,
- BFormatZ,
+ UpperFrontLeft,
+ UpperFrontRight,
+ UpperBackLeft,
+ UpperBackRight,
+ LowerFrontLeft,
+ LowerFrontRight,
+ LowerBackLeft,
+ LowerBackRight,
+
+ Aux0,
+ Aux1,
+ Aux2,
+ Aux3,
+ Aux4,
+ Aux5,
+ Aux6,
+ Aux7,
+ Aux8,
+ Aux9,
+ Aux10,
+ Aux11,
+ Aux12,
+ Aux13,
+ Aux14,
+ Aux15,
InvalidChannel
};
@@ -345,30 +445,36 @@ enum DevFmtChannels {
DevFmtX51 = ALC_5POINT1_SOFT,
DevFmtX61 = ALC_6POINT1_SOFT,
DevFmtX71 = ALC_7POINT1_SOFT,
+ DevFmtAmbi3D = ALC_BFORMAT3D_SOFT,
/* Similar to 5.1, except using rear channels instead of sides */
DevFmtX51Rear = 0x80000000,
- DevFmtBFormat3D,
-
DevFmtChannelsDefault = DevFmtStereo
};
-#define MAX_OUTPUT_CHANNELS (8)
+#define MAX_OUTPUT_CHANNELS (16)
-ALuint BytesFromDevFmt(enum DevFmtType type) DECL_CONST;
-ALuint ChannelsFromDevFmt(enum DevFmtChannels chans) DECL_CONST;
-inline ALuint FrameSizeFromDevFmt(enum DevFmtChannels chans, enum DevFmtType type)
+ALsizei BytesFromDevFmt(enum DevFmtType type);
+ALsizei ChannelsFromDevFmt(enum DevFmtChannels chans, ALsizei ambiorder);
+inline ALsizei FrameSizeFromDevFmt(enum DevFmtChannels chans, enum DevFmtType type, ALsizei ambiorder)
{
- return ChannelsFromDevFmt(chans) * BytesFromDevFmt(type);
+ return ChannelsFromDevFmt(chans, ambiorder) * BytesFromDevFmt(type);
}
+enum AmbiLayout {
+ AmbiLayout_FuMa = ALC_FUMA_SOFT, /* FuMa channel order */
+ AmbiLayout_ACN = ALC_ACN_SOFT, /* ACN channel order */
-extern const struct EffectList {
- const char *name;
- int type;
- const char *ename;
- ALenum val;
-} EffectList[];
+ AmbiLayout_Default = AmbiLayout_ACN
+};
+
+enum AmbiNorm {
+ AmbiNorm_FuMa = ALC_FUMA_SOFT, /* FuMa normalization */
+ AmbiNorm_SN3D = ALC_SN3D_SOFT, /* SN3D normalization */
+ AmbiNorm_N3D = ALC_N3D_SOFT, /* N3D normalization */
+
+ AmbiNorm_Default = AmbiNorm_SN3D
+};
enum DeviceType {
@@ -378,112 +484,232 @@ enum DeviceType {
};
-enum HrtfMode {
- DisabledHrtf,
- BasicHrtf,
- FullHrtf
+enum RenderMode {
+ NormalRender,
+ StereoPair,
+ HrtfRender
};
/* The maximum number of Ambisonics coefficients. For a given order (o), the
* size needed will be (o+1)**2, thus zero-order has 1, first-order has 4,
- * second-order has 9, and third-order has 16. */
-#define MAX_AMBI_COEFFS 16
+ * second-order has 9, third-order has 16, and fourth-order has 25.
+ */
+#define MAX_AMBI_ORDER 3
+#define MAX_AMBI_COEFFS ((MAX_AMBI_ORDER+1) * (MAX_AMBI_ORDER+1))
+
+/* A bitmask of ambisonic channels with height information. If none of these
+ * channels are used/needed, there's no height (e.g. with most surround sound
+ * speaker setups). This only specifies up to 4th order, which is the highest
+ * order a 32-bit mask value can specify (a 64-bit mask could handle up to 7th
+ * order). This is ACN ordering, with bit 0 being ACN 0, etc.
+ */
+#define AMBI_PERIPHONIC_MASK (0xfe7ce4)
+
+/* The maximum number of Ambisonic coefficients for 2D (non-periphonic)
+ * representation. This is 2 per each order above zero-order, plus 1 for zero-
+ * order. Or simply, o*2 + 1.
+ */
+#define MAX_AMBI2D_COEFFS (MAX_AMBI_ORDER*2 + 1)
+
typedef ALfloat ChannelConfig[MAX_AMBI_COEFFS];
+typedef struct BFChannelConfig {
+ ALfloat Scale;
+ ALsizei Index;
+} BFChannelConfig;
+
+typedef union AmbiConfig {
+ /* Ambisonic coefficients for mixing to the dry buffer. */
+ ChannelConfig Coeffs[MAX_OUTPUT_CHANNELS];
+ /* Coefficient channel mapping for mixing to the dry buffer. */
+ BFChannelConfig Map[MAX_OUTPUT_CHANNELS];
+} AmbiConfig;
+
+
+typedef struct BufferSubList {
+ ALuint64 FreeMask;
+ struct ALbuffer *Buffers; /* 64 */
+} BufferSubList;
+TYPEDEF_VECTOR(BufferSubList, vector_BufferSubList)
+
+typedef struct EffectSubList {
+ ALuint64 FreeMask;
+ struct ALeffect *Effects; /* 64 */
+} EffectSubList;
+TYPEDEF_VECTOR(EffectSubList, vector_EffectSubList)
+
+typedef struct FilterSubList {
+ ALuint64 FreeMask;
+ struct ALfilter *Filters; /* 64 */
+} FilterSubList;
+TYPEDEF_VECTOR(FilterSubList, vector_FilterSubList)
+
+typedef struct SourceSubList {
+ ALuint64 FreeMask;
+ struct ALsource *Sources; /* 64 */
+} SourceSubList;
+TYPEDEF_VECTOR(SourceSubList, vector_SourceSubList)
+
+/* Effect slots are rather large, and apps aren't likely to have more than one
+ * or two (let alone 64), so hold them individually.
+ */
+typedef struct ALeffectslot *ALeffectslotPtr;
+TYPEDEF_VECTOR(ALeffectslotPtr, vector_ALeffectslotPtr)
-#define HRTF_HISTORY_BITS (6)
-#define HRTF_HISTORY_LENGTH (1<<HRTF_HISTORY_BITS)
-#define HRTF_HISTORY_MASK (HRTF_HISTORY_LENGTH-1)
+typedef struct EnumeratedHrtf {
+ al_string name;
-typedef struct HrtfState {
- alignas(16) ALfloat History[HRTF_HISTORY_LENGTH];
- alignas(16) ALfloat Values[HRIR_LENGTH][2];
-} HrtfState;
+ struct HrtfEntry *hrtf;
+} EnumeratedHrtf;
+TYPEDEF_VECTOR(EnumeratedHrtf, vector_EnumeratedHrtf)
-typedef struct HrtfParams {
- alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
- alignas(16) ALfloat CoeffStep[HRIR_LENGTH][2];
- ALuint Delay[2];
- ALint DelayStep[2];
-} HrtfParams;
+/* Maximum delay in samples for speaker distance compensation. */
+#define MAX_DELAY_LENGTH 1024
+
+typedef struct DistanceComp {
+ ALfloat Gain;
+ ALsizei Length; /* Valid range is [0...MAX_DELAY_LENGTH). */
+ ALfloat *Buffer;
+} DistanceComp;
/* 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.
*/
-#define BUFFERSIZE (2048u)
+#define BUFFERSIZE 2048
-struct ALCdevice_struct
-{
+typedef struct MixParams {
+ AmbiConfig Ambi;
+ /* Number of coefficients in each Ambi.Coeffs to mix together (4 for first-
+ * order, 9 for second-order, etc). If the count is 0, Ambi.Map is used
+ * instead to map each output to a coefficient index.
+ */
+ ALsizei CoeffCount;
+
+ ALfloat (*Buffer)[BUFFERSIZE];
+ ALsizei NumChannels;
+} MixParams;
+
+typedef struct RealMixParams {
+ enum Channel ChannelName[MAX_OUTPUT_CHANNELS];
+
+ ALfloat (*Buffer)[BUFFERSIZE];
+ ALsizei NumChannels;
+} RealMixParams;
+
+typedef void (*POSTPROCESS)(ALCdevice *device, ALsizei SamplesToDo);
+
+struct ALCdevice_struct {
RefCount ref;
- ALCboolean Connected;
+ ATOMIC(ALenum) Connected;
enum DeviceType Type;
- ALuint Frequency;
- ALuint UpdateSize;
- ALuint NumUpdates;
+ ALuint Frequency;
+ ALuint UpdateSize;
+ ALuint NumUpdates;
enum DevFmtChannels FmtChans;
enum DevFmtType FmtType;
- ALboolean IsHeadphones;
+ ALboolean IsHeadphones;
+ ALsizei AmbiOrder;
+ /* For DevFmtAmbi* output only, specifies the channel order and
+ * normalization.
+ */
+ enum AmbiLayout AmbiLayout;
+ enum AmbiNorm AmbiScale;
+
+ ALCenum LimiterState;
al_string DeviceName;
ATOMIC(ALCenum) LastError;
// Maximum number of sources that can be created
- ALuint MaxNoOfSources;
+ ALuint SourcesMax;
// Maximum number of slots that can be created
- ALuint AuxiliaryEffectSlotMax;
+ ALuint AuxiliaryEffectSlotMax;
- ALCuint NumMonoSources;
- ALCuint NumStereoSources;
- ALuint NumAuxSends;
+ ALCuint NumMonoSources;
+ ALCuint NumStereoSources;
+ ALsizei NumAuxSends;
// Map of Buffers for this device
- UIntMap BufferMap;
+ vector_BufferSubList BufferList;
+ almtx_t BufferLock;
// Map of Effects for this device
- UIntMap EffectMap;
+ vector_EffectSubList EffectList;
+ almtx_t EffectLock;
// Map of Filters for this device
- UIntMap FilterMap;
-
- /* HRTF filter tables */
- vector_HrtfEntry Hrtf_List;
- al_string Hrtf_Name;
- const struct Hrtf *Hrtf;
- ALCenum Hrtf_Status;
- enum HrtfMode Hrtf_Mode;
- HrtfState Hrtf_State[MAX_OUTPUT_CHANNELS];
- HrtfParams Hrtf_Params[MAX_OUTPUT_CHANNELS];
- ALuint Hrtf_Offset;
-
- // Stereo-to-binaural filter
+ vector_FilterSubList FilterList;
+ almtx_t FilterLock;
+
+ POSTPROCESS PostProcess;
+
+ /* HRTF state and info */
+ struct DirectHrtfState *Hrtf;
+ al_string HrtfName;
+ struct Hrtf *HrtfHandle;
+ vector_EnumeratedHrtf HrtfList;
+ ALCenum HrtfStatus;
+
+ /* UHJ encoder state */
+ struct Uhj2Encoder *Uhj_Encoder;
+
+ /* High quality Ambisonic decoder */
+ struct BFormatDec *AmbiDecoder;
+
+ /* Stereo-to-binaural filter */
struct bs2b *Bs2b;
+ /* First-order ambisonic upsampler for higher-order output */
+ struct AmbiUpsampler *AmbiUp;
+
+ /* Rendering mode. */
+ enum RenderMode Render_Mode;
+
// Device flags
ALuint Flags;
- enum Channel ChannelName[MAX_OUTPUT_CHANNELS];
- ChannelConfig AmbiCoeffs[MAX_OUTPUT_CHANNELS];
- ALfloat AmbiScale; /* Scale for first-order XYZ inputs using AmbCoeffs. */
- ALuint NumChannels;
-
ALuint64 ClockBase;
ALuint SamplesDone;
+ ALuint FixedLatency;
+
+ /* Temp storage used for mixer processing. */
+ alignas(16) ALfloat TempBuffer[4][BUFFERSIZE];
- /* Temp storage used for each source when mixing. */
- alignas(16) ALfloat SourceData[BUFFERSIZE];
- alignas(16) ALfloat ResampledData[BUFFERSIZE];
- alignas(16) ALfloat FilteredData[BUFFERSIZE];
+ /* The "dry" path corresponds to the main output. */
+ MixParams Dry;
+ ALsizei NumChannelsPerOrder[MAX_AMBI_ORDER+1];
+
+ /* First-order ambisonics output, to be upsampled to the dry buffer if different. */
+ MixParams FOAOut;
+
+ /* "Real" output, which will be written to the device buffer. May alias the
+ * dry buffer.
+ */
+ RealMixParams RealOut;
- /* Dry path buffer mix. */
- alignas(16) ALfloat (*DryBuffer)[BUFFERSIZE];
+ struct FrontStablizer *Stablizer;
+
+ struct Compressor *Limiter;
+
+ /* The average speaker distance as determined by the ambdec configuration
+ * (or alternatively, by the NFC-HOA reference delay). Only used for NFC.
+ */
+ ALfloat AvgSpeakerDist;
+
+ /* Delay buffers used to compensate for speaker distances. */
+ DistanceComp ChannelDelay[MAX_OUTPUT_CHANNELS];
+
+ /* Dithering control. */
+ ALfloat DitherDepth;
+ ALuint DitherSeed;
/* Running count of the mixer invocations, in 31.1 fixed point. This
* actually increments *twice* when mixing, first at the start and then at
@@ -492,34 +718,27 @@ struct ALCdevice_struct
*/
RefCount MixCount;
- /* Default effect slot */
- struct ALeffectslot *DefaultSlot;
-
// Contexts created on this device
ATOMIC(ALCcontext*) ContextList;
+ almtx_t BackendLock;
struct ALCbackend *Backend;
- void *ExtraData; // For the backend's use
-
- ALCdevice *volatile next;
-
- /* Memory space used by the default slot (Playback devices only) */
- alignas(16) ALCbyte _slot_mem[];
+ ATOMIC(ALCdevice*) next;
};
// Frequency was requested by the app or config file
-#define DEVICE_FREQUENCY_REQUEST (1<<1)
+#define DEVICE_FREQUENCY_REQUEST (1u<<1)
// Channel configuration was requested by the config file
-#define DEVICE_CHANNELS_REQUEST (1<<2)
+#define DEVICE_CHANNELS_REQUEST (1u<<2)
// Sample type was requested by the config file
-#define DEVICE_SAMPLE_TYPE_REQUEST (1<<3)
+#define DEVICE_SAMPLE_TYPE_REQUEST (1u<<3)
// Specifies if the DSP is paused at user request
-#define DEVICE_PAUSED (1<<30)
+#define DEVICE_PAUSED (1u<<30)
// Specifies if the device is currently running
-#define DEVICE_RUNNING (1<<31)
+#define DEVICE_RUNNING (1u<<31)
/* Nanosecond resolution for the device clock time. */
@@ -533,207 +752,167 @@ struct ALCdevice_struct
#define RECORD_THREAD_NAME "alsoft-record"
-struct ALCcontext_struct
-{
+enum {
+ /* End event thread processing. */
+ EventType_KillThread = 0,
+
+ /* User event types. */
+ EventType_SourceStateChange = 1<<0,
+ EventType_BufferCompleted = 1<<1,
+ EventType_Error = 1<<2,
+ EventType_Performance = 1<<3,
+ EventType_Deprecated = 1<<4,
+ EventType_Disconnected = 1<<5,
+
+ /* Internal events. */
+ EventType_ReleaseEffectState = 65536,
+};
+
+typedef struct AsyncEvent {
+ unsigned int EnumType;
+ union {
+ char dummy;
+ struct {
+ ALenum type;
+ ALuint id;
+ ALuint param;
+ ALchar msg[1008];
+ } user;
+ struct ALeffectState *EffectState;
+ } u;
+} AsyncEvent;
+#define ASYNC_EVENT(t) { t, { 0 } }
+
+struct ALCcontext_struct {
RefCount ref;
struct ALlistener *Listener;
- UIntMap SourceMap;
- UIntMap EffectSlotMap;
+ vector_SourceSubList SourceList;
+ ALuint NumSources;
+ almtx_t SourceLock;
+
+ vector_ALeffectslotPtr EffectSlotList;
+ almtx_t EffectSlotLock;
ATOMIC(ALenum) LastError;
- ATOMIC(ALenum) UpdateSources;
+ enum DistanceModel DistanceModel;
+ ALboolean SourceDistanceModel;
- volatile enum DistanceModel DistanceModel;
- volatile ALboolean SourceDistanceModel;
+ ALfloat DopplerFactor;
+ ALfloat DopplerVelocity;
+ ALfloat SpeedOfSound;
+ ALfloat MetersPerUnit;
- volatile ALfloat DopplerFactor;
- volatile ALfloat DopplerVelocity;
- volatile ALfloat SpeedOfSound;
- volatile ALenum DeferUpdates;
+ ATOMIC_FLAG PropsClean;
+ ATOMIC(ALenum) DeferUpdates;
- struct ALvoice *Voices;
+ almtx_t PropLock;
+
+ /* Counter for the pre-mixing updates, in 31.1 fixed point (lowest bit
+ * indicates if updates are currently happening).
+ */
+ RefCount UpdateCount;
+ ATOMIC(ALenum) HoldUpdates;
+
+ ALfloat GainBoost;
+
+ ATOMIC(struct ALcontextProps*) Update;
+
+ /* Linked lists of unused property containers, free to use for future
+ * updates.
+ */
+ ATOMIC(struct ALcontextProps*) FreeContextProps;
+ ATOMIC(struct ALlistenerProps*) FreeListenerProps;
+ ATOMIC(struct ALvoiceProps*) FreeVoiceProps;
+ ATOMIC(struct ALeffectslotProps*) FreeEffectslotProps;
+
+ struct ALvoice **Voices;
ALsizei VoiceCount;
ALsizei MaxVoices;
- VECTOR(struct ALeffectslot*) ActiveAuxSlots;
+ ATOMIC(struct ALeffectslotArray*) ActiveAuxSlots;
+
+ althrd_t EventThread;
+ alsem_t EventSem;
+ struct ll_ringbuffer *AsyncEvents;
+ ATOMIC(ALbitfieldSOFT) EnabledEvts;
+ almtx_t EventCbLock;
+ ALEVENTPROCSOFT EventCb;
+ void *EventParam;
+
+ /* Default effect slot */
+ struct ALeffectslot *DefaultSlot;
ALCdevice *Device;
const ALCchar *ExtensionList;
- ALCcontext *volatile next;
+ ATOMIC(ALCcontext*) next;
- /* Memory space used by the listener */
+ /* Memory space used by the listener (and possibly default effect slot) */
alignas(16) ALCbyte _listener_mem[];
};
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_Lock(ALCdevice *device);
-void ALCdevice_Unlock(ALCdevice *device);
-
void ALCcontext_DeferUpdates(ALCcontext *context);
void ALCcontext_ProcessUpdates(ALCcontext *context);
-inline void LockContext(ALCcontext *context)
-{ ALCdevice_Lock(context->Device); }
-
-inline void UnlockContext(ALCcontext *context)
-{ ALCdevice_Unlock(context->Device); }
-
+void AllocateVoices(ALCcontext *context, ALsizei num_voices, ALsizei old_sends);
-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 {
-#ifdef HAVE_FENV_H
- DERIVE_FROM_TYPE(fenv_t);
-#else
- int state;
-#endif
-#ifdef HAVE_SSE
- int sse_state;
-#endif
-} FPUCtl;
-void SetMixerFPUMode(FPUCtl *ctl);
-void RestoreFPUMode(const FPUCtl *ctl);
-
-
-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);
-
-typedef struct ll_ringbuffer ll_ringbuffer_t;
-typedef struct ll_ringbuffer_data {
- char *buf;
- size_t len;
-} ll_ringbuffer_data_t;
-ll_ringbuffer_t *ll_ringbuffer_create(size_t sz, size_t elem_sz);
-void ll_ringbuffer_free(ll_ringbuffer_t *rb);
-void ll_ringbuffer_get_read_vector(const ll_ringbuffer_t *rb, ll_ringbuffer_data_t *vec);
-void ll_ringbuffer_get_write_vector(const ll_ringbuffer_t *rb, ll_ringbuffer_data_t *vec);
-size_t ll_ringbuffer_read(ll_ringbuffer_t *rb, char *dest, size_t cnt);
-size_t ll_ringbuffer_peek(ll_ringbuffer_t *rb, char *dest, size_t cnt);
-void ll_ringbuffer_read_advance(ll_ringbuffer_t *rb, size_t cnt);
-size_t ll_ringbuffer_read_space(const ll_ringbuffer_t *rb);
-int ll_ringbuffer_mlock(ll_ringbuffer_t *rb);
-void ll_ringbuffer_reset(ll_ringbuffer_t *rb);
-size_t ll_ringbuffer_write(ll_ringbuffer_t *rb, const char *src, size_t cnt);
-void ll_ringbuffer_write_advance(ll_ringbuffer_t *rb, size_t cnt);
-size_t ll_ringbuffer_write_space(const ll_ringbuffer_t *rb);
-
-void ReadALConfig(void);
-void FreeALConfig(void);
-int ConfigValueExists(const char *devName, const char *blockName, const char *keyName);
-const char *GetConfigValue(const char *devName, const char *blockName, const char *keyName, const char *def);
-int GetConfigValueBool(const char *devName, const char *blockName, const char *keyName, int def);
-int ConfigValueStr(const char *devName, const char *blockName, const char *keyName, const char **ret);
-int ConfigValueInt(const char *devName, const char *blockName, const char *keyName, int *ret);
-int ConfigValueUInt(const char *devName, const char *blockName, const char *keyName, unsigned int *ret);
-int ConfigValueFloat(const char *devName, const char *blockName, const char *keyName, float *ret);
-int ConfigValueBool(const char *devName, const char *blockName, const char *keyName, int *ret);
+extern ALint RTPrioLevel;
void SetRTPriority(void);
void SetDefaultChannelOrder(ALCdevice *device);
void SetDefaultWFXChannelOrder(ALCdevice *device);
-const ALCchar *DevFmtTypeString(enum DevFmtType type) DECL_CONST;
-const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans) DECL_CONST;
+const ALCchar *DevFmtTypeString(enum DevFmtType type);
+const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans);
-/**
- * GetChannelIdxByName
- *
- * Returns the device's channel index given a channel name (e.g. FrontCenter),
- * or -1 if it doesn't exist.
- */
-inline ALint GetChannelIdxByName(const ALCdevice *device, enum Channel chan)
+inline ALint GetChannelIndex(const enum Channel names[MAX_OUTPUT_CHANNELS], enum Channel chan)
{
- ALint i = 0;
+ ALint i;
for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
{
- if(device->ChannelName[i] == chan)
+ if(names[i] == chan)
return i;
}
return -1;
}
+/**
+ * GetChannelIdxByName
+ *
+ * Returns the index for the given channel name (e.g. FrontCenter), or -1 if it
+ * doesn't exist.
+ */
+inline ALint GetChannelIdxByName(const RealMixParams *real, enum Channel chan)
+{ return GetChannelIndex(real->ChannelName, chan); }
-extern FILE *LogFile;
-
-#if defined(__GNUC__) && !defined(_WIN32) && !defined(IN_IDE_PARSER)
-#define AL_PRINT(T, MSG, ...) fprintf(LogFile, "AL lib: %s %s: "MSG, T, __FUNCTION__ , ## __VA_ARGS__)
-#else
-void al_print(const char *type, const char *func, const char *fmt, ...) DECL_FORMAT(printf, 3,4);
-#define AL_PRINT(T, ...) al_print((T), __FUNCTION__, __VA_ARGS__)
-#endif
-
-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)
+inline void LockBufferList(ALCdevice *device) { almtx_lock(&device->BufferLock); }
+inline void UnlockBufferList(ALCdevice *device) { almtx_unlock(&device->BufferLock); }
+inline void LockEffectList(ALCdevice *device) { almtx_lock(&device->EffectLock); }
+inline void UnlockEffectList(ALCdevice *device) { almtx_unlock(&device->EffectLock); }
-extern ALint RTPrioLevel;
+inline void LockFilterList(ALCdevice *device) { almtx_lock(&device->FilterLock); }
+inline void UnlockFilterList(ALCdevice *device) { almtx_unlock(&device->FilterLock); }
+inline void LockEffectSlotList(ALCcontext *context)
+{ almtx_lock(&context->EffectSlotLock); }
+inline void UnlockEffectSlotList(ALCcontext *context)
+{ almtx_unlock(&context->EffectSlotLock); }
-extern ALuint CPUCapFlags;
-enum {
- CPU_CAP_SSE = 1<<0,
- CPU_CAP_SSE2 = 1<<1,
- CPU_CAP_SSE3 = 1<<2,
- CPU_CAP_SSE4_1 = 1<<3,
- CPU_CAP_NEON = 1<<4,
-};
-void FillCPUCaps(ALuint capfilter);
+int EventThread(void *arg);
-FILE *OpenDataFile(const char *fname, const char *subdir);
vector_al_string SearchDataFiles(const char *match, const char *subdir);
-/* Small hack to use a pointer-to-array type as a normal argument type.
- * Shouldn't be used directly. */
-typedef ALfloat ALfloatBUFFERSIZE[BUFFERSIZE];
-
-
#ifdef __cplusplus
}
#endif
diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h
index 13596161..5f07c09d 100644
--- a/OpenAL32/Include/alSource.h
+++ b/OpenAL32/Include/alSource.h
@@ -1,11 +1,14 @@
#ifndef _AL_SOURCE_H_
#define _AL_SOURCE_H_
-#define MAX_SENDS 4
-
+#include "bool.h"
#include "alMain.h"
#include "alu.h"
#include "hrtf.h"
+#include "atomic.h"
+
+#define MAX_SENDS 16
+#define DEFAULT_SENDS 2
#ifdef __cplusplus
extern "C" {
@@ -16,96 +19,51 @@ struct ALsource;
typedef struct ALbufferlistitem {
- struct ALbuffer *buffer;
- struct ALbufferlistitem *volatile next;
- struct ALbufferlistitem *volatile prev;
+ ATOMIC(struct ALbufferlistitem*) next;
+ ALsizei max_samples;
+ ALsizei num_buffers;
+ struct ALbuffer *buffers[];
} ALbufferlistitem;
-typedef struct ALvoice {
- struct ALsource *volatile Source;
-
- /** Method to update mixing parameters. */
- ALvoid (*Update)(struct ALvoice *self, const struct ALsource *source, const ALCcontext *context);
-
- /** Current target parameters used for mixing. */
- ALint Step;
-
- ALboolean IsHrtf;
-
- ALuint Offset; /* Number of output samples mixed since starting. */
-
- alignas(16) ALfloat PrevSamples[MAX_INPUT_CHANNELS][MAX_PRE_SAMPLES];
-
- BsincState SincState;
-
- DirectParams Direct;
- SendParams Send[MAX_SENDS];
-} ALvoice;
-
-
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;
- aluVector Position;
- aluVector Velocity;
- aluVector Direction;
- volatile ALfloat Orientation[2][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;
-
- volatile ALfloat Radius;
-
- /**
- * 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.
+ ALfloat Pitch;
+ ALfloat Gain;
+ ALfloat OuterGain;
+ ALfloat MinGain;
+ ALfloat MaxGain;
+ ALfloat InnerAngle;
+ ALfloat OuterAngle;
+ ALfloat RefDistance;
+ ALfloat MaxDistance;
+ ALfloat RolloffFactor;
+ ALfloat Position[3];
+ ALfloat Velocity[3];
+ ALfloat Direction[3];
+ ALfloat Orientation[2][3];
+ ALboolean HeadRelative;
+ ALboolean Looping;
+ enum DistanceModel DistanceModel;
+ enum Resampler Resampler;
+ ALboolean DirectChannels;
+ enum SpatializeMode Spatialize;
+
+ ALboolean DryGainHFAuto;
+ ALboolean WetGainAuto;
+ ALboolean WetGainHFAuto;
+ ALfloat OuterGainHF;
+
+ ALfloat AirAbsorptionFactor;
+ ALfloat RoomRolloffFactor;
+ ALfloat DopplerFactor;
+
+ /* NOTE: Stereo pan angles are specified in radians, counter-clockwise
+ * rather than clockwise.
*/
- ALuint position;
- ALuint position_fraction;
-
- /** Source Buffer Queue info. */
- ATOMIC(ALbufferlistitem*) queue;
- ATOMIC(ALbufferlistitem*) current_buffer;
- RWLock queue_lock;
+ ALfloat StereoPan[2];
- /** Current buffer sample info. */
- ALuint NumChannels;
- ALuint SampleSize;
+ ALfloat Radius;
/** Direct filter and auxiliary send info. */
struct {
@@ -122,22 +80,36 @@ typedef struct ALsource {
ALfloat HFReference;
ALfloat GainLF;
ALfloat LFReference;
- } Send[MAX_SENDS];
+ } *Send;
+
+ /**
+ * Last user-specified offset, and the offset type (bytes, samples, or
+ * seconds).
+ */
+ ALdouble Offset;
+ ALenum OffsetType;
+
+ /** Source type (static, streaming, or undetermined) */
+ ALint SourceType;
+
+ /** Source state (initial, playing, paused, or stopped) */
+ ALenum state;
+
+ /** Source Buffer Queue head. */
+ ALbufferlistitem *queue;
- /** Source needs to update its mixing parameters. */
- ATOMIC(ALenum) NeedsUpdate;
+ ATOMIC_FLAG PropsClean;
+
+ /* Index into the context's Voices array. Lazily updated, only checked and
+ * reset when looking up the voice.
+ */
+ ALint VoiceIdx;
/** Self ID */
ALuint id;
} ALsource;
-inline struct ALsource *LookupSource(ALCcontext *context, ALuint id)
-{ return (struct ALsource*)LookupUIntMapKey(&context->SourceMap, id); }
-inline struct ALsource *RemoveSource(ALCcontext *context, ALuint id)
-{ return (struct ALsource*)RemoveUIntMapKey(&context->SourceMap, id); }
-
-ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state);
-ALboolean ApplyOffset(ALsource *Source);
+void UpdateAllSourceProps(ALCcontext *context);
ALvoid ReleaseALSources(ALCcontext *Context);
diff --git a/OpenAL32/Include/alThunk.h b/OpenAL32/Include/alThunk.h
deleted file mode 100644
index adc77dec..00000000
--- a/OpenAL32/Include/alThunk.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#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
-
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index a309c4ab..c572fd71 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -12,31 +12,56 @@
#include "alMain.h"
#include "alBuffer.h"
-#include "alFilter.h"
#include "hrtf.h"
#include "align.h"
#include "math_defs.h"
+#include "filters/defs.h"
+#include "filters/nfc.h"
#define MAX_PITCH (255)
-/* Maximum number of buffer samples before the current pos needed for resampling. */
-#define MAX_PRE_SAMPLES 12
-
-/* Maximum number of buffer samples after the current pos needed for resampling. */
-#define MAX_POST_SAMPLES 12
+/* Maximum number of samples to pad on either end of a buffer for resampling.
+ * Note that both the beginning and end need padding!
+ */
+#define MAX_RESAMPLE_PADDING 24
#ifdef __cplusplus
extern "C" {
#endif
+struct BSincTable;
struct ALsource;
+struct ALbufferlistitem;
struct ALvoice;
+struct ALeffectslot;
+
+#define DITHER_RNG_SEED 22222
+
+
+enum SpatializeMode {
+ SpatializeOff = AL_FALSE,
+ SpatializeOn = AL_TRUE,
+ SpatializeAuto = AL_AUTO_SOFT
+};
-/* The number of distinct scale and phase intervals within the filter table. */
+enum Resampler {
+ PointResampler,
+ LinearResampler,
+ FIR4Resampler,
+ BSinc12Resampler,
+ BSinc24Resampler,
+
+ ResamplerMax = BSinc24Resampler
+};
+extern enum Resampler ResamplerDefault;
+
+/* The number of distinct scale and phase intervals within the bsinc filter
+ * table.
+ */
#define BSINC_SCALE_BITS 4
#define BSINC_SCALE_COUNT (1<<BSINC_SCALE_BITS)
#define BSINC_PHASE_BITS 4
@@ -48,16 +73,29 @@ struct ALvoice;
*/
typedef struct BsincState {
ALfloat sf; /* Scale interpolation factor. */
- ALuint m; /* Coefficient count. */
- ALint l; /* Left coefficient offset. */
- struct {
- const ALfloat *filter; /* Filter coefficients. */
- const ALfloat *scDelta; /* Scale deltas. */
- const ALfloat *phDelta; /* Phase deltas. */
- const ALfloat *spDelta; /* Scale-phase deltas. */
- } coeffs[BSINC_PHASE_COUNT];
+ ALsizei m; /* Coefficient count. */
+ ALsizei l; /* Left coefficient offset. */
+ /* Filter coefficients, followed by the scale, phase, and scale-phase
+ * delta coefficients. Starting at phase index 0, each subsequent phase
+ * index follows contiguously.
+ */
+ const ALfloat *filter;
} BsincState;
+typedef union InterpState {
+ BsincState bsinc;
+} InterpState;
+
+typedef const ALfloat* (*ResamplerFunc)(const InterpState *state,
+ const ALfloat *restrict src, ALsizei frac, ALint increment,
+ ALfloat *restrict dst, ALsizei dstlen
+);
+
+void BsincPrepare(const ALuint increment, BsincState *state, const struct BSincTable *table);
+
+extern const struct BSincTable bsinc12;
+extern const struct BSincTable bsinc24;
+
typedef union aluVector {
alignas(16) ALfloat v[4];
@@ -75,6 +113,7 @@ inline void aluVectorSet(aluVector *vector, ALfloat x, ALfloat y, ALfloat z, ALf
typedef union aluMatrixf {
alignas(16) ALfloat m[4][4];
} aluMatrixf;
+extern const aluMatrixf IdentityMatrixf;
inline void aluMatrixfSetRow(aluMatrixf *matrix, ALuint row,
ALfloat m0, ALfloat m1, ALfloat m2, ALfloat m3)
@@ -97,31 +136,6 @@ inline void aluMatrixfSet(aluMatrixf *matrix, ALfloat m00, ALfloat m01, ALfloat
}
-typedef union aluMatrixd {
- alignas(16) ALdouble m[4][4];
-} aluMatrixd;
-
-inline void aluMatrixdSetRow(aluMatrixd *matrix, ALuint row,
- ALdouble m0, ALdouble m1, ALdouble m2, ALdouble m3)
-{
- matrix->m[row][0] = m0;
- matrix->m[row][1] = m1;
- matrix->m[row][2] = m2;
- matrix->m[row][3] = m3;
-}
-
-inline void aluMatrixdSet(aluMatrixd *matrix, ALdouble m00, ALdouble m01, ALdouble m02, ALdouble m03,
- ALdouble m10, ALdouble m11, ALdouble m12, ALdouble m13,
- ALdouble m20, ALdouble m21, ALdouble m22, ALdouble m23,
- ALdouble m30, ALdouble m31, ALdouble m32, ALdouble m33)
-{
- aluMatrixdSetRow(matrix, 0, m00, m01, m02, m03);
- aluMatrixdSetRow(matrix, 1, m10, m11, m12, m13);
- aluMatrixdSetRow(matrix, 2, m20, m21, m22, m23);
- aluMatrixdSetRow(matrix, 3, m30, m31, m32, m33);
-}
-
-
enum ActiveFilters {
AF_None = 0,
AF_LowPass = 1,
@@ -130,74 +144,199 @@ enum ActiveFilters {
};
-typedef struct MixGains {
- ALfloat Current;
- ALfloat Step;
- ALfloat Target;
-} MixGains;
+typedef struct MixHrtfParams {
+ const ALfloat (*Coeffs)[2];
+ ALsizei Delay[2];
+ ALfloat Gain;
+ ALfloat GainStep;
+} MixHrtfParams;
typedef struct DirectParams {
- ALfloat (*OutBuffer)[BUFFERSIZE];
- ALuint OutChannels;
+ BiquadFilter LowPass;
+ BiquadFilter HighPass;
- /* If not 'moving', gain/coefficients are set directly without fading. */
- ALboolean Moving;
- /* Stepping counter for gain/coefficient fading. */
- ALuint Counter;
- /* Last direction (relative to listener) and gain of a moving source. */
- aluVector LastDir;
- ALfloat LastGain;
+ NfcFilter NFCtrlFilter;
struct {
- enum ActiveFilters ActiveType;
- ALfilterState LowPass;
- ALfilterState HighPass;
- } Filters[MAX_INPUT_CHANNELS];
+ HrtfParams Old;
+ HrtfParams Target;
+ HrtfState State;
+ } Hrtf;
struct {
- HrtfParams Params;
- HrtfState State;
- } Hrtf[MAX_INPUT_CHANNELS];
- MixGains Gains[MAX_INPUT_CHANNELS][MAX_OUTPUT_CHANNELS];
+ ALfloat Current[MAX_OUTPUT_CHANNELS];
+ ALfloat Target[MAX_OUTPUT_CHANNELS];
+ } Gains;
} DirectParams;
typedef struct SendParams {
- ALfloat (*OutBuffer)[BUFFERSIZE];
-
- ALboolean Moving;
- ALuint Counter;
+ BiquadFilter LowPass;
+ BiquadFilter HighPass;
struct {
- enum ActiveFilters ActiveType;
- ALfilterState LowPass;
- ALfilterState HighPass;
- } Filters[MAX_INPUT_CHANNELS];
-
- /* Gain control, which applies to each input channel to a single (mono)
- * output buffer. */
- MixGains Gains[MAX_INPUT_CHANNELS];
+ ALfloat Current[MAX_OUTPUT_CHANNELS];
+ ALfloat Target[MAX_OUTPUT_CHANNELS];
+ } Gains;
} SendParams;
-typedef const ALfloat* (*ResamplerFunc)(const BsincState *state,
- const ALfloat *src, ALuint frac, ALuint increment, ALfloat *restrict dst, ALuint dstlen
-);
+struct ALvoiceProps {
+ ATOMIC(struct ALvoiceProps*) next;
+
+ ALfloat Pitch;
+ ALfloat Gain;
+ ALfloat OuterGain;
+ ALfloat MinGain;
+ ALfloat MaxGain;
+ ALfloat InnerAngle;
+ ALfloat OuterAngle;
+ ALfloat RefDistance;
+ ALfloat MaxDistance;
+ ALfloat RolloffFactor;
+ ALfloat Position[3];
+ ALfloat Velocity[3];
+ ALfloat Direction[3];
+ ALfloat Orientation[2][3];
+ ALboolean HeadRelative;
+ enum DistanceModel DistanceModel;
+ enum Resampler Resampler;
+ ALboolean DirectChannels;
+ enum SpatializeMode SpatializeMode;
+
+ ALboolean DryGainHFAuto;
+ ALboolean WetGainAuto;
+ ALboolean WetGainHFAuto;
+ ALfloat OuterGainHF;
+
+ ALfloat AirAbsorptionFactor;
+ ALfloat RoomRolloffFactor;
+ ALfloat DopplerFactor;
+
+ ALfloat StereoPan[2];
+
+ ALfloat Radius;
+
+ /** Direct filter and auxiliary send info. */
+ struct {
+ ALfloat Gain;
+ ALfloat GainHF;
+ ALfloat HFReference;
+ ALfloat GainLF;
+ ALfloat LFReference;
+ } Direct;
+ struct {
+ struct ALeffectslot *Slot;
+ ALfloat Gain;
+ ALfloat GainHF;
+ ALfloat HFReference;
+ ALfloat GainLF;
+ ALfloat LFReference;
+ } Send[];
+};
+
+#define VOICE_IS_STATIC (1<<0)
+#define VOICE_IS_FADING (1<<1) /* Fading sources use gain stepping for smooth transitions. */
+#define VOICE_HAS_HRTF (1<<2)
+#define VOICE_HAS_NFC (1<<3)
+
+typedef struct ALvoice {
+ struct ALvoiceProps *Props;
+
+ ATOMIC(struct ALvoiceProps*) Update;
+
+ ATOMIC(struct ALsource*) Source;
+ ATOMIC(bool) Playing;
+
+ /**
+ * Source offset in samples, relative to the currently playing buffer, NOT
+ * the whole queue, and the fractional (fixed-point) offset to the next
+ * sample.
+ */
+ ATOMIC(ALuint) position;
+ ATOMIC(ALsizei) position_fraction;
+
+ /* Current buffer queue item being played. */
+ ATOMIC(struct ALbufferlistitem*) current_buffer;
+
+ /* Buffer queue item to loop to at end of queue (will be NULL for non-
+ * looping voices).
+ */
+ ATOMIC(struct ALbufferlistitem*) loop_buffer;
+
+ /**
+ * Number of channels and bytes-per-sample for the attached source's
+ * buffer(s).
+ */
+ ALsizei NumChannels;
+ ALsizei SampleSize;
-typedef void (*MixerFunc)(const ALfloat *data, ALuint OutChans,
- ALfloat (*restrict OutBuffer)[BUFFERSIZE], struct MixGains *Gains,
- ALuint Counter, ALuint OutPos, ALuint BufferSize);
-typedef void (*HrtfMixerFunc)(ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat *data,
- ALuint Counter, ALuint Offset, ALuint OutPos,
- const ALuint IrSize, const HrtfParams *hrtfparams,
- HrtfState *hrtfstate, ALuint BufferSize);
+ /** Current target parameters used for mixing. */
+ ALint Step;
+ ResamplerFunc Resampler;
+
+ ALuint Flags;
+
+ ALuint Offset; /* Number of output samples mixed since starting. */
+
+ alignas(16) ALfloat PrevSamples[MAX_INPUT_CHANNELS][MAX_RESAMPLE_PADDING];
+
+ InterpState ResampleState;
+
+ struct {
+ enum ActiveFilters FilterType;
+ DirectParams Params[MAX_INPUT_CHANNELS];
+
+ ALfloat (*Buffer)[BUFFERSIZE];
+ ALsizei Channels;
+ ALsizei ChannelsPerOrder[MAX_AMBI_ORDER+1];
+ } Direct;
+
+ struct {
+ enum ActiveFilters FilterType;
+ SendParams Params[MAX_INPUT_CHANNELS];
+
+ ALfloat (*Buffer)[BUFFERSIZE];
+ ALsizei Channels;
+ } Send[];
+} ALvoice;
+
+void DeinitVoice(ALvoice *voice);
+
+
+typedef void (*MixerFunc)(const ALfloat *data, ALsizei OutChans,
+ ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALfloat *CurrentGains,
+ const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
+ ALsizei BufferSize);
+typedef void (*RowMixerFunc)(ALfloat *OutBuffer, const ALfloat *gains,
+ const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans,
+ ALsizei InPos, ALsizei BufferSize);
+typedef void (*HrtfMixerFunc)(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, MixHrtfParams *hrtfparams,
+ HrtfState *hrtfstate, ALsizei BufferSize);
+typedef void (*HrtfMixerBlendFunc)(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, const HrtfParams *oldparams,
+ MixHrtfParams *newparams, HrtfState *hrtfstate,
+ ALsizei BufferSize);
+typedef void (*HrtfDirectMixerFunc)(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2],
+ ALfloat (*restrict Values)[2], ALsizei BufferSize);
+
+
+#define GAIN_MIX_MAX (16.0f) /* +24dB */
#define GAIN_SILENCE_THRESHOLD (0.00001f) /* -100dB */
#define SPEEDOFSOUNDMETRESPERSEC (343.3f)
#define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
+/* Target gain for the reverb decay feedback reaching the decay time. */
+#define REVERB_DECAY_GAIN (0.001f) /* -60 dB */
+
#define FRACTIONBITS (12)
#define FRACTIONONE (1<<FRACTIONBITS)
#define FRACTIONMASK (FRACTIONONE-1)
@@ -245,83 +384,148 @@ inline ALuint64 maxu64(ALuint64 a, ALuint64 b)
inline ALuint64 clampu64(ALuint64 val, ALuint64 min, ALuint64 max)
{ return minu64(max, maxu64(min, val)); }
-
-union ResamplerCoeffs {
- ALfloat FIR4[FRACTIONONE][4];
- ALfloat FIR8[FRACTIONONE][8];
-};
-extern alignas(16) union ResamplerCoeffs ResampleCoeffs;
-
-extern alignas(16) const ALfloat bsincTab[18840];
+inline size_t minz(size_t a, size_t b)
+{ return ((a > b) ? b : a); }
+inline size_t maxz(size_t a, size_t b)
+{ return ((a > b) ? a : b); }
+inline size_t clampz(size_t val, size_t min, size_t max)
+{ return minz(max, maxz(min, val)); }
inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu)
{
return val1 + (val2-val1)*mu;
}
-inline ALfloat resample_fir4(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALuint frac)
-{
- const ALfloat *k = ResampleCoeffs.FIR4[frac];
- return k[0]*val0 + k[1]*val1 + k[2]*val2 + k[3]*val3;
-}
-inline ALfloat resample_fir8(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALfloat val4, ALfloat val5, ALfloat val6, ALfloat val7, ALuint frac)
+inline ALfloat cubic(ALfloat val1, ALfloat val2, ALfloat val3, ALfloat val4, ALfloat mu)
{
- const ALfloat *k = ResampleCoeffs.FIR8[frac];
- return k[0]*val0 + k[1]*val1 + k[2]*val2 + k[3]*val3 +
- k[4]*val4 + k[5]*val5 + k[6]*val6 + k[7]*val7;
+ ALfloat mu2 = mu*mu, mu3 = mu2*mu;
+ ALfloat a0 = -0.5f*mu3 + mu2 + -0.5f*mu;
+ ALfloat a1 = 1.5f*mu3 + -2.5f*mu2 + 1.0f;
+ ALfloat a2 = -1.5f*mu3 + 2.0f*mu2 + 0.5f*mu;
+ ALfloat a3 = 0.5f*mu3 + -0.5f*mu2;
+ return val1*a0 + val2*a1 + val3*a2 + val4*a3;
}
+enum HrtfRequestMode {
+ Hrtf_Default = 0,
+ Hrtf_Enable = 1,
+ Hrtf_Disable = 2,
+};
+
+void aluInit(void);
+
void aluInitMixer(void);
-ALvoid aluInitPanning(ALCdevice *Device);
+ResamplerFunc SelectResampler(enum Resampler resampler);
+
+/* aluInitRenderer
+ *
+ * Set up the appropriate panning method and mixing method given the device
+ * properties.
+ */
+void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf_appreq, enum HrtfRequestMode hrtf_userreq);
+
+void aluInitEffectPanning(struct ALeffectslot *slot);
+
+void aluSelectPostProcess(ALCdevice *device);
/**
- * ComputeDirectionalGains
+ * Calculates ambisonic encoder coefficients using the X, Y, and Z direction
+ * components, which must represent a normalized (unit length) vector, and the
+ * spread is the angular width of the sound (0...tau).
+ *
+ * NOTE: The components use ambisonic coordinates. As a result:
+ *
+ * Ambisonic Y = OpenAL -X
+ * Ambisonic Z = OpenAL Y
+ * Ambisonic X = OpenAL -Z
*
- * Sets channel gains based on a direction. The direction must be a 3-component
- * vector no longer than 1 unit.
+ * The components are ordered such that OpenAL's X, Y, and Z are the first,
+ * second, and third parameters respectively -- simply negate X and Z.
*/
-void ComputeDirectionalGains(const ALCdevice *device, const ALfloat dir[3], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
+void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALfloat spread,
+ ALfloat coeffs[MAX_AMBI_COEFFS]);
/**
- * ComputeAngleGains
+ * CalcDirectionCoeffs
*
- * Sets channel gains based on angle and elevation. The angle and elevation
- * parameters are in radians, going right and up respectively.
+ * Calculates ambisonic coefficients based on an OpenAL direction vector. The
+ * vector must be normalized (unit length), and the spread is the angular width
+ * of the sound (0...tau).
*/
-void ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat elevation, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
+inline void CalcDirectionCoeffs(const ALfloat dir[3], ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS])
+{
+ /* Convert from OpenAL coords to Ambisonics. */
+ CalcAmbiCoeffs(-dir[0], dir[1], -dir[2], spread, coeffs);
+}
/**
- * ComputeAmbientGains
+ * CalcAngleCoeffs
*
- * Sets channel gains for ambient, omni-directional sounds.
+ * Calculates ambisonic coefficients based on azimuth and elevation. The
+ * azimuth and elevation parameters are in radians, going right and up
+ * respectively.
*/
-void ComputeAmbientGains(const ALCdevice *device, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
+inline void CalcAngleCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS])
+{
+ ALfloat x = -sinf(azimuth) * cosf(elevation);
+ ALfloat y = sinf(elevation);
+ ALfloat z = cosf(azimuth) * cosf(elevation);
+
+ CalcAmbiCoeffs(x, y, z, spread, coeffs);
+}
/**
- * ComputeBFormatGains
+ * ScaleAzimuthFront
*
- * Sets channel gains for a given (first-order) B-Format channel. The matrix is
- * a 1x4 'slice' of the rotation matrix for a given channel used to orient the
- * coefficients.
+ * Scales the given azimuth toward the side (+/- pi/2 radians) for positions in
+ * front.
*/
-void ComputeBFormatGains(const ALCdevice *device, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
+inline float ScaleAzimuthFront(float azimuth, float scale)
+{
+ ALfloat sign = copysignf(1.0f, azimuth);
+ if(!(fabsf(azimuth) > F_PI_2))
+ return minf(fabsf(azimuth) * scale, F_PI_2) * sign;
+ return azimuth;
+}
+
+
+void ComputePanningGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, ALsizei numcoeffs, const ALfloat*restrict coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
+void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, const ALfloat*restrict coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]);
+
+/**
+ * ComputePanGains
+ *
+ * Computes panning gains using the given channel decoder coefficients and the
+ * pre-calculated direction or angle coefficients. For B-Format sources, the
+ * coeffs are a 'slice' of a transform matrix for the input channel, used to
+ * scale and orient the sound samples.
+ */
+inline void ComputePanGains(const MixParams *dry, const ALfloat*restrict coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
+{
+ if(dry->CoeffCount > 0)
+ ComputePanningGainsMC(dry->Ambi.Coeffs, dry->NumChannels, dry->CoeffCount,
+ coeffs, ingain, gains);
+ else
+ ComputePanningGainsBF(dry->Ambi.Map, dry->NumChannels, coeffs, ingain, gains);
+}
-ALvoid UpdateContextSources(ALCcontext *context);
+ALboolean MixSource(struct ALvoice *voice, ALuint SourceID, ALCcontext *Context, ALsizei SamplesToDo);
-ALvoid CalcSourceParams(struct ALvoice *voice, const struct ALsource *source, const ALCcontext *ALContext);
-ALvoid CalcNonAttnSourceParams(struct ALvoice *voice, const struct ALsource *source, const ALCcontext *ALContext);
+void aluMixData(ALCdevice *device, ALvoid *OutBuffer, ALsizei NumSamples);
+/* Caller must lock the device, and the mixer must not be running. */
+void aluHandleDisconnect(ALCdevice *device, const char *msg, ...) DECL_FORMAT(printf, 2, 3);
-ALvoid MixSource(struct ALvoice *voice, struct ALsource *source, ALCdevice *Device, ALuint SamplesToDo);
+void UpdateContextProps(ALCcontext *context);
-ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size);
-/* Caller must lock the device. */
-ALvoid aluHandleDisconnect(ALCdevice *device);
+extern MixerFunc MixSamples;
+extern RowMixerFunc MixRowSamples;
extern ALfloat ConeScale;
extern ALfloat ZScale;
+extern ALboolean OverrideReverbSpeedOfSound;
#ifdef __cplusplus
}
diff --git a/OpenAL32/Include/bs2b.h b/OpenAL32/Include/bs2b.h
index 903c6bc5..e845d906 100644
--- a/OpenAL32/Include/bs2b.h
+++ b/OpenAL32/Include/bs2b.h
@@ -63,10 +63,10 @@ struct bs2b {
* [0] - first channel, [1] - second channel
*/
struct t_last_sample {
- float asis[2];
- float lo[2];
- float hi[2];
- } last_sample;
+ float asis;
+ float lo;
+ float hi;
+ } last_sample[2];
};
/* Clear buffers and set new coefficients with new crossfeed level and sample
@@ -85,38 +85,7 @@ 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 sample by sample pointer.
- */
-inline void bs2b_cross_feed(struct bs2b *bs2b, float *restrict sample)
-{
-/* Single pole IIR filter.
- * O[n] = a0*I[n] + a1*I[n-1] + b1*O[n-1]
- */
-
-/* Lowpass filter */
-#define lo_filter(in, out_1) (bs2b->a0_lo*(in) + bs2b->b1_lo*(out_1))
-
-/* Highboost filter */
-#define hi_filter(in, in_1, out_1) (bs2b->a0_hi*(in) + bs2b->a1_hi*(in_1) + bs2b->b1_hi*(out_1))
-
- /* Lowpass filter */
- bs2b->last_sample.lo[0] = lo_filter(sample[0], bs2b->last_sample.lo[0]);
- bs2b->last_sample.lo[1] = lo_filter(sample[1], bs2b->last_sample.lo[1]);
-
- /* Highboost filter */
- bs2b->last_sample.hi[0] = hi_filter(sample[0], bs2b->last_sample.asis[0], bs2b->last_sample.hi[0]);
- bs2b->last_sample.hi[1] = hi_filter(sample[1], bs2b->last_sample.asis[1], bs2b->last_sample.hi[1]);
- bs2b->last_sample.asis[0] = sample[0];
- bs2b->last_sample.asis[1] = sample[1];
-
- /* Crossfeed */
- sample[0] = bs2b->last_sample.hi[0] + bs2b->last_sample.lo[1];
- sample[1] = bs2b->last_sample.hi[1] + bs2b->last_sample.lo[0];
-#undef hi_filter
-#undef lo_filter
-} /* bs2b_cross_feed */
+void bs2b_cross_feed(struct bs2b *bs2b, float *restrict Left, float *restrict Right, int SamplesToDo);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/OpenAL32/Include/sample_cvt.h b/OpenAL32/Include/sample_cvt.h
index 12bb1fa6..c041760e 100644
--- a/OpenAL32/Include/sample_cvt.h
+++ b/OpenAL32/Include/sample_cvt.h
@@ -4,6 +4,12 @@
#include "AL/al.h"
#include "alBuffer.h"
-void ConvertData(ALvoid *dst, enum UserFmtType dstType, const ALvoid *src, enum UserFmtType srcType, ALsizei numchans, ALsizei len, ALsizei align);
+extern const ALshort muLawDecompressionTable[256];
+extern const ALshort aLawDecompressionTable[256];
+
+void Convert_ALshort_ALima4(ALshort *dst, const ALubyte *src, ALsizei numchans, ALsizei len,
+ ALsizei align);
+void Convert_ALshort_ALmsadpcm(ALshort *dst, const ALubyte *src, ALsizei numchans, ALsizei len,
+ ALsizei align);
#endif /* SAMPLE_CVT_H */
diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c
index c1314301..8141e0f6 100644
--- a/OpenAL32/alAuxEffectSlot.c
+++ b/OpenAL32/alAuxEffectSlot.c
@@ -27,83 +27,145 @@
#include "AL/alc.h"
#include "alMain.h"
#include "alAuxEffectSlot.h"
-#include "alThunk.h"
#include "alError.h"
+#include "alListener.h"
#include "alSource.h"
+#include "fpu_modes.h"
+#include "almalloc.h"
+
+
+extern inline void LockEffectSlotList(ALCcontext *context);
+extern inline void UnlockEffectSlotList(ALCcontext *context);
+
+static void AddActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *context);
+static void RemoveActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *context);
+
+static const struct {
+ ALenum Type;
+ EffectStateFactory* (*GetFactory)(void);
+} FactoryList[] = {
+ { AL_EFFECT_NULL, NullStateFactory_getFactory },
+ { AL_EFFECT_EAXREVERB, ReverbStateFactory_getFactory },
+ { AL_EFFECT_REVERB, ReverbStateFactory_getFactory },
+ { AL_EFFECT_AUTOWAH, AutowahStateFactory_getFactory },
+ { AL_EFFECT_CHORUS, ChorusStateFactory_getFactory },
+ { AL_EFFECT_COMPRESSOR, CompressorStateFactory_getFactory },
+ { AL_EFFECT_DISTORTION, DistortionStateFactory_getFactory },
+ { AL_EFFECT_ECHO, EchoStateFactory_getFactory },
+ { AL_EFFECT_EQUALIZER, EqualizerStateFactory_getFactory },
+ { AL_EFFECT_FLANGER, FlangerStateFactory_getFactory },
+ { AL_EFFECT_FREQUENCY_SHIFTER, FshifterStateFactory_getFactory },
+ { AL_EFFECT_RING_MODULATOR, ModulatorStateFactory_getFactory },
+ { AL_EFFECT_PITCH_SHIFTER, PshifterStateFactory_getFactory},
+ { AL_EFFECT_DEDICATED_DIALOGUE, DedicatedStateFactory_getFactory },
+ { AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, DedicatedStateFactory_getFactory }
+};
+
+static inline EffectStateFactory *getFactoryByType(ALenum type)
+{
+ size_t i;
+ for(i = 0;i < COUNTOF(FactoryList);i++)
+ {
+ if(FactoryList[i].Type == type)
+ return FactoryList[i].GetFactory();
+ }
+ return NULL;
+}
-extern inline struct ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id);
-extern inline struct ALeffectslot *RemoveEffectSlot(ALCcontext *context, ALuint id);
+static void ALeffectState_IncRef(ALeffectState *state);
-static ALenum AddEffectSlotArray(ALCcontext *Context, ALeffectslot **start, ALsizei count);
-static void RemoveEffectSlotArray(ALCcontext *Context, const ALeffectslot *slot);
+static inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id)
+{
+ id--;
+ if(UNLIKELY(id >= VECTOR_SIZE(context->EffectSlotList)))
+ return NULL;
+ return VECTOR_ELEM(context->EffectSlotList, id);
+}
-static UIntMap EffectStateFactoryMap;
-static inline ALeffectStateFactory *getFactoryByType(ALenum type)
+static inline ALeffect *LookupEffect(ALCdevice *device, ALuint id)
{
- ALeffectStateFactory* (*getFactory)(void) = LookupUIntMapKey(&EffectStateFactoryMap, type);
- if(getFactory != NULL)
- return getFactory();
- return NULL;
+ EffectSubList *sublist;
+ ALuint lidx = (id-1) >> 6;
+ ALsizei slidx = (id-1) & 0x3f;
+
+ if(UNLIKELY(lidx >= VECTOR_SIZE(device->EffectList)))
+ return NULL;
+ sublist = &VECTOR_ELEM(device->EffectList, lidx);
+ if(UNLIKELY(sublist->FreeMask & (U64(1)<<slidx)))
+ return NULL;
+ return sublist->Effects + slidx;
}
+#define DO_UPDATEPROPS() do { \
+ if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) \
+ UpdateEffectSlotProps(slot, context); \
+ else \
+ ATOMIC_FLAG_CLEAR(&slot->PropsClean, almemory_order_release); \
+} while(0)
+
+
AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
{
+ ALCdevice *device;
ALCcontext *context;
- VECTOR(ALeffectslot*) slotvec;
ALsizei cur;
- ALenum err;
context = GetContextRef();
if(!context) return;
- VECTOR_INIT(slotvec);
-
if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- if(!VECTOR_RESERVE(slotvec, n))
- SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done);
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Generating %d effect slots", n);
+ if(n == 0) goto done;
+ LockEffectSlotList(context);
+ device = context->Device;
for(cur = 0;cur < n;cur++)
{
- ALeffectslot *slot = al_calloc(16, sizeof(ALeffectslot));
- err = AL_OUT_OF_MEMORY;
- if(!slot || (err=InitEffectSlot(slot)) != AL_NO_ERROR)
+ ALeffectslotPtr *iter = VECTOR_BEGIN(context->EffectSlotList);
+ ALeffectslotPtr *end = VECTOR_END(context->EffectSlotList);
+ ALeffectslot *slot = NULL;
+ ALenum err = AL_OUT_OF_MEMORY;
+
+ for(;iter != end;iter++)
{
- al_free(slot);
- alDeleteAuxiliaryEffectSlots(cur, effectslots);
- SET_ERROR_AND_GOTO(context, err, done);
+ if(!*iter)
+ break;
}
-
- err = NewThunkEntry(&slot->id);
- if(err == AL_NO_ERROR)
- err = InsertUIntMapEntry(&context->EffectSlotMap, slot->id, slot);
- if(err != AL_NO_ERROR)
+ if(iter == end)
+ {
+ if(device->AuxiliaryEffectSlotMax == VECTOR_SIZE(context->EffectSlotList))
+ {
+ UnlockEffectSlotList(context);
+ alDeleteAuxiliaryEffectSlots(cur, effectslots);
+ SETERR_GOTO(context, AL_OUT_OF_MEMORY, done,
+ "Exceeding %u auxiliary effect slot limit", device->AuxiliaryEffectSlotMax);
+ }
+ VECTOR_PUSH_BACK(context->EffectSlotList, NULL);
+ iter = &VECTOR_BACK(context->EffectSlotList);
+ }
+ slot = al_calloc(16, sizeof(ALeffectslot));
+ if(!slot || (err=InitEffectSlot(slot)) != AL_NO_ERROR)
{
- FreeThunkEntry(slot->id);
- DELETE_OBJ(slot->EffectState);
al_free(slot);
+ UnlockEffectSlotList(context);
alDeleteAuxiliaryEffectSlots(cur, effectslots);
- SET_ERROR_AND_GOTO(context, err, done);
+ SETERR_GOTO(context, err, done, "Effect slot object allocation failed");
}
+ aluInitEffectPanning(slot);
- VECTOR_PUSH_BACK(slotvec, slot);
+ slot->id = (iter - VECTOR_BEGIN(context->EffectSlotList)) + 1;
+ *iter = slot;
effectslots[cur] = slot->id;
}
- err = AddEffectSlotArray(context, VECTOR_ITER_BEGIN(slotvec), n);
- if(err != AL_NO_ERROR)
- {
- alDeleteAuxiliaryEffectSlots(cur, effectslots);
- SET_ERROR_AND_GOTO(context, err, done);
- }
+ AddActiveEffectSlots(effectslots, n, context);
+ UnlockEffectSlotList(context);
done:
- VECTOR_DEINIT(slotvec);
-
ALCcontext_DecRef(context);
}
@@ -116,31 +178,37 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint *
context = GetContextRef();
if(!context) return;
+ LockEffectSlotList(context);
if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Deleting %d effect slots", n);
+ if(n == 0) goto done;
+
for(i = 0;i < n;i++)
{
if((slot=LookupEffectSlot(context, effectslots[i])) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u",
+ effectslots[i]);
if(ReadRef(&slot->ref) != 0)
- SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Deleting in-use effect slot %u",
+ effectslots[i]);
}
// All effectslots are valid
+ RemoveActiveEffectSlots(effectslots, n, context);
for(i = 0;i < n;i++)
{
- if((slot=RemoveEffectSlot(context, effectslots[i])) == NULL)
+ if((slot=LookupEffectSlot(context, effectslots[i])) == NULL)
continue;
- FreeThunkEntry(slot->id);
+ VECTOR_ELEM(context->EffectSlotList, effectslots[i]-1) = NULL;
- RemoveEffectSlotArray(context, slot);
- DELETE_OBJ(slot->EffectState);
+ DeinitEffectSlot(slot);
memset(slot, 0, sizeof(*slot));
al_free(slot);
}
done:
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
}
@@ -152,7 +220,9 @@ AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot)
context = GetContextRef();
if(!context) return AL_FALSE;
+ LockEffectSlotList(context);
ret = (LookupEffectSlot(context, effectslot) ? AL_TRUE : AL_FALSE);
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
@@ -170,35 +240,45 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param
context = GetContextRef();
if(!context) return;
- device = context->Device;
+ almtx_lock(&context->PropLock);
+ LockEffectSlotList(context);
if((slot=LookupEffectSlot(context, effectslot)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
{
case AL_EFFECTSLOT_EFFECT:
+ device = context->Device;
+
+ LockEffectList(device);
effect = (value ? LookupEffect(device, value) : NULL);
if(!(value == 0 || effect != NULL))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ {
+ UnlockEffectList(device);
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Invalid effect ID %u", value);
+ }
+ err = InitializeEffect(context, slot, effect);
+ UnlockEffectList(device);
- err = InitializeEffect(device, slot, effect);
if(err != AL_NO_ERROR)
- SET_ERROR_AND_GOTO(context, err, done);
- ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
+ SETERR_GOTO(context, err, done, "Effect initialization failed");
break;
case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
if(!(value == AL_TRUE || value == AL_FALSE))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
+ SETERR_GOTO(context, AL_INVALID_VALUE, done,
+ "Effect slot auxiliary send auto out of range");
slot->AuxSendAuto = value;
- ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ SETERR_GOTO(context, AL_INVALID_ENUM, done, "Invalid effect slot integer property 0x%04x",
+ param);
}
+ DO_UPDATEPROPS();
done:
+ UnlockEffectSlotList(context);
+ almtx_unlock(&context->PropLock);
ALCcontext_DecRef(context);
}
@@ -217,15 +297,18 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum para
context = GetContextRef();
if(!context) return;
+ LockEffectSlotList(context);
if(LookupEffectSlot(context, effectslot) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid effect slot integer-vector property 0x%04x",
+ param);
}
done:
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
}
@@ -237,23 +320,27 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param
context = GetContextRef();
if(!context) return;
+ almtx_lock(&context->PropLock);
+ LockEffectSlotList(context);
if((slot=LookupEffectSlot(context, effectslot)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
{
case AL_EFFECTSLOT_GAIN:
if(!(value >= 0.0f && value <= 1.0f))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Effect slot gain out of range");
slot->Gain = value;
- ATOMIC_STORE(&slot->NeedsUpdate, AL_TRUE);
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ SETERR_GOTO(context, AL_INVALID_ENUM, done, "Invalid effect slot float property 0x%04x",
+ param);
}
+ DO_UPDATEPROPS();
done:
+ UnlockEffectSlotList(context);
+ almtx_unlock(&context->PropLock);
ALCcontext_DecRef(context);
}
@@ -271,15 +358,18 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum para
context = GetContextRef();
if(!context) return;
+ LockEffectSlotList(context);
if(LookupEffectSlot(context, effectslot) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid effect slot float-vector property 0x%04x",
+ param);
}
done:
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
}
@@ -291,8 +381,9 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum pa
context = GetContextRef();
if(!context) return;
+ LockEffectSlotList(context);
if((slot=LookupEffectSlot(context, effectslot)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
{
case AL_EFFECTSLOT_AUXILIARY_SEND_AUTO:
@@ -300,10 +391,11 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum pa
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid effect slot integer property 0x%04x", param);
}
done:
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
}
@@ -322,15 +414,18 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum p
context = GetContextRef();
if(!context) return;
+ LockEffectSlotList(context);
if(LookupEffectSlot(context, effectslot) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid effect slot integer-vector property 0x%04x",
+ param);
}
done:
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
}
@@ -342,8 +437,9 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum pa
context = GetContextRef();
if(!context) return;
+ LockEffectSlotList(context);
if((slot=LookupEffectSlot(context, effectslot)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
{
case AL_EFFECTSLOT_GAIN:
@@ -351,10 +447,11 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum pa
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid effect slot float property 0x%04x", param);
}
done:
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
}
@@ -372,82 +469,32 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum p
context = GetContextRef();
if(!context) return;
+ LockEffectSlotList(context);
if(LookupEffectSlot(context, effectslot) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid effect slot float-vector property 0x%04x",
+ param);
}
done:
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
}
-static ALenum AddEffectSlotArray(ALCcontext *context, ALeffectslot **start, ALsizei count)
-{
- ALenum err = AL_NO_ERROR;
-
- LockContext(context);
- if(!VECTOR_INSERT(context->ActiveAuxSlots, VECTOR_ITER_END(context->ActiveAuxSlots), start, start+count))
- err = AL_OUT_OF_MEMORY;
- UnlockContext(context);
-
- return err;
-}
-
-static void RemoveEffectSlotArray(ALCcontext *context, const ALeffectslot *slot)
-{
- ALeffectslot **iter;
-
- LockContext(context);
-#define MATCH_SLOT(_i) (slot == *(_i))
- VECTOR_FIND_IF(iter, ALeffectslot*, context->ActiveAuxSlots, MATCH_SLOT);
- if(iter != VECTOR_ITER_END(context->ActiveAuxSlots))
- {
- *iter = VECTOR_BACK(context->ActiveAuxSlots);
- VECTOR_POP_BACK(context->ActiveAuxSlots);
- }
-#undef MATCH_SLOT
- UnlockContext(context);
-}
-
-
-void InitEffectFactoryMap(void)
-{
- InitUIntMap(&EffectStateFactoryMap, ~0);
-
- InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_NULL, ALnullStateFactory_getFactory);
- InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_EAXREVERB, ALreverbStateFactory_getFactory);
- InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_REVERB, ALreverbStateFactory_getFactory);
- InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_AUTOWAH, ALautowahStateFactory_getFactory);
- InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_CHORUS, ALchorusStateFactory_getFactory);
- InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_COMPRESSOR, ALcompressorStateFactory_getFactory);
- InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_DISTORTION, ALdistortionStateFactory_getFactory);
- InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_ECHO, ALechoStateFactory_getFactory);
- InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_EQUALIZER, ALequalizerStateFactory_getFactory);
- InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_FLANGER, ALflangerStateFactory_getFactory);
- InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_RING_MODULATOR, ALmodulatorStateFactory_getFactory);
- InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_DEDICATED_DIALOGUE, ALdedicatedStateFactory_getFactory);
- InsertUIntMapEntry(&EffectStateFactoryMap, AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, ALdedicatedStateFactory_getFactory);
-}
-
-void DeinitEffectFactoryMap(void)
-{
- ResetUIntMap(&EffectStateFactoryMap);
-}
-
-
-ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *effect)
+ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect)
{
+ ALCdevice *Device = Context->Device;
ALenum newtype = (effect ? effect->type : AL_EFFECT_NULL);
- ALeffectStateFactory *factory;
+ struct ALeffectslotProps *props;
+ ALeffectState *State;
- if(newtype != EffectSlot->EffectType)
+ if(newtype != EffectSlot->Effect.Type)
{
- ALeffectState *State;
- FPUCtl oldMode;
+ EffectStateFactory *factory;
factory = getFactoryByType(newtype);
if(!factory)
@@ -455,96 +502,301 @@ ALenum InitializeEffect(ALCdevice *Device, ALeffectslot *EffectSlot, ALeffect *e
ERR("Failed to find factory for effect type 0x%04x\n", newtype);
return AL_INVALID_ENUM;
}
- State = V0(factory,create)();
- if(!State)
- return AL_OUT_OF_MEMORY;
-
- SetMixerFPUMode(&oldMode);
+ State = EffectStateFactory_create(factory);
+ if(!State) return AL_OUT_OF_MEMORY;
- ALCdevice_Lock(Device);
+ START_MIXER_MODE();
+ almtx_lock(&Device->BackendLock);
+ State->OutBuffer = Device->Dry.Buffer;
+ State->OutChannels = Device->Dry.NumChannels;
if(V(State,deviceUpdate)(Device) == AL_FALSE)
{
- ALCdevice_Unlock(Device);
- RestoreFPUMode(&oldMode);
- DELETE_OBJ(State);
+ almtx_unlock(&Device->BackendLock);
+ LEAVE_MIXER_MODE();
+ ALeffectState_DecRef(State);
return AL_OUT_OF_MEMORY;
}
+ almtx_unlock(&Device->BackendLock);
+ END_MIXER_MODE();
- State = ExchangePtr((XchgPtr*)&EffectSlot->EffectState, State);
if(!effect)
{
- memset(&EffectSlot->EffectProps, 0, sizeof(EffectSlot->EffectProps));
- EffectSlot->EffectType = AL_EFFECT_NULL;
+ EffectSlot->Effect.Type = AL_EFFECT_NULL;
+ memset(&EffectSlot->Effect.Props, 0, sizeof(EffectSlot->Effect.Props));
}
else
{
- memcpy(&EffectSlot->EffectProps, &effect->Props, sizeof(effect->Props));
- EffectSlot->EffectType = effect->type;
+ EffectSlot->Effect.Type = effect->type;
+ EffectSlot->Effect.Props = effect->Props;
}
- /* FIXME: This should be done asynchronously, but since the EffectState
- * object was changed, it needs an update before its Process method can
- * be called. */
- ATOMIC_STORE(&EffectSlot->NeedsUpdate, AL_FALSE);
- V(EffectSlot->EffectState,update)(Device, EffectSlot);
- ALCdevice_Unlock(Device);
+ ALeffectState_DecRef(EffectSlot->Effect.State);
+ EffectSlot->Effect.State = State;
+ }
+ else if(effect)
+ EffectSlot->Effect.Props = effect->Props;
+
+ /* Remove state references from old effect slot property updates. */
+ props = ATOMIC_LOAD_SEQ(&Context->FreeEffectslotProps);
+ while(props)
+ {
+ if(props->State)
+ ALeffectState_DecRef(props->State);
+ props->State = NULL;
+ props = ATOMIC_LOAD(&props->next, almemory_order_relaxed);
+ }
+
+ return AL_NO_ERROR;
+}
- RestoreFPUMode(&oldMode);
- DELETE_OBJ(State);
- State = NULL;
+static void ALeffectState_IncRef(ALeffectState *state)
+{
+ uint ref;
+ ref = IncrementRef(&state->Ref);
+ TRACEREF("%p increasing refcount to %u\n", state, ref);
+}
+
+void ALeffectState_DecRef(ALeffectState *state)
+{
+ uint ref;
+ ref = DecrementRef(&state->Ref);
+ TRACEREF("%p decreasing refcount to %u\n", state, ref);
+ if(ref == 0) DELETE_OBJ(state);
+}
+
+
+void ALeffectState_Construct(ALeffectState *state)
+{
+ InitRef(&state->Ref, 1);
+
+ state->OutBuffer = NULL;
+ state->OutChannels = 0;
+}
+
+void ALeffectState_Destruct(ALeffectState *UNUSED(state))
+{
+}
+
+
+static void AddActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *context)
+{
+ struct ALeffectslotArray *curarray = ATOMIC_LOAD(&context->ActiveAuxSlots,
+ almemory_order_acquire);
+ struct ALeffectslotArray *newarray = NULL;
+ ALsizei newcount = curarray->count + count;
+ ALCdevice *device = context->Device;
+ ALsizei i, j;
+
+ /* Insert the new effect slots into the head of the array, followed by the
+ * existing ones.
+ */
+ newarray = al_calloc(DEF_ALIGN, FAM_SIZE(struct ALeffectslotArray, slot, newcount));
+ newarray->count = newcount;
+ for(i = 0;i < count;i++)
+ newarray->slot[i] = LookupEffectSlot(context, slotids[i]);
+ for(j = 0;i < newcount;)
+ newarray->slot[i++] = curarray->slot[j++];
+ /* Remove any duplicates (first instance of each will be kept). */
+ for(i = 1;i < newcount;i++)
+ {
+ for(j = i;j != 0;)
+ {
+ if(UNLIKELY(newarray->slot[i] == newarray->slot[--j]))
+ {
+ newcount--;
+ for(j = i;j < newcount;j++)
+ newarray->slot[j] = newarray->slot[j+1];
+ i--;
+ break;
+ }
+ }
}
- else
+
+ /* Reallocate newarray if the new size ended up smaller from duplicate
+ * removal.
+ */
+ if(UNLIKELY(newcount < newarray->count))
{
- if(effect)
+ struct ALeffectslotArray *tmpnewarray = al_calloc(DEF_ALIGN,
+ FAM_SIZE(struct ALeffectslotArray, slot, newcount));
+ memcpy(tmpnewarray, newarray, FAM_SIZE(struct ALeffectslotArray, slot, newcount));
+ al_free(newarray);
+ newarray = tmpnewarray;
+ newarray->count = newcount;
+ }
+
+ curarray = ATOMIC_EXCHANGE_PTR(&context->ActiveAuxSlots, newarray, almemory_order_acq_rel);
+ while((ATOMIC_LOAD(&device->MixCount, almemory_order_acquire)&1))
+ althrd_yield();
+ al_free(curarray);
+}
+
+static void RemoveActiveEffectSlots(const ALuint *slotids, ALsizei count, ALCcontext *context)
+{
+ struct ALeffectslotArray *curarray = ATOMIC_LOAD(&context->ActiveAuxSlots,
+ almemory_order_acquire);
+ struct ALeffectslotArray *newarray = NULL;
+ ALCdevice *device = context->Device;
+ ALsizei i, j;
+
+ /* Don't shrink the allocated array size since we don't know how many (if
+ * any) of the effect slots to remove are in the array.
+ */
+ newarray = al_calloc(DEF_ALIGN, FAM_SIZE(struct ALeffectslotArray, slot, curarray->count));
+ newarray->count = 0;
+ for(i = 0;i < curarray->count;i++)
+ {
+ /* Insert this slot into the new array only if it's not one to remove. */
+ ALeffectslot *slot = curarray->slot[i];
+ for(j = count;j != 0;)
{
- ALCdevice_Lock(Device);
- memcpy(&EffectSlot->EffectProps, &effect->Props, sizeof(effect->Props));
- ALCdevice_Unlock(Device);
- ATOMIC_STORE(&EffectSlot->NeedsUpdate, AL_TRUE);
+ if(slot->id == slotids[--j])
+ goto skip_ins;
}
+ newarray->slot[newarray->count++] = slot;
+ skip_ins: ;
}
- return AL_NO_ERROR;
+ /* TODO: Could reallocate newarray now that we know it's needed size. */
+
+ curarray = ATOMIC_EXCHANGE_PTR(&context->ActiveAuxSlots, newarray, almemory_order_acq_rel);
+ while((ATOMIC_LOAD(&device->MixCount, almemory_order_acquire)&1))
+ althrd_yield();
+ al_free(curarray);
}
ALenum InitEffectSlot(ALeffectslot *slot)
{
- ALeffectStateFactory *factory;
- ALuint i, c;
+ EffectStateFactory *factory;
- slot->EffectType = AL_EFFECT_NULL;
+ slot->Effect.Type = AL_EFFECT_NULL;
factory = getFactoryByType(AL_EFFECT_NULL);
- if(!(slot->EffectState=V0(factory,create)()))
- return AL_OUT_OF_MEMORY;
+ slot->Effect.State = EffectStateFactory_create(factory);
+ if(!slot->Effect.State) return AL_OUT_OF_MEMORY;
slot->Gain = 1.0;
slot->AuxSendAuto = AL_TRUE;
- ATOMIC_INIT(&slot->NeedsUpdate, AL_FALSE);
- for(c = 0;c < 1;c++)
- {
- for(i = 0;i < BUFFERSIZE;i++)
- slot->WetBuffer[c][i] = 0.0f;
- }
+ ATOMIC_FLAG_TEST_AND_SET(&slot->PropsClean, almemory_order_relaxed);
InitRef(&slot->ref, 0);
+ ATOMIC_INIT(&slot->Update, NULL);
+
+ slot->Params.Gain = 1.0f;
+ slot->Params.AuxSendAuto = AL_TRUE;
+ ALeffectState_IncRef(slot->Effect.State);
+ slot->Params.EffectState = slot->Effect.State;
+ slot->Params.RoomRolloff = 0.0f;
+ slot->Params.DecayTime = 0.0f;
+ slot->Params.DecayLFRatio = 0.0f;
+ slot->Params.DecayHFRatio = 0.0f;
+ slot->Params.DecayHFLimit = AL_FALSE;
+ slot->Params.AirAbsorptionGainHF = 1.0f;
+
return AL_NO_ERROR;
}
-ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context)
+void DeinitEffectSlot(ALeffectslot *slot)
+{
+ struct ALeffectslotProps *props;
+
+ props = ATOMIC_LOAD_SEQ(&slot->Update);
+ if(props)
+ {
+ if(props->State) ALeffectState_DecRef(props->State);
+ TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n", props);
+ al_free(props);
+ }
+
+ ALeffectState_DecRef(slot->Effect.State);
+ if(slot->Params.EffectState)
+ ALeffectState_DecRef(slot->Params.EffectState);
+}
+
+void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context)
+{
+ struct ALeffectslotProps *props;
+ ALeffectState *oldstate;
+
+ /* Get an unused property container, or allocate a new one as needed. */
+ props = ATOMIC_LOAD(&context->FreeEffectslotProps, almemory_order_relaxed);
+ if(!props)
+ props = al_calloc(16, sizeof(*props));
+ else
+ {
+ struct ALeffectslotProps *next;
+ do {
+ next = ATOMIC_LOAD(&props->next, almemory_order_relaxed);
+ } while(ATOMIC_COMPARE_EXCHANGE_PTR_WEAK(&context->FreeEffectslotProps, &props, next,
+ almemory_order_seq_cst, almemory_order_acquire) == 0);
+ }
+
+ /* Copy in current property values. */
+ props->Gain = slot->Gain;
+ props->AuxSendAuto = slot->AuxSendAuto;
+
+ props->Type = slot->Effect.Type;
+ props->Props = slot->Effect.Props;
+ /* Swap out any stale effect state object there may be in the container, to
+ * delete it.
+ */
+ ALeffectState_IncRef(slot->Effect.State);
+ oldstate = props->State;
+ props->State = slot->Effect.State;
+
+ /* Set the new container for updating internal parameters. */
+ props = ATOMIC_EXCHANGE_PTR(&slot->Update, props, almemory_order_acq_rel);
+ if(props)
+ {
+ /* If there was an unused update container, put it back in the
+ * freelist.
+ */
+ if(props->State)
+ ALeffectState_DecRef(props->State);
+ props->State = NULL;
+ ATOMIC_REPLACE_HEAD(struct ALeffectslotProps*, &context->FreeEffectslotProps, props);
+ }
+
+ if(oldstate)
+ ALeffectState_DecRef(oldstate);
+}
+
+void UpdateAllEffectSlotProps(ALCcontext *context)
{
- ALsizei pos;
- for(pos = 0;pos < Context->EffectSlotMap.size;pos++)
+ struct ALeffectslotArray *auxslots;
+ ALsizei i;
+
+ LockEffectSlotList(context);
+ auxslots = ATOMIC_LOAD(&context->ActiveAuxSlots, almemory_order_acquire);
+ for(i = 0;i < auxslots->count;i++)
{
- ALeffectslot *temp = Context->EffectSlotMap.array[pos].value;
- Context->EffectSlotMap.array[pos].value = NULL;
+ ALeffectslot *slot = auxslots->slot[i];
+ if(!ATOMIC_FLAG_TEST_AND_SET(&slot->PropsClean, almemory_order_acq_rel))
+ UpdateEffectSlotProps(slot, context);
+ }
+ UnlockEffectSlotList(context);
+}
+
+ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *context)
+{
+ ALeffectslotPtr *iter = VECTOR_BEGIN(context->EffectSlotList);
+ ALeffectslotPtr *end = VECTOR_END(context->EffectSlotList);
+ size_t leftover = 0;
- DELETE_OBJ(temp->EffectState);
+ for(;iter != end;iter++)
+ {
+ ALeffectslot *slot = *iter;
+ if(!slot) continue;
+ *iter = NULL;
- FreeThunkEntry(temp->id);
- memset(temp, 0, sizeof(ALeffectslot));
- al_free(temp);
+ DeinitEffectSlot(slot);
+
+ memset(slot, 0, sizeof(*slot));
+ al_free(slot);
+ ++leftover;
}
+ if(leftover > 0)
+ WARN("(%p) Deleted "SZFMT" AuxiliaryEffectSlot%s\n", context, leftover, (leftover==1)?"":"s");
}
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c
index 904fd61d..ed712434 100644
--- a/OpenAL32/alBuffer.c
+++ b/OpenAL32/alBuffer.c
@@ -32,20 +32,41 @@
#include "alu.h"
#include "alError.h"
#include "alBuffer.h"
-#include "alThunk.h"
#include "sample_cvt.h"
-extern inline struct ALbuffer *LookupBuffer(ALCdevice *device, ALuint id);
-extern inline struct ALbuffer *RemoveBuffer(ALCdevice *device, ALuint id);
-extern inline ALuint FrameSizeFromUserFmt(enum UserFmtChannels chans, enum UserFmtType type);
-extern inline ALuint FrameSizeFromFmt(enum FmtChannels chans, enum FmtType type);
+extern inline void LockBufferList(ALCdevice *device);
+extern inline void UnlockBufferList(ALCdevice *device);
+extern inline ALsizei FrameSizeFromUserFmt(enum UserFmtChannels chans, enum UserFmtType type);
+extern inline ALsizei FrameSizeFromFmt(enum FmtChannels chans, enum FmtType type);
-static ALboolean IsValidType(ALenum type) DECL_CONST;
-static ALboolean IsValidChannels(ALenum channels) DECL_CONST;
-static ALboolean DecomposeUserFormat(ALenum format, enum UserFmtChannels *chans, enum UserFmtType *type) DECL_CONST;
-static ALboolean DecomposeFormat(ALenum format, enum FmtChannels *chans, enum FmtType *type) DECL_CONST;
-static ALboolean SanitizeAlignment(enum UserFmtType type, ALsizei *align);
+static ALbuffer *AllocBuffer(ALCcontext *context);
+static void FreeBuffer(ALCdevice *device, ALbuffer *buffer);
+static const ALchar *NameFromUserFmtType(enum UserFmtType type);
+static void LoadData(ALCcontext *context, ALbuffer *buffer, ALuint freq, ALsizei size,
+ enum UserFmtChannels SrcChannels, enum UserFmtType SrcType,
+ const ALvoid *data, ALbitfieldSOFT access);
+static ALboolean DecomposeUserFormat(ALenum format, enum UserFmtChannels *chans, enum UserFmtType *type);
+static ALsizei SanitizeAlignment(enum UserFmtType type, ALsizei align);
+
+static inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id)
+{
+ BufferSubList *sublist;
+ ALuint lidx = (id-1) >> 6;
+ ALsizei slidx = (id-1) & 0x3f;
+
+ if(UNLIKELY(lidx >= VECTOR_SIZE(device->BufferList)))
+ return NULL;
+ sublist = &VECTOR_ELEM(device->BufferList, lidx);
+ if(UNLIKELY(sublist->FreeMask & (U64(1)<<slidx)))
+ return NULL;
+ return sublist->Buffers + slidx;
+}
+
+
+#define INVALID_STORAGE_MASK ~(AL_MAP_READ_BIT_SOFT | AL_MAP_WRITE_BIT_SOFT | AL_PRESERVE_DATA_BIT_SOFT | AL_MAP_PERSISTENT_BIT_SOFT)
+#define MAP_READ_WRITE_FLAGS (AL_MAP_READ_BIT_SOFT | AL_MAP_WRITE_BIT_SOFT)
+#define INVALID_MAP_FLAGS ~(AL_MAP_READ_BIT_SOFT | AL_MAP_WRITE_BIT_SOFT | AL_MAP_PERSISTENT_BIT_SOFT)
AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers)
@@ -57,11 +78,10 @@ AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers)
if(!context) return;
if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- for(cur = 0;cur < n;cur++)
+ alSetError(context, AL_INVALID_VALUE, "Generating %d buffers", n);
+ else for(cur = 0;cur < n;cur++)
{
- ALbuffer *buffer = NewBuffer(context);
+ ALbuffer *buffer = AllocBuffer(context);
if(!buffer)
{
alDeleteBuffers(cur, buffers);
@@ -71,7 +91,6 @@ AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers)
buffers[cur] = buffer->id;
}
-done:
ALCcontext_DecRef(context);
}
@@ -85,29 +104,40 @@ AL_API ALvoid AL_APIENTRY alDeleteBuffers(ALsizei n, const ALuint *buffers)
context = GetContextRef();
if(!context) return;
- if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
device = context->Device;
+
+ LockBufferList(device);
+ if(UNLIKELY(n < 0))
+ {
+ alSetError(context, AL_INVALID_VALUE, "Deleting %d buffers", n);
+ goto done;
+ }
+
for(i = 0;i < n;i++)
{
if(!buffers[i])
continue;
- /* Check for valid Buffer ID */
+ /* Check for valid Buffer ID, and make sure it's not in use. */
if((ALBuf=LookupBuffer(device, buffers[i])) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ {
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffers[i]);
+ goto done;
+ }
if(ReadRef(&ALBuf->ref) != 0)
- SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done);
+ {
+ alSetError(context, AL_INVALID_OPERATION, "Deleting in-use buffer %u", buffers[i]);
+ goto done;
+ }
}
-
for(i = 0;i < n;i++)
{
if((ALBuf=LookupBuffer(device, buffers[i])) != NULL)
- DeleteBuffer(device, ALBuf);
+ FreeBuffer(device, ALBuf);
}
done:
+ UnlockBufferList(device);
ALCcontext_DecRef(context);
}
@@ -119,8 +149,10 @@ AL_API ALboolean AL_APIENTRY alIsBuffer(ALuint buffer)
context = GetContextRef();
if(!context) return AL_FALSE;
+ LockBufferList(context->Device);
ret = ((!buffer || LookupBuffer(context->Device, buffer)) ?
AL_TRUE : AL_FALSE);
+ UnlockBufferList(context->Device);
ALCcontext_DecRef(context);
@@ -129,389 +161,297 @@ AL_API ALboolean AL_APIENTRY alIsBuffer(ALuint buffer)
AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq)
+{ alBufferStorageSOFT(buffer, format, data, size, freq, 0); }
+
+AL_API void AL_APIENTRY alBufferStorageSOFT(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq, ALbitfieldSOFT flags)
{
- enum UserFmtChannels srcchannels;
- enum UserFmtType srctype;
+ enum UserFmtChannels srcchannels = UserFmtMono;
+ enum UserFmtType srctype = UserFmtUByte;
ALCdevice *device;
ALCcontext *context;
ALbuffer *albuf;
- ALenum newformat = AL_NONE;
- ALuint framesize;
- ALsizei align;
- ALenum err;
context = GetContextRef();
if(!context) return;
device = context->Device;
- if((albuf=LookupBuffer(device, buffer)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
- if(!(size >= 0 && freq > 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- if(DecomposeUserFormat(format, &srcchannels, &srctype) == AL_FALSE)
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
-
- align = ATOMIC_LOAD(&albuf->UnpackAlign);
- if(SanitizeAlignment(srctype, &align) == AL_FALSE)
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(srctype)
- {
- case UserFmtByte:
- case UserFmtUByte:
- case UserFmtShort:
- case UserFmtUShort:
- case UserFmtFloat:
- framesize = FrameSizeFromUserFmt(srcchannels, srctype) * align;
- if((size%framesize) != 0)
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- err = LoadData(albuf, freq, format, size/framesize*align,
- srcchannels, srctype, data, align, AL_TRUE);
- if(err != AL_NO_ERROR)
- SET_ERROR_AND_GOTO(context, err, done);
- break;
-
- case UserFmtInt:
- case UserFmtUInt:
- case UserFmtByte3:
- case UserFmtUByte3:
- case UserFmtDouble:
- framesize = FrameSizeFromUserFmt(srcchannels, srctype) * align;
- if((size%framesize) != 0)
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- switch(srcchannels)
- {
- case UserFmtMono: newformat = AL_FORMAT_MONO_FLOAT32; break;
- case UserFmtStereo: newformat = AL_FORMAT_STEREO_FLOAT32; break;
- case UserFmtRear: newformat = AL_FORMAT_REAR32; break;
- case UserFmtQuad: newformat = AL_FORMAT_QUAD32; break;
- case UserFmtX51: newformat = AL_FORMAT_51CHN32; break;
- case UserFmtX61: newformat = AL_FORMAT_61CHN32; break;
- case UserFmtX71: newformat = AL_FORMAT_71CHN32; break;
- case UserFmtBFormat2D: newformat = AL_FORMAT_BFORMAT2D_FLOAT32; break;
- case UserFmtBFormat3D: newformat = AL_FORMAT_BFORMAT3D_FLOAT32; break;
- }
- err = LoadData(albuf, freq, newformat, size/framesize*align,
- srcchannels, srctype, data, align, AL_TRUE);
- if(err != AL_NO_ERROR)
- SET_ERROR_AND_GOTO(context, err, done);
- break;
-
- case UserFmtMulaw:
- case UserFmtAlaw:
- framesize = FrameSizeFromUserFmt(srcchannels, srctype) * align;
- if((size%framesize) != 0)
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- switch(srcchannels)
- {
- case UserFmtMono: newformat = AL_FORMAT_MONO16; break;
- case UserFmtStereo: newformat = AL_FORMAT_STEREO16; break;
- case UserFmtRear: newformat = AL_FORMAT_REAR16; break;
- case UserFmtQuad: newformat = AL_FORMAT_QUAD16; break;
- case UserFmtX51: newformat = AL_FORMAT_51CHN16; break;
- case UserFmtX61: newformat = AL_FORMAT_61CHN16; break;
- case UserFmtX71: newformat = AL_FORMAT_71CHN16; break;
- case UserFmtBFormat2D: newformat = AL_FORMAT_BFORMAT2D_16; break;
- case UserFmtBFormat3D: newformat = AL_FORMAT_BFORMAT3D_16; break;
- }
- err = LoadData(albuf, freq, newformat, size/framesize*align,
- srcchannels, srctype, data, align, AL_TRUE);
- if(err != AL_NO_ERROR)
- SET_ERROR_AND_GOTO(context, err, done);
- break;
+ LockBufferList(device);
+ if(UNLIKELY((albuf=LookupBuffer(device, buffer)) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else if(UNLIKELY(size < 0))
+ alSetError(context, AL_INVALID_VALUE, "Negative storage size %d", size);
+ else if(UNLIKELY(freq < 1))
+ alSetError(context, AL_INVALID_VALUE, "Invalid sample rate %d", freq);
+ else if(UNLIKELY((flags&INVALID_STORAGE_MASK) != 0))
+ alSetError(context, AL_INVALID_VALUE, "Invalid storage flags 0x%x",
+ flags&INVALID_STORAGE_MASK);
+ else if(UNLIKELY((flags&AL_MAP_PERSISTENT_BIT_SOFT) && !(flags&MAP_READ_WRITE_FLAGS)))
+ alSetError(context, AL_INVALID_VALUE,
+ "Declaring persistently mapped storage without read or write access");
+ else if(UNLIKELY(DecomposeUserFormat(format, &srcchannels, &srctype) == AL_FALSE))
+ alSetError(context, AL_INVALID_ENUM, "Invalid format 0x%04x", format);
+ else
+ LoadData(context, albuf, freq, size, srcchannels, srctype, data, flags);
- case UserFmtIMA4:
- framesize = (align-1)/2 + 4;
- framesize *= ChannelsFromUserFmt(srcchannels);
- if((size%framesize) != 0)
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ UnlockBufferList(device);
+ ALCcontext_DecRef(context);
+}
- switch(srcchannels)
- {
- case UserFmtMono: newformat = AL_FORMAT_MONO16; break;
- case UserFmtStereo: newformat = AL_FORMAT_STEREO16; break;
- case UserFmtRear: newformat = AL_FORMAT_REAR16; break;
- case UserFmtQuad: newformat = AL_FORMAT_QUAD16; break;
- case UserFmtX51: newformat = AL_FORMAT_51CHN16; break;
- case UserFmtX61: newformat = AL_FORMAT_61CHN16; break;
- case UserFmtX71: newformat = AL_FORMAT_71CHN16; break;
- case UserFmtBFormat2D: newformat = AL_FORMAT_BFORMAT2D_16; break;
- case UserFmtBFormat3D: newformat = AL_FORMAT_BFORMAT3D_16; break;
- }
- err = LoadData(albuf, freq, newformat, size/framesize*align,
- srcchannels, srctype, data, align, AL_TRUE);
- if(err != AL_NO_ERROR)
- SET_ERROR_AND_GOTO(context, err, done);
- break;
+AL_API void* AL_APIENTRY alMapBufferSOFT(ALuint buffer, ALsizei offset, ALsizei length, ALbitfieldSOFT access)
+{
+ void *retval = NULL;
+ ALCdevice *device;
+ ALCcontext *context;
+ ALbuffer *albuf;
- case UserFmtMSADPCM:
- framesize = (align-2)/2 + 7;
- framesize *= ChannelsFromUserFmt(srcchannels);
- if((size%framesize) != 0)
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ context = GetContextRef();
+ if(!context) return retval;
- switch(srcchannels)
- {
- case UserFmtMono: newformat = AL_FORMAT_MONO16; break;
- case UserFmtStereo: newformat = AL_FORMAT_STEREO16; break;
- case UserFmtRear: newformat = AL_FORMAT_REAR16; break;
- case UserFmtQuad: newformat = AL_FORMAT_QUAD16; break;
- case UserFmtX51: newformat = AL_FORMAT_51CHN16; break;
- case UserFmtX61: newformat = AL_FORMAT_61CHN16; break;
- case UserFmtX71: newformat = AL_FORMAT_71CHN16; break;
- case UserFmtBFormat2D: newformat = AL_FORMAT_BFORMAT2D_16; break;
- case UserFmtBFormat3D: newformat = AL_FORMAT_BFORMAT3D_16; break;
- }
- err = LoadData(albuf, freq, newformat, size/framesize*align,
- srcchannels, srctype, data, align, AL_TRUE);
- if(err != AL_NO_ERROR)
- SET_ERROR_AND_GOTO(context, err, done);
- break;
+ device = context->Device;
+ LockBufferList(device);
+ if(UNLIKELY((albuf=LookupBuffer(device, buffer)) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else if(UNLIKELY((access&INVALID_MAP_FLAGS) != 0))
+ alSetError(context, AL_INVALID_VALUE, "Invalid map flags 0x%x", access&INVALID_MAP_FLAGS);
+ else if(UNLIKELY(!(access&MAP_READ_WRITE_FLAGS)))
+ alSetError(context, AL_INVALID_VALUE, "Mapping buffer %u without read or write access",
+ buffer);
+ else
+ {
+ ALbitfieldSOFT unavailable = (albuf->Access^access) & access;
+ if(UNLIKELY(ReadRef(&albuf->ref) != 0 && !(access&AL_MAP_PERSISTENT_BIT_SOFT)))
+ alSetError(context, AL_INVALID_OPERATION,
+ "Mapping in-use buffer %u without persistent mapping", buffer);
+ else if(UNLIKELY(albuf->MappedAccess != 0))
+ alSetError(context, AL_INVALID_OPERATION, "Mapping already-mapped buffer %u", buffer);
+ else if(UNLIKELY((unavailable&AL_MAP_READ_BIT_SOFT)))
+ alSetError(context, AL_INVALID_VALUE,
+ "Mapping buffer %u for reading without read access", buffer);
+ else if(UNLIKELY((unavailable&AL_MAP_WRITE_BIT_SOFT)))
+ alSetError(context, AL_INVALID_VALUE,
+ "Mapping buffer %u for writing without write access", buffer);
+ else if(UNLIKELY((unavailable&AL_MAP_PERSISTENT_BIT_SOFT)))
+ alSetError(context, AL_INVALID_VALUE,
+ "Mapping buffer %u persistently without persistent access", buffer);
+ else if(UNLIKELY(offset < 0 || offset >= albuf->OriginalSize ||
+ length <= 0 || length > albuf->OriginalSize - offset))
+ alSetError(context, AL_INVALID_VALUE, "Mapping invalid range %d+%d for buffer %u",
+ offset, length, buffer);
+ else
+ {
+ retval = (ALbyte*)albuf->data + offset;
+ albuf->MappedAccess = access;
+ albuf->MappedOffset = offset;
+ albuf->MappedSize = length;
+ }
}
+ UnlockBufferList(device);
-done:
ALCcontext_DecRef(context);
+ return retval;
}
-AL_API ALvoid AL_APIENTRY alBufferSubDataSOFT(ALuint buffer, ALenum format, const ALvoid *data, ALsizei offset, ALsizei length)
+AL_API void AL_APIENTRY alUnmapBufferSOFT(ALuint buffer)
{
- enum UserFmtChannels srcchannels;
- enum UserFmtType srctype;
ALCdevice *device;
ALCcontext *context;
ALbuffer *albuf;
- ALuint byte_align;
- ALuint channels;
- ALuint bytes;
- ALsizei align;
context = GetContextRef();
if(!context) return;
device = context->Device;
+ LockBufferList(device);
if((albuf=LookupBuffer(device, buffer)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
- if(!(length >= 0 && offset >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- if(DecomposeUserFormat(format, &srcchannels, &srctype) == AL_FALSE)
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
-
- WriteLock(&albuf->lock);
- align = ATOMIC_LOAD(&albuf->UnpackAlign);
- if(SanitizeAlignment(srctype, &align) == AL_FALSE)
- {
- WriteUnlock(&albuf->lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- }
- if(srcchannels != albuf->OriginalChannels || srctype != albuf->OriginalType)
- {
- WriteUnlock(&albuf->lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
- }
- if(align != albuf->OriginalAlign)
- {
- WriteUnlock(&albuf->lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
- }
-
- if(albuf->OriginalType == UserFmtIMA4)
- {
- byte_align = (albuf->OriginalAlign-1)/2 + 4;
- byte_align *= ChannelsFromUserFmt(albuf->OriginalChannels);
- }
- else if(albuf->OriginalType == UserFmtMSADPCM)
- {
- byte_align = (albuf->OriginalAlign-2)/2 + 7;
- byte_align *= ChannelsFromUserFmt(albuf->OriginalChannels);
- }
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else if(albuf->MappedAccess == 0)
+ alSetError(context, AL_INVALID_OPERATION, "Unmapping unmapped buffer %u", buffer);
else
{
- byte_align = albuf->OriginalAlign;
- byte_align *= FrameSizeFromUserFmt(albuf->OriginalChannels,
- albuf->OriginalType);
- }
-
- if(offset > albuf->OriginalSize || length > albuf->OriginalSize-offset ||
- (offset%byte_align) != 0 || (length%byte_align) != 0)
- {
- WriteUnlock(&albuf->lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ albuf->MappedAccess = 0;
+ albuf->MappedOffset = 0;
+ albuf->MappedSize = 0;
}
+ UnlockBufferList(device);
- channels = ChannelsFromFmt(albuf->FmtChannels);
- bytes = BytesFromFmt(albuf->FmtType);
- /* offset -> byte offset, length -> sample count */
- offset = offset/byte_align * channels*bytes;
- length = length/byte_align * albuf->OriginalAlign;
-
- ConvertData((char*)albuf->data+offset, (enum UserFmtType)albuf->FmtType,
- data, srctype, channels, length, align);
- WriteUnlock(&albuf->lock);
-
-done:
ALCcontext_DecRef(context);
}
-
-AL_API void AL_APIENTRY alBufferSamplesSOFT(ALuint buffer,
- ALuint samplerate, ALenum internalformat, ALsizei samples,
- ALenum channels, ALenum type, const ALvoid *data)
+AL_API void AL_APIENTRY alFlushMappedBufferSOFT(ALuint buffer, ALsizei offset, ALsizei length)
{
ALCdevice *device;
ALCcontext *context;
ALbuffer *albuf;
- ALsizei align;
- ALenum err;
context = GetContextRef();
if(!context) return;
device = context->Device;
- if((albuf=LookupBuffer(device, buffer)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
- if(!(samples >= 0 && samplerate != 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- if(IsValidType(type) == AL_FALSE || IsValidChannels(channels) == AL_FALSE)
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
-
- align = ATOMIC_LOAD(&albuf->UnpackAlign);
- if(SanitizeAlignment(type, &align) == AL_FALSE)
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- if((samples%align) != 0)
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- err = LoadData(albuf, samplerate, internalformat, samples,
- channels, type, data, align, AL_FALSE);
- if(err != AL_NO_ERROR)
- SET_ERROR_AND_GOTO(context, err, done);
+ LockBufferList(device);
+ if(UNLIKELY((albuf=LookupBuffer(device, buffer)) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else if(UNLIKELY(!(albuf->MappedAccess&AL_MAP_WRITE_BIT_SOFT)))
+ alSetError(context, AL_INVALID_OPERATION,
+ "Flushing buffer %u while not mapped for writing", buffer);
+ else if(UNLIKELY(offset < albuf->MappedOffset ||
+ offset >= albuf->MappedOffset+albuf->MappedSize ||
+ length <= 0 || length > albuf->MappedOffset+albuf->MappedSize-offset))
+ alSetError(context, AL_INVALID_VALUE, "Flushing invalid range %d+%d on buffer %u",
+ offset, length, buffer);
+ else
+ {
+ /* FIXME: Need to use some method of double-buffering for the mixer and
+ * app to hold separate memory, which can be safely transfered
+ * asynchronously. Currently we just say the app shouldn't write where
+ * OpenAL's reading, and hope for the best...
+ */
+ ATOMIC_THREAD_FENCE(almemory_order_seq_cst);
+ }
+ UnlockBufferList(device);
-done:
ALCcontext_DecRef(context);
}
-AL_API void AL_APIENTRY alBufferSubSamplesSOFT(ALuint buffer,
- ALsizei offset, ALsizei samples,
- ALenum channels, ALenum type, const ALvoid *data)
+AL_API ALvoid AL_APIENTRY alBufferSubDataSOFT(ALuint buffer, ALenum format, const ALvoid *data, ALsizei offset, ALsizei length)
{
+ enum UserFmtChannels srcchannels = UserFmtMono;
+ enum UserFmtType srctype = UserFmtUByte;
ALCdevice *device;
ALCcontext *context;
ALbuffer *albuf;
- ALsizei align;
context = GetContextRef();
if(!context) return;
device = context->Device;
- if((albuf=LookupBuffer(device, buffer)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
- if(!(samples >= 0 && offset >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- if(IsValidType(type) == AL_FALSE)
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
-
- WriteLock(&albuf->lock);
- align = ATOMIC_LOAD(&albuf->UnpackAlign);
- if(SanitizeAlignment(type, &align) == AL_FALSE)
- {
- WriteUnlock(&albuf->lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- }
- if(channels != (ALenum)albuf->FmtChannels)
- {
- WriteUnlock(&albuf->lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
- }
- if(offset > albuf->SampleLen || samples > albuf->SampleLen-offset)
- {
- WriteUnlock(&albuf->lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- }
- if((samples%align) != 0)
+ LockBufferList(device);
+ if(UNLIKELY((albuf=LookupBuffer(device, buffer)) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else if(UNLIKELY(DecomposeUserFormat(format, &srcchannels, &srctype) == AL_FALSE))
+ alSetError(context, AL_INVALID_ENUM, "Invalid format 0x%04x", format);
+ else
{
- WriteUnlock(&albuf->lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ ALsizei unpack_align, align;
+ ALsizei byte_align;
+ ALsizei frame_size;
+ ALsizei num_chans;
+ void *dst;
+
+ unpack_align = ATOMIC_LOAD_SEQ(&albuf->UnpackAlign);
+ align = SanitizeAlignment(srctype, unpack_align);
+ if(UNLIKELY(align < 1))
+ alSetError(context, AL_INVALID_VALUE, "Invalid unpack alignment %d", unpack_align);
+ else if(UNLIKELY((long)srcchannels != (long)albuf->FmtChannels ||
+ srctype != albuf->OriginalType))
+ alSetError(context, AL_INVALID_ENUM, "Unpacking data with mismatched format");
+ else if(UNLIKELY(align != albuf->OriginalAlign))
+ alSetError(context, AL_INVALID_VALUE,
+ "Unpacking data with alignment %u does not match original alignment %u",
+ align, albuf->OriginalAlign);
+ else if(UNLIKELY(albuf->MappedAccess != 0))
+ alSetError(context, AL_INVALID_OPERATION, "Unpacking data into mapped buffer %u",
+ buffer);
+ else
+ {
+ num_chans = ChannelsFromFmt(albuf->FmtChannels);
+ frame_size = num_chans * BytesFromFmt(albuf->FmtType);
+ if(albuf->OriginalType == UserFmtIMA4)
+ byte_align = ((align-1)/2 + 4) * num_chans;
+ else if(albuf->OriginalType == UserFmtMSADPCM)
+ byte_align = ((align-2)/2 + 7) * num_chans;
+ else
+ byte_align = align * frame_size;
+
+ if(UNLIKELY(offset < 0 || length < 0 || offset > albuf->OriginalSize ||
+ length > albuf->OriginalSize-offset))
+ alSetError(context, AL_INVALID_VALUE, "Invalid data sub-range %d+%d on buffer %u",
+ offset, length, buffer);
+ else if(UNLIKELY((offset%byte_align) != 0))
+ alSetError(context, AL_INVALID_VALUE,
+ "Sub-range offset %d is not a multiple of frame size %d (%d unpack alignment)",
+ offset, byte_align, align);
+ else if(UNLIKELY((length%byte_align) != 0))
+ alSetError(context, AL_INVALID_VALUE,
+ "Sub-range length %d is not a multiple of frame size %d (%d unpack alignment)",
+ length, byte_align, align);
+ else
+ {
+ /* offset -> byte offset, length -> sample count */
+ offset = offset/byte_align * align * frame_size;
+ length = length/byte_align * align;
+
+ dst = (ALbyte*)albuf->data + offset;
+ if(srctype == UserFmtIMA4 && albuf->FmtType == FmtShort)
+ Convert_ALshort_ALima4(dst, data, num_chans, length, align);
+ else if(srctype == UserFmtMSADPCM && albuf->FmtType == FmtShort)
+ Convert_ALshort_ALmsadpcm(dst, data, num_chans, length, align);
+ else
+ {
+ assert((long)srctype == (long)albuf->FmtType);
+ memcpy(dst, data, length*frame_size);
+ }
+ }
+ }
}
+ UnlockBufferList(device);
- /* offset -> byte offset */
- offset *= FrameSizeFromFmt(albuf->FmtChannels, albuf->FmtType);
- ConvertData((char*)albuf->data+offset, (enum UserFmtType)albuf->FmtType,
- data, type, ChannelsFromFmt(albuf->FmtChannels), samples, align);
- WriteUnlock(&albuf->lock);
+ ALCcontext_DecRef(context);
+}
+
+
+AL_API void AL_APIENTRY alBufferSamplesSOFT(ALuint UNUSED(buffer),
+ ALuint UNUSED(samplerate), ALenum UNUSED(internalformat), ALsizei UNUSED(samples),
+ ALenum UNUSED(channels), ALenum UNUSED(type), const ALvoid *UNUSED(data))
+{
+ ALCcontext *context;
+
+ context = GetContextRef();
+ if(!context) return;
+
+ alSetError(context, AL_INVALID_OPERATION, "alBufferSamplesSOFT not supported");
-done:
ALCcontext_DecRef(context);
}
-AL_API void AL_APIENTRY alGetBufferSamplesSOFT(ALuint buffer,
- ALsizei offset, ALsizei samples,
- ALenum channels, ALenum type, ALvoid *data)
+AL_API void AL_APIENTRY alBufferSubSamplesSOFT(ALuint UNUSED(buffer),
+ ALsizei UNUSED(offset), ALsizei UNUSED(samples),
+ ALenum UNUSED(channels), ALenum UNUSED(type), const ALvoid *UNUSED(data))
{
- ALCdevice *device;
ALCcontext *context;
- ALbuffer *albuf;
- ALsizei align;
context = GetContextRef();
if(!context) return;
- device = context->Device;
- if((albuf=LookupBuffer(device, buffer)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
- if(!(samples >= 0 && offset >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- if(IsValidType(type) == AL_FALSE)
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
-
- ReadLock(&albuf->lock);
- align = ATOMIC_LOAD(&albuf->PackAlign);
- if(SanitizeAlignment(type, &align) == AL_FALSE)
- {
- ReadUnlock(&albuf->lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- }
- if(channels != (ALenum)albuf->FmtChannels)
- {
- ReadUnlock(&albuf->lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
- }
- if(offset > albuf->SampleLen || samples > albuf->SampleLen-offset)
- {
- ReadUnlock(&albuf->lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- }
- if((samples%align) != 0)
- {
- ReadUnlock(&albuf->lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- }
+ alSetError(context, AL_INVALID_OPERATION, "alBufferSubSamplesSOFT not supported");
- /* offset -> byte offset */
- offset *= FrameSizeFromFmt(albuf->FmtChannels, albuf->FmtType);
- ConvertData(data, type, (char*)albuf->data+offset, (enum UserFmtType)albuf->FmtType,
- ChannelsFromFmt(albuf->FmtChannels), samples, align);
- ReadUnlock(&albuf->lock);
+ ALCcontext_DecRef(context);
+}
+
+AL_API void AL_APIENTRY alGetBufferSamplesSOFT(ALuint UNUSED(buffer),
+ ALsizei UNUSED(offset), ALsizei UNUSED(samples),
+ ALenum UNUSED(channels), ALenum UNUSED(type), ALvoid *UNUSED(data))
+{
+ ALCcontext *context;
+
+ context = GetContextRef();
+ if(!context) return;
+
+ alSetError(context, AL_INVALID_OPERATION, "alGetBufferSamplesSOFT not supported");
-done:
ALCcontext_DecRef(context);
}
-AL_API ALboolean AL_APIENTRY alIsBufferFormatSupportedSOFT(ALenum format)
+AL_API ALboolean AL_APIENTRY alIsBufferFormatSupportedSOFT(ALenum UNUSED(format))
{
- enum FmtChannels dstchannels;
- enum FmtType dsttype;
ALCcontext *context;
- ALboolean ret;
context = GetContextRef();
if(!context) return AL_FALSE;
- ret = DecomposeFormat(format, &dstchannels, &dsttype);
+ alSetError(context, AL_INVALID_OPERATION, "alIsBufferFormatSupportedSOFT not supported");
ALCcontext_DecRef(context);
-
- return ret;
+ return AL_FALSE;
}
@@ -524,16 +464,16 @@ AL_API void AL_APIENTRY alBufferf(ALuint buffer, ALenum param, ALfloat UNUSED(va
if(!context) return;
device = context->Device;
- if(LookupBuffer(device, buffer) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
-
- switch(param)
+ LockBufferList(device);
+ if(UNLIKELY(LookupBuffer(device, buffer) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid buffer float property 0x%04x", param);
}
+ UnlockBufferList(device);
-done:
ALCcontext_DecRef(context);
}
@@ -547,16 +487,16 @@ AL_API void AL_APIENTRY alBuffer3f(ALuint buffer, ALenum param, ALfloat UNUSED(v
if(!context) return;
device = context->Device;
- if(LookupBuffer(device, buffer) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
-
- switch(param)
+ LockBufferList(device);
+ if(UNLIKELY(LookupBuffer(device, buffer) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid buffer 3-float property 0x%04x", param);
}
+ UnlockBufferList(device);
-done:
ALCcontext_DecRef(context);
}
@@ -570,18 +510,18 @@ AL_API void AL_APIENTRY alBufferfv(ALuint buffer, ALenum param, const ALfloat *v
if(!context) return;
device = context->Device;
- if(LookupBuffer(device, buffer) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
-
- if(!(values))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(param)
+ LockBufferList(device);
+ if(UNLIKELY(LookupBuffer(device, buffer) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else if(UNLIKELY(!values))
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid buffer float-vector property 0x%04x", param);
}
+ UnlockBufferList(device);
-done:
ALCcontext_DecRef(context);
}
@@ -596,28 +536,30 @@ AL_API void AL_APIENTRY alBufferi(ALuint buffer, ALenum param, ALint value)
if(!context) return;
device = context->Device;
- if((albuf=LookupBuffer(device, buffer)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
-
- switch(param)
+ LockBufferList(device);
+ if(UNLIKELY((albuf=LookupBuffer(device, buffer)) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else switch(param)
{
case AL_UNPACK_BLOCK_ALIGNMENT_SOFT:
- if(!(value >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- ATOMIC_STORE(&albuf->UnpackAlign, value);
+ if(UNLIKELY(value < 0))
+ alSetError(context, AL_INVALID_VALUE, "Invalid unpack block alignment %d", value);
+ else
+ ATOMIC_STORE_SEQ(&albuf->UnpackAlign, value);
break;
case AL_PACK_BLOCK_ALIGNMENT_SOFT:
- if(!(value >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- ATOMIC_STORE(&albuf->PackAlign, value);
+ if(UNLIKELY(value < 0))
+ alSetError(context, AL_INVALID_VALUE, "Invalid pack block alignment %d", value);
+ else
+ ATOMIC_STORE_SEQ(&albuf->PackAlign, value);
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid buffer integer property 0x%04x", param);
}
+ UnlockBufferList(device);
-done:
ALCcontext_DecRef(context);
}
@@ -631,16 +573,16 @@ AL_API void AL_APIENTRY alBuffer3i(ALuint buffer, ALenum param, ALint UNUSED(val
if(!context) return;
device = context->Device;
- if(LookupBuffer(device, buffer) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
-
- switch(param)
+ LockBufferList(device);
+ if(UNLIKELY(LookupBuffer(device, buffer) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid buffer 3-integer property 0x%04x", param);
}
+ UnlockBufferList(device);
-done:
ALCcontext_DecRef(context);
}
@@ -666,37 +608,33 @@ AL_API void AL_APIENTRY alBufferiv(ALuint buffer, ALenum param, const ALint *val
if(!context) return;
device = context->Device;
- if((albuf=LookupBuffer(device, buffer)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
-
- if(!(values))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(param)
+ LockBufferList(device);
+ if(UNLIKELY((albuf=LookupBuffer(device, buffer)) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else if(UNLIKELY(!values))
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
case AL_LOOP_POINTS_SOFT:
- WriteLock(&albuf->lock);
- if(ReadRef(&albuf->ref) != 0)
- {
- WriteUnlock(&albuf->lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done);
- }
- if(values[0] >= values[1] || values[0] < 0 ||
- values[1] > albuf->SampleLen)
+ if(UNLIKELY(ReadRef(&albuf->ref) != 0))
+ alSetError(context, AL_INVALID_OPERATION, "Modifying in-use buffer %u's loop points",
+ buffer);
+ else if(UNLIKELY(values[0] >= values[1] || values[0] < 0 || values[1] > albuf->SampleLen))
+ alSetError(context, AL_INVALID_VALUE, "Invalid loop point range %d -> %d o buffer %u",
+ values[0], values[1], buffer);
+ else
{
- WriteUnlock(&albuf->lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ albuf->LoopStart = values[0];
+ albuf->LoopEnd = values[1];
}
-
- albuf->LoopStart = values[0];
- albuf->LoopEnd = values[1];
- WriteUnlock(&albuf->lock);
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid buffer integer-vector property 0x%04x",
+ param);
}
+ UnlockBufferList(device);
-done:
ALCcontext_DecRef(context);
}
@@ -711,27 +649,18 @@ AL_API ALvoid AL_APIENTRY alGetBufferf(ALuint buffer, ALenum param, ALfloat *val
if(!context) return;
device = context->Device;
- if((albuf=LookupBuffer(device, buffer)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
-
- if(!(value))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(param)
+ LockBufferList(device);
+ if(UNLIKELY((albuf=LookupBuffer(device, buffer)) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else if(UNLIKELY(!value))
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
- case AL_SEC_LENGTH_SOFT:
- ReadLock(&albuf->lock);
- if(albuf->SampleLen != 0)
- *value = albuf->SampleLen / (ALfloat)albuf->Frequency;
- else
- *value = 0.0f;
- ReadUnlock(&albuf->lock);
- break;
-
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid buffer float property 0x%04x", param);
}
+ UnlockBufferList(device);
-done:
ALCcontext_DecRef(context);
}
@@ -745,18 +674,18 @@ AL_API void AL_APIENTRY alGetBuffer3f(ALuint buffer, ALenum param, ALfloat *valu
if(!context) return;
device = context->Device;
- if(LookupBuffer(device, buffer) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
-
- if(!(value1 && value2 && value3))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(param)
+ LockBufferList(device);
+ if(UNLIKELY(LookupBuffer(device, buffer) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else if(UNLIKELY(!value1 || !value2 || !value3))
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid buffer 3-float property 0x%04x", param);
}
+ UnlockBufferList(device);
-done:
ALCcontext_DecRef(context);
}
@@ -777,18 +706,18 @@ AL_API void AL_APIENTRY alGetBufferfv(ALuint buffer, ALenum param, ALfloat *valu
if(!context) return;
device = context->Device;
- if(LookupBuffer(device, buffer) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
-
- if(!(values))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(param)
+ LockBufferList(device);
+ if(UNLIKELY(LookupBuffer(device, buffer) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else if(UNLIKELY(!values))
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid buffer float-vector property 0x%04x", param);
}
+ UnlockBufferList(device);
-done:
ALCcontext_DecRef(context);
}
@@ -803,12 +732,12 @@ AL_API ALvoid AL_APIENTRY alGetBufferi(ALuint buffer, ALenum param, ALint *value
if(!context) return;
device = context->Device;
- if((albuf=LookupBuffer(device, buffer)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
-
- if(!(value))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(param)
+ LockBufferList(device);
+ if(UNLIKELY((albuf=LookupBuffer(device, buffer)) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else if(UNLIKELY(!value))
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
case AL_FREQUENCY:
*value = albuf->Frequency;
@@ -823,37 +752,23 @@ AL_API ALvoid AL_APIENTRY alGetBufferi(ALuint buffer, ALenum param, ALint *value
break;
case AL_SIZE:
- ReadLock(&albuf->lock);
*value = albuf->SampleLen * FrameSizeFromFmt(albuf->FmtChannels,
albuf->FmtType);
- ReadUnlock(&albuf->lock);
- break;
-
- case AL_INTERNAL_FORMAT_SOFT:
- *value = albuf->Format;
- break;
-
- case AL_BYTE_LENGTH_SOFT:
- *value = albuf->OriginalSize;
- break;
-
- case AL_SAMPLE_LENGTH_SOFT:
- *value = albuf->SampleLen;
break;
case AL_UNPACK_BLOCK_ALIGNMENT_SOFT:
- *value = ATOMIC_LOAD(&albuf->UnpackAlign);
+ *value = ATOMIC_LOAD_SEQ(&albuf->UnpackAlign);
break;
case AL_PACK_BLOCK_ALIGNMENT_SOFT:
- *value = ATOMIC_LOAD(&albuf->PackAlign);
+ *value = ATOMIC_LOAD_SEQ(&albuf->PackAlign);
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid buffer integer property 0x%04x", param);
}
+ UnlockBufferList(device);
-done:
ALCcontext_DecRef(context);
}
@@ -867,18 +782,18 @@ AL_API void AL_APIENTRY alGetBuffer3i(ALuint buffer, ALenum param, ALint *value1
if(!context) return;
device = context->Device;
- if(LookupBuffer(device, buffer) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
-
- if(!(value1 && value2 && value3))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(param)
+ LockBufferList(device);
+ if(UNLIKELY(LookupBuffer(device, buffer) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else if(UNLIKELY(!value1 || !value2 || !value3))
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid buffer 3-integer property 0x%04x", param);
}
+ UnlockBufferList(device);
-done:
ALCcontext_DecRef(context);
}
@@ -908,133 +823,214 @@ AL_API void AL_APIENTRY alGetBufferiv(ALuint buffer, ALenum param, ALint *values
if(!context) return;
device = context->Device;
- if((albuf=LookupBuffer(device, buffer)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
-
- if(!(values))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(param)
+ LockBufferList(device);
+ if(UNLIKELY((albuf=LookupBuffer(device, buffer)) == NULL))
+ alSetError(context, AL_INVALID_NAME, "Invalid buffer ID %u", buffer);
+ else if(UNLIKELY(!values))
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
case AL_LOOP_POINTS_SOFT:
- ReadLock(&albuf->lock);
values[0] = albuf->LoopStart;
values[1] = albuf->LoopEnd;
- ReadUnlock(&albuf->lock);
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid buffer integer-vector property 0x%04x",
+ param);
}
+ UnlockBufferList(device);
-done:
ALCcontext_DecRef(context);
}
+static const ALchar *NameFromUserFmtType(enum UserFmtType type)
+{
+ switch(type)
+ {
+ case UserFmtUByte: return "Unsigned Byte";
+ case UserFmtShort: return "Signed Short";
+ case UserFmtFloat: return "Float32";
+ case UserFmtDouble: return "Float64";
+ case UserFmtMulaw: return "muLaw";
+ case UserFmtAlaw: return "aLaw";
+ case UserFmtIMA4: return "IMA4 ADPCM";
+ case UserFmtMSADPCM: return "MSADPCM";
+ }
+ return "<internal type error>";
+}
+
/*
* LoadData
*
- * Loads the specified data into the buffer, using the specified formats.
- * Currently, the new format must have the same channel configuration as the
- * original format.
+ * Loads the specified data into the buffer, using the specified format.
*/
-ALenum LoadData(ALbuffer *ALBuf, ALuint freq, ALenum NewFormat, ALsizei frames, enum UserFmtChannels SrcChannels, enum UserFmtType SrcType, const ALvoid *data, ALsizei align, ALboolean storesrc)
+static void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, enum UserFmtChannels SrcChannels, enum UserFmtType SrcType, const ALvoid *data, ALbitfieldSOFT access)
{
- ALuint NewChannels, NewBytes;
- enum FmtChannels DstChannels;
- enum FmtType DstType;
- ALuint64 newsize;
- ALvoid *temp;
-
- if(DecomposeFormat(NewFormat, &DstChannels, &DstType) == AL_FALSE ||
- (long)SrcChannels != (long)DstChannels)
- return AL_INVALID_ENUM;
-
- NewChannels = ChannelsFromFmt(DstChannels);
- NewBytes = BytesFromFmt(DstType);
-
- newsize = frames;
- newsize *= NewBytes;
- newsize *= NewChannels;
- if(newsize > INT_MAX)
- return AL_OUT_OF_MEMORY;
-
- WriteLock(&ALBuf->lock);
- if(ReadRef(&ALBuf->ref) != 0)
+ enum FmtChannels DstChannels = FmtMono;
+ enum FmtType DstType = FmtUByte;
+ ALsizei NumChannels, FrameSize;
+ ALsizei SrcByteAlign;
+ ALsizei unpackalign;
+ ALsizei newsize;
+ ALsizei frames;
+ ALsizei align;
+
+ if(UNLIKELY(ReadRef(&ALBuf->ref) != 0 || ALBuf->MappedAccess != 0))
+ SETERR_RETURN(context, AL_INVALID_OPERATION,, "Modifying storage for in-use buffer %u",
+ ALBuf->id);
+
+ /* Currently no channel configurations need to be converted. */
+ switch(SrcChannels)
+ {
+ case UserFmtMono: DstChannels = FmtMono; break;
+ case UserFmtStereo: DstChannels = FmtStereo; break;
+ case UserFmtRear: DstChannels = FmtRear; break;
+ case UserFmtQuad: DstChannels = FmtQuad; break;
+ case UserFmtX51: DstChannels = FmtX51; break;
+ case UserFmtX61: DstChannels = FmtX61; break;
+ case UserFmtX71: DstChannels = FmtX71; break;
+ case UserFmtBFormat2D: DstChannels = FmtBFormat2D; break;
+ case UserFmtBFormat3D: DstChannels = FmtBFormat3D; break;
+ }
+ if(UNLIKELY((long)SrcChannels != (long)DstChannels))
+ SETERR_RETURN(context, AL_INVALID_ENUM,, "Invalid format");
+
+ /* IMA4 and MSADPCM convert to 16-bit short. */
+ switch(SrcType)
{
- WriteUnlock(&ALBuf->lock);
- return AL_INVALID_OPERATION;
+ case UserFmtUByte: DstType = FmtUByte; break;
+ case UserFmtShort: DstType = FmtShort; break;
+ case UserFmtFloat: DstType = FmtFloat; break;
+ case UserFmtDouble: DstType = FmtDouble; break;
+ case UserFmtAlaw: DstType = FmtAlaw; break;
+ case UserFmtMulaw: DstType = FmtMulaw; break;
+ case UserFmtIMA4: DstType = FmtShort; break;
+ case UserFmtMSADPCM: DstType = FmtShort; break;
}
- temp = realloc(ALBuf->data, (size_t)newsize);
- if(!temp && newsize)
+ /* TODO: Currently we can only map samples when they're not converted. To
+ * allow it would need some kind of double-buffering to hold onto a copy of
+ * the original data.
+ */
+ if((access&MAP_READ_WRITE_FLAGS))
{
- WriteUnlock(&ALBuf->lock);
- return AL_OUT_OF_MEMORY;
+ if(UNLIKELY((long)SrcType != (long)DstType))
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "%s samples cannot be mapped",
+ NameFromUserFmtType(SrcType));
}
- ALBuf->data = temp;
- if(data != NULL)
- ConvertData(ALBuf->data, (enum UserFmtType)DstType, data, SrcType, NewChannels, frames, align);
+ unpackalign = ATOMIC_LOAD_SEQ(&ALBuf->UnpackAlign);
+ if(UNLIKELY((align=SanitizeAlignment(SrcType, unpackalign)) < 1))
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid unpack alignment %d for %s samples",
+ unpackalign, NameFromUserFmtType(SrcType));
- if(storesrc)
+ if((access&AL_PRESERVE_DATA_BIT_SOFT))
{
- ALBuf->OriginalChannels = SrcChannels;
- ALBuf->OriginalType = SrcType;
- if(SrcType == UserFmtIMA4)
- {
- ALsizei byte_align = ((align-1)/2 + 4) * ChannelsFromUserFmt(SrcChannels);
- ALBuf->OriginalSize = frames / align * byte_align;
- ALBuf->OriginalAlign = align;
- }
- else if(SrcType == UserFmtMSADPCM)
- {
- ALsizei byte_align = ((align-2)/2 + 7) * ChannelsFromUserFmt(SrcChannels);
- ALBuf->OriginalSize = frames / align * byte_align;
- ALBuf->OriginalAlign = align;
- }
- else
+ /* Can only preserve data with the same format and alignment. */
+ if(UNLIKELY(ALBuf->FmtChannels != DstChannels || ALBuf->OriginalType != SrcType))
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Preserving data of mismatched format");
+ if(UNLIKELY(ALBuf->OriginalAlign != align))
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Preserving data of mismatched alignment");
+ }
+
+ /* Convert the input/source size in bytes to sample frames using the unpack
+ * block alignment.
+ */
+ if(SrcType == UserFmtIMA4)
+ SrcByteAlign = ((align-1)/2 + 4) * ChannelsFromUserFmt(SrcChannels);
+ else if(SrcType == UserFmtMSADPCM)
+ SrcByteAlign = ((align-2)/2 + 7) * ChannelsFromUserFmt(SrcChannels);
+ else
+ SrcByteAlign = align * FrameSizeFromUserFmt(SrcChannels, SrcType);
+ if(UNLIKELY((size%SrcByteAlign) != 0))
+ SETERR_RETURN(context, AL_INVALID_VALUE,,
+ "Data size %d is not a multiple of frame size %d (%d unpack alignment)",
+ size, SrcByteAlign, align);
+
+ if(UNLIKELY(size / SrcByteAlign > INT_MAX / align))
+ SETERR_RETURN(context, AL_OUT_OF_MEMORY,,
+ "Buffer size overflow, %d blocks x %d samples per block", size/SrcByteAlign, align);
+ frames = size / SrcByteAlign * align;
+
+ /* Convert the sample frames to the number of bytes needed for internal
+ * storage.
+ */
+ NumChannels = ChannelsFromFmt(DstChannels);
+ FrameSize = NumChannels * BytesFromFmt(DstType);
+ if(UNLIKELY(frames > INT_MAX/FrameSize))
+ SETERR_RETURN(context, AL_OUT_OF_MEMORY,,
+ "Buffer size overflow, %d frames x %d bytes per frame", frames, FrameSize);
+ newsize = frames*FrameSize;
+
+ /* Round up to the next 16-byte multiple. This could reallocate only when
+ * increasing or the new size is less than half the current, but then the
+ * buffer's AL_SIZE would not be very reliable for accounting buffer memory
+ * usage, and reporting the real size could cause problems for apps that
+ * use AL_SIZE to try to get the buffer's play length.
+ */
+ if(LIKELY(newsize <= INT_MAX-15))
+ newsize = (newsize+15) & ~0xf;
+ if(newsize != ALBuf->BytesAlloc)
+ {
+ void *temp = al_malloc(16, (size_t)newsize);
+ if(UNLIKELY(!temp && newsize))
+ SETERR_RETURN(context, AL_OUT_OF_MEMORY,, "Failed to allocate %d bytes of storage",
+ newsize);
+ if((access&AL_PRESERVE_DATA_BIT_SOFT))
{
- ALBuf->OriginalSize = frames * FrameSizeFromUserFmt(SrcChannels, SrcType);
- ALBuf->OriginalAlign = 1;
+ ALsizei tocopy = mini(newsize, ALBuf->BytesAlloc);
+ if(tocopy > 0) memcpy(temp, ALBuf->data, tocopy);
}
+ al_free(ALBuf->data);
+ ALBuf->data = temp;
+ ALBuf->BytesAlloc = newsize;
+ }
+
+ if(SrcType == UserFmtIMA4)
+ {
+ assert(DstType == FmtShort);
+ if(data != NULL && ALBuf->data != NULL)
+ Convert_ALshort_ALima4(ALBuf->data, data, NumChannels, frames, align);
+ ALBuf->OriginalAlign = align;
+ }
+ else if(SrcType == UserFmtMSADPCM)
+ {
+ assert(DstType == FmtShort);
+ if(data != NULL && ALBuf->data != NULL)
+ Convert_ALshort_ALmsadpcm(ALBuf->data, data, NumChannels, frames, align);
+ ALBuf->OriginalAlign = align;
}
else
{
- ALBuf->OriginalChannels = (enum UserFmtChannels)DstChannels;
- ALBuf->OriginalType = (enum UserFmtType)DstType;
- ALBuf->OriginalSize = frames * NewBytes * NewChannels;
- ALBuf->OriginalAlign = 1;
+ assert((long)SrcType == (long)DstType);
+ if(data != NULL && ALBuf->data != NULL)
+ memcpy(ALBuf->data, data, frames*FrameSize);
+ ALBuf->OriginalAlign = 1;
}
+ ALBuf->OriginalSize = size;
+ ALBuf->OriginalType = SrcType;
ALBuf->Frequency = freq;
ALBuf->FmtChannels = DstChannels;
ALBuf->FmtType = DstType;
- ALBuf->Format = NewFormat;
+ ALBuf->Access = access;
ALBuf->SampleLen = frames;
ALBuf->LoopStart = 0;
ALBuf->LoopEnd = ALBuf->SampleLen;
-
- WriteUnlock(&ALBuf->lock);
- return AL_NO_ERROR;
}
-ALuint BytesFromUserFmt(enum UserFmtType type)
+ALsizei BytesFromUserFmt(enum UserFmtType type)
{
switch(type)
{
- case UserFmtByte: return sizeof(ALbyte);
case UserFmtUByte: return sizeof(ALubyte);
case UserFmtShort: return sizeof(ALshort);
- case UserFmtUShort: return sizeof(ALushort);
- case UserFmtInt: return sizeof(ALint);
- case UserFmtUInt: return sizeof(ALuint);
case UserFmtFloat: return sizeof(ALfloat);
case UserFmtDouble: return sizeof(ALdouble);
- case UserFmtByte3: return sizeof(ALbyte[3]);
- case UserFmtUByte3: return sizeof(ALubyte[3]);
case UserFmtMulaw: return sizeof(ALubyte);
case UserFmtAlaw: return sizeof(ALubyte);
case UserFmtIMA4: break; /* not handled here */
@@ -1042,7 +1038,7 @@ ALuint BytesFromUserFmt(enum UserFmtType type)
}
return 0;
}
-ALuint ChannelsFromUserFmt(enum UserFmtChannels chans)
+ALsizei ChannelsFromUserFmt(enum UserFmtChannels chans)
{
switch(chans)
{
@@ -1137,17 +1133,20 @@ static ALboolean DecomposeUserFormat(ALenum format, enum UserFmtChannels *chans,
return AL_FALSE;
}
-ALuint BytesFromFmt(enum FmtType type)
+ALsizei BytesFromFmt(enum FmtType type)
{
switch(type)
{
- case FmtByte: return sizeof(ALbyte);
+ case FmtUByte: return sizeof(ALubyte);
case FmtShort: return sizeof(ALshort);
case FmtFloat: return sizeof(ALfloat);
+ case FmtDouble: return sizeof(ALdouble);
+ case FmtMulaw: return sizeof(ALubyte);
+ case FmtAlaw: return sizeof(ALubyte);
}
return 0;
}
-ALuint ChannelsFromFmt(enum FmtChannels chans)
+ALsizei ChannelsFromFmt(enum FmtChannels chans)
{
switch(chans)
{
@@ -1163,73 +1162,13 @@ ALuint ChannelsFromFmt(enum FmtChannels chans)
}
return 0;
}
-static ALboolean DecomposeFormat(ALenum format, enum FmtChannels *chans, enum FmtType *type)
-{
- static const struct {
- ALenum format;
- enum FmtChannels channels;
- enum FmtType type;
- } list[] = {
- { AL_MONO8_SOFT, FmtMono, FmtByte },
- { AL_MONO16_SOFT, FmtMono, FmtShort },
- { AL_MONO32F_SOFT, FmtMono, FmtFloat },
-
- { AL_STEREO8_SOFT, FmtStereo, FmtByte },
- { AL_STEREO16_SOFT, FmtStereo, FmtShort },
- { AL_STEREO32F_SOFT, FmtStereo, FmtFloat },
-
- { AL_REAR8_SOFT, FmtRear, FmtByte },
- { AL_REAR16_SOFT, FmtRear, FmtShort },
- { AL_REAR32F_SOFT, FmtRear, FmtFloat },
- { AL_FORMAT_QUAD8_LOKI, FmtQuad, FmtByte },
- { AL_FORMAT_QUAD16_LOKI, FmtQuad, FmtShort },
-
- { AL_QUAD8_SOFT, FmtQuad, FmtByte },
- { AL_QUAD16_SOFT, FmtQuad, FmtShort },
- { AL_QUAD32F_SOFT, FmtQuad, FmtFloat },
-
- { AL_5POINT1_8_SOFT, FmtX51, FmtByte },
- { AL_5POINT1_16_SOFT, FmtX51, FmtShort },
- { AL_5POINT1_32F_SOFT, FmtX51, FmtFloat },
-
- { AL_6POINT1_8_SOFT, FmtX61, FmtByte },
- { AL_6POINT1_16_SOFT, FmtX61, FmtShort },
- { AL_6POINT1_32F_SOFT, FmtX61, FmtFloat },
-
- { AL_7POINT1_8_SOFT, FmtX71, FmtByte },
- { AL_7POINT1_16_SOFT, FmtX71, FmtShort },
- { AL_7POINT1_32F_SOFT, FmtX71, FmtFloat },
-
- { AL_FORMAT_BFORMAT2D_8, FmtBFormat2D, FmtByte },
- { AL_FORMAT_BFORMAT2D_16, FmtBFormat2D, FmtShort },
- { AL_FORMAT_BFORMAT2D_FLOAT32, FmtBFormat2D, FmtFloat },
-
- { AL_FORMAT_BFORMAT3D_8, FmtBFormat3D, FmtByte },
- { AL_FORMAT_BFORMAT3D_16, FmtBFormat3D, FmtShort },
- { AL_FORMAT_BFORMAT3D_FLOAT32, FmtBFormat3D, FmtFloat },
- };
- ALuint i;
-
- for(i = 0;i < COUNTOF(list);i++)
- {
- if(list[i].format == format)
- {
- *chans = list[i].channels;
- *type = list[i].type;
- return AL_TRUE;
- }
- }
-
- return AL_FALSE;
-}
-
-static ALboolean SanitizeAlignment(enum UserFmtType type, ALsizei *align)
+static ALsizei SanitizeAlignment(enum UserFmtType type, ALsizei align)
{
- if(*align < 0)
- return AL_FALSE;
+ if(align < 0)
+ return 0;
- if(*align == 0)
+ if(align == 0)
{
if(type == UserFmtIMA4)
{
@@ -1237,103 +1176,101 @@ static ALboolean SanitizeAlignment(enum UserFmtType type, ALsizei *align)
* nVidia and Apple use 64+1 sample frames per block -> block_size=36 bytes per channel
* Most PC sound software uses 2040+1 sample frames per block -> block_size=1024 bytes per channel
*/
- *align = 65;
+ return 65;
}
- else if(type == UserFmtMSADPCM)
- *align = 64;
- else
- *align = 1;
- return AL_TRUE;
+ if(type == UserFmtMSADPCM)
+ return 64;
+ return 1;
}
if(type == UserFmtIMA4)
{
/* IMA4 block alignment must be a multiple of 8, plus 1. */
- return ((*align)&7) == 1;
+ if((align&7) == 1) return align;
+ return 0;
}
if(type == UserFmtMSADPCM)
{
/* MSADPCM block alignment must be a multiple of 2. */
- /* FIXME: Too strict? Might only require align*channels to be a
- * multiple of 2. */
- return ((*align)&1) == 0;
+ if((align&1) == 0) return align;
+ return 0;
}
- return AL_TRUE;
+ return align;
}
-static ALboolean IsValidType(ALenum type)
+static ALbuffer *AllocBuffer(ALCcontext *context)
{
- switch(type)
+ ALCdevice *device = context->Device;
+ BufferSubList *sublist, *subend;
+ ALbuffer *buffer = NULL;
+ ALsizei lidx = 0;
+ ALsizei slidx;
+
+ almtx_lock(&device->BufferLock);
+ sublist = VECTOR_BEGIN(device->BufferList);
+ subend = VECTOR_END(device->BufferList);
+ for(;sublist != subend;++sublist)
{
- case AL_BYTE_SOFT:
- case AL_UNSIGNED_BYTE_SOFT:
- case AL_SHORT_SOFT:
- case AL_UNSIGNED_SHORT_SOFT:
- case AL_INT_SOFT:
- case AL_UNSIGNED_INT_SOFT:
- case AL_FLOAT_SOFT:
- case AL_DOUBLE_SOFT:
- case AL_BYTE3_SOFT:
- case AL_UNSIGNED_BYTE3_SOFT:
- return AL_TRUE;
+ if(sublist->FreeMask)
+ {
+ slidx = CTZ64(sublist->FreeMask);
+ buffer = sublist->Buffers + slidx;
+ break;
+ }
+ ++lidx;
}
- return AL_FALSE;
-}
-
-static ALboolean IsValidChannels(ALenum channels)
-{
- switch(channels)
+ if(UNLIKELY(!buffer))
{
- case AL_MONO_SOFT:
- case AL_STEREO_SOFT:
- case AL_REAR_SOFT:
- case AL_QUAD_SOFT:
- case AL_5POINT1_SOFT:
- case AL_6POINT1_SOFT:
- case AL_7POINT1_SOFT:
- return AL_TRUE;
+ const BufferSubList empty_sublist = { 0, NULL };
+ /* Don't allocate so many list entries that the 32-bit ID could
+ * overflow...
+ */
+ if(UNLIKELY(VECTOR_SIZE(device->BufferList) >= 1<<25))
+ {
+ almtx_unlock(&device->BufferLock);
+ alSetError(context, AL_OUT_OF_MEMORY, "Too many buffers allocated");
+ return NULL;
+ }
+ lidx = (ALsizei)VECTOR_SIZE(device->BufferList);
+ VECTOR_PUSH_BACK(device->BufferList, empty_sublist);
+ sublist = &VECTOR_BACK(device->BufferList);
+ sublist->FreeMask = ~U64(0);
+ sublist->Buffers = al_calloc(16, sizeof(ALbuffer)*64);
+ if(UNLIKELY(!sublist->Buffers))
+ {
+ VECTOR_POP_BACK(device->BufferList);
+ almtx_unlock(&device->BufferLock);
+ alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate buffer batch");
+ return NULL;
+ }
+
+ slidx = 0;
+ buffer = sublist->Buffers + slidx;
}
- return AL_FALSE;
-}
+ memset(buffer, 0, sizeof(*buffer));
-ALbuffer *NewBuffer(ALCcontext *context)
-{
- ALCdevice *device = context->Device;
- ALbuffer *buffer;
- ALenum err;
-
- buffer = calloc(1, sizeof(ALbuffer));
- if(!buffer)
- SET_ERROR_AND_RETURN_VALUE(context, AL_OUT_OF_MEMORY, NULL);
- RWLockInit(&buffer->lock);
-
- err = NewThunkEntry(&buffer->id);
- if(err == AL_NO_ERROR)
- err = InsertUIntMapEntry(&device->BufferMap, buffer->id, buffer);
- if(err != AL_NO_ERROR)
- {
- FreeThunkEntry(buffer->id);
- memset(buffer, 0, sizeof(ALbuffer));
- free(buffer);
+ /* Add 1 to avoid buffer ID 0. */
+ buffer->id = ((lidx<<6) | slidx) + 1;
- SET_ERROR_AND_RETURN_VALUE(context, err, NULL);
- }
+ sublist->FreeMask &= ~(U64(1)<<slidx);
+ almtx_unlock(&device->BufferLock);
return buffer;
}
-void DeleteBuffer(ALCdevice *device, ALbuffer *buffer)
+static void FreeBuffer(ALCdevice *device, ALbuffer *buffer)
{
- RemoveBuffer(device, buffer->id);
- FreeThunkEntry(buffer->id);
-
- free(buffer->data);
+ ALuint id = buffer->id - 1;
+ ALsizei lidx = id >> 6;
+ ALsizei slidx = id & 0x3f;
+ al_free(buffer->data);
memset(buffer, 0, sizeof(*buffer));
- free(buffer);
+
+ VECTOR_ELEM(device->BufferList, lidx).FreeMask |= U64(1) << slidx;
}
@@ -1344,16 +1281,25 @@ void DeleteBuffer(ALCdevice *device, ALbuffer *buffer)
*/
ALvoid ReleaseALBuffers(ALCdevice *device)
{
- ALsizei i;
- for(i = 0;i < device->BufferMap.size;i++)
+ BufferSubList *sublist = VECTOR_BEGIN(device->BufferList);
+ BufferSubList *subend = VECTOR_END(device->BufferList);
+ size_t leftover = 0;
+ for(;sublist != subend;++sublist)
{
- ALbuffer *temp = device->BufferMap.array[i].value;
- device->BufferMap.array[i].value = NULL;
+ ALuint64 usemask = ~sublist->FreeMask;
+ while(usemask)
+ {
+ ALsizei idx = CTZ64(usemask);
+ ALbuffer *buffer = sublist->Buffers + idx;
- free(temp->data);
+ al_free(buffer->data);
+ memset(buffer, 0, sizeof(*buffer));
+ ++leftover;
- FreeThunkEntry(temp->id);
- memset(temp, 0, sizeof(ALbuffer));
- free(temp);
+ usemask &= ~(U64(1) << idx);
+ }
+ sublist->FreeMask = ~usemask;
}
+ if(leftover > 0)
+ WARN("(%p) Deleted "SZFMT" Buffer%s\n", device, leftover, (leftover==1)?"":"s");
}
diff --git a/OpenAL32/alEffect.c b/OpenAL32/alEffect.c
index 0bfe11b9..c2a78a0c 100644
--- a/OpenAL32/alEffect.c
+++ b/OpenAL32/alEffect.c
@@ -28,22 +28,53 @@
#include "AL/alc.h"
#include "alMain.h"
#include "alEffect.h"
-#include "alThunk.h"
#include "alError.h"
-ALboolean DisabledEffects[MAX_EFFECTS];
-
-extern inline struct ALeffect *LookupEffect(ALCdevice *device, ALuint id);
-extern inline struct ALeffect *RemoveEffect(ALCdevice *device, ALuint id);
+extern inline void LockEffectList(ALCdevice *device);
+extern inline void UnlockEffectList(ALCdevice *device);
extern inline ALboolean IsReverbEffect(ALenum type);
+const struct EffectList EffectList[EFFECTLIST_SIZE] = {
+ { "eaxreverb", EAXREVERB_EFFECT, AL_EFFECT_EAXREVERB },
+ { "reverb", REVERB_EFFECT, AL_EFFECT_REVERB },
+ { "autowah", AUTOWAH_EFFECT, AL_EFFECT_AUTOWAH },
+ { "chorus", CHORUS_EFFECT, AL_EFFECT_CHORUS },
+ { "compressor", COMPRESSOR_EFFECT, AL_EFFECT_COMPRESSOR },
+ { "distortion", DISTORTION_EFFECT, AL_EFFECT_DISTORTION },
+ { "echo", ECHO_EFFECT, AL_EFFECT_ECHO },
+ { "equalizer", EQUALIZER_EFFECT, AL_EFFECT_EQUALIZER },
+ { "flanger", FLANGER_EFFECT, AL_EFFECT_FLANGER },
+ { "fshifter", FSHIFTER_EFFECT, AL_EFFECT_FREQUENCY_SHIFTER },
+ { "modulator", MODULATOR_EFFECT, AL_EFFECT_RING_MODULATOR },
+ { "pshifter", PSHIFTER_EFFECT, AL_EFFECT_PITCH_SHIFTER },
+ { "dedicated", DEDICATED_EFFECT, AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT },
+ { "dedicated", DEDICATED_EFFECT, AL_EFFECT_DEDICATED_DIALOGUE },
+};
+
+ALboolean DisabledEffects[MAX_EFFECTS];
+
+static ALeffect *AllocEffect(ALCcontext *context);
+static void FreeEffect(ALCdevice *device, ALeffect *effect);
static void InitEffectParams(ALeffect *effect, ALenum type);
+static inline ALeffect *LookupEffect(ALCdevice *device, ALuint id)
+{
+ EffectSubList *sublist;
+ ALuint lidx = (id-1) >> 6;
+ ALsizei slidx = (id-1) & 0x3f;
+
+ if(UNLIKELY(lidx >= VECTOR_SIZE(device->EffectList)))
+ return NULL;
+ sublist = &VECTOR_ELEM(device->EffectList, lidx);
+ if(UNLIKELY(sublist->FreeMask & (U64(1)<<slidx)))
+ return NULL;
+ return sublist->Effects + slidx;
+}
+
AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
{
- ALCdevice *device;
ALCcontext *context;
ALsizei cur;
@@ -51,37 +82,18 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
if(!context) return;
if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- device = context->Device;
- for(cur = 0;cur < n;cur++)
+ alSetError(context, AL_INVALID_VALUE, "Generating %d effects", n);
+ else for(cur = 0;cur < n;cur++)
{
- ALeffect *effect = calloc(1, sizeof(ALeffect));
- ALenum err = AL_OUT_OF_MEMORY;
- if(!effect || (err=InitEffect(effect)) != AL_NO_ERROR)
- {
- free(effect);
- alDeleteEffects(cur, effects);
- SET_ERROR_AND_GOTO(context, err, done);
- }
-
- err = NewThunkEntry(&effect->id);
- if(err == AL_NO_ERROR)
- err = InsertUIntMapEntry(&device->EffectMap, effect->id, effect);
- if(err != AL_NO_ERROR)
+ ALeffect *effect = AllocEffect(context);
+ if(!effect)
{
- FreeThunkEntry(effect->id);
- memset(effect, 0, sizeof(ALeffect));
- free(effect);
-
alDeleteEffects(cur, effects);
- SET_ERROR_AND_GOTO(context, err, done);
+ break;
}
-
effects[cur] = effect->id;
}
-done:
ALCcontext_DecRef(context);
}
@@ -95,26 +107,23 @@ AL_API ALvoid AL_APIENTRY alDeleteEffects(ALsizei n, const ALuint *effects)
context = GetContextRef();
if(!context) return;
- if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
device = context->Device;
+ LockEffectList(device);
+ if(!(n >= 0))
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Deleting %d effects", n);
for(i = 0;i < n;i++)
{
if(effects[i] && LookupEffect(device, effects[i]) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect ID %u", effects[i]);
}
for(i = 0;i < n;i++)
{
- if((effect=RemoveEffect(device, effects[i])) == NULL)
- continue;
- FreeThunkEntry(effect->id);
-
- memset(effect, 0, sizeof(*effect));
- free(effect);
+ if((effect=LookupEffect(device, effects[i])) != NULL)
+ FreeEffect(device, effect);
}
done:
+ UnlockEffectList(device);
ALCcontext_DecRef(context);
}
@@ -126,8 +135,10 @@ AL_API ALboolean AL_APIENTRY alIsEffect(ALuint effect)
Context = GetContextRef();
if(!Context) return AL_FALSE;
+ LockEffectList(Context->Device);
result = ((!effect || LookupEffect(Context->Device, effect)) ?
AL_TRUE : AL_FALSE);
+ UnlockEffectList(Context->Device);
ALCcontext_DecRef(Context);
@@ -144,15 +155,16 @@ AL_API ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint value)
if(!Context) return;
Device = Context->Device;
+ LockEffectList(Device);
if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
if(param == AL_EFFECT_TYPE)
{
ALboolean isOk = (value == AL_EFFECT_NULL);
ALint i;
- for(i = 0;!isOk && EffectList[i].val;i++)
+ for(i = 0;!isOk && i < EFFECTLIST_SIZE;i++)
{
if(value == EffectList[i].val &&
!DisabledEffects[EffectList[i].type])
@@ -162,14 +174,15 @@ AL_API ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint value)
if(isOk)
InitEffectParams(ALEffect, value);
else
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "Effect type 0x%04x not supported", value);
}
else
{
/* Call the appropriate handler */
- V(ALEffect,setParami)(Context, param, value);
+ ALeffect_setParami(ALEffect, Context, param, value);
}
}
+ UnlockEffectList(Device);
ALCcontext_DecRef(Context);
}
@@ -191,13 +204,15 @@ AL_API ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, const ALint *v
if(!Context) return;
Device = Context->Device;
+ LockEffectList(Device);
if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
/* Call the appropriate handler */
- V(ALEffect,setParamiv)(Context, param, values);
+ ALeffect_setParamiv(ALEffect, Context, param, values);
}
+ UnlockEffectList(Device);
ALCcontext_DecRef(Context);
}
@@ -212,13 +227,15 @@ AL_API ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat value)
if(!Context) return;
Device = Context->Device;
+ LockEffectList(Device);
if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
/* Call the appropriate handler */
- V(ALEffect,setParamf)(Context, param, value);
+ ALeffect_setParamf(ALEffect, Context, param, value);
}
+ UnlockEffectList(Device);
ALCcontext_DecRef(Context);
}
@@ -233,13 +250,15 @@ AL_API ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, const ALfloat
if(!Context) return;
Device = Context->Device;
+ LockEffectList(Device);
if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
/* Call the appropriate handler */
- V(ALEffect,setParamfv)(Context, param, values);
+ ALeffect_setParamfv(ALEffect, Context, param, values);
}
+ UnlockEffectList(Device);
ALCcontext_DecRef(Context);
}
@@ -254,8 +273,9 @@ AL_API ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *value
if(!Context) return;
Device = Context->Device;
+ LockEffectList(Device);
if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
if(param == AL_EFFECT_TYPE)
@@ -263,9 +283,10 @@ AL_API ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *value
else
{
/* Call the appropriate handler */
- V(ALEffect,getParami)(Context, param, value);
+ ALeffect_getParami(ALEffect, Context, param, value);
}
}
+ UnlockEffectList(Device);
ALCcontext_DecRef(Context);
}
@@ -287,13 +308,15 @@ AL_API ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *valu
if(!Context) return;
Device = Context->Device;
+ LockEffectList(Device);
if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
/* Call the appropriate handler */
- V(ALEffect,getParamiv)(Context, param, values);
+ ALeffect_getParamiv(ALEffect, Context, param, values);
}
+ UnlockEffectList(Device);
ALCcontext_DecRef(Context);
}
@@ -308,13 +331,15 @@ AL_API ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *val
if(!Context) return;
Device = Context->Device;
+ LockEffectList(Device);
if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
/* Call the appropriate handler */
- V(ALEffect,getParamf)(Context, param, value);
+ ALeffect_getParamf(ALEffect, Context, param, value);
}
+ UnlockEffectList(Device);
ALCcontext_DecRef(Context);
}
@@ -329,37 +354,120 @@ AL_API ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *va
if(!Context) return;
Device = Context->Device;
+ LockEffectList(Device);
if((ALEffect=LookupEffect(Device, effect)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid effect ID %u", effect);
else
{
/* Call the appropriate handler */
- V(ALEffect,getParamfv)(Context, param, values);
+ ALeffect_getParamfv(ALEffect, Context, param, values);
}
+ UnlockEffectList(Device);
ALCcontext_DecRef(Context);
}
-ALenum InitEffect(ALeffect *effect)
+void InitEffect(ALeffect *effect)
{
InitEffectParams(effect, AL_EFFECT_NULL);
- return AL_NO_ERROR;
}
-ALvoid ReleaseALEffects(ALCdevice *device)
+static ALeffect *AllocEffect(ALCcontext *context)
{
- ALsizei i;
- for(i = 0;i < device->EffectMap.size;i++)
+ ALCdevice *device = context->Device;
+ EffectSubList *sublist, *subend;
+ ALeffect *effect = NULL;
+ ALsizei lidx = 0;
+ ALsizei slidx;
+
+ almtx_lock(&device->EffectLock);
+ sublist = VECTOR_BEGIN(device->EffectList);
+ subend = VECTOR_END(device->EffectList);
+ for(;sublist != subend;++sublist)
+ {
+ if(sublist->FreeMask)
+ {
+ slidx = CTZ64(sublist->FreeMask);
+ effect = sublist->Effects + slidx;
+ break;
+ }
+ ++lidx;
+ }
+ if(UNLIKELY(!effect))
+ {
+ const EffectSubList empty_sublist = { 0, NULL };
+ /* Don't allocate so many list entries that the 32-bit ID could
+ * overflow...
+ */
+ if(UNLIKELY(VECTOR_SIZE(device->EffectList) >= 1<<25))
+ {
+ almtx_unlock(&device->EffectLock);
+ alSetError(context, AL_OUT_OF_MEMORY, "Too many effects allocated");
+ return NULL;
+ }
+ lidx = (ALsizei)VECTOR_SIZE(device->EffectList);
+ VECTOR_PUSH_BACK(device->EffectList, empty_sublist);
+ sublist = &VECTOR_BACK(device->EffectList);
+ sublist->FreeMask = ~U64(0);
+ sublist->Effects = al_calloc(16, sizeof(ALeffect)*64);
+ if(UNLIKELY(!sublist->Effects))
+ {
+ VECTOR_POP_BACK(device->EffectList);
+ almtx_unlock(&device->EffectLock);
+ alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate effect batch");
+ return NULL;
+ }
+
+ slidx = 0;
+ effect = sublist->Effects + slidx;
+ }
+
+ memset(effect, 0, sizeof(*effect));
+ InitEffectParams(effect, AL_EFFECT_NULL);
+
+ /* Add 1 to avoid effect ID 0. */
+ effect->id = ((lidx<<6) | slidx) + 1;
+
+ sublist->FreeMask &= ~(U64(1)<<slidx);
+ almtx_unlock(&device->EffectLock);
+
+ return effect;
+}
+
+static void FreeEffect(ALCdevice *device, ALeffect *effect)
+{
+ ALuint id = effect->id - 1;
+ ALsizei lidx = id >> 6;
+ ALsizei slidx = id & 0x3f;
+
+ memset(effect, 0, sizeof(*effect));
+
+ VECTOR_ELEM(device->EffectList, lidx).FreeMask |= U64(1) << slidx;
+}
+
+void ReleaseALEffects(ALCdevice *device)
+{
+ EffectSubList *sublist = VECTOR_BEGIN(device->EffectList);
+ EffectSubList *subend = VECTOR_END(device->EffectList);
+ size_t leftover = 0;
+ for(;sublist != subend;++sublist)
{
- ALeffect *temp = device->EffectMap.array[i].value;
- device->EffectMap.array[i].value = NULL;
+ ALuint64 usemask = ~sublist->FreeMask;
+ while(usemask)
+ {
+ ALsizei idx = CTZ64(usemask);
+ ALeffect *effect = sublist->Effects + idx;
+
+ memset(effect, 0, sizeof(*effect));
+ ++leftover;
- // Release effect structure
- FreeThunkEntry(temp->id);
- memset(temp, 0, sizeof(ALeffect));
- free(temp);
+ usemask &= ~(U64(1) << idx);
+ }
+ sublist->FreeMask = ~usemask;
}
+ if(leftover > 0)
+ WARN("(%p) Deleted "SZFMT" Effect%s\n", device, leftover, (leftover==1)?"":"s");
}
@@ -395,7 +503,7 @@ static void InitEffectParams(ALeffect *effect, ALenum type)
effect->Props.Reverb.LFReference = AL_EAXREVERB_DEFAULT_LFREFERENCE;
effect->Props.Reverb.RoomRolloffFactor = AL_EAXREVERB_DEFAULT_ROOM_ROLLOFF_FACTOR;
effect->Props.Reverb.DecayHFLimit = AL_EAXREVERB_DEFAULT_DECAY_HFLIMIT;
- SET_VTABLE1(ALeaxreverb, effect);
+ effect->vtab = &ALeaxreverb_vtable;
break;
case AL_EFFECT_REVERB:
effect->Props.Reverb.Density = AL_REVERB_DEFAULT_DENSITY;
@@ -425,14 +533,14 @@ static void InitEffectParams(ALeffect *effect, ALenum type)
effect->Props.Reverb.LFReference = 250.0f;
effect->Props.Reverb.RoomRolloffFactor = AL_REVERB_DEFAULT_ROOM_ROLLOFF_FACTOR;
effect->Props.Reverb.DecayHFLimit = AL_REVERB_DEFAULT_DECAY_HFLIMIT;
- SET_VTABLE1(ALreverb, effect);
+ effect->vtab = &ALreverb_vtable;
break;
case AL_EFFECT_AUTOWAH:
effect->Props.Autowah.AttackTime = AL_AUTOWAH_DEFAULT_ATTACK_TIME;
- effect->Props.Autowah.PeakGain = AL_AUTOWAH_DEFAULT_PEAK_GAIN;
effect->Props.Autowah.ReleaseTime = AL_AUTOWAH_DEFAULT_RELEASE_TIME;
effect->Props.Autowah.Resonance = AL_AUTOWAH_DEFAULT_RESONANCE;
- SET_VTABLE1(ALautowah, effect);
+ effect->Props.Autowah.PeakGain = AL_AUTOWAH_DEFAULT_PEAK_GAIN;
+ effect->vtab = &ALautowah_vtable;
break;
case AL_EFFECT_CHORUS:
effect->Props.Chorus.Waveform = AL_CHORUS_DEFAULT_WAVEFORM;
@@ -441,11 +549,11 @@ static void InitEffectParams(ALeffect *effect, ALenum type)
effect->Props.Chorus.Depth = AL_CHORUS_DEFAULT_DEPTH;
effect->Props.Chorus.Feedback = AL_CHORUS_DEFAULT_FEEDBACK;
effect->Props.Chorus.Delay = AL_CHORUS_DEFAULT_DELAY;
- SET_VTABLE1(ALchorus, effect);
+ effect->vtab = &ALchorus_vtable;
break;
case AL_EFFECT_COMPRESSOR:
effect->Props.Compressor.OnOff = AL_COMPRESSOR_DEFAULT_ONOFF;
- SET_VTABLE1(ALcompressor, effect);
+ effect->vtab = &ALcompressor_vtable;
break;
case AL_EFFECT_DISTORTION:
effect->Props.Distortion.Edge = AL_DISTORTION_DEFAULT_EDGE;
@@ -453,7 +561,7 @@ static void InitEffectParams(ALeffect *effect, ALenum type)
effect->Props.Distortion.LowpassCutoff = AL_DISTORTION_DEFAULT_LOWPASS_CUTOFF;
effect->Props.Distortion.EQCenter = AL_DISTORTION_DEFAULT_EQCENTER;
effect->Props.Distortion.EQBandwidth = AL_DISTORTION_DEFAULT_EQBANDWIDTH;
- SET_VTABLE1(ALdistortion, effect);
+ effect->vtab = &ALdistortion_vtable;
break;
case AL_EFFECT_ECHO:
effect->Props.Echo.Delay = AL_ECHO_DEFAULT_DELAY;
@@ -461,7 +569,7 @@ static void InitEffectParams(ALeffect *effect, ALenum type)
effect->Props.Echo.Damping = AL_ECHO_DEFAULT_DAMPING;
effect->Props.Echo.Feedback = AL_ECHO_DEFAULT_FEEDBACK;
effect->Props.Echo.Spread = AL_ECHO_DEFAULT_SPREAD;
- SET_VTABLE1(ALecho, effect);
+ effect->vtab = &ALecho_vtable;
break;
case AL_EFFECT_EQUALIZER:
effect->Props.Equalizer.LowCutoff = AL_EQUALIZER_DEFAULT_LOW_CUTOFF;
@@ -474,30 +582,41 @@ static void InitEffectParams(ALeffect *effect, ALenum type)
effect->Props.Equalizer.Mid2Width = AL_EQUALIZER_DEFAULT_MID2_WIDTH;
effect->Props.Equalizer.HighCutoff = AL_EQUALIZER_DEFAULT_HIGH_CUTOFF;
effect->Props.Equalizer.HighGain = AL_EQUALIZER_DEFAULT_HIGH_GAIN;
- SET_VTABLE1(ALequalizer, effect);
+ effect->vtab = &ALequalizer_vtable;
break;
case AL_EFFECT_FLANGER:
- effect->Props.Flanger.Waveform = AL_FLANGER_DEFAULT_WAVEFORM;
- effect->Props.Flanger.Phase = AL_FLANGER_DEFAULT_PHASE;
- effect->Props.Flanger.Rate = AL_FLANGER_DEFAULT_RATE;
- effect->Props.Flanger.Depth = AL_FLANGER_DEFAULT_DEPTH;
- effect->Props.Flanger.Feedback = AL_FLANGER_DEFAULT_FEEDBACK;
- effect->Props.Flanger.Delay = AL_FLANGER_DEFAULT_DELAY;
- SET_VTABLE1(ALflanger, effect);
+ effect->Props.Chorus.Waveform = AL_FLANGER_DEFAULT_WAVEFORM;
+ effect->Props.Chorus.Phase = AL_FLANGER_DEFAULT_PHASE;
+ effect->Props.Chorus.Rate = AL_FLANGER_DEFAULT_RATE;
+ effect->Props.Chorus.Depth = AL_FLANGER_DEFAULT_DEPTH;
+ effect->Props.Chorus.Feedback = AL_FLANGER_DEFAULT_FEEDBACK;
+ effect->Props.Chorus.Delay = AL_FLANGER_DEFAULT_DELAY;
+ effect->vtab = &ALflanger_vtable;
+ break;
+ case AL_EFFECT_FREQUENCY_SHIFTER:
+ effect->Props.Fshifter.Frequency = AL_FREQUENCY_SHIFTER_DEFAULT_FREQUENCY;
+ effect->Props.Fshifter.LeftDirection = AL_FREQUENCY_SHIFTER_DEFAULT_LEFT_DIRECTION;
+ effect->Props.Fshifter.RightDirection = AL_FREQUENCY_SHIFTER_DEFAULT_RIGHT_DIRECTION;
+ effect->vtab = &ALfshifter_vtable;
break;
case AL_EFFECT_RING_MODULATOR:
effect->Props.Modulator.Frequency = AL_RING_MODULATOR_DEFAULT_FREQUENCY;
effect->Props.Modulator.HighPassCutoff = AL_RING_MODULATOR_DEFAULT_HIGHPASS_CUTOFF;
effect->Props.Modulator.Waveform = AL_RING_MODULATOR_DEFAULT_WAVEFORM;
- SET_VTABLE1(ALmodulator, effect);
+ effect->vtab = &ALmodulator_vtable;
+ break;
+ case AL_EFFECT_PITCH_SHIFTER:
+ effect->Props.Pshifter.CoarseTune = AL_PITCH_SHIFTER_DEFAULT_COARSE_TUNE;
+ effect->Props.Pshifter.FineTune = AL_PITCH_SHIFTER_DEFAULT_FINE_TUNE;
+ effect->vtab = &ALpshifter_vtable;
break;
case AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT:
case AL_EFFECT_DEDICATED_DIALOGUE:
effect->Props.Dedicated.Gain = 1.0f;
- SET_VTABLE1(ALdedicated, effect);
+ effect->vtab = &ALdedicated_vtable;
break;
default:
- SET_VTABLE1(ALnull, effect);
+ effect->vtab = &ALnull_vtable;
break;
}
effect->type = type;
@@ -640,7 +759,7 @@ static const struct {
};
#undef DECL
-ALvoid LoadReverbPreset(const char *name, ALeffect *effect)
+void LoadReverbPreset(const char *name, ALeffect *effect)
{
size_t i;
@@ -651,9 +770,9 @@ ALvoid LoadReverbPreset(const char *name, ALeffect *effect)
return;
}
- if(!DisabledEffects[EAXREVERB])
+ if(!DisabledEffects[EAXREVERB_EFFECT])
InitEffectParams(effect, AL_EFFECT_EAXREVERB);
- else if(!DisabledEffects[REVERB])
+ else if(!DisabledEffects[REVERB_EFFECT])
InitEffectParams(effect, AL_EFFECT_REVERB);
else
InitEffectParams(effect, AL_EFFECT_NULL);
diff --git a/OpenAL32/alError.c b/OpenAL32/alError.c
index b38d8dfe..b6208f77 100644
--- a/OpenAL32/alError.c
+++ b/OpenAL32/alError.c
@@ -21,6 +21,7 @@
#include "config.h"
#include <signal.h>
+#include <stdarg.h>
#ifdef HAVE_WINDOWS_H
#define WIN32_LEAN_AND_MEAN
@@ -33,9 +34,32 @@
ALboolean TrapALError = AL_FALSE;
-ALvoid alSetError(ALCcontext *Context, ALenum errorCode)
+void alSetError(ALCcontext *context, ALenum errorCode, const char *msg, ...)
{
ALenum curerr = AL_NO_ERROR;
+ char message[1024] = { 0 };
+ va_list args;
+ int msglen;
+
+ va_start(args, msg);
+ msglen = vsnprintf(message, sizeof(message), msg, args);
+ va_end(args);
+
+ if(msglen < 0 || (size_t)msglen >= sizeof(message))
+ {
+ message[sizeof(message)-1] = 0;
+ msglen = (int)strlen(message);
+ }
+ if(msglen > 0)
+ msg = message;
+ else
+ {
+ msg = "<internal error constructing message>";
+ msglen = (int)strlen(msg);
+ }
+
+ WARN("Error generated on context %p, code 0x%04x, \"%s\"\n",
+ context, errorCode, message);
if(TrapALError)
{
#ifdef _WIN32
@@ -46,17 +70,30 @@ ALvoid alSetError(ALCcontext *Context, ALenum errorCode)
raise(SIGTRAP);
#endif
}
- ATOMIC_COMPARE_EXCHANGE_STRONG(ALenum, &Context->LastError, &curerr, errorCode);
+
+ ATOMIC_COMPARE_EXCHANGE_STRONG_SEQ(&context->LastError, &curerr, errorCode);
+ if((ATOMIC_LOAD(&context->EnabledEvts, almemory_order_relaxed)&EventType_Error))
+ {
+ ALbitfieldSOFT enabledevts;
+ almtx_lock(&context->EventCbLock);
+ enabledevts = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_relaxed);
+ if((enabledevts&EventType_Error) && context->EventCb)
+ (*context->EventCb)(AL_EVENT_TYPE_ERROR_SOFT, 0, errorCode, msglen, msg,
+ context->EventParam);
+ almtx_unlock(&context->EventCbLock);
+ }
}
AL_API ALenum AL_APIENTRY alGetError(void)
{
- ALCcontext *Context;
+ ALCcontext *context;
ALenum errorCode;
- Context = GetContextRef();
- if(!Context)
+ context = GetContextRef();
+ if(!context)
{
+ const ALenum deferror = AL_INVALID_OPERATION;
+ WARN("Querying error state on null context (implicitly 0x%04x)\n", deferror);
if(TrapALError)
{
#ifdef _WIN32
@@ -66,12 +103,11 @@ AL_API ALenum AL_APIENTRY alGetError(void)
raise(SIGTRAP);
#endif
}
- return AL_INVALID_OPERATION;
+ return deferror;
}
- errorCode = ATOMIC_EXCHANGE(ALenum, &Context->LastError, AL_NO_ERROR);
-
- ALCcontext_DecRef(Context);
+ errorCode = ATOMIC_EXCHANGE_SEQ(&context->LastError, AL_NO_ERROR);
+ ALCcontext_DecRef(context);
return errorCode;
}
diff --git a/OpenAL32/alExtension.c b/OpenAL32/alExtension.c
index 609cc969..f6378c70 100644
--- a/OpenAL32/alExtension.c
+++ b/OpenAL32/alExtension.c
@@ -35,25 +35,6 @@
#include "AL/alc.h"
-const struct EffectList EffectList[] = {
- { "eaxreverb", EAXREVERB, "AL_EFFECT_EAXREVERB", AL_EFFECT_EAXREVERB },
- { "reverb", REVERB, "AL_EFFECT_REVERB", AL_EFFECT_REVERB },
-#if 0
- { "autowah", AUTOWAH, "AL_EFFECT_AUTOWAH", AL_EFFECT_AUTOWAH },
-#endif
- { "chorus", CHORUS, "AL_EFFECT_CHORUS", AL_EFFECT_CHORUS },
- { "compressor", COMPRESSOR, "AL_EFFECT_COMPRESSOR", AL_EFFECT_COMPRESSOR },
- { "distortion", DISTORTION, "AL_EFFECT_DISTORTION", AL_EFFECT_DISTORTION },
- { "echo", ECHO, "AL_EFFECT_ECHO", AL_EFFECT_ECHO },
- { "equalizer", EQUALIZER, "AL_EFFECT_EQUALIZER", AL_EFFECT_EQUALIZER },
- { "flanger", FLANGER, "AL_EFFECT_FLANGER", AL_EFFECT_FLANGER },
- { "modulator", MODULATOR, "AL_EFFECT_RING_MODULATOR", AL_EFFECT_RING_MODULATOR },
- { "dedicated", DEDICATED, "AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT", AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT },
- { "dedicated", DEDICATED, "AL_EFFECT_DEDICATED_DIALOGUE", AL_EFFECT_DEDICATED_DIALOGUE },
- { NULL, 0, NULL, (ALenum)0 }
-};
-
-
AL_API ALboolean AL_APIENTRY alIsExtensionPresent(const ALchar *extName)
{
ALboolean ret = AL_FALSE;
@@ -64,8 +45,8 @@ AL_API ALboolean AL_APIENTRY alIsExtensionPresent(const ALchar *extName)
context = GetContextRef();
if(!context) return AL_FALSE;
- if(!(extName))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ if(!extName)
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "NULL pointer");
len = strlen(extName);
ptr = context->ExtensionList;
diff --git a/OpenAL32/alFilter.c b/OpenAL32/alFilter.c
index 3cf82c32..e57653e0 100644
--- a/OpenAL32/alFilter.c
+++ b/OpenAL32/alFilter.c
@@ -25,60 +25,56 @@
#include "alMain.h"
#include "alu.h"
#include "alFilter.h"
-#include "alThunk.h"
#include "alError.h"
-extern inline struct ALfilter *LookupFilter(ALCdevice *device, ALuint id);
-extern inline struct ALfilter *RemoveFilter(ALCdevice *device, ALuint id);
-extern inline ALfloat ALfilterState_processSingle(ALfilterState *filter, ALfloat sample);
-extern inline ALfloat calc_rcpQ_from_slope(ALfloat gain, ALfloat slope);
-extern inline ALfloat calc_rcpQ_from_bandwidth(ALfloat freq_mult, ALfloat bandwidth);
+#define FILTER_MIN_GAIN 0.0f
+#define FILTER_MAX_GAIN 4.0f /* +12dB */
+extern inline void LockFilterList(ALCdevice *device);
+extern inline void UnlockFilterList(ALCdevice *device);
+
+static ALfilter *AllocFilter(ALCcontext *context);
+static void FreeFilter(ALCdevice *device, ALfilter *filter);
static void InitFilterParams(ALfilter *filter, ALenum type);
+static inline ALfilter *LookupFilter(ALCdevice *device, ALuint id)
+{
+ FilterSubList *sublist;
+ ALuint lidx = (id-1) >> 6;
+ ALsizei slidx = (id-1) & 0x3f;
+
+ if(UNLIKELY(lidx >= VECTOR_SIZE(device->FilterList)))
+ return NULL;
+ sublist = &VECTOR_ELEM(device->FilterList, lidx);
+ if(UNLIKELY(sublist->FreeMask & (U64(1)<<slidx)))
+ return NULL;
+ return sublist->Filters + slidx;
+}
+
AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
{
- ALCdevice *device;
ALCcontext *context;
ALsizei cur = 0;
- ALenum err;
context = GetContextRef();
if(!context) return;
if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- device = context->Device;
- for(cur = 0;cur < n;cur++)
+ alSetError(context, AL_INVALID_VALUE, "Generating %d filters", n);
+ else for(cur = 0;cur < n;cur++)
{
- ALfilter *filter = calloc(1, sizeof(ALfilter));
+ ALfilter *filter = AllocFilter(context);
if(!filter)
{
alDeleteFilters(cur, filters);
- SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done);
- }
- InitFilterParams(filter, AL_FILTER_NULL);
-
- err = NewThunkEntry(&filter->id);
- if(err == AL_NO_ERROR)
- err = InsertUIntMapEntry(&device->FilterMap, filter->id, filter);
- if(err != AL_NO_ERROR)
- {
- FreeThunkEntry(filter->id);
- memset(filter, 0, sizeof(ALfilter));
- free(filter);
-
- alDeleteFilters(cur, filters);
- SET_ERROR_AND_GOTO(context, err, done);
+ break;
}
filters[cur] = filter->id;
}
-done:
ALCcontext_DecRef(context);
}
@@ -92,26 +88,23 @@ AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, const ALuint *filters)
context = GetContextRef();
if(!context) return;
- if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
device = context->Device;
+ LockFilterList(device);
+ if(!(n >= 0))
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Deleting %d filters", n);
for(i = 0;i < n;i++)
{
if(filters[i] && LookupFilter(device, filters[i]) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid filter ID %u", filters[i]);
}
for(i = 0;i < n;i++)
{
- if((filter=RemoveFilter(device, filters[i])) == NULL)
- continue;
- FreeThunkEntry(filter->id);
-
- memset(filter, 0, sizeof(*filter));
- free(filter);
+ if((filter=LookupFilter(device, filters[i])) != NULL)
+ FreeFilter(device, filter);
}
done:
+ UnlockFilterList(device);
ALCcontext_DecRef(context);
}
@@ -123,8 +116,10 @@ AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter)
Context = GetContextRef();
if(!Context) return AL_FALSE;
+ LockFilterList(Context->Device);
result = ((!filter || LookupFilter(Context->Device, filter)) ?
AL_TRUE : AL_FALSE);
+ UnlockFilterList(Context->Device);
ALCcontext_DecRef(Context);
@@ -141,8 +136,9 @@ AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint value)
if(!Context) return;
Device = Context->Device;
+ LockFilterList(Device);
if((ALFilter=LookupFilter(Device, filter)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid filter ID %u", filter);
else
{
if(param == AL_FILTER_TYPE)
@@ -151,14 +147,15 @@ AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint value)
value == AL_FILTER_HIGHPASS || value == AL_FILTER_BANDPASS)
InitFilterParams(ALFilter, value);
else
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "Invalid filter type 0x%04x", value);
}
else
{
/* Call the appropriate handler */
- ALfilter_SetParami(ALFilter, Context, param, value);
+ ALfilter_setParami(ALFilter, Context, param, value);
}
}
+ UnlockFilterList(Device);
ALCcontext_DecRef(Context);
}
@@ -180,13 +177,15 @@ AL_API ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, const ALint *v
if(!Context) return;
Device = Context->Device;
+ LockFilterList(Device);
if((ALFilter=LookupFilter(Device, filter)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid filter ID %u", filter);
else
{
/* Call the appropriate handler */
- ALfilter_SetParamiv(ALFilter, Context, param, values);
+ ALfilter_setParamiv(ALFilter, Context, param, values);
}
+ UnlockFilterList(Device);
ALCcontext_DecRef(Context);
}
@@ -201,13 +200,15 @@ AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat value)
if(!Context) return;
Device = Context->Device;
+ LockFilterList(Device);
if((ALFilter=LookupFilter(Device, filter)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid filter ID %u", filter);
else
{
/* Call the appropriate handler */
- ALfilter_SetParamf(ALFilter, Context, param, value);
+ ALfilter_setParamf(ALFilter, Context, param, value);
}
+ UnlockFilterList(Device);
ALCcontext_DecRef(Context);
}
@@ -222,13 +223,15 @@ AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, const ALfloat
if(!Context) return;
Device = Context->Device;
+ LockFilterList(Device);
if((ALFilter=LookupFilter(Device, filter)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid filter ID %u", filter);
else
{
/* Call the appropriate handler */
- ALfilter_SetParamfv(ALFilter, Context, param, values);
+ ALfilter_setParamfv(ALFilter, Context, param, values);
}
+ UnlockFilterList(Device);
ALCcontext_DecRef(Context);
}
@@ -243,8 +246,9 @@ AL_API ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *value
if(!Context) return;
Device = Context->Device;
+ LockFilterList(Device);
if((ALFilter=LookupFilter(Device, filter)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid filter ID %u", filter);
else
{
if(param == AL_FILTER_TYPE)
@@ -252,9 +256,10 @@ AL_API ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *value
else
{
/* Call the appropriate handler */
- ALfilter_GetParami(ALFilter, Context, param, value);
+ ALfilter_getParami(ALFilter, Context, param, value);
}
}
+ UnlockFilterList(Device);
ALCcontext_DecRef(Context);
}
@@ -276,13 +281,15 @@ AL_API ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *valu
if(!Context) return;
Device = Context->Device;
+ LockFilterList(Device);
if((ALFilter=LookupFilter(Device, filter)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid filter ID %u", filter);
else
{
/* Call the appropriate handler */
- ALfilter_GetParamiv(ALFilter, Context, param, values);
+ ALfilter_getParamiv(ALFilter, Context, param, values);
}
+ UnlockFilterList(Device);
ALCcontext_DecRef(Context);
}
@@ -297,13 +304,15 @@ AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *val
if(!Context) return;
Device = Context->Device;
+ LockFilterList(Device);
if((ALFilter=LookupFilter(Device, filter)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid filter ID %u", filter);
else
{
/* Call the appropriate handler */
- ALfilter_GetParamf(ALFilter, Context, param, value);
+ ALfilter_getParamf(ALFilter, Context, param, value);
}
+ UnlockFilterList(Device);
ALCcontext_DecRef(Context);
}
@@ -318,159 +327,52 @@ AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *va
if(!Context) return;
Device = Context->Device;
+ LockFilterList(Device);
if((ALFilter=LookupFilter(Device, filter)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid filter ID %u", filter);
else
{
/* Call the appropriate handler */
- ALfilter_GetParamfv(ALFilter, Context, param, values);
+ ALfilter_getParamfv(ALFilter, Context, param, values);
}
+ UnlockFilterList(Device);
ALCcontext_DecRef(Context);
}
-void ALfilterState_clear(ALfilterState *filter)
-{
- filter->x[0] = 0.0f;
- filter->x[1] = 0.0f;
- filter->y[0] = 0.0f;
- filter->y[1] = 0.0f;
-}
-
-void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat gain, ALfloat freq_mult, ALfloat rcpQ)
-{
- ALfloat alpha, sqrtgain_alpha_2;
- ALfloat w0, sin_w0, cos_w0;
-
- // Limit gain to -100dB
- gain = maxf(gain, 0.00001f);
-
- w0 = F_TAU * freq_mult;
- sin_w0 = sinf(w0);
- cos_w0 = cosf(w0);
- alpha = sin_w0/2.0f * rcpQ;
-
- /* Calculate filter coefficients depending on filter type */
- switch(type)
- {
- case ALfilterType_HighShelf:
- sqrtgain_alpha_2 = 2.0f * sqrtf(gain) * alpha;
- filter->b[0] = gain*((gain+1.0f) + (gain-1.0f)*cos_w0 + sqrtgain_alpha_2);
- filter->b[1] = -2.0f*gain*((gain-1.0f) + (gain+1.0f)*cos_w0 );
- filter->b[2] = gain*((gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2);
- filter->a[0] = (gain+1.0f) - (gain-1.0f)*cos_w0 + sqrtgain_alpha_2;
- filter->a[1] = 2.0f* ((gain-1.0f) - (gain+1.0f)*cos_w0 );
- filter->a[2] = (gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2;
- break;
- case ALfilterType_LowShelf:
- sqrtgain_alpha_2 = 2.0f * sqrtf(gain) * alpha;
- filter->b[0] = gain*((gain+1.0f) - (gain-1.0f)*cos_w0 + sqrtgain_alpha_2);
- filter->b[1] = 2.0f*gain*((gain-1.0f) - (gain+1.0f)*cos_w0 );
- filter->b[2] = gain*((gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2);
- filter->a[0] = (gain+1.0f) + (gain-1.0f)*cos_w0 + sqrtgain_alpha_2;
- filter->a[1] = -2.0f* ((gain-1.0f) + (gain+1.0f)*cos_w0 );
- filter->a[2] = (gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2;
- break;
- case ALfilterType_Peaking:
- gain = sqrtf(gain);
- filter->b[0] = 1.0f + alpha * gain;
- filter->b[1] = -2.0f * cos_w0;
- filter->b[2] = 1.0f - alpha * gain;
- filter->a[0] = 1.0f + alpha / gain;
- filter->a[1] = -2.0f * cos_w0;
- filter->a[2] = 1.0f - alpha / gain;
- break;
-
- case ALfilterType_LowPass:
- filter->b[0] = (1.0f - cos_w0) / 2.0f;
- filter->b[1] = 1.0f - cos_w0;
- filter->b[2] = (1.0f - cos_w0) / 2.0f;
- filter->a[0] = 1.0f + alpha;
- filter->a[1] = -2.0f * cos_w0;
- filter->a[2] = 1.0f - alpha;
- break;
- case ALfilterType_HighPass:
- filter->b[0] = (1.0f + cos_w0) / 2.0f;
- filter->b[1] = -(1.0f + cos_w0);
- filter->b[2] = (1.0f + cos_w0) / 2.0f;
- filter->a[0] = 1.0f + alpha;
- filter->a[1] = -2.0f * cos_w0;
- filter->a[2] = 1.0f - alpha;
- break;
- case ALfilterType_BandPass:
- filter->b[0] = alpha;
- filter->b[1] = 0;
- filter->b[2] = -alpha;
- filter->a[0] = 1.0f + alpha;
- filter->a[1] = -2.0f * cos_w0;
- filter->a[2] = 1.0f - alpha;
- break;
- }
-
- filter->b[2] /= filter->a[0];
- filter->b[1] /= filter->a[0];
- filter->b[0] /= filter->a[0];
- filter->a[2] /= filter->a[0];
- filter->a[1] /= filter->a[0];
- filter->a[0] /= filter->a[0];
-
- filter->process = ALfilterState_processC;
-}
-
-void ALfilterState_processPassthru(ALfilterState *filter, const ALfloat *src, ALuint numsamples)
-{
- if(numsamples >= 2)
- {
- filter->x[1] = src[numsamples-2];
- filter->x[0] = src[numsamples-1];
- filter->y[1] = src[numsamples-2];
- filter->y[0] = src[numsamples-1];
- }
- else if(numsamples == 1)
- {
- filter->x[1] = filter->x[0];
- filter->x[0] = src[0];
- filter->y[1] = filter->y[0];
- filter->y[0] = src[0];
- }
-}
-
-
-static void lp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void lp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void lp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
+static void ALlowpass_setParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALint UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid low-pass integer property 0x%04x", param); }
+static void ALlowpass_setParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, const ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid low-pass integer-vector property 0x%04x", param); }
+static void ALlowpass_setParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
{
switch(param)
{
case AL_LOWPASS_GAIN:
- if(!(val >= AL_LOWPASS_MIN_GAIN && val <= AL_LOWPASS_MAX_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ if(!(val >= FILTER_MIN_GAIN && val <= FILTER_MAX_GAIN))
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Low-pass gain %f out of range", val);
filter->Gain = val;
break;
case AL_LOWPASS_GAINHF:
if(!(val >= AL_LOWPASS_MIN_GAINHF && val <= AL_LOWPASS_MAX_GAINHF))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Low-pass gainhf %f out of range", val);
filter->GainHF = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid low-pass float property 0x%04x", param);
}
}
-static void lp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
-{
- lp_SetParamf(filter, context, param, vals[0]);
-}
-
-static void lp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void lp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void lp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
+static void ALlowpass_setParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
+{ ALlowpass_setParamf(filter, context, param, vals[0]); }
+
+static void ALlowpass_getParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALint *UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid low-pass integer property 0x%04x", param); }
+static void ALlowpass_getParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid low-pass integer-vector property 0x%04x", param); }
+static void ALlowpass_getParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
{
switch(param)
{
@@ -483,49 +385,47 @@ static void lp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, AL
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid low-pass float property 0x%04x", param);
}
}
-static void lp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
-{
- lp_GetParamf(filter, context, param, vals);
-}
+static void ALlowpass_getParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
+{ ALlowpass_getParamf(filter, context, param, vals); }
+DEFINE_ALFILTER_VTABLE(ALlowpass);
-static void hp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void hp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void hp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
+
+static void ALhighpass_setParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALint UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid high-pass integer property 0x%04x", param); }
+static void ALhighpass_setParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, const ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid high-pass integer-vector property 0x%04x", param); }
+static void ALhighpass_setParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
{
switch(param)
{
case AL_HIGHPASS_GAIN:
- if(!(val >= AL_HIGHPASS_MIN_GAIN && val <= AL_HIGHPASS_MAX_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ if(!(val >= FILTER_MIN_GAIN && val <= FILTER_MAX_GAIN))
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "High-pass gain out of range");
filter->Gain = val;
break;
case AL_HIGHPASS_GAINLF:
if(!(val >= AL_HIGHPASS_MIN_GAINLF && val <= AL_HIGHPASS_MAX_GAINLF))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "High-pass gainlf out of range");
filter->GainLF = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid high-pass float property 0x%04x", param);
}
}
-static void hp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
-{
- hp_SetParamf(filter, context, param, vals[0]);
-}
-
-static void hp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void hp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void hp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
+static void ALhighpass_setParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
+{ ALhighpass_setParamf(filter, context, param, vals[0]); }
+
+static void ALhighpass_getParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALint *UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid high-pass integer property 0x%04x", param); }
+static void ALhighpass_getParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid high-pass integer-vector property 0x%04x", param); }
+static void ALhighpass_getParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
{
switch(param)
{
@@ -538,55 +438,53 @@ static void hp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, AL
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid high-pass float property 0x%04x", param);
}
}
-static void hp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
-{
- hp_GetParamf(filter, context, param, vals);
-}
+static void ALhighpass_getParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
+{ ALhighpass_getParamf(filter, context, param, vals); }
+DEFINE_ALFILTER_VTABLE(ALhighpass);
-static void bp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void bp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void bp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
+
+static void ALbandpass_setParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALint UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid band-pass integer property 0x%04x", param); }
+static void ALbandpass_setParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, const ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid band-pass integer-vector property 0x%04x", param); }
+static void ALbandpass_setParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
{
switch(param)
{
case AL_BANDPASS_GAIN:
- if(!(val >= AL_BANDPASS_MIN_GAIN && val <= AL_BANDPASS_MAX_GAIN))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ if(!(val >= FILTER_MIN_GAIN && val <= FILTER_MAX_GAIN))
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Band-pass gain out of range");
filter->Gain = val;
break;
case AL_BANDPASS_GAINHF:
if(!(val >= AL_BANDPASS_MIN_GAINHF && val <= AL_BANDPASS_MAX_GAINHF))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Band-pass gainhf out of range");
filter->GainHF = val;
break;
case AL_BANDPASS_GAINLF:
if(!(val >= AL_BANDPASS_MIN_GAINLF && val <= AL_BANDPASS_MAX_GAINLF))
- SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
+ SETERR_RETURN(context, AL_INVALID_VALUE,, "Band-pass gainlf out of range");
filter->GainLF = val;
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid band-pass float property 0x%04x", param);
}
}
-static void bp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
-{
- bp_SetParamf(filter, context, param, vals[0]);
-}
-
-static void bp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void bp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void bp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
+static void ALbandpass_setParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
+{ ALbandpass_setParamf(filter, context, param, vals[0]); }
+
+static void ALbandpass_getParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALint *UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid band-pass integer property 0x%04x", param); }
+static void ALbandpass_getParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid band-pass integer-vector property 0x%04x", param); }
+static void ALbandpass_getParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
{
switch(param)
{
@@ -603,47 +501,131 @@ static void bp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, AL
break;
default:
- SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
+ alSetError(context, AL_INVALID_ENUM, "Invalid band-pass float property 0x%04x", param);
}
}
-static void bp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
+static void ALbandpass_getParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
+{ ALbandpass_getParamf(filter, context, param, vals); }
+
+DEFINE_ALFILTER_VTABLE(ALbandpass);
+
+
+static void ALnullfilter_setParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALint UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); }
+static void ALnullfilter_setParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, const ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); }
+static void ALnullfilter_setParamf(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALfloat UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); }
+static void ALnullfilter_setParamfv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, const ALfloat *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); }
+
+static void ALnullfilter_getParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALint *UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); }
+static void ALnullfilter_getParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALint *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); }
+static void ALnullfilter_getParamf(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALfloat *UNUSED(val))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); }
+static void ALnullfilter_getParamfv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum param, ALfloat *UNUSED(vals))
+{ alSetError(context, AL_INVALID_ENUM, "Invalid null filter property 0x%04x", param); }
+
+DEFINE_ALFILTER_VTABLE(ALnullfilter);
+
+
+static ALfilter *AllocFilter(ALCcontext *context)
{
- bp_GetParamf(filter, context, param, vals);
-}
+ ALCdevice *device = context->Device;
+ FilterSubList *sublist, *subend;
+ ALfilter *filter = NULL;
+ ALsizei lidx = 0;
+ ALsizei slidx;
+
+ almtx_lock(&device->FilterLock);
+ sublist = VECTOR_BEGIN(device->FilterList);
+ subend = VECTOR_END(device->FilterList);
+ for(;sublist != subend;++sublist)
+ {
+ if(sublist->FreeMask)
+ {
+ slidx = CTZ64(sublist->FreeMask);
+ filter = sublist->Filters + slidx;
+ break;
+ }
+ ++lidx;
+ }
+ if(UNLIKELY(!filter))
+ {
+ const FilterSubList empty_sublist = { 0, NULL };
+ /* Don't allocate so many list entries that the 32-bit ID could
+ * overflow...
+ */
+ if(UNLIKELY(VECTOR_SIZE(device->FilterList) >= 1<<25))
+ {
+ almtx_unlock(&device->FilterLock);
+ alSetError(context, AL_OUT_OF_MEMORY, "Too many filters allocated");
+ return NULL;
+ }
+ lidx = (ALsizei)VECTOR_SIZE(device->FilterList);
+ VECTOR_PUSH_BACK(device->FilterList, empty_sublist);
+ sublist = &VECTOR_BACK(device->FilterList);
+ sublist->FreeMask = ~U64(0);
+ sublist->Filters = al_calloc(16, sizeof(ALfilter)*64);
+ if(UNLIKELY(!sublist->Filters))
+ {
+ VECTOR_POP_BACK(device->FilterList);
+ almtx_unlock(&device->FilterLock);
+ alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate filter batch");
+ return NULL;
+ }
+
+ slidx = 0;
+ filter = sublist->Filters + slidx;
+ }
+ memset(filter, 0, sizeof(*filter));
+ InitFilterParams(filter, AL_FILTER_NULL);
-static void null_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void null_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void null_SetParamf(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void null_SetParamfv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALfloat *UNUSED(vals))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
+ /* Add 1 to avoid filter ID 0. */
+ filter->id = ((lidx<<6) | slidx) + 1;
-static void null_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void null_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void null_GetParamf(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat *UNUSED(val))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
-static void null_GetParamfv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat *UNUSED(vals))
-{ SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
+ sublist->FreeMask &= ~(U64(1)<<slidx);
+ almtx_unlock(&device->FilterLock);
+ return filter;
+}
-ALvoid ReleaseALFilters(ALCdevice *device)
+static void FreeFilter(ALCdevice *device, ALfilter *filter)
{
- ALsizei i;
- for(i = 0;i < device->FilterMap.size;i++)
+ ALuint id = filter->id - 1;
+ ALsizei lidx = id >> 6;
+ ALsizei slidx = id & 0x3f;
+
+ memset(filter, 0, sizeof(*filter));
+
+ VECTOR_ELEM(device->FilterList, lidx).FreeMask |= U64(1) << slidx;
+}
+
+void ReleaseALFilters(ALCdevice *device)
+{
+ FilterSubList *sublist = VECTOR_BEGIN(device->FilterList);
+ FilterSubList *subend = VECTOR_END(device->FilterList);
+ size_t leftover = 0;
+ for(;sublist != subend;++sublist)
{
- ALfilter *temp = device->FilterMap.array[i].value;
- device->FilterMap.array[i].value = NULL;
+ ALuint64 usemask = ~sublist->FreeMask;
+ while(usemask)
+ {
+ ALsizei idx = CTZ64(usemask);
+ ALfilter *filter = sublist->Filters + idx;
+
+ memset(filter, 0, sizeof(*filter));
+ ++leftover;
- // Release filter structure
- FreeThunkEntry(temp->id);
- memset(temp, 0, sizeof(ALfilter));
- free(temp);
+ usemask &= ~(U64(1) << idx);
+ }
+ sublist->FreeMask = ~usemask;
}
+ if(leftover > 0)
+ WARN("(%p) Deleted "SZFMT" Filter%s\n", device, leftover, (leftover==1)?"":"s");
}
@@ -656,15 +638,7 @@ static void InitFilterParams(ALfilter *filter, ALenum type)
filter->HFReference = LOWPASSFREQREF;
filter->GainLF = 1.0f;
filter->LFReference = HIGHPASSFREQREF;
-
- filter->SetParami = lp_SetParami;
- filter->SetParamiv = lp_SetParamiv;
- filter->SetParamf = lp_SetParamf;
- filter->SetParamfv = lp_SetParamfv;
- filter->GetParami = lp_GetParami;
- filter->GetParamiv = lp_GetParamiv;
- filter->GetParamf = lp_GetParamf;
- filter->GetParamfv = lp_GetParamfv;
+ filter->vtab = &ALlowpass_vtable;
}
else if(type == AL_FILTER_HIGHPASS)
{
@@ -673,15 +647,7 @@ static void InitFilterParams(ALfilter *filter, ALenum type)
filter->HFReference = LOWPASSFREQREF;
filter->GainLF = AL_HIGHPASS_DEFAULT_GAINLF;
filter->LFReference = HIGHPASSFREQREF;
-
- filter->SetParami = hp_SetParami;
- filter->SetParamiv = hp_SetParamiv;
- filter->SetParamf = hp_SetParamf;
- filter->SetParamfv = hp_SetParamfv;
- filter->GetParami = hp_GetParami;
- filter->GetParamiv = hp_GetParamiv;
- filter->GetParamf = hp_GetParamf;
- filter->GetParamfv = hp_GetParamfv;
+ filter->vtab = &ALhighpass_vtable;
}
else if(type == AL_FILTER_BANDPASS)
{
@@ -690,15 +656,7 @@ static void InitFilterParams(ALfilter *filter, ALenum type)
filter->HFReference = LOWPASSFREQREF;
filter->GainLF = AL_BANDPASS_DEFAULT_GAINLF;
filter->LFReference = HIGHPASSFREQREF;
-
- filter->SetParami = bp_SetParami;
- filter->SetParamiv = bp_SetParamiv;
- filter->SetParamf = bp_SetParamf;
- filter->SetParamfv = bp_SetParamfv;
- filter->GetParami = bp_GetParami;
- filter->GetParamiv = bp_GetParamiv;
- filter->GetParamf = bp_GetParamf;
- filter->GetParamfv = bp_GetParamfv;
+ filter->vtab = &ALbandpass_vtable;
}
else
{
@@ -707,15 +665,7 @@ static void InitFilterParams(ALfilter *filter, ALenum type)
filter->HFReference = LOWPASSFREQREF;
filter->GainLF = 1.0f;
filter->LFReference = HIGHPASSFREQREF;
-
- filter->SetParami = null_SetParami;
- filter->SetParamiv = null_SetParamiv;
- filter->SetParamf = null_SetParamf;
- filter->SetParamfv = null_SetParamfv;
- filter->GetParami = null_GetParami;
- filter->GetParamiv = null_GetParamiv;
- filter->GetParamf = null_GetParamf;
- filter->GetParamfv = null_GetParamfv;
+ filter->vtab = &ALnullfilter_vtable;
}
filter->type = type;
}
diff --git a/OpenAL32/alListener.c b/OpenAL32/alListener.c
index 66865473..f1ac3ff4 100644
--- a/OpenAL32/alListener.c
+++ b/OpenAL32/alListener.c
@@ -21,85 +21,101 @@
#include "config.h"
#include "alMain.h"
-#include "AL/alc.h"
+#include "alu.h"
#include "alError.h"
#include "alListener.h"
#include "alSource.h"
+#define DO_UPDATEPROPS() do { \
+ if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) \
+ UpdateListenerProps(context); \
+ else \
+ ATOMIC_FLAG_CLEAR(&listener->PropsClean, almemory_order_release); \
+} while(0)
+
+
AL_API ALvoid AL_APIENTRY alListenerf(ALenum param, ALfloat value)
{
+ ALlistener *listener;
ALCcontext *context;
context = GetContextRef();
if(!context) return;
+ listener = context->Listener;
+ almtx_lock(&context->PropLock);
switch(param)
{
case AL_GAIN:
if(!(value >= 0.0f && isfinite(value)))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- context->Listener->Gain = value;
- ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Listener gain out of range");
+ listener->Gain = value;
+ DO_UPDATEPROPS();
break;
case AL_METERS_PER_UNIT:
- if(!(value >= 0.0f && isfinite(value)))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- context->Listener->MetersPerUnit = value;
- ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
+ if(!(value >= AL_MIN_METERS_PER_UNIT && value <= AL_MAX_METERS_PER_UNIT))
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Listener meters per unit out of range");
+ context->MetersPerUnit = value;
+ if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire))
+ UpdateContextProps(context);
+ else
+ ATOMIC_FLAG_CLEAR(&context->PropsClean, almemory_order_release);
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid listener float property");
}
done:
+ almtx_unlock(&context->PropLock);
ALCcontext_DecRef(context);
}
AL_API ALvoid AL_APIENTRY alListener3f(ALenum param, ALfloat value1, ALfloat value2, ALfloat value3)
{
+ ALlistener *listener;
ALCcontext *context;
context = GetContextRef();
if(!context) return;
+ listener = context->Listener;
+ almtx_lock(&context->PropLock);
switch(param)
{
case AL_POSITION:
if(!(isfinite(value1) && isfinite(value2) && isfinite(value3)))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- LockContext(context);
- aluVectorSet(&context->Listener->Position, value1, value2, value3, 1.0f);
- ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
- UnlockContext(context);
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Listener position out of range");
+ listener->Position[0] = value1;
+ listener->Position[1] = value2;
+ listener->Position[2] = value3;
+ DO_UPDATEPROPS();
break;
case AL_VELOCITY:
if(!(isfinite(value1) && isfinite(value2) && isfinite(value3)))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- LockContext(context);
- aluVectorSet(&context->Listener->Velocity, value1, value2, value3, 0.0f);
- ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
- UnlockContext(context);
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Listener velocity out of range");
+ listener->Velocity[0] = value1;
+ listener->Velocity[1] = value2;
+ listener->Velocity[2] = value3;
+ DO_UPDATEPROPS();
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid listener 3-float property");
}
done:
+ almtx_unlock(&context->PropLock);
ALCcontext_DecRef(context);
}
AL_API ALvoid AL_APIENTRY alListenerfv(ALenum param, const ALfloat *values)
{
+ ALlistener *listener;
ALCcontext *context;
if(values)
@@ -121,32 +137,31 @@ AL_API ALvoid AL_APIENTRY alListenerfv(ALenum param, const ALfloat *values)
context = GetContextRef();
if(!context) return;
- if(!(values))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ listener = context->Listener;
+ almtx_lock(&context->PropLock);
+ if(!values) SETERR_GOTO(context, AL_INVALID_VALUE, done, "NULL pointer");
switch(param)
{
case AL_ORIENTATION:
if(!(isfinite(values[0]) && isfinite(values[1]) && isfinite(values[2]) &&
isfinite(values[3]) && isfinite(values[4]) && isfinite(values[5])))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- LockContext(context);
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Listener orientation out of range");
/* AT then UP */
- context->Listener->Forward[0] = values[0];
- context->Listener->Forward[1] = values[1];
- context->Listener->Forward[2] = values[2];
- context->Listener->Up[0] = values[3];
- context->Listener->Up[1] = values[4];
- context->Listener->Up[2] = values[5];
- ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
- UnlockContext(context);
+ listener->Forward[0] = values[0];
+ listener->Forward[1] = values[1];
+ listener->Forward[2] = values[2];
+ listener->Up[0] = values[3];
+ listener->Up[1] = values[4];
+ listener->Up[2] = values[5];
+ DO_UPDATEPROPS();
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid listener float-vector property");
}
done:
+ almtx_unlock(&context->PropLock);
ALCcontext_DecRef(context);
}
@@ -158,13 +173,14 @@ AL_API ALvoid AL_APIENTRY alListeneri(ALenum param, ALint UNUSED(value))
context = GetContextRef();
if(!context) return;
+ almtx_lock(&context->PropLock);
switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid listener integer property");
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
}
@@ -184,13 +200,14 @@ AL_API void AL_APIENTRY alListener3i(ALenum param, ALint value1, ALint value2, A
context = GetContextRef();
if(!context) return;
+ almtx_lock(&context->PropLock);
switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid listener 3-integer property");
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
}
@@ -224,15 +241,16 @@ AL_API void AL_APIENTRY alListeneriv(ALenum param, const ALint *values)
context = GetContextRef();
if(!context) return;
- if(!(values))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(param)
+ almtx_lock(&context->PropLock);
+ if(!values)
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid listener integer-vector property");
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
}
@@ -244,23 +262,24 @@ AL_API ALvoid AL_APIENTRY alGetListenerf(ALenum param, ALfloat *value)
context = GetContextRef();
if(!context) return;
- if(!(value))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(param)
+ almtx_lock(&context->PropLock);
+ if(!value)
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
case AL_GAIN:
*value = context->Listener->Gain;
break;
case AL_METERS_PER_UNIT:
- *value = context->Listener->MetersPerUnit;
+ *value = context->MetersPerUnit;
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid listener float property");
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
}
@@ -272,31 +291,28 @@ AL_API ALvoid AL_APIENTRY alGetListener3f(ALenum param, ALfloat *value1, ALfloat
context = GetContextRef();
if(!context) return;
- if(!(value1 && value2 && value3))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(param)
+ almtx_lock(&context->PropLock);
+ if(!value1 || !value2 || !value3)
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
case AL_POSITION:
- LockContext(context);
- *value1 = context->Listener->Position.v[0];
- *value2 = context->Listener->Position.v[1];
- *value3 = context->Listener->Position.v[2];
- UnlockContext(context);
+ *value1 = context->Listener->Position[0];
+ *value2 = context->Listener->Position[1];
+ *value3 = context->Listener->Position[2];
break;
case AL_VELOCITY:
- LockContext(context);
- *value1 = context->Listener->Velocity.v[0];
- *value2 = context->Listener->Velocity.v[1];
- *value3 = context->Listener->Velocity.v[2];
- UnlockContext(context);
+ *value1 = context->Listener->Velocity[0];
+ *value2 = context->Listener->Velocity[1];
+ *value3 = context->Listener->Velocity[2];
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid listener 3-float property");
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
}
@@ -321,12 +337,12 @@ AL_API ALvoid AL_APIENTRY alGetListenerfv(ALenum param, ALfloat *values)
context = GetContextRef();
if(!context) return;
- if(!(values))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(param)
+ almtx_lock(&context->PropLock);
+ if(!values)
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
case AL_ORIENTATION:
- LockContext(context);
// AT then UP
values[0] = context->Listener->Forward[0];
values[1] = context->Listener->Forward[1];
@@ -334,14 +350,13 @@ AL_API ALvoid AL_APIENTRY alGetListenerfv(ALenum param, ALfloat *values)
values[3] = context->Listener->Up[0];
values[4] = context->Listener->Up[1];
values[5] = context->Listener->Up[2];
- UnlockContext(context);
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid listener float-vector property");
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
}
@@ -353,15 +368,16 @@ AL_API ALvoid AL_APIENTRY alGetListeneri(ALenum param, ALint *value)
context = GetContextRef();
if(!context) return;
- if(!(value))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(param)
+ almtx_lock(&context->PropLock);
+ if(!value)
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid listener integer property");
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
}
@@ -373,31 +389,28 @@ AL_API void AL_APIENTRY alGetListener3i(ALenum param, ALint *value1, ALint *valu
context = GetContextRef();
if(!context) return;
- if(!(value1 && value2 && value3))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch (param)
+ almtx_lock(&context->PropLock);
+ if(!value1 || !value2 || !value3)
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
case AL_POSITION:
- LockContext(context);
- *value1 = (ALint)context->Listener->Position.v[0];
- *value2 = (ALint)context->Listener->Position.v[1];
- *value3 = (ALint)context->Listener->Position.v[2];
- UnlockContext(context);
+ *value1 = (ALint)context->Listener->Position[0];
+ *value2 = (ALint)context->Listener->Position[1];
+ *value3 = (ALint)context->Listener->Position[2];
break;
case AL_VELOCITY:
- LockContext(context);
- *value1 = (ALint)context->Listener->Velocity.v[0];
- *value2 = (ALint)context->Listener->Velocity.v[1];
- *value3 = (ALint)context->Listener->Velocity.v[2];
- UnlockContext(context);
+ *value1 = (ALint)context->Listener->Velocity[0];
+ *value2 = (ALint)context->Listener->Velocity[1];
+ *value3 = (ALint)context->Listener->Velocity[2];
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid listener 3-integer property");
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
}
@@ -417,12 +430,12 @@ AL_API void AL_APIENTRY alGetListeneriv(ALenum param, ALint* values)
context = GetContextRef();
if(!context) return;
- if(!(values))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- switch(param)
+ almtx_lock(&context->PropLock);
+ if(!values)
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ else switch(param)
{
case AL_ORIENTATION:
- LockContext(context);
// AT then UP
values[0] = (ALint)context->Listener->Forward[0];
values[1] = (ALint)context->Listener->Forward[1];
@@ -430,13 +443,60 @@ AL_API void AL_APIENTRY alGetListeneriv(ALenum param, ALint* values)
values[3] = (ALint)context->Listener->Up[0];
values[4] = (ALint)context->Listener->Up[1];
values[5] = (ALint)context->Listener->Up[2];
- UnlockContext(context);
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_ENUM, "Invalid listener integer-vector property");
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
}
+
+
+void UpdateListenerProps(ALCcontext *context)
+{
+ ALlistener *listener = context->Listener;
+ struct ALlistenerProps *props;
+
+ /* Get an unused proprty container, or allocate a new one as needed. */
+ props = ATOMIC_LOAD(&context->FreeListenerProps, almemory_order_acquire);
+ if(!props)
+ props = al_calloc(16, sizeof(*props));
+ else
+ {
+ struct ALlistenerProps *next;
+ do {
+ next = ATOMIC_LOAD(&props->next, almemory_order_relaxed);
+ } while(ATOMIC_COMPARE_EXCHANGE_PTR_WEAK(&context->FreeListenerProps, &props, next,
+ almemory_order_seq_cst, almemory_order_acquire) == 0);
+ }
+
+ /* Copy in current property values. */
+ props->Position[0] = listener->Position[0];
+ props->Position[1] = listener->Position[1];
+ props->Position[2] = listener->Position[2];
+
+ props->Velocity[0] = listener->Velocity[0];
+ props->Velocity[1] = listener->Velocity[1];
+ props->Velocity[2] = listener->Velocity[2];
+
+ props->Forward[0] = listener->Forward[0];
+ props->Forward[1] = listener->Forward[1];
+ props->Forward[2] = listener->Forward[2];
+ props->Up[0] = listener->Up[0];
+ props->Up[1] = listener->Up[1];
+ props->Up[2] = listener->Up[2];
+
+ props->Gain = listener->Gain;
+
+ /* Set the new container for updating internal parameters. */
+ props = ATOMIC_EXCHANGE_PTR(&listener->Update, props, almemory_order_acq_rel);
+ if(props)
+ {
+ /* If there was an unused update container, put it back in the
+ * freelist.
+ */
+ ATOMIC_REPLACE_HEAD(struct ALlistenerProps*, &context->FreeListenerProps, props);
+ }
+}
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c
index 0d454882..d7c68e4e 100644
--- a/OpenAL32/alSource.c
+++ b/OpenAL32/alSource.c
@@ -31,22 +31,82 @@
#include "alError.h"
#include "alSource.h"
#include "alBuffer.h"
-#include "alThunk.h"
+#include "alFilter.h"
#include "alAuxEffectSlot.h"
+#include "ringbuffer.h"
#include "backends/base.h"
#include "threads.h"
+#include "almalloc.h"
+
+
+static ALsource *AllocSource(ALCcontext *context);
+static void FreeSource(ALCcontext *context, ALsource *source);
+static void InitSourceParams(ALsource *Source, ALsizei num_sends);
+static void DeinitSource(ALsource *source, ALsizei num_sends);
+static void UpdateSourceProps(ALsource *source, ALvoice *voice, ALsizei num_sends, ALCcontext *context);
+static ALint64 GetSourceSampleOffset(ALsource *Source, ALCcontext *context, ALuint64 *clocktime);
+static ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, ALuint64 *clocktime);
+static ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context);
+static ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALsizei *frac);
+static ALboolean ApplyOffset(ALsource *Source, ALvoice *voice);
+
+static inline void LockSourceList(ALCcontext *context)
+{ almtx_lock(&context->SourceLock); }
+static inline void UnlockSourceList(ALCcontext *context)
+{ almtx_unlock(&context->SourceLock); }
+
+static inline ALsource *LookupSource(ALCcontext *context, ALuint id)
+{
+ SourceSubList *sublist;
+ ALuint lidx = (id-1) >> 6;
+ ALsizei slidx = (id-1) & 0x3f;
+
+ if(UNLIKELY(lidx >= VECTOR_SIZE(context->SourceList)))
+ return NULL;
+ sublist = &VECTOR_ELEM(context->SourceList, lidx);
+ if(UNLIKELY(sublist->FreeMask & (U64(1)<<slidx)))
+ return NULL;
+ return sublist->Sources + slidx;
+}
+
+static inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id)
+{
+ BufferSubList *sublist;
+ ALuint lidx = (id-1) >> 6;
+ ALsizei slidx = (id-1) & 0x3f;
+
+ if(UNLIKELY(lidx >= VECTOR_SIZE(device->BufferList)))
+ return NULL;
+ sublist = &VECTOR_ELEM(device->BufferList, lidx);
+ if(UNLIKELY(sublist->FreeMask & (U64(1)<<slidx)))
+ return NULL;
+ return sublist->Buffers + slidx;
+}
+static inline ALfilter *LookupFilter(ALCdevice *device, ALuint id)
+{
+ FilterSubList *sublist;
+ ALuint lidx = (id-1) >> 6;
+ ALsizei slidx = (id-1) & 0x3f;
+
+ if(UNLIKELY(lidx >= VECTOR_SIZE(device->FilterList)))
+ return NULL;
+ sublist = &VECTOR_ELEM(device->FilterList, lidx);
+ if(UNLIKELY(sublist->FreeMask & (U64(1)<<slidx)))
+ return NULL;
+ return sublist->Filters + slidx;
+}
-extern inline struct ALsource *LookupSource(ALCcontext *context, ALuint id);
-extern inline struct ALsource *RemoveSource(ALCcontext *context, ALuint id);
+static inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id)
+{
+ id--;
+ if(UNLIKELY(id >= VECTOR_SIZE(context->EffectSlotList)))
+ return NULL;
+ return VECTOR_ELEM(context->EffectSlotList, id);
+}
-static ALvoid InitSourceParams(ALsource *Source);
-static ALint64 GetSourceSampleOffset(ALsource *Source);
-static ALdouble GetSourceSecOffset(ALsource *Source);
-static ALvoid GetSourceOffsets(ALsource *Source, ALenum name, ALdouble *offsets, ALdouble updateLen);
-static ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALuint *frac);
typedef enum SourceProp {
srcPitch = AL_PITCH,
@@ -92,20 +152,28 @@ typedef enum SourceProp {
/* AL_EXT_source_distance_model */
srcDistanceModel = AL_DISTANCE_MODEL,
- srcByteLengthSOFT = AL_BYTE_LENGTH_SOFT,
- srcSampleLengthSOFT = AL_SAMPLE_LENGTH_SOFT,
- srcSecLengthSOFT = AL_SEC_LENGTH_SOFT,
-
- /* AL_SOFT_buffer_sub_data / AL_SOFT_buffer_samples */
- srcSampleRWOffsetsSOFT = AL_SAMPLE_RW_OFFSETS_SOFT,
- srcByteRWOffsetsSOFT = AL_BYTE_RW_OFFSETS_SOFT,
-
/* AL_SOFT_source_latency */
srcSampleOffsetLatencySOFT = AL_SAMPLE_OFFSET_LATENCY_SOFT,
srcSecOffsetLatencySOFT = AL_SEC_OFFSET_LATENCY_SOFT,
+ /* AL_EXT_STEREO_ANGLES */
+ srcAngles = AL_STEREO_ANGLES,
+
+ /* AL_EXT_SOURCE_RADIUS */
+ srcRadius = AL_SOURCE_RADIUS,
+
/* AL_EXT_BFORMAT */
srcOrientation = AL_ORIENTATION,
+
+ /* AL_SOFT_source_resampler */
+ srcResampler = AL_SOURCE_RESAMPLER_SOFT,
+
+ /* AL_SOFT_source_spatialize */
+ srcSpatialize = AL_SOURCE_SPATIALIZE_SOFT,
+
+ /* ALC_SOFT_device_clock */
+ srcSampleOffsetClockSOFT = AL_SAMPLE_OFFSET_CLOCK_SOFT,
+ srcSecOffsetClockSOFT = AL_SEC_OFFSET_CLOCK_SOFT,
} SourceProp;
static ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALfloat *values);
@@ -116,6 +184,75 @@ static ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp p
static ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint *values);
static ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint64 *values);
+static inline ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context)
+{
+ ALint idx = source->VoiceIdx;
+ if(idx >= 0 && idx < context->VoiceCount)
+ {
+ ALvoice *voice = context->Voices[idx];
+ if(ATOMIC_LOAD(&voice->Source, almemory_order_acquire) == source)
+ return voice;
+ }
+ source->VoiceIdx = -1;
+ return NULL;
+}
+
+/**
+ * Returns if the last known state for the source was playing or paused. Does
+ * not sync with the mixer voice.
+ */
+static inline bool IsPlayingOrPaused(ALsource *source)
+{ return source->state == AL_PLAYING || source->state == AL_PAUSED; }
+
+/**
+ * Returns an updated source state using the matching voice's status (or lack
+ * thereof).
+ */
+static inline ALenum GetSourceState(ALsource *source, ALvoice *voice)
+{
+ if(!voice && source->state == AL_PLAYING)
+ source->state = AL_STOPPED;
+ return source->state;
+}
+
+/**
+ * Returns if the source should specify an update, given the context's
+ * deferring state and the source's last known state.
+ */
+static inline bool SourceShouldUpdate(ALsource *source, ALCcontext *context)
+{
+ return !ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire) &&
+ IsPlayingOrPaused(source);
+}
+
+
+/** Can only be called while the mixer is locked! */
+static void SendStateChangeEvent(ALCcontext *context, ALuint id, ALenum state)
+{
+ AsyncEvent evt = ASYNC_EVENT(EventType_SourceStateChange);
+ ALbitfieldSOFT enabledevt;
+
+ enabledevt = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_acquire);
+ if(!(enabledevt&EventType_SourceStateChange)) return;
+
+ evt.u.user.type = AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT;
+ evt.u.user.id = id;
+ evt.u.user.param = state;
+ snprintf(evt.u.user.msg, sizeof(evt.u.user.msg), "Source ID %u state changed to %s", id,
+ (state==AL_INITIAL) ? "AL_INITIAL" :
+ (state==AL_PLAYING) ? "AL_PLAYING" :
+ (state==AL_PAUSED) ? "AL_PAUSED" :
+ (state==AL_STOPPED) ? "AL_STOPPED" : "<unknown>"
+ );
+ /* The mixer may have queued a state change that's not yet been processed,
+ * and we don't want state change messages to occur out of order, so send
+ * it through the async queue to ensure proper ordering.
+ */
+ if(ll_ringbuffer_write(context->AsyncEvents, (const char*)&evt, 1) == 1)
+ alsem_post(&context->EventSem);
+}
+
+
static ALint FloatValsByProp(ALenum prop)
{
if(prop != (ALenum)((SourceProp)prop))
@@ -150,13 +287,12 @@ static ALint FloatValsByProp(ALenum prop)
case AL_BUFFERS_QUEUED:
case AL_BUFFERS_PROCESSED:
case AL_SOURCE_TYPE:
- case AL_BYTE_LENGTH_SOFT:
- case AL_SAMPLE_LENGTH_SOFT:
- case AL_SEC_LENGTH_SOFT:
+ case AL_SOURCE_RADIUS:
+ case AL_SOURCE_RESAMPLER_SOFT:
+ case AL_SOURCE_SPATIALIZE_SOFT:
return 1;
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- case AL_BYTE_RW_OFFSETS_SOFT:
+ case AL_STEREO_ANGLES:
return 2;
case AL_POSITION:
@@ -168,6 +304,7 @@ static ALint FloatValsByProp(ALenum prop)
return 6;
case AL_SEC_OFFSET_LATENCY_SOFT:
+ case AL_SEC_OFFSET_CLOCK_SOFT:
break; /* Double only */
case AL_BUFFER:
@@ -175,6 +312,7 @@ static ALint FloatValsByProp(ALenum prop)
case AL_AUXILIARY_SEND_FILTER:
break; /* i/i64 only */
case AL_SAMPLE_OFFSET_LATENCY_SOFT:
+ case AL_SAMPLE_OFFSET_CLOCK_SOFT:
break; /* i64 only */
}
return 0;
@@ -213,14 +351,14 @@ static ALint DoubleValsByProp(ALenum prop)
case AL_BUFFERS_QUEUED:
case AL_BUFFERS_PROCESSED:
case AL_SOURCE_TYPE:
- case AL_BYTE_LENGTH_SOFT:
- case AL_SAMPLE_LENGTH_SOFT:
- case AL_SEC_LENGTH_SOFT:
+ case AL_SOURCE_RADIUS:
+ case AL_SOURCE_RESAMPLER_SOFT:
+ case AL_SOURCE_SPATIALIZE_SOFT:
return 1;
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- case AL_BYTE_RW_OFFSETS_SOFT:
case AL_SEC_OFFSET_LATENCY_SOFT:
+ case AL_SEC_OFFSET_CLOCK_SOFT:
+ case AL_STEREO_ANGLES:
return 2;
case AL_POSITION:
@@ -236,6 +374,7 @@ static ALint DoubleValsByProp(ALenum prop)
case AL_AUXILIARY_SEND_FILTER:
break; /* i/i64 only */
case AL_SAMPLE_OFFSET_LATENCY_SOFT:
+ case AL_SAMPLE_OFFSET_CLOCK_SOFT:
break; /* i64 only */
}
return 0;
@@ -277,15 +416,11 @@ static ALint IntValsByProp(ALenum prop)
case AL_BUFFERS_PROCESSED:
case AL_SOURCE_TYPE:
case AL_DIRECT_FILTER:
- case AL_BYTE_LENGTH_SOFT:
- case AL_SAMPLE_LENGTH_SOFT:
- case AL_SEC_LENGTH_SOFT:
+ case AL_SOURCE_RADIUS:
+ case AL_SOURCE_RESAMPLER_SOFT:
+ case AL_SOURCE_SPATIALIZE_SOFT:
return 1;
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- case AL_BYTE_RW_OFFSETS_SOFT:
- return 2;
-
case AL_POSITION:
case AL_VELOCITY:
case AL_DIRECTION:
@@ -296,9 +431,13 @@ static ALint IntValsByProp(ALenum prop)
return 6;
case AL_SAMPLE_OFFSET_LATENCY_SOFT:
+ case AL_SAMPLE_OFFSET_CLOCK_SOFT:
break; /* i64 only */
case AL_SEC_OFFSET_LATENCY_SOFT:
+ case AL_SEC_OFFSET_CLOCK_SOFT:
break; /* Double only */
+ case AL_STEREO_ANGLES:
+ break; /* Float/double only */
}
return 0;
}
@@ -338,14 +477,13 @@ static ALint Int64ValsByProp(ALenum prop)
case AL_BUFFERS_PROCESSED:
case AL_SOURCE_TYPE:
case AL_DIRECT_FILTER:
- case AL_BYTE_LENGTH_SOFT:
- case AL_SAMPLE_LENGTH_SOFT:
- case AL_SEC_LENGTH_SOFT:
+ case AL_SOURCE_RADIUS:
+ case AL_SOURCE_RESAMPLER_SOFT:
+ case AL_SOURCE_SPATIALIZE_SOFT:
return 1;
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- case AL_BYTE_RW_OFFSETS_SOFT:
case AL_SAMPLE_OFFSET_LATENCY_SOFT:
+ case AL_SAMPLE_OFFSET_CLOCK_SOFT:
return 2;
case AL_POSITION:
@@ -358,7 +496,10 @@ static ALint Int64ValsByProp(ALenum prop)
return 6;
case AL_SEC_OFFSET_LATENCY_SOFT:
+ case AL_SEC_OFFSET_CLOCK_SOFT:
break; /* Double only */
+ case AL_STEREO_ANGLES:
+ break; /* Float/double only */
}
return 0;
}
@@ -366,120 +507,130 @@ static ALint Int64ValsByProp(ALenum prop)
#define CHECKVAL(x) do { \
if(!(x)) \
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_VALUE, AL_FALSE); \
+ { \
+ alSetError(Context, AL_INVALID_VALUE, "Value out of range"); \
+ return AL_FALSE; \
+ } \
+} while(0)
+
+#define DO_UPDATEPROPS() do { \
+ ALvoice *voice; \
+ if(SourceShouldUpdate(Source, Context) && \
+ (voice=GetSourceVoice(Source, Context)) != NULL) \
+ UpdateSourceProps(Source, voice, device->NumAuxSends, Context); \
+ else \
+ ATOMIC_FLAG_CLEAR(&Source->PropsClean, almemory_order_release); \
} while(0)
static ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALfloat *values)
{
+ ALCdevice *device = Context->Device;
ALint ival;
switch(prop)
{
- case AL_BYTE_RW_OFFSETS_SOFT:
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- case AL_BYTE_LENGTH_SOFT:
- case AL_SAMPLE_LENGTH_SOFT:
- case AL_SEC_LENGTH_SOFT:
case AL_SEC_OFFSET_LATENCY_SOFT:
+ case AL_SEC_OFFSET_CLOCK_SOFT:
/* Query only */
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_OPERATION, AL_FALSE);
+ SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE,
+ "Setting read-only source property 0x%04x", prop);
case AL_PITCH:
CHECKVAL(*values >= 0.0f);
Source->Pitch = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_CONE_INNER_ANGLE:
CHECKVAL(*values >= 0.0f && *values <= 360.0f);
Source->InnerAngle = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_CONE_OUTER_ANGLE:
CHECKVAL(*values >= 0.0f && *values <= 360.0f);
Source->OuterAngle = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_GAIN:
CHECKVAL(*values >= 0.0f);
Source->Gain = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_MAX_DISTANCE:
CHECKVAL(*values >= 0.0f);
Source->MaxDistance = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_ROLLOFF_FACTOR:
CHECKVAL(*values >= 0.0f);
- Source->RollOffFactor = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ Source->RolloffFactor = *values;
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_REFERENCE_DISTANCE:
CHECKVAL(*values >= 0.0f);
Source->RefDistance = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_MIN_GAIN:
- CHECKVAL(*values >= 0.0f && *values <= 1.0f);
+ CHECKVAL(*values >= 0.0f);
Source->MinGain = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_MAX_GAIN:
- CHECKVAL(*values >= 0.0f && *values <= 1.0f);
+ CHECKVAL(*values >= 0.0f);
Source->MaxGain = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_CONE_OUTER_GAIN:
CHECKVAL(*values >= 0.0f && *values <= 1.0f);
Source->OuterGain = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_CONE_OUTER_GAINHF:
CHECKVAL(*values >= 0.0f && *values <= 1.0f);
Source->OuterGainHF = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_AIR_ABSORPTION_FACTOR:
CHECKVAL(*values >= 0.0f && *values <= 10.0f);
Source->AirAbsorptionFactor = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_ROOM_ROLLOFF_FACTOR:
CHECKVAL(*values >= 0.0f && *values <= 10.0f);
Source->RoomRolloffFactor = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_DOPPLER_FACTOR:
CHECKVAL(*values >= 0.0f && *values <= 1.0f);
Source->DopplerFactor = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_SEC_OFFSET:
@@ -487,66 +638,84 @@ static ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp p
case AL_BYTE_OFFSET:
CHECKVAL(*values >= 0.0f);
- LockContext(Context);
Source->OffsetType = prop;
Source->Offset = *values;
- if((Source->state == AL_PLAYING || Source->state == AL_PAUSED) &&
- !Context->DeferUpdates)
+ if(IsPlayingOrPaused(Source))
{
- WriteLock(&Source->queue_lock);
- if(ApplyOffset(Source) == AL_FALSE)
+ ALvoice *voice;
+
+ ALCdevice_Lock(Context->Device);
+ /* Double-check that the source is still playing while we have
+ * the lock.
+ */
+ voice = GetSourceVoice(Source, Context);
+ if(voice)
{
- WriteUnlock(&Source->queue_lock);
- UnlockContext(Context);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_VALUE, AL_FALSE);
+ if(ApplyOffset(Source, voice) == AL_FALSE)
+ {
+ ALCdevice_Unlock(Context->Device);
+ SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid offset");
+ }
}
- WriteUnlock(&Source->queue_lock);
+ ALCdevice_Unlock(Context->Device);
}
- UnlockContext(Context);
+ return AL_TRUE;
+
+ case AL_SOURCE_RADIUS:
+ CHECKVAL(*values >= 0.0f && isfinite(*values));
+
+ Source->Radius = *values;
+ DO_UPDATEPROPS();
+ return AL_TRUE;
+
+ case AL_STEREO_ANGLES:
+ CHECKVAL(isfinite(values[0]) && isfinite(values[1]));
+
+ Source->StereoPan[0] = values[0];
+ Source->StereoPan[1] = values[1];
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_POSITION:
CHECKVAL(isfinite(values[0]) && isfinite(values[1]) && isfinite(values[2]));
- LockContext(Context);
- aluVectorSet(&Source->Position, values[0], values[1], values[2], 1.0f);
- UnlockContext(Context);
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ Source->Position[0] = values[0];
+ Source->Position[1] = values[1];
+ Source->Position[2] = values[2];
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_VELOCITY:
CHECKVAL(isfinite(values[0]) && isfinite(values[1]) && isfinite(values[2]));
- LockContext(Context);
- aluVectorSet(&Source->Velocity, values[0], values[1], values[2], 0.0f);
- UnlockContext(Context);
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ Source->Velocity[0] = values[0];
+ Source->Velocity[1] = values[1];
+ Source->Velocity[2] = values[2];
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_DIRECTION:
CHECKVAL(isfinite(values[0]) && isfinite(values[1]) && isfinite(values[2]));
- LockContext(Context);
- aluVectorSet(&Source->Direction, values[0], values[1], values[2], 0.0f);
- UnlockContext(Context);
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ Source->Direction[0] = values[0];
+ Source->Direction[1] = values[1];
+ Source->Direction[2] = values[2];
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_ORIENTATION:
CHECKVAL(isfinite(values[0]) && isfinite(values[1]) && isfinite(values[2]) &&
isfinite(values[3]) && isfinite(values[4]) && isfinite(values[5]));
- LockContext(Context);
Source->Orientation[0][0] = values[0];
Source->Orientation[0][1] = values[1];
Source->Orientation[0][2] = values[2];
Source->Orientation[1][0] = values[3];
Source->Orientation[1][1] = values[4];
Source->Orientation[1][2] = values[5];
- UnlockContext(Context);
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
@@ -559,6 +728,8 @@ static ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp p
case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO:
case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO:
case AL_DIRECT_CHANNELS_SOFT:
+ case AL_SOURCE_RESAMPLER_SOFT:
+ case AL_SOURCE_SPATIALIZE_SOFT:
ival = (ALint)values[0];
return SetSourceiv(Source, Context, prop, &ival);
@@ -571,11 +742,12 @@ static ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp p
case AL_DIRECT_FILTER:
case AL_AUXILIARY_SEND_FILTER:
case AL_SAMPLE_OFFSET_LATENCY_SOFT:
+ case AL_SAMPLE_OFFSET_CLOCK_SOFT:
break;
}
ERR("Unexpected property: 0x%04x\n", prop);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_ENUM, AL_FALSE);
+ SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source float property 0x%04x", prop);
}
static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALint *values)
@@ -585,7 +757,6 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
ALfilter *filter = NULL;
ALeffectslot *slot = NULL;
ALbufferlistitem *oldlist;
- ALbufferlistitem *newlist;
ALfloat fvals[6];
switch(prop)
@@ -594,73 +765,105 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
case AL_SOURCE_TYPE:
case AL_BUFFERS_QUEUED:
case AL_BUFFERS_PROCESSED:
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- case AL_BYTE_RW_OFFSETS_SOFT:
- case AL_BYTE_LENGTH_SOFT:
- case AL_SAMPLE_LENGTH_SOFT:
- case AL_SEC_LENGTH_SOFT:
/* Query only */
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_OPERATION, AL_FALSE);
+ SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE,
+ "Setting read-only source property 0x%04x", prop);
case AL_SOURCE_RELATIVE:
CHECKVAL(*values == AL_FALSE || *values == AL_TRUE);
Source->HeadRelative = (ALboolean)*values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_LOOPING:
CHECKVAL(*values == AL_FALSE || *values == AL_TRUE);
Source->Looping = (ALboolean)*values;
+ if(IsPlayingOrPaused(Source))
+ {
+ ALvoice *voice = GetSourceVoice(Source, Context);
+ if(voice)
+ {
+ if(Source->Looping)
+ ATOMIC_STORE(&voice->loop_buffer, Source->queue, almemory_order_release);
+ else
+ ATOMIC_STORE(&voice->loop_buffer, NULL, almemory_order_release);
+
+ /* If the source is playing, wait for the current mix to finish
+ * to ensure it isn't currently looping back or reaching the
+ * end.
+ */
+ while((ATOMIC_LOAD(&device->MixCount, almemory_order_acquire)&1))
+ althrd_yield();
+ }
+ }
return AL_TRUE;
case AL_BUFFER:
- CHECKVAL(*values == 0 || (buffer=LookupBuffer(device, *values)) != NULL);
+ LockBufferList(device);
+ if(!(*values == 0 || (buffer=LookupBuffer(device, *values)) != NULL))
+ {
+ UnlockBufferList(device);
+ SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid buffer ID %u",
+ *values);
+ }
- WriteLock(&Source->queue_lock);
- if(!(Source->state == AL_STOPPED || Source->state == AL_INITIAL))
+ if(buffer && buffer->MappedAccess != 0 &&
+ !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT))
{
- WriteUnlock(&Source->queue_lock);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_OPERATION, AL_FALSE);
+ UnlockBufferList(device);
+ SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE,
+ "Setting non-persistently mapped buffer %u", buffer->id);
+ }
+ else
+ {
+ ALenum state = GetSourceState(Source, GetSourceVoice(Source, Context));
+ if(state == AL_PLAYING || state == AL_PAUSED)
+ {
+ UnlockBufferList(device);
+ SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE,
+ "Setting buffer on playing or paused source %u", Source->id);
+ }
}
+ oldlist = Source->queue;
if(buffer != NULL)
{
/* Add the selected buffer to a one-item queue */
- newlist = malloc(sizeof(ALbufferlistitem));
- newlist->buffer = buffer;
- newlist->next = NULL;
- newlist->prev = NULL;
+ ALbufferlistitem *newlist = al_calloc(DEF_ALIGN,
+ FAM_SIZE(ALbufferlistitem, buffers, 1));
+ ATOMIC_INIT(&newlist->next, NULL);
+ newlist->max_samples = buffer->SampleLen;
+ newlist->num_buffers = 1;
+ newlist->buffers[0] = buffer;
IncrementRef(&buffer->ref);
/* Source is now Static */
Source->SourceType = AL_STATIC;
-
- ReadLock(&buffer->lock);
- Source->NumChannels = ChannelsFromFmt(buffer->FmtChannels);
- Source->SampleSize = BytesFromFmt(buffer->FmtType);
- ReadUnlock(&buffer->lock);
+ Source->queue = newlist;
}
else
{
/* Source is now Undetermined */
Source->SourceType = AL_UNDETERMINED;
- newlist = NULL;
+ Source->queue = NULL;
}
- oldlist = ATOMIC_EXCHANGE(ALbufferlistitem*, &Source->queue, newlist);
- ATOMIC_STORE(&Source->current_buffer, newlist);
- WriteUnlock(&Source->queue_lock);
+ UnlockBufferList(device);
/* Delete all elements in the previous queue */
while(oldlist != NULL)
{
+ ALsizei i;
ALbufferlistitem *temp = oldlist;
- oldlist = temp->next;
+ oldlist = ATOMIC_LOAD(&temp->next, almemory_order_relaxed);
- if(temp->buffer)
- DecrementRef(&temp->buffer->ref);
- free(temp);
+ for(i = 0;i < temp->num_buffers;i++)
+ {
+ if(temp->buffers[i])
+ DecrementRef(&temp->buffers[i]->ref);
+ }
+ al_free(temp);
}
return AL_TRUE;
@@ -669,29 +872,37 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
case AL_BYTE_OFFSET:
CHECKVAL(*values >= 0);
- LockContext(Context);
Source->OffsetType = prop;
Source->Offset = *values;
- if((Source->state == AL_PLAYING || Source->state == AL_PAUSED) &&
- !Context->DeferUpdates)
+ if(IsPlayingOrPaused(Source))
{
- WriteLock(&Source->queue_lock);
- if(ApplyOffset(Source) == AL_FALSE)
+ ALvoice *voice;
+
+ ALCdevice_Lock(Context->Device);
+ voice = GetSourceVoice(Source, Context);
+ if(voice)
{
- WriteUnlock(&Source->queue_lock);
- UnlockContext(Context);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_VALUE, AL_FALSE);
+ if(ApplyOffset(Source, voice) == AL_FALSE)
+ {
+ ALCdevice_Unlock(Context->Device);
+ SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE,
+ "Invalid source offset");
+ }
}
- WriteUnlock(&Source->queue_lock);
+ ALCdevice_Unlock(Context->Device);
}
- UnlockContext(Context);
return AL_TRUE;
case AL_DIRECT_FILTER:
- CHECKVAL(*values == 0 || (filter=LookupFilter(device, *values)) != NULL);
+ LockFilterList(device);
+ if(!(*values == 0 || (filter=LookupFilter(device, *values)) != NULL))
+ {
+ UnlockFilterList(device);
+ SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid filter ID %u",
+ *values);
+ }
- LockContext(Context);
if(!filter)
{
Source->Direct.Gain = 1.0f;
@@ -708,36 +919,36 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
Source->Direct.GainLF = filter->GainLF;
Source->Direct.LFReference = filter->LFReference;
}
- UnlockContext(Context);
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ UnlockFilterList(device);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_DIRECT_FILTER_GAINHF_AUTO:
CHECKVAL(*values == AL_FALSE || *values == AL_TRUE);
Source->DryGainHFAuto = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO:
CHECKVAL(*values == AL_FALSE || *values == AL_TRUE);
Source->WetGainAuto = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO:
CHECKVAL(*values == AL_FALSE || *values == AL_TRUE);
Source->WetGainHFAuto = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_DIRECT_CHANNELS_SOFT:
CHECKVAL(*values == AL_FALSE || *values == AL_TRUE);
Source->DirectChannels = *values;
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_DISTANCE_MODEL:
@@ -751,24 +962,45 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
Source->DistanceModel = *values;
if(Context->SourceDistanceModel)
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ DO_UPDATEPROPS();
+ return AL_TRUE;
+
+ case AL_SOURCE_RESAMPLER_SOFT:
+ CHECKVAL(*values >= 0 && *values <= ResamplerMax);
+
+ Source->Resampler = *values;
+ DO_UPDATEPROPS();
+ return AL_TRUE;
+
+ case AL_SOURCE_SPATIALIZE_SOFT:
+ CHECKVAL(*values >= AL_FALSE && *values <= AL_AUTO_SOFT);
+
+ Source->Spatialize = *values;
+ DO_UPDATEPROPS();
return AL_TRUE;
case AL_AUXILIARY_SEND_FILTER:
- LockContext(Context);
- if(!((ALuint)values[1] < device->NumAuxSends &&
- (values[0] == 0 || (slot=LookupEffectSlot(Context, values[0])) != NULL) &&
- (values[2] == 0 || (filter=LookupFilter(device, values[2])) != NULL)))
+ LockEffectSlotList(Context);
+ if(!(values[0] == 0 || (slot=LookupEffectSlot(Context, values[0])) != NULL))
{
- UnlockContext(Context);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_VALUE, AL_FALSE);
+ UnlockEffectSlotList(Context);
+ SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid effect ID %u",
+ values[0]);
+ }
+ if(!((ALuint)values[1] < (ALuint)device->NumAuxSends))
+ {
+ UnlockEffectSlotList(Context);
+ SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid send %u", values[1]);
+ }
+ LockFilterList(device);
+ if(!(values[2] == 0 || (filter=LookupFilter(device, values[2])) != NULL))
+ {
+ UnlockFilterList(device);
+ UnlockEffectSlotList(Context);
+ SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid filter ID %u",
+ values[2]);
}
-
- /* Add refcount on the new slot, and release the previous slot */
- if(slot) IncrementRef(&slot->ref);
- slot = ExchangePtr((XchgPtr*)&Source->Send[values[1]].Slot, slot);
- if(slot) DecrementRef(&slot->ref);
if(!filter)
{
@@ -787,8 +1019,35 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
Source->Send[values[1]].GainLF = filter->GainLF;
Source->Send[values[1]].LFReference = filter->LFReference;
}
- UnlockContext(Context);
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
+ UnlockFilterList(device);
+
+ if(slot != Source->Send[values[1]].Slot && IsPlayingOrPaused(Source))
+ {
+ ALvoice *voice;
+ /* Add refcount on the new slot, and release the previous slot */
+ if(slot) IncrementRef(&slot->ref);
+ if(Source->Send[values[1]].Slot)
+ DecrementRef(&Source->Send[values[1]].Slot->ref);
+ Source->Send[values[1]].Slot = slot;
+
+ /* We must force an update if the auxiliary slot changed on an
+ * active source, in case the slot is about to be deleted.
+ */
+ if((voice=GetSourceVoice(Source, Context)) != NULL)
+ UpdateSourceProps(Source, voice, device->NumAuxSends, Context);
+ else
+ ATOMIC_FLAG_CLEAR(&Source->PropsClean, almemory_order_release);
+ }
+ else
+ {
+ if(slot) IncrementRef(&slot->ref);
+ if(Source->Send[values[1]].Slot)
+ DecrementRef(&Source->Send[values[1]].Slot->ref);
+ Source->Send[values[1]].Slot = slot;
+ DO_UPDATEPROPS();
+ }
+ UnlockEffectSlotList(Context);
+
return AL_TRUE;
@@ -807,6 +1066,7 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
case AL_CONE_OUTER_GAINHF:
case AL_AIR_ABSORPTION_FACTOR:
case AL_ROOM_ROLLOFF_FACTOR:
+ case AL_SOURCE_RADIUS:
fvals[0] = (ALfloat)*values;
return SetSourcefv(Source, Context, (int)prop, fvals);
@@ -831,11 +1091,15 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
case AL_SAMPLE_OFFSET_LATENCY_SOFT:
case AL_SEC_OFFSET_LATENCY_SOFT:
+ case AL_SEC_OFFSET_CLOCK_SOFT:
+ case AL_SAMPLE_OFFSET_CLOCK_SOFT:
+ case AL_STEREO_ANGLES:
break;
}
ERR("Unexpected property: 0x%04x\n", prop);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_ENUM, AL_FALSE);
+ SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source integer property 0x%04x",
+ prop);
}
static ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const ALint64SOFT *values)
@@ -849,15 +1113,11 @@ static ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp
case AL_BUFFERS_QUEUED:
case AL_BUFFERS_PROCESSED:
case AL_SOURCE_STATE:
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- case AL_BYTE_RW_OFFSETS_SOFT:
case AL_SAMPLE_OFFSET_LATENCY_SOFT:
- case AL_BYTE_LENGTH_SOFT:
- case AL_SAMPLE_LENGTH_SOFT:
- case AL_SEC_LENGTH_SOFT:
+ case AL_SAMPLE_OFFSET_CLOCK_SOFT:
/* Query only */
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_OPERATION, AL_FALSE);
-
+ SETERR_RETURN(Context, AL_INVALID_OPERATION, AL_FALSE,
+ "Setting read-only source property 0x%04x", prop);
/* 1x int */
case AL_SOURCE_RELATIVE:
@@ -870,6 +1130,8 @@ static ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp
case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO:
case AL_DIRECT_CHANNELS_SOFT:
case AL_DISTANCE_MODEL:
+ case AL_SOURCE_RESAMPLER_SOFT:
+ case AL_SOURCE_SPATIALIZE_SOFT:
CHECKVAL(*values <= INT_MAX && *values >= INT_MIN);
ivals[0] = (ALint)*values;
@@ -909,6 +1171,7 @@ static ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp
case AL_CONE_OUTER_GAINHF:
case AL_AIR_ABSORPTION_FACTOR:
case AL_ROOM_ROLLOFF_FACTOR:
+ case AL_SOURCE_RADIUS:
fvals[0] = (ALfloat)*values;
return SetSourcefv(Source, Context, (int)prop, fvals);
@@ -932,11 +1195,14 @@ static ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp
return SetSourcefv(Source, Context, (int)prop, fvals);
case AL_SEC_OFFSET_LATENCY_SOFT:
+ case AL_SEC_OFFSET_CLOCK_SOFT:
+ case AL_STEREO_ANGLES:
break;
}
ERR("Unexpected property: 0x%04x\n", prop);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_ENUM, AL_FALSE);
+ SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source integer64 property 0x%04x",
+ prop);
}
#undef CHECKVAL
@@ -945,9 +1211,8 @@ static ALboolean SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp
static ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALdouble *values)
{
ALCdevice *device = Context->Device;
- ALbufferlistitem *BufferList;
- ALdouble offsets[2];
- ALdouble updateLen;
+ ClockLatency clocktime;
+ ALuint64 srcclock;
ALint ivals[3];
ALboolean err;
@@ -966,7 +1231,7 @@ static ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp p
return AL_TRUE;
case AL_ROLLOFF_FACTOR:
- *values = Source->RollOffFactor;
+ *values = Source->RolloffFactor;
return AL_TRUE;
case AL_REFERENCE_DISTANCE:
@@ -996,10 +1261,7 @@ static ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp p
case AL_SEC_OFFSET:
case AL_SAMPLE_OFFSET:
case AL_BYTE_OFFSET:
- LockContext(Context);
- GetSourceOffsets(Source, prop, offsets, 0.0);
- UnlockContext(Context);
- *values = offsets[0];
+ *values = GetSourceOffset(Source, prop, Context);
return AL_TRUE;
case AL_CONE_OUTER_GAINHF:
@@ -1018,76 +1280,67 @@ static ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp p
*values = Source->DopplerFactor;
return AL_TRUE;
- case AL_SEC_LENGTH_SOFT:
- ReadLock(&Source->queue_lock);
- if(!(BufferList=ATOMIC_LOAD(&Source->queue)))
- *values = 0;
- else
- {
- ALint length = 0;
- ALsizei freq = 1;
- do {
- ALbuffer *buffer = BufferList->buffer;
- if(buffer && buffer->SampleLen > 0)
- {
- freq = buffer->Frequency;
- length += buffer->SampleLen;
- }
- } while((BufferList=BufferList->next) != NULL);
- *values = (ALdouble)length / (ALdouble)freq;
- }
- ReadUnlock(&Source->queue_lock);
+ case AL_SOURCE_RADIUS:
+ *values = Source->Radius;
return AL_TRUE;
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- case AL_BYTE_RW_OFFSETS_SOFT:
- LockContext(Context);
- updateLen = (ALdouble)device->UpdateSize / device->Frequency;
- GetSourceOffsets(Source, prop, values, updateLen);
- UnlockContext(Context);
+ case AL_STEREO_ANGLES:
+ values[0] = Source->StereoPan[0];
+ values[1] = Source->StereoPan[1];
return AL_TRUE;
case AL_SEC_OFFSET_LATENCY_SOFT:
- LockContext(Context);
- values[0] = GetSourceSecOffset(Source);
- values[1] = (ALdouble)(V0(device->Backend,getLatency)()) /
- 1000000000.0;
- UnlockContext(Context);
+ /* Get the source offset with the clock time first. Then get the
+ * clock time with the device latency. Order is important.
+ */
+ values[0] = GetSourceSecOffset(Source, Context, &srcclock);
+ almtx_lock(&device->BackendLock);
+ clocktime = GetClockLatency(device);
+ almtx_unlock(&device->BackendLock);
+ if(srcclock == (ALuint64)clocktime.ClockTime)
+ values[1] = (ALdouble)clocktime.Latency / 1000000000.0;
+ else
+ {
+ /* If the clock time incremented, reduce the latency by that
+ * much since it's that much closer to the source offset it got
+ * earlier.
+ */
+ ALuint64 diff = clocktime.ClockTime - srcclock;
+ values[1] = (ALdouble)(clocktime.Latency - minu64(clocktime.Latency, diff)) /
+ 1000000000.0;
+ }
+ return AL_TRUE;
+
+ case AL_SEC_OFFSET_CLOCK_SOFT:
+ values[0] = GetSourceSecOffset(Source, Context, &srcclock);
+ values[1] = srcclock / 1000000000.0;
return AL_TRUE;
case AL_POSITION:
- LockContext(Context);
- values[0] = Source->Position.v[0];
- values[1] = Source->Position.v[1];
- values[2] = Source->Position.v[2];
- UnlockContext(Context);
+ values[0] = Source->Position[0];
+ values[1] = Source->Position[1];
+ values[2] = Source->Position[2];
return AL_TRUE;
case AL_VELOCITY:
- LockContext(Context);
- values[0] = Source->Velocity.v[0];
- values[1] = Source->Velocity.v[1];
- values[2] = Source->Velocity.v[2];
- UnlockContext(Context);
+ values[0] = Source->Velocity[0];
+ values[1] = Source->Velocity[1];
+ values[2] = Source->Velocity[2];
return AL_TRUE;
case AL_DIRECTION:
- LockContext(Context);
- values[0] = Source->Direction.v[0];
- values[1] = Source->Direction.v[1];
- values[2] = Source->Direction.v[2];
- UnlockContext(Context);
+ values[0] = Source->Direction[0];
+ values[1] = Source->Direction[1];
+ values[2] = Source->Direction[2];
return AL_TRUE;
case AL_ORIENTATION:
- LockContext(Context);
values[0] = Source->Orientation[0][0];
values[1] = Source->Orientation[0][1];
values[2] = Source->Orientation[0][2];
values[3] = Source->Orientation[1][0];
values[4] = Source->Orientation[1][1];
values[5] = Source->Orientation[1][2];
- UnlockContext(Context);
return AL_TRUE;
/* 1x int */
@@ -1101,9 +1354,9 @@ static ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp p
case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO:
case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO:
case AL_DIRECT_CHANNELS_SOFT:
- case AL_BYTE_LENGTH_SOFT:
- case AL_SAMPLE_LENGTH_SOFT:
case AL_DISTANCE_MODEL:
+ case AL_SOURCE_RESAMPLER_SOFT:
+ case AL_SOURCE_SPATIALIZE_SOFT:
if((err=GetSourceiv(Source, Context, (int)prop, ivals)) != AL_FALSE)
*values = (ALdouble)ivals[0];
return err;
@@ -1112,11 +1365,13 @@ static ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp p
case AL_DIRECT_FILTER:
case AL_AUXILIARY_SEND_FILTER:
case AL_SAMPLE_OFFSET_LATENCY_SOFT:
+ case AL_SAMPLE_OFFSET_CLOCK_SOFT:
break;
}
ERR("Unexpected property: 0x%04x\n", prop);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_ENUM, AL_FALSE);
+ SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source double property 0x%04x",
+ prop);
}
static ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint *values)
@@ -1136,89 +1391,30 @@ static ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
return AL_TRUE;
case AL_BUFFER:
- ReadLock(&Source->queue_lock);
- BufferList = (Source->SourceType == AL_STATIC) ? ATOMIC_LOAD(&Source->queue) :
- ATOMIC_LOAD(&Source->current_buffer);
- *values = (BufferList && BufferList->buffer) ? BufferList->buffer->id : 0;
- ReadUnlock(&Source->queue_lock);
+ BufferList = (Source->SourceType == AL_STATIC) ? Source->queue : NULL;
+ *values = (BufferList && BufferList->num_buffers >= 1 && BufferList->buffers[0]) ?
+ BufferList->buffers[0]->id : 0;
return AL_TRUE;
case AL_SOURCE_STATE:
- *values = Source->state;
- return AL_TRUE;
-
- case AL_BYTE_LENGTH_SOFT:
- ReadLock(&Source->queue_lock);
- if(!(BufferList=ATOMIC_LOAD(&Source->queue)))
- *values = 0;
- else
- {
- ALint length = 0;
- do {
- ALbuffer *buffer = BufferList->buffer;
- if(buffer && buffer->SampleLen > 0)
- {
- ALuint byte_align, sample_align;
- if(buffer->OriginalType == UserFmtIMA4)
- {
- ALsizei align = (buffer->OriginalAlign-1)/2 + 4;
- byte_align = align * ChannelsFromFmt(buffer->FmtChannels);
- sample_align = buffer->OriginalAlign;
- }
- else if(buffer->OriginalType == UserFmtMSADPCM)
- {
- ALsizei align = (buffer->OriginalAlign-2)/2 + 7;
- byte_align = align * ChannelsFromFmt(buffer->FmtChannels);
- sample_align = buffer->OriginalAlign;
- }
- else
- {
- ALsizei align = buffer->OriginalAlign;
- byte_align = align * ChannelsFromFmt(buffer->FmtChannels);
- sample_align = buffer->OriginalAlign;
- }
-
- length += buffer->SampleLen / sample_align * byte_align;
- }
- } while((BufferList=BufferList->next) != NULL);
- *values = length;
- }
- ReadUnlock(&Source->queue_lock);
- return AL_TRUE;
-
- case AL_SAMPLE_LENGTH_SOFT:
- ReadLock(&Source->queue_lock);
- if(!(BufferList=ATOMIC_LOAD(&Source->queue)))
- *values = 0;
- else
- {
- ALint length = 0;
- do {
- ALbuffer *buffer = BufferList->buffer;
- if(buffer) length += buffer->SampleLen;
- } while((BufferList=BufferList->next) != NULL);
- *values = length;
- }
- ReadUnlock(&Source->queue_lock);
+ *values = GetSourceState(Source, GetSourceVoice(Source, Context));
return AL_TRUE;
case AL_BUFFERS_QUEUED:
- ReadLock(&Source->queue_lock);
- if(!(BufferList=ATOMIC_LOAD(&Source->queue)))
+ if(!(BufferList=Source->queue))
*values = 0;
else
{
ALsizei count = 0;
do {
- ++count;
- } while((BufferList=BufferList->next) != NULL);
+ count += BufferList->num_buffers;
+ BufferList = ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed);
+ } while(BufferList != NULL);
*values = count;
}
- ReadUnlock(&Source->queue_lock);
return AL_TRUE;
case AL_BUFFERS_PROCESSED:
- ReadLock(&Source->queue_lock);
if(Source->Looping || Source->SourceType != AL_STREAMING)
{
/* Buffers on a looping source are in a perpetual state of
@@ -1227,17 +1423,24 @@ static ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
}
else
{
- const ALbufferlistitem *BufferList = ATOMIC_LOAD(&Source->queue);
- const ALbufferlistitem *Current = ATOMIC_LOAD(&Source->current_buffer);
+ const ALbufferlistitem *BufferList = Source->queue;
+ const ALbufferlistitem *Current = NULL;
ALsizei played = 0;
+ ALvoice *voice;
+
+ if((voice=GetSourceVoice(Source, Context)) != NULL)
+ Current = ATOMIC_LOAD(&voice->current_buffer, almemory_order_relaxed);
+ else if(Source->state == AL_INITIAL)
+ Current = BufferList;
+
while(BufferList && BufferList != Current)
{
- played++;
- BufferList = BufferList->next;
+ played += BufferList->num_buffers;
+ BufferList = ATOMIC_LOAD(&CONST_CAST(ALbufferlistitem*,BufferList)->next,
+ almemory_order_relaxed);
}
*values = played;
}
- ReadUnlock(&Source->queue_lock);
return AL_TRUE;
case AL_SOURCE_TYPE:
@@ -1264,6 +1467,14 @@ static ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
*values = Source->DistanceModel;
return AL_TRUE;
+ case AL_SOURCE_RESAMPLER_SOFT:
+ *values = Source->Resampler;
+ return AL_TRUE;
+
+ case AL_SOURCE_SPATIALIZE_SOFT:
+ *values = Source->Spatialize;
+ return AL_TRUE;
+
/* 1x float/double */
case AL_CONE_INNER_ANGLE:
case AL_CONE_OUTER_ANGLE:
@@ -1282,21 +1493,11 @@ static ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
case AL_AIR_ABSORPTION_FACTOR:
case AL_ROOM_ROLLOFF_FACTOR:
case AL_CONE_OUTER_GAINHF:
- case AL_SEC_LENGTH_SOFT:
+ case AL_SOURCE_RADIUS:
if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE)
*values = (ALint)dvals[0];
return err;
- /* 2x float/double */
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- case AL_BYTE_RW_OFFSETS_SOFT:
- if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE)
- {
- values[0] = (ALint)dvals[0];
- values[1] = (ALint)dvals[1];
- }
- return err;
-
/* 3x float/double */
case AL_POSITION:
case AL_VELOCITY:
@@ -1323,9 +1524,13 @@ static ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
return err;
case AL_SAMPLE_OFFSET_LATENCY_SOFT:
+ case AL_SAMPLE_OFFSET_CLOCK_SOFT:
break; /* i64 only */
case AL_SEC_OFFSET_LATENCY_SOFT:
+ case AL_SEC_OFFSET_CLOCK_SOFT:
break; /* Double only */
+ case AL_STEREO_ANGLES:
+ break; /* Float/double only */
case AL_DIRECT_FILTER:
case AL_AUXILIARY_SEND_FILTER:
@@ -1333,12 +1538,15 @@ static ALboolean GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
}
ERR("Unexpected property: 0x%04x\n", prop);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_ENUM, AL_FALSE);
+ SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source integer property 0x%04x",
+ prop);
}
static ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, ALint64 *values)
{
ALCdevice *device = Context->Device;
+ ClockLatency clocktime;
+ ALuint64 srcclock;
ALdouble dvals[6];
ALint ivals[3];
ALboolean err;
@@ -1346,10 +1554,29 @@ static ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp
switch(prop)
{
case AL_SAMPLE_OFFSET_LATENCY_SOFT:
- LockContext(Context);
- values[0] = GetSourceSampleOffset(Source);
- values[1] = V0(device->Backend,getLatency)();
- UnlockContext(Context);
+ /* Get the source offset with the clock time first. Then get the
+ * clock time with the device latency. Order is important.
+ */
+ values[0] = GetSourceSampleOffset(Source, Context, &srcclock);
+ almtx_lock(&device->BackendLock);
+ clocktime = GetClockLatency(device);
+ almtx_unlock(&device->BackendLock);
+ if(srcclock == (ALuint64)clocktime.ClockTime)
+ values[1] = clocktime.Latency;
+ else
+ {
+ /* If the clock time incremented, reduce the latency by that
+ * much since it's that much closer to the source offset it got
+ * earlier.
+ */
+ ALuint64 diff = clocktime.ClockTime - srcclock;
+ values[1] = clocktime.Latency - minu64(clocktime.Latency, diff);
+ }
+ return AL_TRUE;
+
+ case AL_SAMPLE_OFFSET_CLOCK_SOFT:
+ values[0] = GetSourceSampleOffset(Source, Context, &srcclock);
+ values[1] = srcclock;
return AL_TRUE;
/* 1x float/double */
@@ -1370,21 +1597,11 @@ static ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp
case AL_AIR_ABSORPTION_FACTOR:
case AL_ROOM_ROLLOFF_FACTOR:
case AL_CONE_OUTER_GAINHF:
- case AL_SEC_LENGTH_SOFT:
+ case AL_SOURCE_RADIUS:
if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE)
*values = (ALint64)dvals[0];
return err;
- /* 2x float/double */
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- case AL_BYTE_RW_OFFSETS_SOFT:
- if((err=GetSourcedv(Source, Context, prop, dvals)) != AL_FALSE)
- {
- values[0] = (ALint64)dvals[0];
- values[1] = (ALint64)dvals[1];
- }
- return err;
-
/* 3x float/double */
case AL_POSITION:
case AL_VELOCITY:
@@ -1416,14 +1633,14 @@ static ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp
case AL_SOURCE_STATE:
case AL_BUFFERS_QUEUED:
case AL_BUFFERS_PROCESSED:
- case AL_BYTE_LENGTH_SOFT:
- case AL_SAMPLE_LENGTH_SOFT:
case AL_SOURCE_TYPE:
case AL_DIRECT_FILTER_GAINHF_AUTO:
case AL_AUXILIARY_SEND_FILTER_GAIN_AUTO:
case AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO:
case AL_DIRECT_CHANNELS_SOFT:
case AL_DISTANCE_MODEL:
+ case AL_SOURCE_RESAMPLER_SOFT:
+ case AL_SOURCE_SPATIALIZE_SOFT:
if((err=GetSourceiv(Source, Context, prop, ivals)) != AL_FALSE)
*values = ivals[0];
return err;
@@ -1446,11 +1663,15 @@ static ALboolean GetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp
return err;
case AL_SEC_OFFSET_LATENCY_SOFT:
+ case AL_SEC_OFFSET_CLOCK_SOFT:
break; /* Double only */
+ case AL_STEREO_ANGLES:
+ break; /* Float/double only */
}
ERR("Unexpected property: 0x%04x\n", prop);
- SET_ERROR_AND_RETURN_VALUE(Context, AL_INVALID_ENUM, AL_FALSE);
+ SETERR_RETURN(Context, AL_INVALID_ENUM, AL_FALSE, "Invalid source integer64 property 0x%04x",
+ prop);
}
@@ -1458,40 +1679,23 @@ AL_API ALvoid AL_APIENTRY alGenSources(ALsizei n, ALuint *sources)
{
ALCcontext *context;
ALsizei cur = 0;
- ALenum err;
context = GetContextRef();
if(!context) return;
if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
- for(cur = 0;cur < n;cur++)
+ alSetError(context, AL_INVALID_VALUE, "Generating %d sources", n);
+ else for(cur = 0;cur < n;cur++)
{
- ALsource *source = al_calloc(16, sizeof(ALsource));
+ ALsource *source = AllocSource(context);
if(!source)
{
alDeleteSources(cur, sources);
- SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done);
- }
- InitSourceParams(source);
-
- err = NewThunkEntry(&source->id);
- if(err == AL_NO_ERROR)
- err = InsertUIntMapEntry(&context->SourceMap, source->id, source);
- if(err != AL_NO_ERROR)
- {
- FreeThunkEntry(source->id);
- memset(source, 0, sizeof(ALsource));
- al_free(source);
-
- alDeleteSources(cur, sources);
- SET_ERROR_AND_GOTO(context, err, done);
+ break;
}
-
sources[cur] = source->id;
}
-done:
ALCcontext_DecRef(context);
}
@@ -1499,64 +1703,30 @@ done:
AL_API ALvoid AL_APIENTRY alDeleteSources(ALsizei n, const ALuint *sources)
{
ALCcontext *context;
- ALbufferlistitem *BufferList;
ALsource *Source;
- ALsizei i, j;
+ ALsizei i;
context = GetContextRef();
if(!context) return;
+ LockSourceList(context);
if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Deleting %d sources", n);
/* Check that all Sources are valid */
for(i = 0;i < n;i++)
{
if(LookupSource(context, sources[i]) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid source ID %u", sources[i]);
}
for(i = 0;i < n;i++)
{
- ALvoice *voice, *voice_end;
-
- if((Source=RemoveSource(context, sources[i])) == NULL)
- continue;
- FreeThunkEntry(Source->id);
-
- LockContext(context);
- voice = context->Voices;
- voice_end = voice + context->VoiceCount;
- while(voice != voice_end)
- {
- ALsource *old = Source;
- if(COMPARE_EXCHANGE(&voice->Source, &old, NULL))
- break;
- voice++;
- }
- UnlockContext(context);
-
- BufferList = ATOMIC_EXCHANGE(ALbufferlistitem*, &Source->queue, NULL);
- while(BufferList != NULL)
- {
- ALbufferlistitem *next = BufferList->next;
- if(BufferList->buffer != NULL)
- DecrementRef(&BufferList->buffer->ref);
- free(BufferList);
- BufferList = next;
- }
-
- for(j = 0;j < MAX_SENDS;++j)
- {
- if(Source->Send[j].Slot)
- DecrementRef(&Source->Send[j].Slot->ref);
- Source->Send[j].Slot = NULL;
- }
-
- memset(Source, 0, sizeof(*Source));
- al_free(Source);
+ if((Source=LookupSource(context, sources[i])) != NULL)
+ FreeSource(context, Source);
}
done:
+ UnlockSourceList(context);
ALCcontext_DecRef(context);
}
@@ -1569,7 +1739,9 @@ AL_API ALboolean AL_APIENTRY alIsSource(ALuint source)
context = GetContextRef();
if(!context) return AL_FALSE;
+ LockSourceList(context);
ret = (LookupSource(context, source) ? AL_TRUE : AL_FALSE);
+ UnlockSourceList(context);
ALCcontext_DecRef(context);
@@ -1585,12 +1757,16 @@ AL_API ALvoid AL_APIENTRY alSourcef(ALuint source, ALenum param, ALfloat value)
Context = GetContextRef();
if(!Context) return;
+ almtx_lock(&Context->PropLock);
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(FloatValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid float property 0x%04x", param);
else
SetSourcefv(Source, Context, param, &value);
+ UnlockSourceList(Context);
+ almtx_unlock(&Context->PropLock);
ALCcontext_DecRef(Context);
}
@@ -1603,15 +1779,19 @@ AL_API ALvoid AL_APIENTRY alSource3f(ALuint source, ALenum param, ALfloat value1
Context = GetContextRef();
if(!Context) return;
+ almtx_lock(&Context->PropLock);
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(FloatValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid 3-float property 0x%04x", param);
else
{
ALfloat fvals[3] = { value1, value2, value3 };
SetSourcefv(Source, Context, param, fvals);
}
+ UnlockSourceList(Context);
+ almtx_unlock(&Context->PropLock);
ALCcontext_DecRef(Context);
}
@@ -1624,14 +1804,18 @@ AL_API ALvoid AL_APIENTRY alSourcefv(ALuint source, ALenum param, const ALfloat
Context = GetContextRef();
if(!Context) return;
+ almtx_lock(&Context->PropLock);
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!(FloatValsByProp(param) > 0))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid float-vector property 0x%04x", param);
else
SetSourcefv(Source, Context, param, values);
+ UnlockSourceList(Context);
+ almtx_unlock(&Context->PropLock);
ALCcontext_DecRef(Context);
}
@@ -1645,15 +1829,19 @@ AL_API ALvoid AL_APIENTRY alSourcedSOFT(ALuint source, ALenum param, ALdouble va
Context = GetContextRef();
if(!Context) return;
+ almtx_lock(&Context->PropLock);
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(DoubleValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid double property 0x%04x", param);
else
{
ALfloat fval = (ALfloat)value;
SetSourcefv(Source, Context, param, &fval);
}
+ UnlockSourceList(Context);
+ almtx_unlock(&Context->PropLock);
ALCcontext_DecRef(Context);
}
@@ -1666,15 +1854,19 @@ AL_API ALvoid AL_APIENTRY alSource3dSOFT(ALuint source, ALenum param, ALdouble v
Context = GetContextRef();
if(!Context) return;
+ almtx_lock(&Context->PropLock);
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(DoubleValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid 3-double property 0x%04x", param);
else
{
ALfloat fvals[3] = { (ALfloat)value1, (ALfloat)value2, (ALfloat)value3 };
SetSourcefv(Source, Context, param, fvals);
}
+ UnlockSourceList(Context);
+ almtx_unlock(&Context->PropLock);
ALCcontext_DecRef(Context);
}
@@ -1688,12 +1880,14 @@ AL_API ALvoid AL_APIENTRY alSourcedvSOFT(ALuint source, ALenum param, const ALdo
Context = GetContextRef();
if(!Context) return;
+ almtx_lock(&Context->PropLock);
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!((count=DoubleValsByProp(param)) > 0 && count <= 6))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid double-vector property 0x%04x", param);
else
{
ALfloat fvals[6];
@@ -1703,6 +1897,8 @@ AL_API ALvoid AL_APIENTRY alSourcedvSOFT(ALuint source, ALenum param, const ALdo
fvals[i] = (ALfloat)values[i];
SetSourcefv(Source, Context, param, fvals);
}
+ UnlockSourceList(Context);
+ almtx_unlock(&Context->PropLock);
ALCcontext_DecRef(Context);
}
@@ -1716,12 +1912,16 @@ AL_API ALvoid AL_APIENTRY alSourcei(ALuint source, ALenum param, ALint value)
Context = GetContextRef();
if(!Context) return;
+ almtx_lock(&Context->PropLock);
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(IntValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid integer property 0x%04x", param);
else
SetSourceiv(Source, Context, param, &value);
+ UnlockSourceList(Context);
+ almtx_unlock(&Context->PropLock);
ALCcontext_DecRef(Context);
}
@@ -1734,15 +1934,19 @@ AL_API void AL_APIENTRY alSource3i(ALuint source, ALenum param, ALint value1, AL
Context = GetContextRef();
if(!Context) return;
+ almtx_lock(&Context->PropLock);
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(IntValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid 3-integer property 0x%04x", param);
else
{
ALint ivals[3] = { value1, value2, value3 };
SetSourceiv(Source, Context, param, ivals);
}
+ UnlockSourceList(Context);
+ almtx_unlock(&Context->PropLock);
ALCcontext_DecRef(Context);
}
@@ -1755,14 +1959,18 @@ AL_API void AL_APIENTRY alSourceiv(ALuint source, ALenum param, const ALint *val
Context = GetContextRef();
if(!Context) return;
+ almtx_lock(&Context->PropLock);
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!(IntValsByProp(param) > 0))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid integer-vector property 0x%04x", param);
else
SetSourceiv(Source, Context, param, values);
+ UnlockSourceList(Context);
+ almtx_unlock(&Context->PropLock);
ALCcontext_DecRef(Context);
}
@@ -1776,12 +1984,16 @@ AL_API ALvoid AL_APIENTRY alSourcei64SOFT(ALuint source, ALenum param, ALint64SO
Context = GetContextRef();
if(!Context) return;
+ almtx_lock(&Context->PropLock);
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(Int64ValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid integer64 property 0x%04x", param);
else
SetSourcei64v(Source, Context, param, &value);
+ UnlockSourceList(Context);
+ almtx_unlock(&Context->PropLock);
ALCcontext_DecRef(Context);
}
@@ -1794,15 +2006,19 @@ AL_API void AL_APIENTRY alSource3i64SOFT(ALuint source, ALenum param, ALint64SOF
Context = GetContextRef();
if(!Context) return;
+ almtx_lock(&Context->PropLock);
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(Int64ValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid 3-integer64 property 0x%04x", param);
else
{
ALint64SOFT i64vals[3] = { value1, value2, value3 };
SetSourcei64v(Source, Context, param, i64vals);
}
+ UnlockSourceList(Context);
+ almtx_unlock(&Context->PropLock);
ALCcontext_DecRef(Context);
}
@@ -1815,14 +2031,18 @@ AL_API void AL_APIENTRY alSourcei64vSOFT(ALuint source, ALenum param, const ALin
Context = GetContextRef();
if(!Context) return;
+ almtx_lock(&Context->PropLock);
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!(Int64ValsByProp(param) > 0))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid integer64-vector property 0x%04x", param);
else
SetSourcei64v(Source, Context, param, values);
+ UnlockSourceList(Context);
+ almtx_unlock(&Context->PropLock);
ALCcontext_DecRef(Context);
}
@@ -1836,18 +2056,20 @@ AL_API ALvoid AL_APIENTRY alGetSourcef(ALuint source, ALenum param, ALfloat *val
Context = GetContextRef();
if(!Context) return;
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!value)
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!(FloatValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid float property 0x%04x", param);
else
{
ALdouble dval;
if(GetSourcedv(Source, Context, param, &dval))
*value = (ALfloat)dval;
}
+ UnlockSourceList(Context);
ALCcontext_DecRef(Context);
}
@@ -1861,12 +2083,13 @@ AL_API ALvoid AL_APIENTRY alGetSource3f(ALuint source, ALenum param, ALfloat *va
Context = GetContextRef();
if(!Context) return;
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(value1 && value2 && value3))
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!(FloatValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid 3-float property 0x%04x", param);
else
{
ALdouble dvals[3];
@@ -1877,6 +2100,7 @@ AL_API ALvoid AL_APIENTRY alGetSource3f(ALuint source, ALenum param, ALfloat *va
*value3 = (ALfloat)dvals[2];
}
}
+ UnlockSourceList(Context);
ALCcontext_DecRef(Context);
}
@@ -1891,12 +2115,13 @@ AL_API ALvoid AL_APIENTRY alGetSourcefv(ALuint source, ALenum param, ALfloat *va
Context = GetContextRef();
if(!Context) return;
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!((count=FloatValsByProp(param)) > 0 && count <= 6))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid float-vector property 0x%04x", param);
else
{
ALdouble dvals[6];
@@ -1907,6 +2132,7 @@ AL_API ALvoid AL_APIENTRY alGetSourcefv(ALuint source, ALenum param, ALfloat *va
values[i] = (ALfloat)dvals[i];
}
}
+ UnlockSourceList(Context);
ALCcontext_DecRef(Context);
}
@@ -1920,14 +2146,16 @@ AL_API void AL_APIENTRY alGetSourcedSOFT(ALuint source, ALenum param, ALdouble *
Context = GetContextRef();
if(!Context) return;
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!value)
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!(DoubleValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid double property 0x%04x", param);
else
GetSourcedv(Source, Context, param, value);
+ UnlockSourceList(Context);
ALCcontext_DecRef(Context);
}
@@ -1940,12 +2168,13 @@ AL_API void AL_APIENTRY alGetSource3dSOFT(ALuint source, ALenum param, ALdouble
Context = GetContextRef();
if(!Context) return;
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(value1 && value2 && value3))
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!(DoubleValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid 3-double property 0x%04x", param);
else
{
ALdouble dvals[3];
@@ -1956,6 +2185,7 @@ AL_API void AL_APIENTRY alGetSource3dSOFT(ALuint source, ALenum param, ALdouble
*value3 = dvals[2];
}
}
+ UnlockSourceList(Context);
ALCcontext_DecRef(Context);
}
@@ -1968,14 +2198,16 @@ AL_API void AL_APIENTRY alGetSourcedvSOFT(ALuint source, ALenum param, ALdouble
Context = GetContextRef();
if(!Context) return;
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!(DoubleValsByProp(param) > 0))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid double-vector property 0x%04x", param);
else
GetSourcedv(Source, Context, param, values);
+ UnlockSourceList(Context);
ALCcontext_DecRef(Context);
}
@@ -1989,14 +2221,16 @@ AL_API ALvoid AL_APIENTRY alGetSourcei(ALuint source, ALenum param, ALint *value
Context = GetContextRef();
if(!Context) return;
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!value)
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!(IntValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid integer property 0x%04x", param);
else
GetSourceiv(Source, Context, param, value);
+ UnlockSourceList(Context);
ALCcontext_DecRef(Context);
}
@@ -2010,12 +2244,13 @@ AL_API void AL_APIENTRY alGetSource3i(ALuint source, ALenum param, ALint *value1
Context = GetContextRef();
if(!Context) return;
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(value1 && value2 && value3))
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!(IntValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid 3-integer property 0x%04x", param);
else
{
ALint ivals[3];
@@ -2026,6 +2261,7 @@ AL_API void AL_APIENTRY alGetSource3i(ALuint source, ALenum param, ALint *value1
*value3 = ivals[2];
}
}
+ UnlockSourceList(Context);
ALCcontext_DecRef(Context);
}
@@ -2039,14 +2275,16 @@ AL_API void AL_APIENTRY alGetSourceiv(ALuint source, ALenum param, ALint *values
Context = GetContextRef();
if(!Context) return;
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!(IntValsByProp(param) > 0))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid integer-vector property 0x%04x", param);
else
GetSourceiv(Source, Context, param, values);
+ UnlockSourceList(Context);
ALCcontext_DecRef(Context);
}
@@ -2060,14 +2298,16 @@ AL_API void AL_APIENTRY alGetSourcei64SOFT(ALuint source, ALenum param, ALint64S
Context = GetContextRef();
if(!Context) return;
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!value)
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!(Int64ValsByProp(param) == 1))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid integer64 property 0x%04x", param);
else
GetSourcei64v(Source, Context, param, value);
+ UnlockSourceList(Context);
ALCcontext_DecRef(Context);
}
@@ -2080,12 +2320,13 @@ AL_API void AL_APIENTRY alGetSource3i64SOFT(ALuint source, ALenum param, ALint64
Context = GetContextRef();
if(!Context) return;
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!(value1 && value2 && value3))
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!(Int64ValsByProp(param) == 3))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid 3-integer64 property 0x%04x", param);
else
{
ALint64 i64vals[3];
@@ -2096,6 +2337,7 @@ AL_API void AL_APIENTRY alGetSource3i64SOFT(ALuint source, ALenum param, ALint64
*value3 = i64vals[2];
}
}
+ UnlockSourceList(Context);
ALCcontext_DecRef(Context);
}
@@ -2108,14 +2350,16 @@ AL_API void AL_APIENTRY alGetSourcei64vSOFT(ALuint source, ALenum param, ALint64
Context = GetContextRef();
if(!Context) return;
+ LockSourceList(Context);
if((Source=LookupSource(Context, source)) == NULL)
- alSetError(Context, AL_INVALID_NAME);
+ alSetError(Context, AL_INVALID_NAME, "Invalid source ID %u", source);
else if(!values)
- alSetError(Context, AL_INVALID_VALUE);
+ alSetError(Context, AL_INVALID_VALUE, "NULL pointer");
else if(!(Int64ValsByProp(param) > 0))
- alSetError(Context, AL_INVALID_ENUM);
+ alSetError(Context, AL_INVALID_ENUM, "Invalid integer64-vector property 0x%04x", param);
else
GetSourcei64v(Source, Context, param, values);
+ UnlockSourceList(Context);
ALCcontext_DecRef(Context);
}
@@ -2128,49 +2372,183 @@ AL_API ALvoid AL_APIENTRY alSourcePlay(ALuint source)
AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources)
{
ALCcontext *context;
+ ALCdevice *device;
ALsource *source;
- ALsizei i;
+ ALvoice *voice;
+ ALsizei i, j;
context = GetContextRef();
if(!context) return;
+ LockSourceList(context);
if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Playing %d sources", n);
for(i = 0;i < n;i++)
{
if(!LookupSource(context, sources[i]))
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid source ID %u", sources[i]);
}
- LockContext(context);
- while(n > context->MaxVoices-context->VoiceCount)
+ device = context->Device;
+ ALCdevice_Lock(device);
+ /* If the device is disconnected, go right to stopped. */
+ if(!ATOMIC_LOAD(&device->Connected, almemory_order_acquire))
{
- ALvoice *temp = NULL;
- ALsizei newcount;
-
- newcount = context->MaxVoices << 1;
- if(newcount > 0)
- temp = realloc(context->Voices, newcount * sizeof(context->Voices[0]));
- if(!temp)
+ /* TODO: Send state change event? */
+ for(i = 0;i < n;i++)
{
- UnlockContext(context);
- SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done);
+ source = LookupSource(context, sources[i]);
+ source->OffsetType = AL_NONE;
+ source->Offset = 0.0;
+ source->state = AL_STOPPED;
}
- memset(&temp[context->MaxVoices], 0, (newcount-context->MaxVoices) * sizeof(temp[0]));
+ ALCdevice_Unlock(device);
+ goto done;
+ }
- context->Voices = temp;
- context->MaxVoices = newcount;
+ while(n > context->MaxVoices-context->VoiceCount)
+ {
+ ALsizei newcount = context->MaxVoices << 1;
+ if(context->MaxVoices >= newcount)
+ {
+ ALCdevice_Unlock(device);
+ SETERR_GOTO(context, AL_OUT_OF_MEMORY, done,
+ "Overflow increasing voice count %d -> %d", context->MaxVoices, newcount);
+ }
+ AllocateVoices(context, newcount, device->NumAuxSends);
}
for(i = 0;i < n;i++)
{
+ ALbufferlistitem *BufferList;
+ bool start_fading = false;
+ ALint vidx = -1;
+
source = LookupSource(context, sources[i]);
- if(context->DeferUpdates) source->new_state = AL_PLAYING;
- else SetSourceState(source, context, AL_PLAYING);
+ /* Check that there is a queue containing at least one valid, non zero
+ * length buffer.
+ */
+ BufferList = source->queue;
+ while(BufferList && BufferList->max_samples == 0)
+ BufferList = ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed);
+
+ /* If there's nothing to play, go right to stopped. */
+ if(UNLIKELY(!BufferList))
+ {
+ /* NOTE: A source without any playable buffers should not have an
+ * ALvoice since it shouldn't be in a playing or paused state. So
+ * there's no need to look up its voice and clear the source.
+ */
+ ALenum oldstate = GetSourceState(source, NULL);
+ source->OffsetType = AL_NONE;
+ source->Offset = 0.0;
+ if(oldstate != AL_STOPPED)
+ {
+ source->state = AL_STOPPED;
+ SendStateChangeEvent(context, source->id, AL_STOPPED);
+ }
+ continue;
+ }
+
+ voice = GetSourceVoice(source, context);
+ switch(GetSourceState(source, voice))
+ {
+ case AL_PLAYING:
+ assert(voice != NULL);
+ /* A source that's already playing is restarted from the beginning. */
+ ATOMIC_STORE(&voice->current_buffer, BufferList, almemory_order_relaxed);
+ ATOMIC_STORE(&voice->position, 0, almemory_order_relaxed);
+ ATOMIC_STORE(&voice->position_fraction, 0, almemory_order_release);
+ continue;
+
+ case AL_PAUSED:
+ assert(voice != NULL);
+ /* A source that's paused simply resumes. */
+ ATOMIC_STORE(&voice->Playing, true, almemory_order_release);
+ source->state = AL_PLAYING;
+ SendStateChangeEvent(context, source->id, AL_PLAYING);
+ continue;
+
+ default:
+ break;
+ }
+
+ /* Look for an unused voice to play this source with. */
+ assert(voice == NULL);
+ for(j = 0;j < context->VoiceCount;j++)
+ {
+ if(ATOMIC_LOAD(&context->Voices[j]->Source, almemory_order_acquire) == NULL)
+ {
+ vidx = j;
+ break;
+ }
+ }
+ if(vidx == -1)
+ vidx = context->VoiceCount++;
+ voice = context->Voices[vidx];
+ ATOMIC_STORE(&voice->Playing, false, almemory_order_release);
+
+ ATOMIC_FLAG_TEST_AND_SET(&source->PropsClean, almemory_order_acquire);
+ UpdateSourceProps(source, voice, device->NumAuxSends, context);
+
+ /* A source that's not playing or paused has any offset applied when it
+ * starts playing.
+ */
+ if(source->Looping)
+ ATOMIC_STORE(&voice->loop_buffer, source->queue, almemory_order_relaxed);
+ else
+ ATOMIC_STORE(&voice->loop_buffer, NULL, almemory_order_relaxed);
+ ATOMIC_STORE(&voice->current_buffer, BufferList, almemory_order_relaxed);
+ ATOMIC_STORE(&voice->position, 0, almemory_order_relaxed);
+ ATOMIC_STORE(&voice->position_fraction, 0, almemory_order_relaxed);
+ if(ApplyOffset(source, voice) != AL_FALSE)
+ start_fading = ATOMIC_LOAD(&voice->position, almemory_order_relaxed) != 0 ||
+ ATOMIC_LOAD(&voice->position_fraction, almemory_order_relaxed) != 0 ||
+ ATOMIC_LOAD(&voice->current_buffer, almemory_order_relaxed) != BufferList;
+
+ for(j = 0;j < BufferList->num_buffers;j++)
+ {
+ ALbuffer *buffer = BufferList->buffers[j];
+ if(buffer)
+ {
+ voice->NumChannels = ChannelsFromFmt(buffer->FmtChannels);
+ voice->SampleSize = BytesFromFmt(buffer->FmtType);
+ break;
+ }
+ }
+
+ /* Clear previous samples. */
+ memset(voice->PrevSamples, 0, sizeof(voice->PrevSamples));
+
+ /* Clear the stepping value so the mixer knows not to mix this until
+ * the update gets applied.
+ */
+ voice->Step = 0;
+
+ voice->Flags = start_fading ? VOICE_IS_FADING : 0;
+ if(source->SourceType == AL_STATIC) voice->Flags |= VOICE_IS_STATIC;
+ memset(voice->Direct.Params, 0, sizeof(voice->Direct.Params[0])*voice->NumChannels);
+ for(j = 0;j < device->NumAuxSends;j++)
+ memset(voice->Send[j].Params, 0, sizeof(voice->Send[j].Params[0])*voice->NumChannels);
+ if(device->AvgSpeakerDist > 0.0f)
+ {
+ ALfloat w1 = SPEEDOFSOUNDMETRESPERSEC /
+ (device->AvgSpeakerDist * device->Frequency);
+ for(j = 0;j < voice->NumChannels;j++)
+ NfcFilterCreate(&voice->Direct.Params[j].NFCtrlFilter, 0.0f, w1);
+ }
+
+ ATOMIC_STORE(&voice->Source, source, almemory_order_relaxed);
+ ATOMIC_STORE(&voice->Playing, true, almemory_order_release);
+ source->state = AL_PLAYING;
+ source->VoiceIdx = vidx;
+
+ SendStateChangeEvent(context, source->id, AL_PLAYING);
}
- UnlockContext(context);
+ ALCdevice_Unlock(device);
done:
+ UnlockSourceList(context);
ALCcontext_DecRef(context);
}
@@ -2181,30 +2559,40 @@ AL_API ALvoid AL_APIENTRY alSourcePause(ALuint source)
AL_API ALvoid AL_APIENTRY alSourcePausev(ALsizei n, const ALuint *sources)
{
ALCcontext *context;
+ ALCdevice *device;
ALsource *source;
+ ALvoice *voice;
ALsizei i;
context = GetContextRef();
if(!context) return;
+ LockSourceList(context);
if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Pausing %d sources", n);
for(i = 0;i < n;i++)
{
if(!LookupSource(context, sources[i]))
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid source ID %u", sources[i]);
}
- LockContext(context);
+ device = context->Device;
+ ALCdevice_Lock(device);
for(i = 0;i < n;i++)
{
source = LookupSource(context, sources[i]);
- if(context->DeferUpdates) source->new_state = AL_PAUSED;
- else SetSourceState(source, context, AL_PAUSED);
+ if((voice=GetSourceVoice(source, context)) != NULL)
+ ATOMIC_STORE(&voice->Playing, false, almemory_order_release);
+ if(GetSourceState(source, voice) == AL_PLAYING)
+ {
+ source->state = AL_PAUSED;
+ SendStateChangeEvent(context, source->id, AL_PAUSED);
+ }
}
- UnlockContext(context);
+ ALCdevice_Unlock(device);
done:
+ UnlockSourceList(context);
ALCcontext_DecRef(context);
}
@@ -2215,30 +2603,48 @@ AL_API ALvoid AL_APIENTRY alSourceStop(ALuint source)
AL_API ALvoid AL_APIENTRY alSourceStopv(ALsizei n, const ALuint *sources)
{
ALCcontext *context;
+ ALCdevice *device;
ALsource *source;
+ ALvoice *voice;
ALsizei i;
context = GetContextRef();
if(!context) return;
+ LockSourceList(context);
if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Stopping %d sources", n);
for(i = 0;i < n;i++)
{
if(!LookupSource(context, sources[i]))
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid source ID %u", sources[i]);
}
- LockContext(context);
+ device = context->Device;
+ ALCdevice_Lock(device);
for(i = 0;i < n;i++)
{
+ ALenum oldstate;
source = LookupSource(context, sources[i]);
- source->new_state = AL_NONE;
- SetSourceState(source, context, AL_STOPPED);
+ if((voice=GetSourceVoice(source, context)) != NULL)
+ {
+ ATOMIC_STORE(&voice->Source, NULL, almemory_order_relaxed);
+ ATOMIC_STORE(&voice->Playing, false, almemory_order_release);
+ voice = NULL;
+ }
+ oldstate = GetSourceState(source, voice);
+ if(oldstate != AL_INITIAL && oldstate != AL_STOPPED)
+ {
+ source->state = AL_STOPPED;
+ SendStateChangeEvent(context, source->id, AL_STOPPED);
+ }
+ source->OffsetType = AL_NONE;
+ source->Offset = 0.0;
}
- UnlockContext(context);
+ ALCdevice_Unlock(device);
done:
+ UnlockSourceList(context);
ALCcontext_DecRef(context);
}
@@ -2249,30 +2655,46 @@ AL_API ALvoid AL_APIENTRY alSourceRewind(ALuint source)
AL_API ALvoid AL_APIENTRY alSourceRewindv(ALsizei n, const ALuint *sources)
{
ALCcontext *context;
+ ALCdevice *device;
ALsource *source;
+ ALvoice *voice;
ALsizei i;
context = GetContextRef();
if(!context) return;
+ LockSourceList(context);
if(!(n >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Rewinding %d sources", n);
for(i = 0;i < n;i++)
{
if(!LookupSource(context, sources[i]))
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid source ID %u", sources[i]);
}
- LockContext(context);
+ device = context->Device;
+ ALCdevice_Lock(device);
for(i = 0;i < n;i++)
{
source = LookupSource(context, sources[i]);
- source->new_state = AL_NONE;
- SetSourceState(source, context, AL_INITIAL);
+ if((voice=GetSourceVoice(source, context)) != NULL)
+ {
+ ATOMIC_STORE(&voice->Source, NULL, almemory_order_relaxed);
+ ATOMIC_STORE(&voice->Playing, false, almemory_order_release);
+ voice = NULL;
+ }
+ if(GetSourceState(source, voice) != AL_INITIAL)
+ {
+ source->state = AL_INITIAL;
+ SendStateChangeEvent(context, source->id, AL_INITIAL);
+ }
+ source->OffsetType = AL_NONE;
+ source->Offset = 0.0;
}
- UnlockContext(context);
+ ALCdevice_Unlock(device);
done:
+ UnlockSourceList(context);
ALCcontext_DecRef(context);
}
@@ -2295,133 +2717,122 @@ AL_API ALvoid AL_APIENTRY alSourceQueueBuffers(ALuint src, ALsizei nb, const ALu
device = context->Device;
+ LockSourceList(context);
if(!(nb >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Queueing %d buffers", nb);
if((source=LookupSource(context, src)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid source ID %u", src);
- WriteLock(&source->queue_lock);
if(source->SourceType == AL_STATIC)
{
- WriteUnlock(&source->queue_lock);
/* Can't queue on a Static Source */
- SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done);
+ SETERR_GOTO(context, AL_INVALID_OPERATION, done, "Queueing onto static source %u", src);
}
/* Check for a valid Buffer, for its frequency and format */
- BufferList = ATOMIC_LOAD(&source->queue);
+ BufferList = source->queue;
while(BufferList)
{
- if(BufferList->buffer)
+ for(i = 0;i < BufferList->num_buffers;i++)
{
- BufferFmt = BufferList->buffer;
- break;
+ if((BufferFmt=BufferList->buffers[i]) != NULL)
+ break;
}
- BufferList = BufferList->next;
+ if(BufferFmt) break;
+ BufferList = ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed);
}
+ LockBufferList(device);
BufferListStart = NULL;
BufferList = NULL;
for(i = 0;i < nb;i++)
{
ALbuffer *buffer = NULL;
if(buffers[i] && (buffer=LookupBuffer(device, buffers[i])) == NULL)
- {
- WriteUnlock(&source->queue_lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, buffer_error);
- }
+ SETERR_GOTO(context, AL_INVALID_NAME, buffer_error, "Queueing invalid buffer ID %u",
+ buffers[i]);
if(!BufferListStart)
{
- BufferListStart = malloc(sizeof(ALbufferlistitem));
- BufferListStart->buffer = buffer;
- BufferListStart->next = NULL;
- BufferListStart->prev = NULL;
+ BufferListStart = al_calloc(DEF_ALIGN,
+ FAM_SIZE(ALbufferlistitem, buffers, 1));
BufferList = BufferListStart;
}
else
{
- BufferList->next = malloc(sizeof(ALbufferlistitem));
- BufferList->next->buffer = buffer;
- BufferList->next->next = NULL;
- BufferList->next->prev = BufferList;
- BufferList = BufferList->next;
+ ALbufferlistitem *item = al_calloc(DEF_ALIGN,
+ FAM_SIZE(ALbufferlistitem, buffers, 1));
+ ATOMIC_STORE(&BufferList->next, item, almemory_order_relaxed);
+ BufferList = item;
}
+ ATOMIC_INIT(&BufferList->next, NULL);
+ BufferList->max_samples = buffer ? buffer->SampleLen : 0;
+ BufferList->num_buffers = 1;
+ BufferList->buffers[0] = buffer;
if(!buffer) continue;
- /* Hold a read lock on each buffer being queued while checking all
- * provided buffers. This is done so other threads don't see an extra
- * reference on some buffers if this operation ends up failing. */
- ReadLock(&buffer->lock);
IncrementRef(&buffer->ref);
+ if(buffer->MappedAccess != 0 && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT))
+ SETERR_GOTO(context, AL_INVALID_OPERATION, buffer_error,
+ "Queueing non-persistently mapped buffer %u", buffer->id);
+
if(BufferFmt == NULL)
- {
BufferFmt = buffer;
-
- source->NumChannels = ChannelsFromFmt(buffer->FmtChannels);
- source->SampleSize = BytesFromFmt(buffer->FmtType);
- }
else if(BufferFmt->Frequency != buffer->Frequency ||
- BufferFmt->OriginalChannels != buffer->OriginalChannels ||
+ BufferFmt->FmtChannels != buffer->FmtChannels ||
BufferFmt->OriginalType != buffer->OriginalType)
{
- WriteUnlock(&source->queue_lock);
- SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, buffer_error);
+ alSetError(context, AL_INVALID_OPERATION, "Queueing buffer with mismatched format");
buffer_error:
/* A buffer failed (invalid ID or format), so unlock and release
* each buffer we had. */
- while(BufferList != NULL)
+ while(BufferListStart)
{
- ALbufferlistitem *prev = BufferList->prev;
- if((buffer=BufferList->buffer) != NULL)
+ ALbufferlistitem *next = ATOMIC_LOAD(&BufferListStart->next,
+ almemory_order_relaxed);
+ for(i = 0;i < BufferListStart->num_buffers;i++)
{
- DecrementRef(&buffer->ref);
- ReadUnlock(&buffer->lock);
+ if((buffer=BufferListStart->buffers[i]) != NULL)
+ DecrementRef(&buffer->ref);
}
- free(BufferList);
- BufferList = prev;
+ al_free(BufferListStart);
+ BufferListStart = next;
}
+ UnlockBufferList(device);
goto done;
}
}
- /* All buffers good, unlock them now. */
- while(BufferList != NULL)
- {
- ALbuffer *buffer = BufferList->buffer;
- if(buffer) ReadUnlock(&buffer->lock);
- BufferList = BufferList->prev;
- }
+ /* All buffers good. */
+ UnlockBufferList(device);
/* Source is now streaming */
source->SourceType = AL_STREAMING;
- BufferList = NULL;
- if(!ATOMIC_COMPARE_EXCHANGE_STRONG(ALbufferlistitem*, &source->queue, &BufferList, BufferListStart))
+ if(!(BufferList=source->queue))
+ source->queue = BufferListStart;
+ else
{
- /* Queue head is not NULL, append to the end of the queue */
- while(BufferList->next != NULL)
- BufferList = BufferList->next;
-
- BufferListStart->prev = BufferList;
- BufferList->next = BufferListStart;
+ ALbufferlistitem *next;
+ while((next=ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed)) != NULL)
+ BufferList = next;
+ ATOMIC_STORE(&BufferList->next, BufferListStart, almemory_order_release);
}
- BufferList = NULL;
- ATOMIC_COMPARE_EXCHANGE_STRONG(ALbufferlistitem*, &source->current_buffer, &BufferList, BufferListStart);
- WriteUnlock(&source->queue_lock);
done:
+ UnlockSourceList(context);
ALCcontext_DecRef(context);
}
-AL_API ALvoid AL_APIENTRY alSourceUnqueueBuffers(ALuint src, ALsizei nb, ALuint *buffers)
+AL_API void AL_APIENTRY alSourceQueueBufferLayersSOFT(ALuint src, ALsizei nb, const ALuint *buffers)
{
+ ALCdevice *device;
ALCcontext *context;
+ ALbufferlistitem *BufferListStart;
+ ALbufferlistitem *BufferList;
+ ALbuffer *BufferFmt = NULL;
ALsource *source;
- ALbufferlistitem *NewHead;
- ALbufferlistitem *OldHead;
- ALbufferlistitem *Current;
ALsizei i;
if(nb == 0)
@@ -2430,85 +2841,218 @@ AL_API ALvoid AL_APIENTRY alSourceUnqueueBuffers(ALuint src, ALsizei nb, ALuint
context = GetContextRef();
if(!context) return;
- if(!(nb >= 0))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ device = context->Device;
+ LockSourceList(context);
+ if(!(nb >= 0 && nb < 16))
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Queueing %d buffer layers", nb);
if((source=LookupSource(context, src)) == NULL)
- SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid source ID %u", src);
- WriteLock(&source->queue_lock);
- /* Find the new buffer queue head */
- NewHead = ATOMIC_LOAD(&source->queue);
- Current = ATOMIC_LOAD(&source->current_buffer);
- for(i = 0;i < nb && NewHead;i++)
+ if(source->SourceType == AL_STATIC)
{
- if(NewHead == Current)
- break;
- NewHead = NewHead->next;
+ /* Can't queue on a Static Source */
+ SETERR_GOTO(context, AL_INVALID_OPERATION, done, "Queueing onto static source %u", src);
}
- if(source->Looping || source->SourceType != AL_STREAMING || i != nb)
+
+ /* Check for a valid Buffer, for its frequency and format */
+ BufferList = source->queue;
+ while(BufferList)
{
- WriteUnlock(&source->queue_lock);
- /* Trying to unqueue pending buffers, or a buffer that wasn't queued. */
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ for(i = 0;i < BufferList->num_buffers;i++)
+ {
+ if((BufferFmt=BufferList->buffers[i]) != NULL)
+ break;
+ }
+ if(BufferFmt) break;
+ BufferList = ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed);
}
- /* Swap it, and cut the new head from the old. */
- OldHead = ATOMIC_EXCHANGE(ALbufferlistitem*, &source->queue, NewHead);
- if(NewHead)
+ LockBufferList(device);
+ BufferListStart = al_calloc(DEF_ALIGN, FAM_SIZE(ALbufferlistitem, buffers, nb));
+ BufferList = BufferListStart;
+ ATOMIC_INIT(&BufferList->next, NULL);
+ BufferList->max_samples = 0;
+ BufferList->num_buffers = 0;
+ for(i = 0;i < nb;i++)
{
- ALCdevice *device = context->Device;
- ALbufferlistitem *OldTail = NewHead->prev;
- uint count;
+ ALbuffer *buffer = NULL;
+ if(buffers[i] && (buffer=LookupBuffer(device, buffers[i])) == NULL)
+ SETERR_GOTO(context, AL_INVALID_NAME, buffer_error, "Queueing invalid buffer ID %u",
+ buffers[i]);
- /* Cut the new head's link back to the old body. The mixer is robust
- * enough to handle the link back going away. Once the active mix (if
- * any) is complete, it's safe to finish cutting the old tail from the
- * new head. */
- NewHead->prev = NULL;
- if(((count=ReadRef(&device->MixCount))&1) != 0)
+ BufferList->buffers[BufferList->num_buffers++] = buffer;
+ if(!buffer) continue;
+
+ IncrementRef(&buffer->ref);
+
+ BufferList->max_samples = maxi(BufferList->max_samples, buffer->SampleLen);
+
+ if(buffer->MappedAccess != 0 && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT))
+ SETERR_GOTO(context, AL_INVALID_OPERATION, buffer_error,
+ "Queueing non-persistently mapped buffer %u", buffer->id);
+
+ if(BufferFmt == NULL)
+ BufferFmt = buffer;
+ else if(BufferFmt->Frequency != buffer->Frequency ||
+ BufferFmt->FmtChannels != buffer->FmtChannels ||
+ BufferFmt->OriginalType != buffer->OriginalType)
{
- while(count == ReadRef(&device->MixCount))
- althrd_yield();
+ alSetError(context, AL_INVALID_OPERATION, "Queueing buffer with mismatched format");
+
+ buffer_error:
+ /* A buffer failed (invalid ID or format), so unlock and release
+ * each buffer we had. */
+ while(BufferListStart)
+ {
+ ALbufferlistitem *next = ATOMIC_LOAD(&BufferListStart->next,
+ almemory_order_relaxed);
+ for(i = 0;i < BufferListStart->num_buffers;i++)
+ {
+ if((buffer=BufferListStart->buffers[i]) != NULL)
+ DecrementRef(&buffer->ref);
+ }
+ al_free(BufferListStart);
+ BufferListStart = next;
+ }
+ UnlockBufferList(device);
+ goto done;
}
- OldTail->next = NULL;
}
- WriteUnlock(&source->queue_lock);
+ /* All buffers good. */
+ UnlockBufferList(device);
+
+ /* Source is now streaming */
+ source->SourceType = AL_STREAMING;
- while(OldHead != NULL)
+ if(!(BufferList=source->queue))
+ source->queue = BufferListStart;
+ else
{
- ALbufferlistitem *next = OldHead->next;
- ALbuffer *buffer = OldHead->buffer;
+ ALbufferlistitem *next;
+ while((next=ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed)) != NULL)
+ BufferList = next;
+ ATOMIC_STORE(&BufferList->next, BufferListStart, almemory_order_release);
+ }
- if(!buffer)
- *(buffers++) = 0;
- else
+done:
+ UnlockSourceList(context);
+ ALCcontext_DecRef(context);
+}
+
+AL_API ALvoid AL_APIENTRY alSourceUnqueueBuffers(ALuint src, ALsizei nb, ALuint *buffers)
+{
+ ALCcontext *context;
+ ALsource *source;
+ ALbufferlistitem *BufferList;
+ ALbufferlistitem *Current;
+ ALvoice *voice;
+ ALsizei i;
+
+ context = GetContextRef();
+ if(!context) return;
+
+ LockSourceList(context);
+ if(!(nb >= 0))
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Unqueueing %d buffers", nb);
+ if((source=LookupSource(context, src)) == NULL)
+ SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid source ID %u", src);
+
+ /* Nothing to unqueue. */
+ if(nb == 0) goto done;
+
+ if(source->Looping)
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Unqueueing from looping source %u", src);
+ if(source->SourceType != AL_STREAMING)
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Unqueueing from a non-streaming source %u",
+ src);
+
+ /* Make sure enough buffers have been processed to unqueue. */
+ BufferList = source->queue;
+ Current = NULL;
+ if((voice=GetSourceVoice(source, context)) != NULL)
+ Current = ATOMIC_LOAD(&voice->current_buffer, almemory_order_relaxed);
+ else if(source->state == AL_INITIAL)
+ Current = BufferList;
+ if(BufferList == Current)
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Unqueueing pending buffers");
+
+ i = BufferList->num_buffers;
+ while(i < nb)
+ {
+ /* If the next bufferlist to check is NULL or is the current one, it's
+ * trying to unqueue pending buffers.
+ */
+ ALbufferlistitem *next = ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed);
+ if(!next || next == Current)
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Unqueueing pending buffers");
+ BufferList = next;
+
+ i += BufferList->num_buffers;
+ }
+
+ while(nb > 0)
+ {
+ ALbufferlistitem *head = source->queue;
+ ALbufferlistitem *next = ATOMIC_LOAD(&head->next, almemory_order_relaxed);
+ for(i = 0;i < head->num_buffers && nb > 0;i++,nb--)
{
- *(buffers++) = buffer->id;
- DecrementRef(&buffer->ref);
+ ALbuffer *buffer = head->buffers[i];
+ if(!buffer)
+ *(buffers++) = 0;
+ else
+ {
+ *(buffers++) = buffer->id;
+ DecrementRef(&buffer->ref);
+ }
+ }
+ if(i < head->num_buffers)
+ {
+ /* This head has some buffers left over, so move them to the front
+ * and update the sample and buffer count.
+ */
+ ALsizei max_length = 0;
+ ALsizei j = 0;
+ while(i < head->num_buffers)
+ {
+ ALbuffer *buffer = head->buffers[i++];
+ if(buffer) max_length = maxi(max_length, buffer->SampleLen);
+ head->buffers[j++] = buffer;
+ }
+ head->max_samples = max_length;
+ head->num_buffers = j;
+ break;
}
- free(OldHead);
- OldHead = next;
+ /* Otherwise, free this item and set the source queue head to the next
+ * one.
+ */
+ al_free(head);
+ source->queue = next;
}
done:
+ UnlockSourceList(context);
ALCcontext_DecRef(context);
}
-static ALvoid InitSourceParams(ALsource *Source)
+static void InitSourceParams(ALsource *Source, ALsizei num_sends)
{
- ALuint i;
-
- RWLockInit(&Source->queue_lock);
+ ALsizei i;
Source->InnerAngle = 360.0f;
Source->OuterAngle = 360.0f;
Source->Pitch = 1.0f;
- aluVectorSet(&Source->Position, 0.0f, 0.0f, 0.0f, 1.0f);
- aluVectorSet(&Source->Velocity, 0.0f, 0.0f, 0.0f, 0.0f);
- aluVectorSet(&Source->Direction, 0.0f, 0.0f, 0.0f, 0.0f);
+ Source->Position[0] = 0.0f;
+ Source->Position[1] = 0.0f;
+ Source->Position[2] = 0.0f;
+ Source->Velocity[0] = 0.0f;
+ Source->Velocity[1] = 0.0f;
+ Source->Velocity[2] = 0.0f;
+ Source->Direction[0] = 0.0f;
+ Source->Direction[1] = 0.0f;
+ Source->Direction[2] = 0.0f;
Source->Orientation[0][0] = 0.0f;
Source->Orientation[0][1] = 0.0f;
Source->Orientation[0][2] = -1.0f;
@@ -2517,8 +3061,7 @@ static ALvoid InitSourceParams(ALsource *Source)
Source->Orientation[1][2] = 0.0f;
Source->RefDistance = 1.0f;
Source->MaxDistance = FLT_MAX;
- Source->RollOffFactor = 1.0f;
- Source->Looping = AL_FALSE;
+ Source->RolloffFactor = 1.0f;
Source->Gain = 1.0f;
Source->MinGain = 0.0f;
Source->MaxGain = 1.0f;
@@ -2531,27 +3074,27 @@ static ALvoid InitSourceParams(ALsource *Source)
Source->AirAbsorptionFactor = 0.0f;
Source->RoomRolloffFactor = 0.0f;
Source->DopplerFactor = 1.0f;
- Source->DirectChannels = AL_FALSE;
-
- Source->Radius = 0.0f;
-
+ Source->HeadRelative = AL_FALSE;
+ Source->Looping = AL_FALSE;
Source->DistanceModel = DefaultDistanceModel;
+ Source->Resampler = ResamplerDefault;
+ Source->DirectChannels = AL_FALSE;
+ Source->Spatialize = SpatializeAuto;
- Source->state = AL_INITIAL;
- Source->new_state = AL_NONE;
- Source->SourceType = AL_UNDETERMINED;
- Source->Offset = -1.0;
+ Source->StereoPan[0] = DEG2RAD( 30.0f);
+ Source->StereoPan[1] = DEG2RAD(-30.0f);
- ATOMIC_INIT(&Source->queue, NULL);
- ATOMIC_INIT(&Source->current_buffer, NULL);
+ Source->Radius = 0.0f;
Source->Direct.Gain = 1.0f;
Source->Direct.GainHF = 1.0f;
Source->Direct.HFReference = LOWPASSFREQREF;
Source->Direct.GainLF = 1.0f;
Source->Direct.LFReference = HIGHPASSFREQREF;
- for(i = 0;i < MAX_SENDS;i++)
+ Source->Send = al_calloc(16, num_sends*sizeof(Source->Send[0]));
+ for(i = 0;i < num_sends;i++)
{
+ Source->Send[i].Slot = NULL;
Source->Send[i].Gain = 1.0f;
Source->Send[i].GainHF = 1.0f;
Source->Send[i].HFReference = LOWPASSFREQREF;
@@ -2559,179 +3102,202 @@ static ALvoid InitSourceParams(ALsource *Source)
Source->Send[i].LFReference = HIGHPASSFREQREF;
}
- ATOMIC_INIT(&Source->NeedsUpdate, AL_TRUE);
-}
+ Source->Offset = 0.0;
+ Source->OffsetType = AL_NONE;
+ Source->SourceType = AL_UNDETERMINED;
+ Source->state = AL_INITIAL;
+ Source->queue = NULL;
-/* SetSourceState
- *
- * Sets the source's new play state given its current state.
- */
-ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state)
+ /* No way to do an 'init' here, so just test+set with relaxed ordering and
+ * ignore the test.
+ */
+ ATOMIC_FLAG_TEST_AND_SET(&Source->PropsClean, almemory_order_relaxed);
+
+ Source->VoiceIdx = -1;
+}
+
+static void DeinitSource(ALsource *source, ALsizei num_sends)
{
- WriteLock(&Source->queue_lock);
- if(state == AL_PLAYING)
- {
- ALCdevice *device = Context->Device;
- ALbufferlistitem *BufferList;
- ALboolean discontinuity;
- ALvoice *voice = NULL;
- ALsizei i;
+ ALbufferlistitem *BufferList;
+ ALsizei i;
- /* Check that there is a queue containing at least one valid, non zero
- * length Buffer. */
- BufferList = ATOMIC_LOAD(&Source->queue);
- while(BufferList)
+ BufferList = source->queue;
+ while(BufferList != NULL)
+ {
+ ALbufferlistitem *next = ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed);
+ for(i = 0;i < BufferList->num_buffers;i++)
{
- ALbuffer *buffer;
- if((buffer=BufferList->buffer) != NULL && buffer->SampleLen > 0)
- break;
- BufferList = BufferList->next;
+ if(BufferList->buffers[i] != NULL)
+ DecrementRef(&BufferList->buffers[i]->ref);
}
+ al_free(BufferList);
+ BufferList = next;
+ }
+ source->queue = NULL;
- if(Source->state != AL_PAUSED)
- {
- Source->state = AL_PLAYING;
- Source->position = 0;
- Source->position_fraction = 0;
- ATOMIC_STORE(&Source->current_buffer, BufferList);
- discontinuity = AL_TRUE;
- }
- else
+ if(source->Send)
+ {
+ for(i = 0;i < num_sends;i++)
{
- Source->state = AL_PLAYING;
- discontinuity = AL_FALSE;
+ if(source->Send[i].Slot)
+ DecrementRef(&source->Send[i].Slot->ref);
+ source->Send[i].Slot = NULL;
}
+ al_free(source->Send);
+ source->Send = NULL;
+ }
+}
- // Check if an Offset has been set
- if(Source->Offset >= 0.0)
- {
- ApplyOffset(Source);
- /* discontinuity = AL_TRUE;??? */
- }
+static void UpdateSourceProps(ALsource *source, ALvoice *voice, ALsizei num_sends, ALCcontext *context)
+{
+ struct ALvoiceProps *props;
+ ALsizei i;
- /* If there's nothing to play, or device is disconnected, go right to
- * stopped */
- if(!BufferList || !device->Connected)
- goto do_stop;
+ /* Get an unused property container, or allocate a new one as needed. */
+ props = ATOMIC_LOAD(&context->FreeVoiceProps, almemory_order_acquire);
+ if(!props)
+ props = al_calloc(16, FAM_SIZE(struct ALvoiceProps, Send, num_sends));
+ else
+ {
+ struct ALvoiceProps *next;
+ do {
+ next = ATOMIC_LOAD(&props->next, almemory_order_relaxed);
+ } while(ATOMIC_COMPARE_EXCHANGE_PTR_WEAK(&context->FreeVoiceProps, &props, next,
+ almemory_order_acq_rel, almemory_order_acquire) == 0);
+ }
- /* Make sure this source isn't already active, while looking for an
- * unused active source slot to put it in. */
- for(i = 0;i < Context->VoiceCount;i++)
- {
- ALsource *old = Source;
- if(COMPARE_EXCHANGE(&Context->Voices[i].Source, &old, NULL))
- {
- if(voice == NULL)
- {
- voice = &Context->Voices[i];
- voice->Source = Source;
- }
- break;
- }
- old = NULL;
- if(voice == NULL && COMPARE_EXCHANGE(&Context->Voices[i].Source, &old, Source))
- voice = &Context->Voices[i];
- }
- if(voice == NULL)
- {
- voice = &Context->Voices[Context->VoiceCount++];
- voice->Source = Source;
- }
+ /* Copy in current property values. */
+ props->Pitch = source->Pitch;
+ props->Gain = source->Gain;
+ props->OuterGain = source->OuterGain;
+ props->MinGain = source->MinGain;
+ props->MaxGain = source->MaxGain;
+ props->InnerAngle = source->InnerAngle;
+ props->OuterAngle = source->OuterAngle;
+ props->RefDistance = source->RefDistance;
+ props->MaxDistance = source->MaxDistance;
+ props->RolloffFactor = source->RolloffFactor;
+ for(i = 0;i < 3;i++)
+ props->Position[i] = source->Position[i];
+ for(i = 0;i < 3;i++)
+ props->Velocity[i] = source->Velocity[i];
+ for(i = 0;i < 3;i++)
+ props->Direction[i] = source->Direction[i];
+ for(i = 0;i < 2;i++)
+ {
+ ALsizei j;
+ for(j = 0;j < 3;j++)
+ props->Orientation[i][j] = source->Orientation[i][j];
+ }
+ props->HeadRelative = source->HeadRelative;
+ props->DistanceModel = source->DistanceModel;
+ props->Resampler = source->Resampler;
+ props->DirectChannels = source->DirectChannels;
+ props->SpatializeMode = source->Spatialize;
- /* Clear previous samples if playback is discontinuous. */
- if(discontinuity)
- memset(voice->PrevSamples, 0, sizeof(voice->PrevSamples));
+ props->DryGainHFAuto = source->DryGainHFAuto;
+ props->WetGainAuto = source->WetGainAuto;
+ props->WetGainHFAuto = source->WetGainHFAuto;
+ props->OuterGainHF = source->OuterGainHF;
- voice->Direct.Moving = AL_FALSE;
- voice->Direct.Counter = 0;
- for(i = 0;i < MAX_INPUT_CHANNELS;i++)
- {
- ALsizei j;
- for(j = 0;j < HRTF_HISTORY_LENGTH;j++)
- voice->Direct.Hrtf[i].State.History[j] = 0.0f;
- for(j = 0;j < HRIR_LENGTH;j++)
- {
- voice->Direct.Hrtf[i].State.Values[j][0] = 0.0f;
- voice->Direct.Hrtf[i].State.Values[j][1] = 0.0f;
- }
- }
- for(i = 0;i < (ALsizei)device->NumAuxSends;i++)
- {
- voice->Send[i].Moving = AL_FALSE;
- voice->Send[i].Counter = 0;
- }
+ props->AirAbsorptionFactor = source->AirAbsorptionFactor;
+ props->RoomRolloffFactor = source->RoomRolloffFactor;
+ props->DopplerFactor = source->DopplerFactor;
- if(BufferList->buffer->FmtChannels == FmtMono)
- voice->Update = CalcSourceParams;
- else
- voice->Update = CalcNonAttnSourceParams;
+ props->StereoPan[0] = source->StereoPan[0];
+ props->StereoPan[1] = source->StereoPan[1];
- ATOMIC_STORE(&Source->NeedsUpdate, AL_TRUE);
- }
- else if(state == AL_PAUSED)
+ props->Radius = source->Radius;
+
+ props->Direct.Gain = source->Direct.Gain;
+ props->Direct.GainHF = source->Direct.GainHF;
+ props->Direct.HFReference = source->Direct.HFReference;
+ props->Direct.GainLF = source->Direct.GainLF;
+ props->Direct.LFReference = source->Direct.LFReference;
+
+ for(i = 0;i < num_sends;i++)
{
- if(Source->state == AL_PLAYING)
- Source->state = AL_PAUSED;
+ props->Send[i].Slot = source->Send[i].Slot;
+ props->Send[i].Gain = source->Send[i].Gain;
+ props->Send[i].GainHF = source->Send[i].GainHF;
+ props->Send[i].HFReference = source->Send[i].HFReference;
+ props->Send[i].GainLF = source->Send[i].GainLF;
+ props->Send[i].LFReference = source->Send[i].LFReference;
}
- else if(state == AL_STOPPED)
+
+ /* Set the new container for updating internal parameters. */
+ props = ATOMIC_EXCHANGE_PTR(&voice->Update, props, almemory_order_acq_rel);
+ if(props)
{
- do_stop:
- if(Source->state != AL_INITIAL)
- {
- Source->state = AL_STOPPED;
- ATOMIC_STORE(&Source->current_buffer, NULL);
- }
- Source->Offset = -1.0;
+ /* If there was an unused update container, put it back in the
+ * freelist.
+ */
+ ATOMIC_REPLACE_HEAD(struct ALvoiceProps*, &context->FreeVoiceProps, props);
}
- else if(state == AL_INITIAL)
+}
+
+void UpdateAllSourceProps(ALCcontext *context)
+{
+ ALsizei num_sends = context->Device->NumAuxSends;
+ ALsizei pos;
+
+ for(pos = 0;pos < context->VoiceCount;pos++)
{
- if(Source->state != AL_INITIAL)
- {
- Source->state = AL_INITIAL;
- Source->position = 0;
- Source->position_fraction = 0;
- ATOMIC_STORE(&Source->current_buffer, ATOMIC_LOAD(&Source->queue));
- }
- Source->Offset = -1.0;
+ ALvoice *voice = context->Voices[pos];
+ ALsource *source = ATOMIC_LOAD(&voice->Source, almemory_order_acquire);
+ if(source && !ATOMIC_FLAG_TEST_AND_SET(&source->PropsClean, almemory_order_acq_rel))
+ UpdateSourceProps(source, voice, num_sends, context);
}
- WriteUnlock(&Source->queue_lock);
}
+
/* GetSourceSampleOffset
*
* Gets the current read offset for the given Source, in 32.32 fixed-point
* samples. The offset is relative to the start of the queue (not the start of
* the current buffer).
*/
-ALint64 GetSourceSampleOffset(ALsource *Source)
+static ALint64 GetSourceSampleOffset(ALsource *Source, ALCcontext *context, ALuint64 *clocktime)
{
- const ALbufferlistitem *BufferList;
+ ALCdevice *device = context->Device;
const ALbufferlistitem *Current;
ALuint64 readPos;
+ ALuint refcount;
+ ALvoice *voice;
+
+ do {
+ Current = NULL;
+ readPos = 0;
+ while(((refcount=ATOMIC_LOAD(&device->MixCount, almemory_order_acquire))&1))
+ althrd_yield();
+ *clocktime = GetDeviceClockTime(device);
+
+ voice = GetSourceVoice(Source, context);
+ if(voice)
+ {
+ Current = ATOMIC_LOAD(&voice->current_buffer, almemory_order_relaxed);
- ReadLock(&Source->queue_lock);
- if(Source->state != AL_PLAYING && Source->state != AL_PAUSED)
- {
- ReadUnlock(&Source->queue_lock);
- return 0;
- }
+ readPos = (ALuint64)ATOMIC_LOAD(&voice->position, almemory_order_relaxed) << 32;
+ readPos |= (ALuint64)ATOMIC_LOAD(&voice->position_fraction, almemory_order_relaxed) <<
+ (32-FRACTIONBITS);
+ }
+ ATOMIC_THREAD_FENCE(almemory_order_acquire);
+ } while(refcount != ATOMIC_LOAD(&device->MixCount, almemory_order_relaxed));
- /* NOTE: This is the offset into the *current* buffer, so add the length of
- * any played buffers */
- readPos = (ALuint64)Source->position << 32;
- readPos |= (ALuint64)Source->position_fraction << (32-FRACTIONBITS);
- BufferList = ATOMIC_LOAD(&Source->queue);
- Current = ATOMIC_LOAD(&Source->current_buffer);
- while(BufferList && BufferList != Current)
+ if(voice)
{
- if(BufferList->buffer)
- readPos += (ALuint64)BufferList->buffer->SampleLen << 32;
- BufferList = BufferList->next;
+ const ALbufferlistitem *BufferList = Source->queue;
+ while(BufferList && BufferList != Current)
+ {
+ readPos += (ALuint64)BufferList->max_samples << 32;
+ BufferList = ATOMIC_LOAD(&CONST_CAST(ALbufferlistitem*,BufferList)->next,
+ almemory_order_relaxed);
+ }
+ readPos = minu64(readPos, U64(0x7fffffffffffffff));
}
- ReadUnlock(&Source->queue_lock);
- return (ALint64)minu64(readPos, U64(0x7fffffffffffffff));
+ return (ALint64)readPos;
}
/* GetSourceSecOffset
@@ -2739,174 +3305,171 @@ ALint64 GetSourceSampleOffset(ALsource *Source)
* Gets the current read offset for the given Source, in seconds. The offset is
* relative to the start of the queue (not the start of the current buffer).
*/
-static ALdouble GetSourceSecOffset(ALsource *Source)
+static ALdouble GetSourceSecOffset(ALsource *Source, ALCcontext *context, ALuint64 *clocktime)
{
- const ALbufferlistitem *BufferList;
+ ALCdevice *device = context->Device;
const ALbufferlistitem *Current;
- const ALbuffer *Buffer = NULL;
ALuint64 readPos;
+ ALuint refcount;
+ ALdouble offset;
+ ALvoice *voice;
+
+ do {
+ Current = NULL;
+ readPos = 0;
+ while(((refcount=ATOMIC_LOAD(&device->MixCount, almemory_order_acquire))&1))
+ althrd_yield();
+ *clocktime = GetDeviceClockTime(device);
+
+ voice = GetSourceVoice(Source, context);
+ if(voice)
+ {
+ Current = ATOMIC_LOAD(&voice->current_buffer, almemory_order_relaxed);
- ReadLock(&Source->queue_lock);
- if(Source->state != AL_PLAYING && Source->state != AL_PAUSED)
- {
- ReadUnlock(&Source->queue_lock);
- return 0.0;
- }
+ readPos = (ALuint64)ATOMIC_LOAD(&voice->position, almemory_order_relaxed) <<
+ FRACTIONBITS;
+ readPos |= ATOMIC_LOAD(&voice->position_fraction, almemory_order_relaxed);
+ }
+ ATOMIC_THREAD_FENCE(almemory_order_acquire);
+ } while(refcount != ATOMIC_LOAD(&device->MixCount, almemory_order_relaxed));
- /* NOTE: This is the offset into the *current* buffer, so add the length of
- * any played buffers */
- readPos = (ALuint64)Source->position << FRACTIONBITS;
- readPos |= (ALuint64)Source->position_fraction;
- BufferList = ATOMIC_LOAD(&Source->queue);
- Current = ATOMIC_LOAD(&Source->current_buffer);
- while(BufferList && BufferList != Current)
+ offset = 0.0;
+ if(voice)
{
- const ALbuffer *buffer = BufferList->buffer;
- if(buffer != NULL)
+ const ALbufferlistitem *BufferList = Source->queue;
+ const ALbuffer *BufferFmt = NULL;
+ while(BufferList && BufferList != Current)
{
- if(!Buffer) Buffer = buffer;
- readPos += (ALuint64)buffer->SampleLen << FRACTIONBITS;
+ ALsizei i = 0;
+ while(!BufferFmt && i < BufferList->num_buffers)
+ BufferFmt = BufferList->buffers[i++];
+ readPos += (ALuint64)BufferList->max_samples << FRACTIONBITS;
+ BufferList = ATOMIC_LOAD(&CONST_CAST(ALbufferlistitem*,BufferList)->next,
+ almemory_order_relaxed);
}
- BufferList = BufferList->next;
- }
- while(BufferList && !Buffer)
- {
- Buffer = BufferList->buffer;
- BufferList = BufferList->next;
+ while(BufferList && !BufferFmt)
+ {
+ ALsizei i = 0;
+ while(!BufferFmt && i < BufferList->num_buffers)
+ BufferFmt = BufferList->buffers[i++];
+ BufferList = ATOMIC_LOAD(&CONST_CAST(ALbufferlistitem*,BufferList)->next,
+ almemory_order_relaxed);
+ }
+ assert(BufferFmt != NULL);
+
+ offset = (ALdouble)readPos / (ALdouble)FRACTIONONE /
+ (ALdouble)BufferFmt->Frequency;
}
- assert(Buffer != NULL);
- ReadUnlock(&Source->queue_lock);
- return (ALdouble)readPos / (ALdouble)FRACTIONONE / (ALdouble)Buffer->Frequency;
+ return offset;
}
-/* GetSourceOffsets
+/* GetSourceOffset
*
- * Gets the current read and write offsets for the given Source, in the
- * appropriate format (Bytes, Samples or Seconds). The offsets are relative to
- * the start of the queue (not the start of the current buffer).
+ * Gets the current read offset for the given Source, in the appropriate format
+ * (Bytes, Samples or Seconds). The offset is relative to the start of the
+ * queue (not the start of the current buffer).
*/
-static ALvoid GetSourceOffsets(ALsource *Source, ALenum name, ALdouble *offset, ALdouble updateLen)
+static ALdouble GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context)
{
- const ALbufferlistitem *BufferList;
+ ALCdevice *device = context->Device;
const ALbufferlistitem *Current;
- const ALbuffer *Buffer = NULL;
- ALboolean readFin = AL_FALSE;
- ALuint readPos, readPosFrac, writePos;
- ALuint totalBufferLen;
-
- ReadLock(&Source->queue_lock);
- if(Source->state != AL_PLAYING && Source->state != AL_PAUSED)
- {
- offset[0] = 0.0;
- offset[1] = 0.0;
- ReadUnlock(&Source->queue_lock);
- return;
- }
+ ALuint readPos;
+ ALsizei readPosFrac;
+ ALuint refcount;
+ ALdouble offset;
+ ALvoice *voice;
+
+ do {
+ Current = NULL;
+ readPos = readPosFrac = 0;
+ while(((refcount=ATOMIC_LOAD(&device->MixCount, almemory_order_acquire))&1))
+ althrd_yield();
+ voice = GetSourceVoice(Source, context);
+ if(voice)
+ {
+ Current = ATOMIC_LOAD(&voice->current_buffer, almemory_order_relaxed);
- if(updateLen > 0.0 && updateLen < 0.015)
- updateLen = 0.015;
+ readPos = ATOMIC_LOAD(&voice->position, almemory_order_relaxed);
+ readPosFrac = ATOMIC_LOAD(&voice->position_fraction, almemory_order_relaxed);
+ }
+ ATOMIC_THREAD_FENCE(almemory_order_acquire);
+ } while(refcount != ATOMIC_LOAD(&device->MixCount, almemory_order_relaxed));
- /* NOTE: This is the offset into the *current* buffer, so add the length of
- * any played buffers */
- totalBufferLen = 0;
- readPos = Source->position;
- readPosFrac = Source->position_fraction;
- BufferList = ATOMIC_LOAD(&Source->queue);
- Current = ATOMIC_LOAD(&Source->current_buffer);
- while(BufferList != NULL)
+ offset = 0.0;
+ if(voice)
{
- const ALbuffer *buffer;
- readFin = readFin || (BufferList == Current);
- if((buffer=BufferList->buffer) != NULL)
+ const ALbufferlistitem *BufferList = Source->queue;
+ const ALbuffer *BufferFmt = NULL;
+ ALboolean readFin = AL_FALSE;
+ ALuint totalBufferLen = 0;
+
+ while(BufferList != NULL)
{
- if(!Buffer) Buffer = buffer;
- totalBufferLen += buffer->SampleLen;
- if(!readFin) readPos += buffer->SampleLen;
+ ALsizei i = 0;
+ while(!BufferFmt && i < BufferList->num_buffers)
+ BufferFmt = BufferList->buffers[i++];
+
+ readFin |= (BufferList == Current);
+ totalBufferLen += BufferList->max_samples;
+ if(!readFin) readPos += BufferList->max_samples;
+
+ BufferList = ATOMIC_LOAD(&CONST_CAST(ALbufferlistitem*,BufferList)->next,
+ almemory_order_relaxed);
}
- BufferList = BufferList->next;
- }
- assert(Buffer != NULL);
+ assert(BufferFmt != NULL);
- if(Source->state == AL_PLAYING)
- writePos = readPos + (ALuint)(updateLen*Buffer->Frequency + 0.5f);
- else
- writePos = readPos;
+ if(Source->Looping)
+ readPos %= totalBufferLen;
+ else
+ {
+ /* Wrap back to 0 */
+ if(readPos >= totalBufferLen)
+ readPos = readPosFrac = 0;
+ }
- if(Source->Looping)
- {
- readPos %= totalBufferLen;
- writePos %= totalBufferLen;
- }
- else
- {
- /* Wrap positions back to 0 */
- if(readPos >= totalBufferLen)
- readPos = readPosFrac = 0;
- if(writePos >= totalBufferLen)
- writePos = 0;
- }
+ offset = 0.0;
+ switch(name)
+ {
+ case AL_SEC_OFFSET:
+ offset = (readPos + (ALdouble)readPosFrac/FRACTIONONE) / BufferFmt->Frequency;
+ break;
- switch(name)
- {
- case AL_SEC_OFFSET:
- offset[0] = (readPos + (ALdouble)readPosFrac/FRACTIONONE)/Buffer->Frequency;
- offset[1] = (ALdouble)writePos/Buffer->Frequency;
- break;
+ case AL_SAMPLE_OFFSET:
+ offset = readPos + (ALdouble)readPosFrac/FRACTIONONE;
+ break;
- case AL_SAMPLE_OFFSET:
- case AL_SAMPLE_RW_OFFSETS_SOFT:
- offset[0] = readPos + (ALdouble)readPosFrac/FRACTIONONE;
- offset[1] = (ALdouble)writePos;
- break;
+ case AL_BYTE_OFFSET:
+ if(BufferFmt->OriginalType == UserFmtIMA4)
+ {
+ ALsizei align = (BufferFmt->OriginalAlign-1)/2 + 4;
+ ALuint BlockSize = align * ChannelsFromFmt(BufferFmt->FmtChannels);
+ ALuint FrameBlockSize = BufferFmt->OriginalAlign;
- case AL_BYTE_OFFSET:
- case AL_BYTE_RW_OFFSETS_SOFT:
- if(Buffer->OriginalType == UserFmtIMA4)
- {
- ALsizei align = (Buffer->OriginalAlign-1)/2 + 4;
- ALuint BlockSize = align * ChannelsFromFmt(Buffer->FmtChannels);
- ALuint FrameBlockSize = Buffer->OriginalAlign;
-
- /* Round down to nearest ADPCM block */
- offset[0] = (ALdouble)(readPos / FrameBlockSize * BlockSize);
- if(Source->state != AL_PLAYING)
- offset[1] = offset[0];
- else
+ /* Round down to nearest ADPCM block */
+ offset = (ALdouble)(readPos / FrameBlockSize * BlockSize);
+ }
+ else if(BufferFmt->OriginalType == UserFmtMSADPCM)
{
- /* Round up to nearest ADPCM block */
- offset[1] = (ALdouble)((writePos+FrameBlockSize-1) /
- FrameBlockSize * BlockSize);
+ ALsizei align = (BufferFmt->OriginalAlign-2)/2 + 7;
+ ALuint BlockSize = align * ChannelsFromFmt(BufferFmt->FmtChannels);
+ ALuint FrameBlockSize = BufferFmt->OriginalAlign;
+
+ /* Round down to nearest ADPCM block */
+ offset = (ALdouble)(readPos / FrameBlockSize * BlockSize);
}
- }
- else if(Buffer->OriginalType == UserFmtMSADPCM)
- {
- ALsizei align = (Buffer->OriginalAlign-2)/2 + 7;
- ALuint BlockSize = align * ChannelsFromFmt(Buffer->FmtChannels);
- ALuint FrameBlockSize = Buffer->OriginalAlign;
-
- /* Round down to nearest ADPCM block */
- offset[0] = (ALdouble)(readPos / FrameBlockSize * BlockSize);
- if(Source->state != AL_PLAYING)
- offset[1] = offset[0];
else
{
- /* Round up to nearest ADPCM block */
- offset[1] = (ALdouble)((writePos+FrameBlockSize-1) /
- FrameBlockSize * BlockSize);
+ ALuint FrameSize = FrameSizeFromFmt(BufferFmt->FmtChannels,
+ BufferFmt->FmtType);
+ offset = (ALdouble)(readPos * FrameSize);
}
- }
- else
- {
- ALuint FrameSize = FrameSizeFromUserFmt(Buffer->OriginalChannels, Buffer->OriginalType);
- offset[0] = (ALdouble)(readPos * FrameSize);
- offset[1] = (ALdouble)(writePos * FrameSize);
- }
- break;
+ break;
+ }
}
- ReadUnlock(&Source->queue_lock);
+ return offset;
}
@@ -2915,37 +3478,32 @@ static ALvoid GetSourceOffsets(ALsource *Source, ALenum name, ALdouble *offset,
* Apply the stored playback offset to the Source. This function will update
* the number of buffers "played" given the stored offset.
*/
-ALboolean ApplyOffset(ALsource *Source)
+static ALboolean ApplyOffset(ALsource *Source, ALvoice *voice)
{
ALbufferlistitem *BufferList;
- const ALbuffer *Buffer;
- ALuint bufferLen, totalBufferLen;
- ALuint offset=0, frac=0;
+ ALuint totalBufferLen;
+ ALuint offset = 0;
+ ALsizei frac = 0;
/* Get sample frame offset */
if(!GetSampleOffset(Source, &offset, &frac))
return AL_FALSE;
totalBufferLen = 0;
- BufferList = ATOMIC_LOAD(&Source->queue);
+ BufferList = Source->queue;
while(BufferList && totalBufferLen <= offset)
{
- Buffer = BufferList->buffer;
- bufferLen = Buffer ? Buffer->SampleLen : 0;
-
- if(bufferLen > offset-totalBufferLen)
+ if((ALuint)BufferList->max_samples > offset-totalBufferLen)
{
/* Offset is in this buffer */
- ATOMIC_STORE(&Source->current_buffer, BufferList);
-
- Source->position = offset - totalBufferLen;
- Source->position_fraction = frac;
+ ATOMIC_STORE(&voice->position, offset - totalBufferLen, almemory_order_relaxed);
+ ATOMIC_STORE(&voice->position_fraction, frac, almemory_order_relaxed);
+ ATOMIC_STORE(&voice->current_buffer, BufferList, almemory_order_release);
return AL_TRUE;
}
+ totalBufferLen += BufferList->max_samples;
- totalBufferLen += bufferLen;
-
- BufferList = BufferList->next;
+ BufferList = ATOMIC_LOAD(&BufferList->next, almemory_order_relaxed);
}
/* Offset is out of range of the queue */
@@ -2959,26 +3517,27 @@ ALboolean ApplyOffset(ALsource *Source)
* or Second offset supplied by the application). This takes into account the
* fact that the buffer format may have been modifed since.
*/
-static ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALuint *frac)
+static ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALsizei *frac)
{
- const ALbuffer *Buffer = NULL;
+ const ALbuffer *BufferFmt = NULL;
const ALbufferlistitem *BufferList;
ALdouble dbloff, dblfrac;
/* Find the first valid Buffer in the Queue */
- BufferList = ATOMIC_LOAD(&Source->queue);
+ BufferList = Source->queue;
while(BufferList)
{
- if(BufferList->buffer)
- {
- Buffer = BufferList->buffer;
- break;
- }
- BufferList = BufferList->next;
+ ALsizei i;
+ for(i = 0;i < BufferList->num_buffers && !BufferFmt;i++)
+ BufferFmt = BufferList->buffers[i];
+ if(BufferFmt) break;
+ BufferList = ATOMIC_LOAD(&CONST_CAST(ALbufferlistitem*,BufferList)->next,
+ almemory_order_relaxed);
}
- if(!Buffer)
+ if(!BufferFmt)
{
- Source->Offset = -1.0;
+ Source->OffsetType = AL_NONE;
+ Source->Offset = 0.0;
return AL_FALSE;
}
@@ -2987,74 +3546,160 @@ static ALboolean GetSampleOffset(ALsource *Source, ALuint *offset, ALuint *frac)
case AL_BYTE_OFFSET:
/* Determine the ByteOffset (and ensure it is block aligned) */
*offset = (ALuint)Source->Offset;
- if(Buffer->OriginalType == UserFmtIMA4)
+ if(BufferFmt->OriginalType == UserFmtIMA4)
{
- ALsizei align = (Buffer->OriginalAlign-1)/2 + 4;
- *offset /= align * ChannelsFromUserFmt(Buffer->OriginalChannels);
- *offset *= Buffer->OriginalAlign;
+ ALsizei align = (BufferFmt->OriginalAlign-1)/2 + 4;
+ *offset /= align * ChannelsFromFmt(BufferFmt->FmtChannels);
+ *offset *= BufferFmt->OriginalAlign;
}
- else if(Buffer->OriginalType == UserFmtMSADPCM)
+ else if(BufferFmt->OriginalType == UserFmtMSADPCM)
{
- ALsizei align = (Buffer->OriginalAlign-2)/2 + 7;
- *offset /= align * ChannelsFromUserFmt(Buffer->OriginalChannels);
- *offset *= Buffer->OriginalAlign;
+ ALsizei align = (BufferFmt->OriginalAlign-2)/2 + 7;
+ *offset /= align * ChannelsFromFmt(BufferFmt->FmtChannels);
+ *offset *= BufferFmt->OriginalAlign;
}
else
- *offset /= FrameSizeFromUserFmt(Buffer->OriginalChannels, Buffer->OriginalType);
+ *offset /= FrameSizeFromFmt(BufferFmt->FmtChannels, BufferFmt->FmtType);
*frac = 0;
break;
case AL_SAMPLE_OFFSET:
dblfrac = modf(Source->Offset, &dbloff);
*offset = (ALuint)mind(dbloff, UINT_MAX);
- *frac = (ALuint)mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0);
+ *frac = (ALsizei)mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0);
break;
case AL_SEC_OFFSET:
- dblfrac = modf(Source->Offset*Buffer->Frequency, &dbloff);
+ dblfrac = modf(Source->Offset*BufferFmt->Frequency, &dbloff);
*offset = (ALuint)mind(dbloff, UINT_MAX);
- *frac = (ALuint)mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0);
+ *frac = (ALsizei)mind(dblfrac*FRACTIONONE, FRACTIONONE-1.0);
break;
}
- Source->Offset = -1.0;
+ Source->OffsetType = AL_NONE;
+ Source->Offset = 0.0;
return AL_TRUE;
}
+static ALsource *AllocSource(ALCcontext *context)
+{
+ ALCdevice *device = context->Device;
+ SourceSubList *sublist, *subend;
+ ALsource *source = NULL;
+ ALsizei lidx = 0;
+ ALsizei slidx;
+
+ almtx_lock(&context->SourceLock);
+ if(context->NumSources >= device->SourcesMax)
+ {
+ almtx_unlock(&context->SourceLock);
+ alSetError(context, AL_OUT_OF_MEMORY, "Exceeding %u source limit", device->SourcesMax);
+ return NULL;
+ }
+ sublist = VECTOR_BEGIN(context->SourceList);
+ subend = VECTOR_END(context->SourceList);
+ for(;sublist != subend;++sublist)
+ {
+ if(sublist->FreeMask)
+ {
+ slidx = CTZ64(sublist->FreeMask);
+ source = sublist->Sources + slidx;
+ break;
+ }
+ ++lidx;
+ }
+ if(UNLIKELY(!source))
+ {
+ const SourceSubList empty_sublist = { 0, NULL };
+ /* Don't allocate so many list entries that the 32-bit ID could
+ * overflow...
+ */
+ if(UNLIKELY(VECTOR_SIZE(context->SourceList) >= 1<<25))
+ {
+ almtx_unlock(&device->BufferLock);
+ alSetError(context, AL_OUT_OF_MEMORY, "Too many sources allocated");
+ return NULL;
+ }
+ lidx = (ALsizei)VECTOR_SIZE(context->SourceList);
+ VECTOR_PUSH_BACK(context->SourceList, empty_sublist);
+ sublist = &VECTOR_BACK(context->SourceList);
+ sublist->FreeMask = ~U64(0);
+ sublist->Sources = al_calloc(16, sizeof(ALsource)*64);
+ if(UNLIKELY(!sublist->Sources))
+ {
+ VECTOR_POP_BACK(context->SourceList);
+ almtx_unlock(&context->SourceLock);
+ alSetError(context, AL_OUT_OF_MEMORY, "Failed to allocate source batch");
+ return NULL;
+ }
+
+ slidx = 0;
+ source = sublist->Sources + slidx;
+ }
+
+ memset(source, 0, sizeof(*source));
+ InitSourceParams(source, device->NumAuxSends);
+
+ /* Add 1 to avoid source ID 0. */
+ source->id = ((lidx<<6) | slidx) + 1;
+
+ context->NumSources++;
+ sublist->FreeMask &= ~(U64(1)<<slidx);
+ almtx_unlock(&context->SourceLock);
+
+ return source;
+}
+
+static void FreeSource(ALCcontext *context, ALsource *source)
+{
+ ALCdevice *device = context->Device;
+ ALuint id = source->id - 1;
+ ALsizei lidx = id >> 6;
+ ALsizei slidx = id & 0x3f;
+ ALvoice *voice;
+
+ ALCdevice_Lock(device);
+ if((voice=GetSourceVoice(source, context)) != NULL)
+ {
+ ATOMIC_STORE(&voice->Source, NULL, almemory_order_relaxed);
+ ATOMIC_STORE(&voice->Playing, false, almemory_order_release);
+ }
+ ALCdevice_Unlock(device);
+
+ DeinitSource(source, device->NumAuxSends);
+ memset(source, 0, sizeof(*source));
+
+ VECTOR_ELEM(context->SourceList, lidx).FreeMask |= U64(1) << slidx;
+ context->NumSources--;
+}
+
/* ReleaseALSources
*
* Destroys all sources in the source map.
*/
-ALvoid ReleaseALSources(ALCcontext *Context)
+ALvoid ReleaseALSources(ALCcontext *context)
{
- ALbufferlistitem *item;
- ALsizei pos;
- ALuint j;
- for(pos = 0;pos < Context->SourceMap.size;pos++)
+ ALCdevice *device = context->Device;
+ SourceSubList *sublist = VECTOR_BEGIN(context->SourceList);
+ SourceSubList *subend = VECTOR_END(context->SourceList);
+ size_t leftover = 0;
+ for(;sublist != subend;++sublist)
{
- ALsource *temp = Context->SourceMap.array[pos].value;
- Context->SourceMap.array[pos].value = NULL;
-
- item = ATOMIC_EXCHANGE(ALbufferlistitem*, &temp->queue, NULL);
- while(item != NULL)
+ ALuint64 usemask = ~sublist->FreeMask;
+ while(usemask)
{
- ALbufferlistitem *next = item->next;
- if(item->buffer != NULL)
- DecrementRef(&item->buffer->ref);
- free(item);
- item = next;
- }
+ ALsizei idx = CTZ64(usemask);
+ ALsource *source = sublist->Sources + idx;
- for(j = 0;j < MAX_SENDS;++j)
- {
- if(temp->Send[j].Slot)
- DecrementRef(&temp->Send[j].Slot->ref);
- temp->Send[j].Slot = NULL;
- }
+ DeinitSource(source, device->NumAuxSends);
+ memset(source, 0, sizeof(*source));
+ ++leftover;
- FreeThunkEntry(temp->id);
- memset(temp, 0, sizeof(*temp));
- al_free(temp);
+ usemask &= ~(U64(1) << idx);
+ }
+ sublist->FreeMask = ~usemask;
}
+ if(leftover > 0)
+ WARN("(%p) Deleted "SZFMT" Source%s\n", device, leftover, (leftover==1)?"":"s");
}
diff --git a/OpenAL32/alState.c b/OpenAL32/alState.c
index dca41363..ce93e143 100644
--- a/OpenAL32/alState.c
+++ b/OpenAL32/alState.c
@@ -20,12 +20,15 @@
#include "config.h"
+#include "version.h"
+
#include <stdlib.h>
#include "alMain.h"
#include "AL/alc.h"
#include "AL/al.h"
#include "AL/alext.h"
#include "alError.h"
+#include "alListener.h"
#include "alSource.h"
#include "alAuxEffectSlot.h"
@@ -44,6 +47,31 @@ static const ALchar alErrInvalidValue[] = "Invalid Value";
static const ALchar alErrInvalidOp[] = "Invalid Operation";
static const ALchar alErrOutOfMemory[] = "Out of Memory";
+/* Resampler strings */
+static const ALchar alPointResampler[] = "Nearest";
+static const ALchar alLinearResampler[] = "Linear";
+static const ALchar alCubicResampler[] = "Cubic";
+static const ALchar alBSinc12Resampler[] = "11th order Sinc";
+static const ALchar alBSinc24Resampler[] = "23rd order Sinc";
+
+/* WARNING: Non-standard export! Not part of any extension, or exposed in the
+ * alcFunctions list.
+ */
+AL_API const ALchar* AL_APIENTRY alsoft_get_version(void)
+{
+ const char *spoof = getenv("ALSOFT_SPOOF_VERSION");
+ if(spoof && spoof[0] != '\0') return spoof;
+ return ALSOFT_VERSION;
+}
+
+#define DO_UPDATEPROPS() do { \
+ if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) \
+ UpdateContextProps(context); \
+ else \
+ ATOMIC_FLAG_CLEAR(&context->PropsClean, almemory_order_release); \
+} while(0)
+
+
AL_API ALvoid AL_APIENTRY alEnable(ALenum capability)
{
ALCcontext *context;
@@ -51,18 +79,19 @@ AL_API ALvoid AL_APIENTRY alEnable(ALenum capability)
context = GetContextRef();
if(!context) return;
+ almtx_lock(&context->PropLock);
switch(capability)
{
case AL_SOURCE_DISTANCE_MODEL:
context->SourceDistanceModel = AL_TRUE;
- ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
+ DO_UPDATEPROPS();
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_VALUE, "Invalid enable property 0x%04x", capability);
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
}
@@ -73,18 +102,19 @@ AL_API ALvoid AL_APIENTRY alDisable(ALenum capability)
context = GetContextRef();
if(!context) return;
+ almtx_lock(&context->PropLock);
switch(capability)
{
case AL_SOURCE_DISTANCE_MODEL:
context->SourceDistanceModel = AL_FALSE;
- ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
+ DO_UPDATEPROPS();
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_VALUE, "Invalid disable property 0x%04x", capability);
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
}
@@ -96,6 +126,7 @@ AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability)
context = GetContextRef();
if(!context) return AL_FALSE;
+ almtx_lock(&context->PropLock);
switch(capability)
{
case AL_SOURCE_DISTANCE_MODEL:
@@ -103,12 +134,11 @@ AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability)
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_VALUE, "Invalid is enabled property 0x%04x", capability);
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
-
return value;
}
@@ -120,6 +150,7 @@ AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname)
context = GetContextRef();
if(!context) return AL_FALSE;
+ almtx_lock(&context->PropLock);
switch(pname)
{
case AL_DOPPLER_FACTOR:
@@ -143,16 +174,30 @@ AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname)
break;
case AL_DEFERRED_UPDATES_SOFT:
- value = context->DeferUpdates;
+ if(ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire))
+ value = AL_TRUE;
+ break;
+
+ case AL_GAIN_LIMIT_SOFT:
+ if(GAIN_MIX_MAX/context->GainBoost != 0.0f)
+ value = AL_TRUE;
+ break;
+
+ case AL_NUM_RESAMPLERS_SOFT:
+ /* Always non-0. */
+ value = AL_TRUE;
+ break;
+
+ case AL_DEFAULT_RESAMPLER_SOFT:
+ value = ResamplerDefault ? AL_TRUE : AL_FALSE;
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_VALUE, "Invalid boolean property 0x%04x", pname);
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
-
return value;
}
@@ -164,6 +209,7 @@ AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname)
context = GetContextRef();
if(!context) return 0.0;
+ almtx_lock(&context->PropLock);
switch(pname)
{
case AL_DOPPLER_FACTOR:
@@ -183,16 +229,28 @@ AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname)
break;
case AL_DEFERRED_UPDATES_SOFT:
- value = (ALdouble)context->DeferUpdates;
+ if(ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire))
+ value = (ALdouble)AL_TRUE;
+ break;
+
+ case AL_GAIN_LIMIT_SOFT:
+ value = (ALdouble)GAIN_MIX_MAX/context->GainBoost;
+ break;
+
+ case AL_NUM_RESAMPLERS_SOFT:
+ value = (ALdouble)(ResamplerMax + 1);
+ break;
+
+ case AL_DEFAULT_RESAMPLER_SOFT:
+ value = (ALdouble)ResamplerDefault;
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_VALUE, "Invalid double property 0x%04x", pname);
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
-
return value;
}
@@ -204,6 +262,7 @@ AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname)
context = GetContextRef();
if(!context) return 0.0f;
+ almtx_lock(&context->PropLock);
switch(pname)
{
case AL_DOPPLER_FACTOR:
@@ -223,16 +282,28 @@ AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname)
break;
case AL_DEFERRED_UPDATES_SOFT:
- value = (ALfloat)context->DeferUpdates;
+ if(ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire))
+ value = (ALfloat)AL_TRUE;
+ break;
+
+ case AL_GAIN_LIMIT_SOFT:
+ value = GAIN_MIX_MAX/context->GainBoost;
+ break;
+
+ case AL_NUM_RESAMPLERS_SOFT:
+ value = (ALfloat)(ResamplerMax + 1);
+ break;
+
+ case AL_DEFAULT_RESAMPLER_SOFT:
+ value = (ALfloat)ResamplerDefault;
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_VALUE, "Invalid float property 0x%04x", pname);
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
-
return value;
}
@@ -244,6 +315,7 @@ AL_API ALint AL_APIENTRY alGetInteger(ALenum pname)
context = GetContextRef();
if(!context) return 0;
+ almtx_lock(&context->PropLock);
switch(pname)
{
case AL_DOPPLER_FACTOR:
@@ -263,16 +335,28 @@ AL_API ALint AL_APIENTRY alGetInteger(ALenum pname)
break;
case AL_DEFERRED_UPDATES_SOFT:
- value = (ALint)context->DeferUpdates;
+ if(ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire))
+ value = (ALint)AL_TRUE;
+ break;
+
+ case AL_GAIN_LIMIT_SOFT:
+ value = (ALint)(GAIN_MIX_MAX/context->GainBoost);
+ break;
+
+ case AL_NUM_RESAMPLERS_SOFT:
+ value = ResamplerMax + 1;
+ break;
+
+ case AL_DEFAULT_RESAMPLER_SOFT:
+ value = ResamplerDefault;
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_VALUE, "Invalid integer property 0x%04x", pname);
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
-
return value;
}
@@ -284,6 +368,7 @@ AL_API ALint64SOFT AL_APIENTRY alGetInteger64SOFT(ALenum pname)
context = GetContextRef();
if(!context) return 0;
+ almtx_lock(&context->PropLock);
switch(pname)
{
case AL_DOPPLER_FACTOR:
@@ -303,16 +388,56 @@ AL_API ALint64SOFT AL_APIENTRY alGetInteger64SOFT(ALenum pname)
break;
case AL_DEFERRED_UPDATES_SOFT:
- value = (ALint64SOFT)context->DeferUpdates;
+ if(ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire))
+ value = (ALint64SOFT)AL_TRUE;
+ break;
+
+ case AL_GAIN_LIMIT_SOFT:
+ value = (ALint64SOFT)(GAIN_MIX_MAX/context->GainBoost);
+ break;
+
+ case AL_NUM_RESAMPLERS_SOFT:
+ value = (ALint64SOFT)(ResamplerMax + 1);
+ break;
+
+ case AL_DEFAULT_RESAMPLER_SOFT:
+ value = (ALint64SOFT)ResamplerDefault;
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_VALUE, "Invalid integer64 property 0x%04x", pname);
}
+ almtx_unlock(&context->PropLock);
-done:
ALCcontext_DecRef(context);
+ return value;
+}
+
+AL_API void* AL_APIENTRY alGetPointerSOFT(ALenum pname)
+{
+ ALCcontext *context;
+ void *value = NULL;
+ context = GetContextRef();
+ if(!context) return NULL;
+
+ almtx_lock(&context->PropLock);
+ switch(pname)
+ {
+ case AL_EVENT_CALLBACK_FUNCTION_SOFT:
+ value = context->EventCb;
+ break;
+
+ case AL_EVENT_CALLBACK_USER_PARAM_SOFT:
+ value = context->EventParam;
+ break;
+
+ default:
+ alSetError(context, AL_INVALID_VALUE, "Invalid pointer property 0x%04x", pname);
+ }
+ almtx_unlock(&context->PropLock);
+
+ ALCcontext_DecRef(context);
return value;
}
@@ -329,6 +454,9 @@ AL_API ALvoid AL_APIENTRY alGetBooleanv(ALenum pname, ALboolean *values)
case AL_DISTANCE_MODEL:
case AL_SPEED_OF_SOUND:
case AL_DEFERRED_UPDATES_SOFT:
+ case AL_GAIN_LIMIT_SOFT:
+ case AL_NUM_RESAMPLERS_SOFT:
+ case AL_DEFAULT_RESAMPLER_SOFT:
values[0] = alGetBoolean(pname);
return;
}
@@ -337,15 +465,14 @@ AL_API ALvoid AL_APIENTRY alGetBooleanv(ALenum pname, ALboolean *values)
context = GetContextRef();
if(!context) return;
- if(!(values))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ if(!values)
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
switch(pname)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_VALUE, "Invalid boolean-vector property 0x%04x", pname);
}
-done:
ALCcontext_DecRef(context);
}
@@ -362,6 +489,9 @@ AL_API ALvoid AL_APIENTRY alGetDoublev(ALenum pname, ALdouble *values)
case AL_DISTANCE_MODEL:
case AL_SPEED_OF_SOUND:
case AL_DEFERRED_UPDATES_SOFT:
+ case AL_GAIN_LIMIT_SOFT:
+ case AL_NUM_RESAMPLERS_SOFT:
+ case AL_DEFAULT_RESAMPLER_SOFT:
values[0] = alGetDouble(pname);
return;
}
@@ -370,15 +500,14 @@ AL_API ALvoid AL_APIENTRY alGetDoublev(ALenum pname, ALdouble *values)
context = GetContextRef();
if(!context) return;
- if(!(values))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ if(!values)
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
switch(pname)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_VALUE, "Invalid double-vector property 0x%04x", pname);
}
-done:
ALCcontext_DecRef(context);
}
@@ -395,6 +524,9 @@ AL_API ALvoid AL_APIENTRY alGetFloatv(ALenum pname, ALfloat *values)
case AL_DISTANCE_MODEL:
case AL_SPEED_OF_SOUND:
case AL_DEFERRED_UPDATES_SOFT:
+ case AL_GAIN_LIMIT_SOFT:
+ case AL_NUM_RESAMPLERS_SOFT:
+ case AL_DEFAULT_RESAMPLER_SOFT:
values[0] = alGetFloat(pname);
return;
}
@@ -403,15 +535,14 @@ AL_API ALvoid AL_APIENTRY alGetFloatv(ALenum pname, ALfloat *values)
context = GetContextRef();
if(!context) return;
- if(!(values))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ if(!values)
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
switch(pname)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_VALUE, "Invalid float-vector property 0x%04x", pname);
}
-done:
ALCcontext_DecRef(context);
}
@@ -428,6 +559,9 @@ AL_API ALvoid AL_APIENTRY alGetIntegerv(ALenum pname, ALint *values)
case AL_DISTANCE_MODEL:
case AL_SPEED_OF_SOUND:
case AL_DEFERRED_UPDATES_SOFT:
+ case AL_GAIN_LIMIT_SOFT:
+ case AL_NUM_RESAMPLERS_SOFT:
+ case AL_DEFAULT_RESAMPLER_SOFT:
values[0] = alGetInteger(pname);
return;
}
@@ -436,13 +570,14 @@ AL_API ALvoid AL_APIENTRY alGetIntegerv(ALenum pname, ALint *values)
context = GetContextRef();
if(!context) return;
+ if(!values)
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
switch(pname)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_VALUE, "Invalid integer-vector property 0x%04x", pname);
}
-done:
ALCcontext_DecRef(context);
}
@@ -459,6 +594,9 @@ AL_API void AL_APIENTRY alGetInteger64vSOFT(ALenum pname, ALint64SOFT *values)
case AL_DISTANCE_MODEL:
case AL_SPEED_OF_SOUND:
case AL_DEFERRED_UPDATES_SOFT:
+ case AL_GAIN_LIMIT_SOFT:
+ case AL_NUM_RESAMPLERS_SOFT:
+ case AL_DEFAULT_RESAMPLER_SOFT:
values[0] = alGetInteger64SOFT(pname);
return;
}
@@ -467,13 +605,43 @@ AL_API void AL_APIENTRY alGetInteger64vSOFT(ALenum pname, ALint64SOFT *values)
context = GetContextRef();
if(!context) return;
+ if(!values)
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
switch(pname)
{
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_VALUE, "Invalid integer64-vector property 0x%04x", pname);
+ }
+
+ ALCcontext_DecRef(context);
+}
+
+AL_API void AL_APIENTRY alGetPointervSOFT(ALenum pname, void **values)
+{
+ ALCcontext *context;
+
+ if(values)
+ {
+ switch(pname)
+ {
+ case AL_EVENT_CALLBACK_FUNCTION_SOFT:
+ case AL_EVENT_CALLBACK_USER_PARAM_SOFT:
+ values[0] = alGetPointerSOFT(pname);
+ return;
+ }
+ }
+
+ context = GetContextRef();
+ if(!context) return;
+
+ if(!values)
+ alSetError(context, AL_INVALID_VALUE, "NULL pointer");
+ switch(pname)
+ {
+ default:
+ alSetError(context, AL_INVALID_VALUE, "Invalid pointer-vector property 0x%04x", pname);
}
-done:
ALCcontext_DecRef(context);
}
@@ -528,12 +696,10 @@ AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname)
break;
default:
- SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
+ alSetError(context, AL_INVALID_VALUE, "Invalid string property 0x%04x", pname);
}
-done:
ALCcontext_DecRef(context);
-
return value;
}
@@ -545,12 +711,15 @@ AL_API ALvoid AL_APIENTRY alDopplerFactor(ALfloat value)
if(!context) return;
if(!(value >= 0.0f && isfinite(value)))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- context->DopplerFactor = value;
- ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
+ alSetError(context, AL_INVALID_VALUE, "Doppler factor %f out of range", value);
+ else
+ {
+ almtx_lock(&context->PropLock);
+ context->DopplerFactor = value;
+ DO_UPDATEPROPS();
+ almtx_unlock(&context->PropLock);
+ }
-done:
ALCcontext_DecRef(context);
}
@@ -561,13 +730,30 @@ AL_API ALvoid AL_APIENTRY alDopplerVelocity(ALfloat value)
context = GetContextRef();
if(!context) return;
- if(!(value >= 0.0f && isfinite(value)))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ if((ATOMIC_LOAD(&context->EnabledEvts, almemory_order_relaxed)&EventType_Deprecated))
+ {
+ static const ALCchar msg[] =
+ "alDopplerVelocity is deprecated in AL1.1, use alSpeedOfSound";
+ const ALsizei msglen = (ALsizei)strlen(msg);
+ ALbitfieldSOFT enabledevts;
+ almtx_lock(&context->EventCbLock);
+ enabledevts = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_relaxed);
+ if((enabledevts&EventType_Deprecated) && context->EventCb)
+ (*context->EventCb)(AL_EVENT_TYPE_DEPRECATED_SOFT, 0, 0, msglen, msg,
+ context->EventParam);
+ almtx_unlock(&context->EventCbLock);
+ }
- context->DopplerVelocity = value;
- ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
+ if(!(value >= 0.0f && isfinite(value)))
+ alSetError(context, AL_INVALID_VALUE, "Doppler velocity %f out of range", value);
+ else
+ {
+ almtx_lock(&context->PropLock);
+ context->DopplerVelocity = value;
+ DO_UPDATEPROPS();
+ almtx_unlock(&context->PropLock);
+ }
-done:
ALCcontext_DecRef(context);
}
@@ -579,12 +765,15 @@ AL_API ALvoid AL_APIENTRY alSpeedOfSound(ALfloat value)
if(!context) return;
if(!(value > 0.0f && isfinite(value)))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- context->SpeedOfSound = value;
- ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
+ alSetError(context, AL_INVALID_VALUE, "Speed of sound %f out of range", value);
+ else
+ {
+ almtx_lock(&context->PropLock);
+ context->SpeedOfSound = value;
+ DO_UPDATEPROPS();
+ almtx_unlock(&context->PropLock);
+ }
-done:
ALCcontext_DecRef(context);
}
@@ -599,13 +788,16 @@ AL_API ALvoid AL_APIENTRY alDistanceModel(ALenum value)
value == AL_LINEAR_DISTANCE || value == AL_LINEAR_DISTANCE_CLAMPED ||
value == AL_EXPONENT_DISTANCE || value == AL_EXPONENT_DISTANCE_CLAMPED ||
value == AL_NONE))
- SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
-
- context->DistanceModel = value;
- if(!context->SourceDistanceModel)
- ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
+ alSetError(context, AL_INVALID_VALUE, "Distance model 0x%04x out of range", value);
+ else
+ {
+ almtx_lock(&context->PropLock);
+ context->DistanceModel = value;
+ if(!context->SourceDistanceModel)
+ DO_UPDATEPROPS();
+ almtx_unlock(&context->PropLock);
+ }
-done:
ALCcontext_DecRef(context);
}
@@ -633,3 +825,76 @@ AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void)
ALCcontext_DecRef(context);
}
+
+
+AL_API const ALchar* AL_APIENTRY alGetStringiSOFT(ALenum pname, ALsizei index)
+{
+ const char *ResamplerNames[] = {
+ alPointResampler, alLinearResampler,
+ alCubicResampler, alBSinc12Resampler,
+ alBSinc24Resampler,
+ };
+ const ALchar *value = NULL;
+ ALCcontext *context;
+
+ static_assert(COUNTOF(ResamplerNames) == ResamplerMax+1, "Incorrect ResamplerNames list");
+
+ context = GetContextRef();
+ if(!context) return NULL;
+
+ switch(pname)
+ {
+ case AL_RESAMPLER_NAME_SOFT:
+ if(index < 0 || (size_t)index >= COUNTOF(ResamplerNames))
+ SETERR_GOTO(context, AL_INVALID_VALUE, done, "Resampler name index %d out of range",
+ index);
+ value = ResamplerNames[index];
+ break;
+
+ default:
+ alSetError(context, AL_INVALID_VALUE, "Invalid string indexed property");
+ }
+
+done:
+ ALCcontext_DecRef(context);
+ return value;
+}
+
+
+void UpdateContextProps(ALCcontext *context)
+{
+ struct ALcontextProps *props;
+
+ /* Get an unused proprty container, or allocate a new one as needed. */
+ props = ATOMIC_LOAD(&context->FreeContextProps, almemory_order_acquire);
+ if(!props)
+ props = al_calloc(16, sizeof(*props));
+ else
+ {
+ struct ALcontextProps *next;
+ do {
+ next = ATOMIC_LOAD(&props->next, almemory_order_relaxed);
+ } while(ATOMIC_COMPARE_EXCHANGE_PTR_WEAK(&context->FreeContextProps, &props, next,
+ almemory_order_seq_cst, almemory_order_acquire) == 0);
+ }
+
+ /* Copy in current property values. */
+ props->MetersPerUnit = context->MetersPerUnit;
+
+ props->DopplerFactor = context->DopplerFactor;
+ props->DopplerVelocity = context->DopplerVelocity;
+ props->SpeedOfSound = context->SpeedOfSound;
+
+ props->SourceDistanceModel = context->SourceDistanceModel;
+ props->DistanceModel = context->DistanceModel;
+
+ /* Set the new container for updating internal parameters. */
+ props = ATOMIC_EXCHANGE_PTR(&context->Update, props, almemory_order_acq_rel);
+ if(props)
+ {
+ /* If there was an unused update container, put it back in the
+ * freelist.
+ */
+ ATOMIC_REPLACE_HEAD(struct ALcontextProps*, &context->FreeContextProps, props);
+ }
+}
diff --git a/OpenAL32/alThunk.c b/OpenAL32/alThunk.c
deleted file mode 100644
index 0cebad42..00000000
--- a/OpenAL32/alThunk.c
+++ /dev/null
@@ -1,103 +0,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.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- * Or go to http://www.gnu.org/copyleft/lgpl.html
- */
-
-#include "config.h"
-
-#include <stdlib.h>
-
-#include "alMain.h"
-#include "alThunk.h"
-
-
-static ATOMIC(ALenum) *ThunkArray;
-static ALuint ThunkArraySize;
-static RWLock ThunkLock;
-
-void ThunkInit(void)
-{
- RWLockInit(&ThunkLock);
- ThunkArraySize = 1;
- ThunkArray = al_calloc(16, ThunkArraySize * sizeof(*ThunkArray));
-}
-
-void ThunkExit(void)
-{
- al_free(ThunkArray);
- ThunkArray = NULL;
- ThunkArraySize = 0;
-}
-
-ALenum NewThunkEntry(ALuint *index)
-{
- void *NewList;
- ALuint i;
-
- ReadLock(&ThunkLock);
- for(i = 0;i < ThunkArraySize;i++)
- {
- if(ATOMIC_EXCHANGE(ALenum, &ThunkArray[i], AL_TRUE) == AL_FALSE)
- {
- ReadUnlock(&ThunkLock);
- *index = i+1;
- return AL_NO_ERROR;
- }
- }
- ReadUnlock(&ThunkLock);
-
- WriteLock(&ThunkLock);
- /* Double-check that there's still no free entries, in case another
- * invocation just came through and increased the size of the array.
- */
- for(;i < ThunkArraySize;i++)
- {
- if(ATOMIC_EXCHANGE(ALenum, &ThunkArray[i], AL_TRUE) == AL_FALSE)
- {
- WriteUnlock(&ThunkLock);
- *index = i+1;
- return AL_NO_ERROR;
- }
- }
-
- NewList = al_calloc(16, ThunkArraySize*2 * sizeof(*ThunkArray));
- if(!NewList)
- {
- WriteUnlock(&ThunkLock);
- ERR("Realloc failed to increase to %u entries!\n", ThunkArraySize*2);
- return AL_OUT_OF_MEMORY;
- }
- memcpy(NewList, ThunkArray, ThunkArraySize*sizeof(*ThunkArray));
- al_free(ThunkArray);
- ThunkArray = NewList;
- ThunkArraySize *= 2;
-
- ATOMIC_STORE(&ThunkArray[i], AL_TRUE);
- WriteUnlock(&ThunkLock);
-
- *index = i+1;
- return AL_NO_ERROR;
-}
-
-void FreeThunkEntry(ALuint index)
-{
- ReadLock(&ThunkLock);
- if(index > 0 && index <= ThunkArraySize)
- ATOMIC_STORE(&ThunkArray[index-1], AL_FALSE);
- ReadUnlock(&ThunkLock);
-}
diff --git a/OpenAL32/event.c b/OpenAL32/event.c
new file mode 100644
index 00000000..4c9c0be2
--- /dev/null
+++ b/OpenAL32/event.c
@@ -0,0 +1,127 @@
+
+#include "config.h"
+
+#include "AL/alc.h"
+#include "AL/al.h"
+#include "AL/alext.h"
+#include "alMain.h"
+#include "alError.h"
+#include "alAuxEffectSlot.h"
+#include "ringbuffer.h"
+
+
+int EventThread(void *arg)
+{
+ ALCcontext *context = arg;
+ bool quitnow = false;
+
+ while(!quitnow)
+ {
+ ALbitfieldSOFT enabledevts;
+ AsyncEvent evt;
+
+ if(ll_ringbuffer_read(context->AsyncEvents, (char*)&evt, 1) == 0)
+ {
+ alsem_wait(&context->EventSem);
+ continue;
+ }
+
+ almtx_lock(&context->EventCbLock);
+ do {
+ quitnow = evt.EnumType == EventType_KillThread;
+ if(quitnow) break;
+
+ if(evt.EnumType == EventType_ReleaseEffectState)
+ {
+ ALeffectState_DecRef(evt.u.EffectState);
+ continue;
+ }
+
+ enabledevts = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_acquire);
+ if(context->EventCb && (enabledevts&evt.EnumType) == evt.EnumType)
+ context->EventCb(evt.u.user.type, evt.u.user.id, evt.u.user.param,
+ (ALsizei)strlen(evt.u.user.msg), evt.u.user.msg, context->EventParam
+ );
+ } while(ll_ringbuffer_read(context->AsyncEvents, (char*)&evt, 1) != 0);
+ almtx_unlock(&context->EventCbLock);
+ }
+ return 0;
+}
+
+AL_API void AL_APIENTRY alEventControlSOFT(ALsizei count, const ALenum *types, ALboolean enable)
+{
+ ALCcontext *context;
+ ALbitfieldSOFT enabledevts;
+ ALbitfieldSOFT flags = 0;
+ ALsizei i;
+
+ context = GetContextRef();
+ if(!context) return;
+
+ if(count < 0) SETERR_GOTO(context, AL_INVALID_VALUE, done, "Controlling %d events", count);
+ if(count == 0) goto done;
+ if(!types) SETERR_GOTO(context, AL_INVALID_VALUE, done, "NULL pointer");
+
+ for(i = 0;i < count;i++)
+ {
+ if(types[i] == AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT)
+ flags |= EventType_BufferCompleted;
+ else if(types[i] == AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT)
+ flags |= EventType_SourceStateChange;
+ else if(types[i] == AL_EVENT_TYPE_ERROR_SOFT)
+ flags |= EventType_Error;
+ else if(types[i] == AL_EVENT_TYPE_PERFORMANCE_SOFT)
+ flags |= EventType_Performance;
+ else if(types[i] == AL_EVENT_TYPE_DEPRECATED_SOFT)
+ flags |= EventType_Deprecated;
+ else if(types[i] == AL_EVENT_TYPE_DISCONNECTED_SOFT)
+ flags |= EventType_Disconnected;
+ else
+ SETERR_GOTO(context, AL_INVALID_ENUM, done, "Invalid event type 0x%04x", types[i]);
+ }
+
+ if(enable)
+ {
+ enabledevts = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_relaxed);
+ while(ATOMIC_COMPARE_EXCHANGE_WEAK(&context->EnabledEvts, &enabledevts, enabledevts|flags,
+ almemory_order_acq_rel, almemory_order_acquire) == 0)
+ {
+ /* enabledevts is (re-)filled with the current value on failure, so
+ * just try again.
+ */
+ }
+ }
+ else
+ {
+ enabledevts = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_relaxed);
+ while(ATOMIC_COMPARE_EXCHANGE_WEAK(&context->EnabledEvts, &enabledevts, enabledevts&~flags,
+ almemory_order_acq_rel, almemory_order_acquire) == 0)
+ {
+ }
+ /* Wait to ensure the event handler sees the changed flags before
+ * returning.
+ */
+ almtx_lock(&context->EventCbLock);
+ almtx_unlock(&context->EventCbLock);
+ }
+
+done:
+ ALCcontext_DecRef(context);
+}
+
+AL_API void AL_APIENTRY alEventCallbackSOFT(ALEVENTPROCSOFT callback, void *userParam)
+{
+ ALCcontext *context;
+
+ context = GetContextRef();
+ if(!context) return;
+
+ almtx_lock(&context->PropLock);
+ almtx_lock(&context->EventCbLock);
+ context->EventCb = callback;
+ context->EventParam = userParam;
+ almtx_unlock(&context->EventCbLock);
+ almtx_unlock(&context->PropLock);
+
+ ALCcontext_DecRef(context);
+}
diff --git a/OpenAL32/sample_cvt.c b/OpenAL32/sample_cvt.c
index a02b217e..4a85f74a 100644
--- a/OpenAL32/sample_cvt.c
+++ b/OpenAL32/sample_cvt.c
@@ -3,13 +3,6 @@
#include "sample_cvt.h"
-#ifdef HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-
#include "AL/al.h"
#include "alu.h"
#include "alBuffer.h"
@@ -61,7 +54,7 @@ static const int MSADPCMAdaptionCoeff[7][2] = {
/* A quick'n'dirty lookup table to decode a muLaw-encoded byte sample into a
* signed 16-bit sample */
-static const ALshort muLawDecompressionTable[256] = {
+const ALshort muLawDecompressionTable[256] = {
-32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956,
-23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764,
-15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412,
@@ -96,32 +89,10 @@ static const ALshort muLawDecompressionTable[256] = {
56, 48, 40, 32, 24, 16, 8, 0
};
-/* Values used when encoding a muLaw sample */
-static const int muLawBias = 0x84;
-static const int muLawClip = 32635;
-static const char muLawCompressTable[256] = {
- 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
- 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
-};
-
/* A quick'n'dirty lookup table to decode an aLaw-encoded byte sample into a
* signed 16-bit sample */
-static const ALshort aLawDecompressionTable[256] = {
+const ALshort aLawDecompressionTable[256] = {
-5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
-7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
-2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,
@@ -156,92 +127,13 @@ static const ALshort aLawDecompressionTable[256] = {
944, 912, 1008, 976, 816, 784, 880, 848
};
-/* Values used when encoding an aLaw sample */
-static const int aLawClip = 32635;
-static const char aLawCompressTable[128] = {
- 1,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
-};
-
-
-typedef ALubyte ALmulaw;
-typedef ALubyte ALalaw;
-typedef ALubyte ALima4;
-typedef ALubyte ALmsadpcm;
-typedef struct {
- ALbyte b[3];
-} ALbyte3;
-static_assert(sizeof(ALbyte3)==sizeof(ALbyte[3]), "ALbyte3 size is not 3");
-typedef struct {
- ALubyte b[3];
-} ALubyte3;
-static_assert(sizeof(ALubyte3)==sizeof(ALubyte[3]), "ALubyte3 size is not 3");
-
-static inline ALshort DecodeMuLaw(ALmulaw val)
-{ return muLawDecompressionTable[val]; }
-
-static ALmulaw EncodeMuLaw(ALshort val)
-{
- ALint mant, exp, sign;
-
- sign = (val>>8) & 0x80;
- if(sign)
- {
- /* -32768 doesn't properly negate on a short; it results in itself.
- * So clamp to -32767 */
- val = maxi(val, -32767);
- val = -val;
- }
-
- val = mini(val, muLawClip);
- val += muLawBias;
-
- exp = muLawCompressTable[(val>>7) & 0xff];
- mant = (val >> (exp+3)) & 0x0f;
- return ~(sign | (exp<<4) | mant);
-}
-
-static inline ALshort DecodeALaw(ALalaw val)
-{ return aLawDecompressionTable[val]; }
-
-static ALalaw EncodeALaw(ALshort val)
+static void DecodeIMA4Block(ALshort *dst, const ALubyte *src, ALint numchans, ALsizei align)
{
- ALint mant, exp, sign;
-
- sign = ((~val) >> 8) & 0x80;
- if(!sign)
- {
- val = maxi(val, -32767);
- val = -val;
- }
- val = mini(val, aLawClip);
-
- if(val >= 256)
- {
- exp = aLawCompressTable[(val>>8) & 0x7f];
- mant = (val >> (exp+3)) & 0x0f;
- }
- else
- {
- exp = 0;
- mant = val >> 4;
- }
-
- return ((exp<<4) | mant) ^ (sign^0x55);
-}
-
-static void DecodeIMA4Block(ALshort *dst, const ALima4 *src, ALint numchans, ALsizei align)
-{
- ALint sample[MAX_INPUT_CHANNELS], index[MAX_INPUT_CHANNELS];
- ALuint code[MAX_INPUT_CHANNELS];
- ALsizei j,k,c;
+ ALint sample[MAX_INPUT_CHANNELS] = { 0 };
+ ALint index[MAX_INPUT_CHANNELS] = { 0 };
+ ALuint code[MAX_INPUT_CHANNELS] = { 0 };
+ ALsizei c, i;
for(c = 0;c < numchans;c++)
{
@@ -257,143 +149,77 @@ static void DecodeIMA4Block(ALshort *dst, const ALima4 *src, ALint numchans, ALs
dst[c] = sample[c];
}
- for(j = 1;j < align;j += 8)
+ for(i = 1;i < align;i++)
{
- for(c = 0;c < numchans;c++)
- {
- code[c] = *(src++);
- code[c] |= *(src++) << 8;
- code[c] |= *(src++) << 16;
- code[c] |= *(src++) << 24;
- }
-
- for(k = 0;k < 8;k++)
+ if((i&7) == 1)
{
for(c = 0;c < numchans;c++)
{
- int nibble = code[c]&0xf;
- code[c] >>= 4;
-
- sample[c] += IMA4Codeword[nibble] * IMAStep_size[index[c]] / 8;
- sample[c] = clampi(sample[c], -32768, 32767);
-
- index[c] += IMA4Index_adjust[nibble];
- index[c] = clampi(index[c], 0, 88);
-
- dst[(j+k)*numchans + c] = sample[c];
+ code[c] = *(src++);
+ code[c] |= *(src++) << 8;
+ code[c] |= *(src++) << 16;
+ code[c] |= *(src++) << 24;
}
}
- }
-}
-static void EncodeIMA4Block(ALima4 *dst, const ALshort *src, ALint *sample, ALint *index, ALint numchans, ALsizei align)
-{
- ALsizei j,k,c;
-
- for(c = 0;c < numchans;c++)
- {
- int diff = src[c] - sample[c];
- int step = IMAStep_size[index[c]];
- int nibble;
-
- nibble = 0;
- if(diff < 0)
- {
- nibble = 0x8;
- diff = -diff;
- }
-
- diff = mini(step*2, diff);
- nibble |= (diff*8/step - 1) / 2;
-
- sample[c] += IMA4Codeword[nibble] * step / 8;
- sample[c] = clampi(sample[c], -32768, 32767);
-
- index[c] += IMA4Index_adjust[nibble];
- index[c] = clampi(index[c], 0, 88);
-
- *(dst++) = sample[c] & 0xff;
- *(dst++) = (sample[c]>>8) & 0xff;
- *(dst++) = index[c] & 0xff;
- *(dst++) = (index[c]>>8) & 0xff;
- }
-
- for(j = 1;j < align;j += 8)
- {
for(c = 0;c < numchans;c++)
{
- for(k = 0;k < 8;k++)
- {
- int diff = src[(j+k)*numchans + c] - sample[c];
- int step = IMAStep_size[index[c]];
- int nibble;
-
- nibble = 0;
- if(diff < 0)
- {
- nibble = 0x8;
- diff = -diff;
- }
+ int nibble = code[c]&0xf;
+ code[c] >>= 4;
- diff = mini(step*2, diff);
- nibble |= (diff*8/step - 1) / 2;
+ sample[c] += IMA4Codeword[nibble] * IMAStep_size[index[c]] / 8;
+ sample[c] = clampi(sample[c], -32768, 32767);
- sample[c] += IMA4Codeword[nibble] * step / 8;
- sample[c] = clampi(sample[c], -32768, 32767);
+ index[c] += IMA4Index_adjust[nibble];
+ index[c] = clampi(index[c], 0, 88);
- index[c] += IMA4Index_adjust[nibble];
- index[c] = clampi(index[c], 0, 88);
-
- if(!(k&1)) *dst = nibble;
- else *(dst++) |= nibble<<4;
- }
+ *(dst++) = sample[c];
}
}
}
-
-static void DecodeMSADPCMBlock(ALshort *dst, const ALmsadpcm *src, ALint numchans, ALsizei align)
+static void DecodeMSADPCMBlock(ALshort *dst, const ALubyte *src, ALint numchans, ALsizei align)
{
- ALubyte blockpred[MAX_INPUT_CHANNELS];
- ALint delta[MAX_INPUT_CHANNELS];
- ALshort samples[MAX_INPUT_CHANNELS][2];
- ALint i, j;
+ ALubyte blockpred[MAX_INPUT_CHANNELS] = { 0 };
+ ALint delta[MAX_INPUT_CHANNELS] = { 0 };
+ ALshort samples[MAX_INPUT_CHANNELS][2] = { { 0, 0 } };
+ ALint c, i;
- for(i = 0;i < numchans;i++)
+ for(c = 0;c < numchans;c++)
{
- blockpred[i] = *(src++);
- blockpred[i] = minu(blockpred[i], 6);
+ blockpred[c] = *(src++);
+ blockpred[c] = minu(blockpred[c], 6);
}
- for(i = 0;i < numchans;i++)
+ for(c = 0;c < numchans;c++)
{
- delta[i] = *(src++);
- delta[i] |= *(src++) << 8;
- delta[i] = (delta[i]^0x8000) - 0x8000;
+ delta[c] = *(src++);
+ delta[c] |= *(src++) << 8;
+ delta[c] = (delta[c]^0x8000) - 32768;
}
- for(i = 0;i < numchans;i++)
+ for(c = 0;c < numchans;c++)
{
- samples[i][0] = *(src++);
- samples[i][0] |= *(src++) << 8;
- samples[i][0] = (samples[i][0]^0x8000) - 0x8000;
+ samples[c][0] = *(src++);
+ samples[c][0] |= *(src++) << 8;
+ samples[c][0] = (samples[c][0]^0x8000) - 32768;
}
- for(i = 0;i < numchans;i++)
+ for(c = 0;c < numchans;c++)
{
- samples[i][1] = *(src++);
- samples[i][1] |= *(src++) << 8;
- samples[i][1] = (samples[i][1]^0x8000) - 0x8000;
+ samples[c][1] = *(src++);
+ samples[c][1] |= *(src++) << 8;
+ samples[c][1] = (samples[c][1]^0x8000) - 0x8000;
}
/* Second sample is written first. */
- for(i = 0;i < numchans;i++)
- *(dst++) = samples[i][1];
- for(i = 0;i < numchans;i++)
- *(dst++) = samples[i][0];
+ for(c = 0;c < numchans;c++)
+ *(dst++) = samples[c][1];
+ for(c = 0;c < numchans;c++)
+ *(dst++) = samples[c][0];
- for(j = 2;j < align;j++)
+ for(i = 2;i < align;i++)
{
- for(i = 0;i < numchans;i++)
+ for(c = 0;c < numchans;c++)
{
- const ALint num = (j*numchans) + i;
+ const ALint num = (i*numchans) + c;
ALint nibble, pred;
/* Read the nibble (first is in the upper bits). */
@@ -402,545 +228,28 @@ static void DecodeMSADPCMBlock(ALshort *dst, const ALmsadpcm *src, ALint numchan
else
nibble = (*(src++))&0x0f;
- pred = (samples[i][0]*MSADPCMAdaptionCoeff[blockpred[i]][0] +
- samples[i][1]*MSADPCMAdaptionCoeff[blockpred[i]][1]) / 256;
- pred += ((nibble^0x08) - 0x08) * delta[i];
+ pred = (samples[c][0]*MSADPCMAdaptionCoeff[blockpred[c]][0] +
+ samples[c][1]*MSADPCMAdaptionCoeff[blockpred[c]][1]) / 256;
+ pred += ((nibble^0x08) - 0x08) * delta[c];
pred = clampi(pred, -32768, 32767);
- samples[i][1] = samples[i][0];
- samples[i][0] = pred;
+ samples[c][1] = samples[c][0];
+ samples[c][0] = pred;
- delta[i] = (MSADPCMAdaption[nibble] * delta[i]) / 256;
- delta[i] = maxi(16, delta[i]);
+ delta[c] = (MSADPCMAdaption[nibble] * delta[c]) / 256;
+ delta[c] = maxi(16, delta[c]);
*(dst++) = pred;
}
}
}
-/* NOTE: This encoder is pretty dumb/simplistic. Some kind of pre-processing
- * that tries to find the optimal block predictors would be nice, at least. A
- * multi-pass method that can generate better deltas would be good, too. */
-static void EncodeMSADPCMBlock(ALmsadpcm *dst, const ALshort *src, ALint *sample, ALint numchans, ALsizei align)
-{
- ALubyte blockpred[MAX_INPUT_CHANNELS];
- ALint delta[MAX_INPUT_CHANNELS];
- ALshort samples[MAX_INPUT_CHANNELS][2];
- ALint i, j;
-
- /* Block predictor */
- for(i = 0;i < numchans;i++)
- {
- /* FIXME: Calculate something better. */
- blockpred[i] = 0;
- *(dst++) = blockpred[i];
- }
- /* Initial delta */
- for(i = 0;i < numchans;i++)
- {
- delta[i] = 16;
- *(dst++) = (delta[i] ) & 0xff;
- *(dst++) = (delta[i]>>8) & 0xff;
- }
- /* Initial sample 1 */
- for(i = 0;i < numchans;i++)
- {
- samples[i][0] = src[1*numchans + i];
- *(dst++) = (samples[i][0] ) & 0xff;
- *(dst++) = (samples[i][0]>>8) & 0xff;
- }
- /* Initial sample 2 */
- for(i = 0;i < numchans;i++)
- {
- samples[i][1] = src[i];
- *(dst++) = (samples[i][1] ) & 0xff;
- *(dst++) = (samples[i][1]>>8) & 0xff;
- }
-
- for(j = 2;j < align;j++)
- {
- for(i = 0;i < numchans;i++)
- {
- const ALint num = (j*numchans) + i;
- ALint nibble = 0;
- ALint bias;
-
- sample[i] = (samples[i][0]*MSADPCMAdaptionCoeff[blockpred[i]][0] +
- samples[i][1]*MSADPCMAdaptionCoeff[blockpred[i]][1]) / 256;
-
- nibble = src[num] - sample[i];
- if(nibble >= 0)
- bias = delta[i] / 2;
- else
- bias = -delta[i] / 2;
-
- nibble = (nibble + bias) / delta[i];
- nibble = clampi(nibble, -8, 7)&0x0f;
-
- sample[i] += ((nibble^0x08)-0x08) * delta[i];
- sample[i] = clampi(sample[i], -32768, 32767);
- samples[i][1] = samples[i][0];
- samples[i][0] = sample[i];
-
- delta[i] = (MSADPCMAdaption[nibble] * delta[i]) / 256;
- delta[i] = maxi(16, delta[i]);
-
- if(!(num&1))
- *dst = nibble << 4;
- else
- {
- *dst |= nibble;
- dst++;
- }
- }
- }
-}
-
-
-static inline ALint DecodeByte3(ALbyte3 val)
-{
- if(IS_LITTLE_ENDIAN)
- return (val.b[2]<<16) | (((ALubyte)val.b[1])<<8) | ((ALubyte)val.b[0]);
- return (val.b[0]<<16) | (((ALubyte)val.b[1])<<8) | ((ALubyte)val.b[2]);
-}
-
-static inline ALbyte3 EncodeByte3(ALint val)
-{
- if(IS_LITTLE_ENDIAN)
- {
- ALbyte3 ret = {{ val, val>>8, val>>16 }};
- return ret;
- }
- else
- {
- ALbyte3 ret = {{ val>>16, val>>8, val }};
- return ret;
- }
-}
-
-static inline ALint DecodeUByte3(ALubyte3 val)
-{
- if(IS_LITTLE_ENDIAN)
- return (val.b[2]<<16) | (val.b[1]<<8) | (val.b[0]);
- return (val.b[0]<<16) | (val.b[1]<<8) | val.b[2];
-}
-
-static inline ALubyte3 EncodeUByte3(ALint val)
-{
- if(IS_LITTLE_ENDIAN)
- {
- ALubyte3 ret = {{ val, val>>8, val>>16 }};
- return ret;
- }
- else
- {
- ALubyte3 ret = {{ val>>16, val>>8, val }};
- return ret;
- }
-}
-
-
-static inline ALbyte Conv_ALbyte_ALbyte(ALbyte val)
-{ return val; }
-static inline ALbyte Conv_ALbyte_ALubyte(ALubyte val)
-{ return val-128; }
-static inline ALbyte Conv_ALbyte_ALshort(ALshort val)
-{ return val>>8; }
-static inline ALbyte Conv_ALbyte_ALushort(ALushort val)
-{ return (val>>8)-128; }
-static inline ALbyte Conv_ALbyte_ALint(ALint val)
-{ return val>>24; }
-static inline ALbyte Conv_ALbyte_ALuint(ALuint val)
-{ return (val>>24)-128; }
-static inline ALbyte Conv_ALbyte_ALfloat(ALfloat val)
-{
- if(val > 1.0f) return 127;
- if(val < -1.0f) return -128;
- return (ALint)(val * 127.0f);
-}
-static inline ALbyte Conv_ALbyte_ALdouble(ALdouble val)
-{
- if(val > 1.0) return 127;
- if(val < -1.0) return -128;
- return (ALint)(val * 127.0);
-}
-static inline ALbyte Conv_ALbyte_ALmulaw(ALmulaw val)
-{ return Conv_ALbyte_ALshort(DecodeMuLaw(val)); }
-static inline ALbyte Conv_ALbyte_ALalaw(ALalaw val)
-{ return Conv_ALbyte_ALshort(DecodeALaw(val)); }
-static inline ALbyte Conv_ALbyte_ALbyte3(ALbyte3 val)
-{ return DecodeByte3(val)>>16; }
-static inline ALbyte Conv_ALbyte_ALubyte3(ALubyte3 val)
-{ return (DecodeUByte3(val)>>16)-128; }
-
-static inline ALubyte Conv_ALubyte_ALbyte(ALbyte val)
-{ return val+128; }
-static inline ALubyte Conv_ALubyte_ALubyte(ALubyte val)
-{ return val; }
-static inline ALubyte Conv_ALubyte_ALshort(ALshort val)
-{ return (val>>8)+128; }
-static inline ALubyte Conv_ALubyte_ALushort(ALushort val)
-{ return val>>8; }
-static inline ALubyte Conv_ALubyte_ALint(ALint val)
-{ return (val>>24)+128; }
-static inline ALubyte Conv_ALubyte_ALuint(ALuint val)
-{ return val>>24; }
-static inline ALubyte Conv_ALubyte_ALfloat(ALfloat val)
-{
- if(val > 1.0f) return 255;
- if(val < -1.0f) return 0;
- return (ALint)(val * 127.0f) + 128;
-}
-static inline ALubyte Conv_ALubyte_ALdouble(ALdouble val)
-{
- if(val > 1.0) return 255;
- if(val < -1.0) return 0;
- return (ALint)(val * 127.0) + 128;
-}
-static inline ALubyte Conv_ALubyte_ALmulaw(ALmulaw val)
-{ return Conv_ALubyte_ALshort(DecodeMuLaw(val)); }
-static inline ALubyte Conv_ALubyte_ALalaw(ALalaw val)
-{ return Conv_ALubyte_ALshort(DecodeALaw(val)); }
-static inline ALubyte Conv_ALubyte_ALbyte3(ALbyte3 val)
-{ return (DecodeByte3(val)>>16)+128; }
-static inline ALubyte Conv_ALubyte_ALubyte3(ALubyte3 val)
-{ return DecodeUByte3(val)>>16; }
-
-static inline ALshort Conv_ALshort_ALbyte(ALbyte val)
-{ return val<<8; }
-static inline ALshort Conv_ALshort_ALubyte(ALubyte val)
-{ return (val-128)<<8; }
-static inline ALshort Conv_ALshort_ALshort(ALshort val)
-{ return val; }
-static inline ALshort Conv_ALshort_ALushort(ALushort val)
-{ return val-32768; }
-static inline ALshort Conv_ALshort_ALint(ALint val)
-{ return val>>16; }
-static inline ALshort Conv_ALshort_ALuint(ALuint val)
-{ return (val>>16)-32768; }
-static inline ALshort Conv_ALshort_ALfloat(ALfloat val)
-{
- if(val > 1.0f) return 32767;
- if(val < -1.0f) return -32768;
- return (ALint)(val * 32767.0f);
-}
-static inline ALshort Conv_ALshort_ALdouble(ALdouble val)
-{
- if(val > 1.0) return 32767;
- if(val < -1.0) return -32768;
- return (ALint)(val * 32767.0);
-}
-static inline ALshort Conv_ALshort_ALmulaw(ALmulaw val)
-{ return Conv_ALshort_ALshort(DecodeMuLaw(val)); }
-static inline ALshort Conv_ALshort_ALalaw(ALalaw val)
-{ return Conv_ALshort_ALshort(DecodeALaw(val)); }
-static inline ALshort Conv_ALshort_ALbyte3(ALbyte3 val)
-{ return DecodeByte3(val)>>8; }
-static inline ALshort Conv_ALshort_ALubyte3(ALubyte3 val)
-{ return (DecodeUByte3(val)>>8)-32768; }
-
-static inline ALushort Conv_ALushort_ALbyte(ALbyte val)
-{ return (val+128)<<8; }
-static inline ALushort Conv_ALushort_ALubyte(ALubyte val)
-{ return val<<8; }
-static inline ALushort Conv_ALushort_ALshort(ALshort val)
-{ return val+32768; }
-static inline ALushort Conv_ALushort_ALushort(ALushort val)
-{ return val; }
-static inline ALushort Conv_ALushort_ALint(ALint val)
-{ return (val>>16)+32768; }
-static inline ALushort Conv_ALushort_ALuint(ALuint val)
-{ return val>>16; }
-static inline ALushort Conv_ALushort_ALfloat(ALfloat val)
-{
- if(val > 1.0f) return 65535;
- if(val < -1.0f) return 0;
- return (ALint)(val * 32767.0f) + 32768;
-}
-static inline ALushort Conv_ALushort_ALdouble(ALdouble val)
-{
- if(val > 1.0) return 65535;
- if(val < -1.0) return 0;
- return (ALint)(val * 32767.0) + 32768;
-}
-static inline ALushort Conv_ALushort_ALmulaw(ALmulaw val)
-{ return Conv_ALushort_ALshort(DecodeMuLaw(val)); }
-static inline ALushort Conv_ALushort_ALalaw(ALalaw val)
-{ return Conv_ALushort_ALshort(DecodeALaw(val)); }
-static inline ALushort Conv_ALushort_ALbyte3(ALbyte3 val)
-{ return (DecodeByte3(val)>>8)+32768; }
-static inline ALushort Conv_ALushort_ALubyte3(ALubyte3 val)
-{ return DecodeUByte3(val)>>8; }
-
-static inline ALint Conv_ALint_ALbyte(ALbyte val)
-{ return val<<24; }
-static inline ALint Conv_ALint_ALubyte(ALubyte val)
-{ return (val-128)<<24; }
-static inline ALint Conv_ALint_ALshort(ALshort val)
-{ return val<<16; }
-static inline ALint Conv_ALint_ALushort(ALushort val)
-{ return (val-32768)<<16; }
-static inline ALint Conv_ALint_ALint(ALint val)
-{ return val; }
-static inline ALint Conv_ALint_ALuint(ALuint val)
-{ return val-2147483648u; }
-static inline ALint Conv_ALint_ALfloat(ALfloat val)
-{
- if(val > 1.0f) return 2147483647;
- if(val < -1.0f) return -2147483647-1;
- return (ALint)(val*16777215.0f) << 7;
-}
-static inline ALint Conv_ALint_ALdouble(ALdouble val)
-{
- if(val > 1.0) return 2147483647;
- if(val < -1.0) return -2147483647-1;
- return (ALint)(val * 2147483647.0);
-}
-static inline ALint Conv_ALint_ALmulaw(ALmulaw val)
-{ return Conv_ALint_ALshort(DecodeMuLaw(val)); }
-static inline ALint Conv_ALint_ALalaw(ALalaw val)
-{ return Conv_ALint_ALshort(DecodeALaw(val)); }
-static inline ALint Conv_ALint_ALbyte3(ALbyte3 val)
-{ return DecodeByte3(val)<<8; }
-static inline ALint Conv_ALint_ALubyte3(ALubyte3 val)
-{ return (DecodeUByte3(val)-8388608)<<8; }
-
-static inline ALuint Conv_ALuint_ALbyte(ALbyte val)
-{ return (val+128)<<24; }
-static inline ALuint Conv_ALuint_ALubyte(ALubyte val)
-{ return val<<24; }
-static inline ALuint Conv_ALuint_ALshort(ALshort val)
-{ return (val+32768)<<16; }
-static inline ALuint Conv_ALuint_ALushort(ALushort val)
-{ return val<<16; }
-static inline ALuint Conv_ALuint_ALint(ALint val)
-{ return val+2147483648u; }
-static inline ALuint Conv_ALuint_ALuint(ALuint val)
-{ return val; }
-static inline ALuint Conv_ALuint_ALfloat(ALfloat val)
-{
- if(val > 1.0f) return 4294967295u;
- if(val < -1.0f) return 0;
- return ((ALint)(val*16777215.0f)<<7) + 2147483648u;
-}
-static inline ALuint Conv_ALuint_ALdouble(ALdouble val)
-{
- if(val > 1.0) return 4294967295u;
- if(val < -1.0) return 0;
- return (ALint)(val * 2147483647.0) + 2147483648u;
-}
-static inline ALuint Conv_ALuint_ALmulaw(ALmulaw val)
-{ return Conv_ALuint_ALshort(DecodeMuLaw(val)); }
-static inline ALuint Conv_ALuint_ALalaw(ALalaw val)
-{ return Conv_ALuint_ALshort(DecodeALaw(val)); }
-static inline ALuint Conv_ALuint_ALbyte3(ALbyte3 val)
-{ return (DecodeByte3(val)+8388608)<<8; }
-static inline ALuint Conv_ALuint_ALubyte3(ALubyte3 val)
-{ return DecodeUByte3(val)<<8; }
-
-static inline ALfloat Conv_ALfloat_ALbyte(ALbyte val)
-{ return val * (1.0f/127.0f); }
-static inline ALfloat Conv_ALfloat_ALubyte(ALubyte val)
-{ return (val-128) * (1.0f/127.0f); }
-static inline ALfloat Conv_ALfloat_ALshort(ALshort val)
-{ return val * (1.0f/32767.0f); }
-static inline ALfloat Conv_ALfloat_ALushort(ALushort val)
-{ return (val-32768) * (1.0f/32767.0f); }
-static inline ALfloat Conv_ALfloat_ALint(ALint val)
-{ return (ALfloat)(val>>7) * (1.0f/16777215.0f); }
-static inline ALfloat Conv_ALfloat_ALuint(ALuint val)
-{ return (ALfloat)((ALint)(val>>7)-16777216) * (1.0f/16777215.0f); }
-static inline ALfloat Conv_ALfloat_ALfloat(ALfloat val)
-{ return (val==val) ? val : 0.0f; }
-static inline ALfloat Conv_ALfloat_ALdouble(ALdouble val)
-{ return (val==val) ? (ALfloat)val : 0.0f; }
-static inline ALfloat Conv_ALfloat_ALmulaw(ALmulaw val)
-{ return Conv_ALfloat_ALshort(DecodeMuLaw(val)); }
-static inline ALfloat Conv_ALfloat_ALalaw(ALalaw val)
-{ return Conv_ALfloat_ALshort(DecodeALaw(val)); }
-static inline ALfloat Conv_ALfloat_ALbyte3(ALbyte3 val)
-{ return (ALfloat)(DecodeByte3(val) * (1.0/8388607.0)); }
-static inline ALfloat Conv_ALfloat_ALubyte3(ALubyte3 val)
-{ return (ALfloat)((DecodeUByte3(val)-8388608) * (1.0/8388607.0)); }
-
-static inline ALdouble Conv_ALdouble_ALbyte(ALbyte val)
-{ return val * (1.0/127.0); }
-static inline ALdouble Conv_ALdouble_ALubyte(ALubyte val)
-{ return (val-128) * (1.0/127.0); }
-static inline ALdouble Conv_ALdouble_ALshort(ALshort val)
-{ return val * (1.0/32767.0); }
-static inline ALdouble Conv_ALdouble_ALushort(ALushort val)
-{ return (val-32768) * (1.0/32767.0); }
-static inline ALdouble Conv_ALdouble_ALint(ALint val)
-{ return val * (1.0/2147483647.0); }
-static inline ALdouble Conv_ALdouble_ALuint(ALuint val)
-{ return (ALint)(val-2147483648u) * (1.0/2147483647.0); }
-static inline ALdouble Conv_ALdouble_ALfloat(ALfloat val)
-{ return (val==val) ? val : 0.0f; }
-static inline ALdouble Conv_ALdouble_ALdouble(ALdouble val)
-{ return (val==val) ? val : 0.0; }
-static inline ALdouble Conv_ALdouble_ALmulaw(ALmulaw val)
-{ return Conv_ALdouble_ALshort(DecodeMuLaw(val)); }
-static inline ALdouble Conv_ALdouble_ALalaw(ALalaw val)
-{ return Conv_ALdouble_ALshort(DecodeALaw(val)); }
-static inline ALdouble Conv_ALdouble_ALbyte3(ALbyte3 val)
-{ return DecodeByte3(val) * (1.0/8388607.0); }
-static inline ALdouble Conv_ALdouble_ALubyte3(ALubyte3 val)
-{ return (DecodeUByte3(val)-8388608) * (1.0/8388607.0); }
-
-#define DECL_TEMPLATE(T) \
-static inline ALmulaw Conv_ALmulaw_##T(T val) \
-{ return EncodeMuLaw(Conv_ALshort_##T(val)); }
-
-DECL_TEMPLATE(ALbyte)
-DECL_TEMPLATE(ALubyte)
-DECL_TEMPLATE(ALshort)
-DECL_TEMPLATE(ALushort)
-DECL_TEMPLATE(ALint)
-DECL_TEMPLATE(ALuint)
-DECL_TEMPLATE(ALfloat)
-DECL_TEMPLATE(ALdouble)
-static inline ALmulaw Conv_ALmulaw_ALmulaw(ALmulaw val)
-{ return val; }
-DECL_TEMPLATE(ALalaw)
-DECL_TEMPLATE(ALbyte3)
-DECL_TEMPLATE(ALubyte3)
-
-#undef DECL_TEMPLATE
-
-#define DECL_TEMPLATE(T) \
-static inline ALalaw Conv_ALalaw_##T(T val) \
-{ return EncodeALaw(Conv_ALshort_##T(val)); }
-
-DECL_TEMPLATE(ALbyte)
-DECL_TEMPLATE(ALubyte)
-DECL_TEMPLATE(ALshort)
-DECL_TEMPLATE(ALushort)
-DECL_TEMPLATE(ALint)
-DECL_TEMPLATE(ALuint)
-DECL_TEMPLATE(ALfloat)
-DECL_TEMPLATE(ALdouble)
-DECL_TEMPLATE(ALmulaw)
-static inline ALalaw Conv_ALalaw_ALalaw(ALalaw val)
-{ return val; }
-DECL_TEMPLATE(ALbyte3)
-DECL_TEMPLATE(ALubyte3)
-
-#undef DECL_TEMPLATE
-
-#define DECL_TEMPLATE(T) \
-static inline ALbyte3 Conv_ALbyte3_##T(T val) \
-{ return EncodeByte3(Conv_ALint_##T(val)>>8); }
-
-DECL_TEMPLATE(ALbyte)
-DECL_TEMPLATE(ALubyte)
-DECL_TEMPLATE(ALshort)
-DECL_TEMPLATE(ALushort)
-DECL_TEMPLATE(ALint)
-DECL_TEMPLATE(ALuint)
-DECL_TEMPLATE(ALfloat)
-DECL_TEMPLATE(ALdouble)
-DECL_TEMPLATE(ALmulaw)
-DECL_TEMPLATE(ALalaw)
-static inline ALbyte3 Conv_ALbyte3_ALbyte3(ALbyte3 val)
-{ return val; }
-DECL_TEMPLATE(ALubyte3)
-
-#undef DECL_TEMPLATE
-
-#define DECL_TEMPLATE(T) \
-static inline ALubyte3 Conv_ALubyte3_##T(T val) \
-{ return EncodeUByte3(Conv_ALuint_##T(val)>>8); }
-
-DECL_TEMPLATE(ALbyte)
-DECL_TEMPLATE(ALubyte)
-DECL_TEMPLATE(ALshort)
-DECL_TEMPLATE(ALushort)
-DECL_TEMPLATE(ALint)
-DECL_TEMPLATE(ALuint)
-DECL_TEMPLATE(ALfloat)
-DECL_TEMPLATE(ALdouble)
-DECL_TEMPLATE(ALmulaw)
-DECL_TEMPLATE(ALalaw)
-DECL_TEMPLATE(ALbyte3)
-static inline ALubyte3 Conv_ALubyte3_ALubyte3(ALubyte3 val)
-{ return val; }
-
-#undef DECL_TEMPLATE
-
-
-#define DECL_TEMPLATE(T1, T2) \
-static void Convert_##T1##_##T2(T1 *dst, const T2 *src, ALuint numchans, \
- ALuint len, ALsizei UNUSED(align)) \
-{ \
- ALuint i, j; \
- for(i = 0;i < len;i++) \
- { \
- for(j = 0;j < numchans;j++) \
- *(dst++) = Conv_##T1##_##T2(*(src++)); \
- } \
-}
-
-#define DECL_TEMPLATE2(T) \
-DECL_TEMPLATE(T, ALbyte) \
-DECL_TEMPLATE(T, ALubyte) \
-DECL_TEMPLATE(T, ALshort) \
-DECL_TEMPLATE(T, ALushort) \
-DECL_TEMPLATE(T, ALint) \
-DECL_TEMPLATE(T, ALuint) \
-DECL_TEMPLATE(T, ALfloat) \
-DECL_TEMPLATE(T, ALdouble) \
-DECL_TEMPLATE(T, ALmulaw) \
-DECL_TEMPLATE(T, ALalaw) \
-DECL_TEMPLATE(T, ALbyte3) \
-DECL_TEMPLATE(T, ALubyte3)
-
-DECL_TEMPLATE2(ALbyte)
-DECL_TEMPLATE2(ALubyte)
-DECL_TEMPLATE2(ALshort)
-DECL_TEMPLATE2(ALushort)
-DECL_TEMPLATE2(ALint)
-DECL_TEMPLATE2(ALuint)
-DECL_TEMPLATE2(ALfloat)
-DECL_TEMPLATE2(ALdouble)
-DECL_TEMPLATE2(ALmulaw)
-DECL_TEMPLATE2(ALalaw)
-DECL_TEMPLATE2(ALbyte3)
-DECL_TEMPLATE2(ALubyte3)
-
-#undef DECL_TEMPLATE2
-#undef DECL_TEMPLATE
-
-#define DECL_TEMPLATE(T) \
-static void Convert_##T##_ALima4(T *dst, const ALima4 *src, ALuint numchans, \
- ALuint len, ALuint align) \
-{ \
- ALsizei byte_align = ((align-1)/2 + 4) * numchans; \
- DECL_VLA(ALshort, tmp, align*numchans); \
- ALuint i, j, k; \
- \
- assert(align > 0 && (len%align) == 0); \
- for(i = 0;i < len;i += align) \
- { \
- DecodeIMA4Block(tmp, src, numchans, align); \
- src += byte_align; \
- \
- for(j = 0;j < align;j++) \
- { \
- for(k = 0;k < numchans;k++) \
- *(dst++) = Conv_##T##_ALshort(tmp[j*numchans + k]); \
- } \
- } \
-}
-
-DECL_TEMPLATE(ALbyte)
-DECL_TEMPLATE(ALubyte)
-static void Convert_ALshort_ALima4(ALshort *dst, const ALima4 *src, ALuint numchans,
- ALuint len, ALuint align)
+void Convert_ALshort_ALima4(ALshort *dst, const ALubyte *src, ALsizei numchans, ALsizei len,
+ ALsizei align)
{
ALsizei byte_align = ((align-1)/2 + 4) * numchans;
- ALuint i;
+ ALsizei i;
assert(align > 0 && (len%align) == 0);
for(i = 0;i < len;i += align)
@@ -950,103 +259,12 @@ static void Convert_ALshort_ALima4(ALshort *dst, const ALima4 *src, ALuint numch
dst += align*numchans;
}
}
-DECL_TEMPLATE(ALushort)
-DECL_TEMPLATE(ALint)
-DECL_TEMPLATE(ALuint)
-DECL_TEMPLATE(ALfloat)
-DECL_TEMPLATE(ALdouble)
-DECL_TEMPLATE(ALmulaw)
-DECL_TEMPLATE(ALalaw)
-DECL_TEMPLATE(ALbyte3)
-DECL_TEMPLATE(ALubyte3)
-#undef DECL_TEMPLATE
-
-#define DECL_TEMPLATE(T) \
-static void Convert_ALima4_##T(ALima4 *dst, const T *src, ALuint numchans, \
- ALuint len, ALuint align) \
-{ \
- ALint sample[MAX_INPUT_CHANNELS] = {0,0,0,0,0,0,0,0}; \
- ALint index[MAX_INPUT_CHANNELS] = {0,0,0,0,0,0,0,0}; \
- ALsizei byte_align = ((align-1)/2 + 4) * numchans; \
- DECL_VLA(ALshort, tmp, align*numchans); \
- ALuint i, j, k; \
- \
- assert(align > 0 && (len%align) == 0); \
- for(i = 0;i < len;i += align) \
- { \
- for(j = 0;j < align;j++) \
- { \
- for(k = 0;k < numchans;k++) \
- tmp[j*numchans + k] = Conv_ALshort_##T(*(src++)); \
- } \
- EncodeIMA4Block(dst, tmp, sample, index, numchans, align); \
- dst += byte_align; \
- } \
-}
-
-DECL_TEMPLATE(ALbyte)
-DECL_TEMPLATE(ALubyte)
-static void Convert_ALima4_ALshort(ALima4 *dst, const ALshort *src,
- ALuint numchans, ALuint len, ALuint align)
-{
- ALint sample[MAX_INPUT_CHANNELS] = {0,0,0,0,0,0,0,0};
- ALint index[MAX_INPUT_CHANNELS] = {0,0,0,0,0,0,0,0};
- ALsizei byte_align = ((align-1)/2 + 4) * numchans;
- ALuint i;
-
- assert(align > 0 && (len%align) == 0);
- for(i = 0;i < len;i += align)
- {
- EncodeIMA4Block(dst, src, sample, index, numchans, align);
- src += align*numchans;
- dst += byte_align;
- }
-}
-DECL_TEMPLATE(ALushort)
-DECL_TEMPLATE(ALint)
-DECL_TEMPLATE(ALuint)
-DECL_TEMPLATE(ALfloat)
-DECL_TEMPLATE(ALdouble)
-DECL_TEMPLATE(ALmulaw)
-DECL_TEMPLATE(ALalaw)
-DECL_TEMPLATE(ALbyte3)
-DECL_TEMPLATE(ALubyte3)
-
-#undef DECL_TEMPLATE
-
-
-#define DECL_TEMPLATE(T) \
-static void Convert_##T##_ALmsadpcm(T *dst, const ALmsadpcm *src, \
- ALuint numchans, ALuint len, \
- ALuint align) \
-{ \
- ALsizei byte_align = ((align-2)/2 + 7) * numchans; \
- DECL_VLA(ALshort, tmp, align*numchans); \
- ALuint i, j, k; \
- \
- assert(align > 1 && (len%align) == 0); \
- for(i = 0;i < len;i += align) \
- { \
- DecodeMSADPCMBlock(tmp, src, numchans, align); \
- src += byte_align; \
- \
- for(j = 0;j < align;j++) \
- { \
- for(k = 0;k < numchans;k++) \
- *(dst++) = Conv_##T##_ALshort(tmp[j*numchans + k]); \
- } \
- } \
-}
-
-DECL_TEMPLATE(ALbyte)
-DECL_TEMPLATE(ALubyte)
-static void Convert_ALshort_ALmsadpcm(ALshort *dst, const ALmsadpcm *src,
- ALuint numchans, ALuint len,
- ALuint align)
+void Convert_ALshort_ALmsadpcm(ALshort *dst, const ALubyte *src, ALsizei numchans, ALsizei len,
+ ALsizei align)
{
ALsizei byte_align = ((align-2)/2 + 7) * numchans;
- ALuint i;
+ ALsizei i;
assert(align > 1 && (len%align) == 0);
for(i = 0;i < len;i += align)
@@ -1056,214 +274,3 @@ static void Convert_ALshort_ALmsadpcm(ALshort *dst, const ALmsadpcm *src,
dst += align*numchans;
}
}
-DECL_TEMPLATE(ALushort)
-DECL_TEMPLATE(ALint)
-DECL_TEMPLATE(ALuint)
-DECL_TEMPLATE(ALfloat)
-DECL_TEMPLATE(ALdouble)
-DECL_TEMPLATE(ALmulaw)
-DECL_TEMPLATE(ALalaw)
-DECL_TEMPLATE(ALbyte3)
-DECL_TEMPLATE(ALubyte3)
-
-#undef DECL_TEMPLATE
-
-#define DECL_TEMPLATE(T) \
-static void Convert_ALmsadpcm_##T(ALmsadpcm *dst, const T *src, \
- ALuint numchans, ALuint len, ALuint align) \
-{ \
- ALint sample[MAX_INPUT_CHANNELS] = {0,0,0,0,0,0,0,0}; \
- ALsizei byte_align = ((align-2)/2 + 7) * numchans; \
- DECL_VLA(ALshort, tmp, align*numchans); \
- ALuint i, j, k; \
- \
- assert(align > 1 && (len%align) == 0); \
- for(i = 0;i < len;i += align) \
- { \
- for(j = 0;j < align;j++) \
- { \
- for(k = 0;k < numchans;k++) \
- tmp[j*numchans + k] = Conv_ALshort_##T(*(src++)); \
- } \
- EncodeMSADPCMBlock(dst, tmp, sample, numchans, align); \
- dst += byte_align; \
- } \
-}
-
-DECL_TEMPLATE(ALbyte)
-DECL_TEMPLATE(ALubyte)
-static void Convert_ALmsadpcm_ALshort(ALmsadpcm *dst, const ALshort *src,
- ALuint numchans, ALuint len, ALuint align)
-{
- ALint sample[MAX_INPUT_CHANNELS] = {0,0,0,0,0,0,0,0};
- ALsizei byte_align = ((align-2)/2 + 7) * numchans;
- ALuint i;
-
- assert(align > 1 && (len%align) == 0);
- for(i = 0;i < len;i += align)
- {
- EncodeMSADPCMBlock(dst, src, sample, numchans, align);
- src += align*numchans;
- dst += byte_align;
- }
-}
-DECL_TEMPLATE(ALushort)
-DECL_TEMPLATE(ALint)
-DECL_TEMPLATE(ALuint)
-DECL_TEMPLATE(ALfloat)
-DECL_TEMPLATE(ALdouble)
-DECL_TEMPLATE(ALmulaw)
-DECL_TEMPLATE(ALalaw)
-DECL_TEMPLATE(ALbyte3)
-DECL_TEMPLATE(ALubyte3)
-
-#undef DECL_TEMPLATE
-
-/* NOTE: We don't store compressed samples internally, so these conversions
- * should never happen. */
-static void Convert_ALima4_ALima4(ALima4* UNUSED(dst), const ALima4* UNUSED(src),
- ALuint UNUSED(numchans), ALuint UNUSED(len),
- ALuint UNUSED(align))
-{
- ERR("Unexpected IMA4-to-IMA4 conversion!\n");
-}
-
-static void Convert_ALmsadpcm_ALmsadpcm(ALmsadpcm* UNUSED(dst), const ALmsadpcm* UNUSED(src),
- ALuint UNUSED(numchans), ALuint UNUSED(len),
- ALuint UNUSED(align))
-{
- ERR("Unexpected MSADPCM-to-MSADPCM conversion!\n");
-}
-
-static void Convert_ALmsadpcm_ALima4(ALmsadpcm* UNUSED(dst), const ALima4* UNUSED(src),
- ALuint UNUSED(numchans), ALuint UNUSED(len),
- ALuint UNUSED(align))
-{
- ERR("Unexpected IMA4-to-MSADPCM conversion!\n");
-}
-
-static void Convert_ALima4_ALmsadpcm(ALima4* UNUSED(dst), const ALmsadpcm* UNUSED(src),
- ALuint UNUSED(numchans), ALuint UNUSED(len),
- ALuint UNUSED(align))
-{
- ERR("Unexpected MSADPCM-to-IMA4 conversion!\n");
-}
-
-
-#define DECL_TEMPLATE(T) \
-static void Convert_##T(T *dst, const ALvoid *src, enum UserFmtType srcType, \
- ALsizei numchans, ALsizei len, ALsizei align) \
-{ \
- switch(srcType) \
- { \
- case UserFmtByte: \
- Convert_##T##_ALbyte(dst, src, numchans, len, align); \
- break; \
- case UserFmtUByte: \
- Convert_##T##_ALubyte(dst, src, numchans, len, align); \
- break; \
- case UserFmtShort: \
- Convert_##T##_ALshort(dst, src, numchans, len, align); \
- break; \
- case UserFmtUShort: \
- Convert_##T##_ALushort(dst, src, numchans, len, align); \
- break; \
- case UserFmtInt: \
- Convert_##T##_ALint(dst, src, numchans, len, align); \
- break; \
- case UserFmtUInt: \
- Convert_##T##_ALuint(dst, src, numchans, len, align); \
- break; \
- case UserFmtFloat: \
- Convert_##T##_ALfloat(dst, src, numchans, len, align); \
- break; \
- case UserFmtDouble: \
- Convert_##T##_ALdouble(dst, src, numchans, len, align); \
- break; \
- case UserFmtMulaw: \
- Convert_##T##_ALmulaw(dst, src, numchans, len, align); \
- break; \
- case UserFmtAlaw: \
- Convert_##T##_ALalaw(dst, src, numchans, len, align); \
- break; \
- case UserFmtIMA4: \
- Convert_##T##_ALima4(dst, src, numchans, len, align); \
- break; \
- case UserFmtMSADPCM: \
- Convert_##T##_ALmsadpcm(dst, src, numchans, len, align); \
- break; \
- case UserFmtByte3: \
- Convert_##T##_ALbyte3(dst, src, numchans, len, align); \
- break; \
- case UserFmtUByte3: \
- Convert_##T##_ALubyte3(dst, src, numchans, len, align); \
- break; \
- } \
-}
-
-DECL_TEMPLATE(ALbyte)
-DECL_TEMPLATE(ALubyte)
-DECL_TEMPLATE(ALshort)
-DECL_TEMPLATE(ALushort)
-DECL_TEMPLATE(ALint)
-DECL_TEMPLATE(ALuint)
-DECL_TEMPLATE(ALfloat)
-DECL_TEMPLATE(ALdouble)
-DECL_TEMPLATE(ALmulaw)
-DECL_TEMPLATE(ALalaw)
-DECL_TEMPLATE(ALima4)
-DECL_TEMPLATE(ALmsadpcm)
-DECL_TEMPLATE(ALbyte3)
-DECL_TEMPLATE(ALubyte3)
-
-#undef DECL_TEMPLATE
-
-
-void ConvertData(ALvoid *dst, enum UserFmtType dstType, const ALvoid *src, enum UserFmtType srcType, ALsizei numchans, ALsizei len, ALsizei align)
-{
- switch(dstType)
- {
- case UserFmtByte:
- Convert_ALbyte(dst, src, srcType, numchans, len, align);
- break;
- case UserFmtUByte:
- Convert_ALubyte(dst, src, srcType, numchans, len, align);
- break;
- case UserFmtShort:
- Convert_ALshort(dst, src, srcType, numchans, len, align);
- break;
- case UserFmtUShort:
- Convert_ALushort(dst, src, srcType, numchans, len, align);
- break;
- case UserFmtInt:
- Convert_ALint(dst, src, srcType, numchans, len, align);
- break;
- case UserFmtUInt:
- Convert_ALuint(dst, src, srcType, numchans, len, align);
- break;
- case UserFmtFloat:
- Convert_ALfloat(dst, src, srcType, numchans, len, align);
- break;
- case UserFmtDouble:
- Convert_ALdouble(dst, src, srcType, numchans, len, align);
- break;
- case UserFmtMulaw:
- Convert_ALmulaw(dst, src, srcType, numchans, len, align);
- break;
- case UserFmtAlaw:
- Convert_ALalaw(dst, src, srcType, numchans, len, align);
- break;
- case UserFmtIMA4:
- Convert_ALima4(dst, src, srcType, numchans, len, align);
- break;
- case UserFmtMSADPCM:
- Convert_ALmsadpcm(dst, src, srcType, numchans, len, align);
- break;
- case UserFmtByte3:
- Convert_ALbyte3(dst, src, srcType, numchans, len, align);
- break;
- case UserFmtUByte3:
- Convert_ALubyte3(dst, src, srcType, numchans, len, align);
- break;
- }
-}
diff --git a/README b/README
deleted file mode 100644
index a0178ae5..00000000
--- a/README
+++ /dev/null
@@ -1,55 +0,0 @@
-Source Install
-==============
-
-To install OpenAL Soft, use your favorite shell to go into the build/
-directory, and run:
-
-cmake ..
-
-Assuming configuration went well, you can then build it, typically using GNU
-Make (KDevelop, MSVC, and others are possible depending on your system setup
-and CMake configuration).
-
-Please Note: Double check that the appropriate backends were detected. Often,
-complaints of no sound, crashing, and missing devices can be solved by making
-sure the correct backends are being used. CMake's output will identify which
-backends were enabled.
-
-For most systems, you will likely want to make sure ALSA, OSS, and PulseAudio
-were detected (if your target system uses them). For Windows, make sure
-DirectSound was detected.
-
-
-Utilities
-=========
-
-The source package comes with an informational utility, openal-info, and is
-built by default. It prints out information provided by the ALC and AL sub-
-systems, including discovered devices, version information, and extensions.
-
-
-Configuration
-=============
-
-OpenAL Soft can be configured on a per-user and per-system basis. This allows
-users and sysadmins to control information provided to applications, as well
-as application-agnostic behavior of the library. See alsoftrc.sample for
-available settings.
-
-
-Acknowledgements
-================
-
-Special thanks go to:
-
-Creative Labs for the original source code this is based off of.
-
-Christopher Fitzgerald for the current reverb effect implementation, and
-helping with the low-pass and HRTF filters.
-
-Christian Borss for the 3D panning code previous versions used as a base.
-
-Ben Davis for the idea behind a previous version of the click-removal code.
-
-Richard Furse for helping with my understanding of Ambisonics that is used by
-the various parts of the library.
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..0c9d3027
--- /dev/null
+++ b/README.md
@@ -0,0 +1,61 @@
+OpenAL soft
+===========
+
+`master` branch CI status : [![Build Status](https://travis-ci.org/kcat/openal-soft.svg?branch=master)](https://travis-ci.org/kcat/openal-soft) [![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kcat/openal-soft?branch=master&svg=true)](https://ci.appveyor.com/api/projects/status/github/kcat/openal-soft?branch=master&svg=true)
+
+OpenAL Soft is an LGPL-licensed, cross-platform, software implementation of the OpenAL 3D audio API. It's forked from the open-sourced Windows version available originally from openal.org's SVN repository (now defunct).
+OpenAL provides capabilities for playing audio in a virtual 3D environment. Distance attenuation, doppler shift, and directional sound emitters are among the features handled by the API. More advanced effects, including air absorption, occlusion, and environmental reverb, are available through the EFX extension. It also facilitates streaming audio, multi-channel buffers, and audio capture.
+
+More information is available on the [official website](http://openal-soft.org/)
+
+Source Install
+-------------
+To install OpenAL Soft, use your favorite shell to go into the build/
+directory, and run:
+
+```bash
+cmake ..
+```
+
+Assuming configuration went well, you can then build it, typically using GNU
+Make (KDevelop, MSVC, and others are possible depending on your system setup
+and CMake configuration).
+
+Please Note: Double check that the appropriate backends were detected. Often,
+complaints of no sound, crashing, and missing devices can be solved by making
+sure the correct backends are being used. CMake's output will identify which
+backends were enabled.
+
+For most systems, you will likely want to make sure ALSA, OSS, and PulseAudio
+were detected (if your target system uses them). For Windows, make sure
+DirectSound was detected.
+
+
+Utilities
+---------
+The source package comes with an informational utility, openal-info, and is
+built by default. It prints out information provided by the ALC and AL sub-
+systems, including discovered devices, version information, and extensions.
+
+
+Configuration
+-------------
+
+OpenAL Soft can be configured on a per-user and per-system basis. This allows
+users and sysadmins to control information provided to applications, as well
+as application-agnostic behavior of the library. See alsoftrc.sample for
+available settings.
+
+
+Acknowledgements
+----------------
+
+Special thanks go to:
+
+ - Creative Labs for the original source code this is based off of.
+ - Christopher Fitzgerald for the current reverb effect implementation, and
+helping with the low-pass and HRTF filters.
+ - Christian Borss for the 3D panning code previous versions used as a base.
+ - Ben Davis for the idea behind a previous version of the click-removal code.
+ - Richard Furse for helping with my understanding of Ambisonics that is used by
+the various parts of the library.
diff --git a/alsoftrc.sample b/alsoftrc.sample
index eccc88b5..8061ed1c 100644
--- a/alsoftrc.sample
+++ b/alsoftrc.sample
@@ -48,7 +48,10 @@
## channels:
# Sets the output channel configuration. If left unspecified, one will try to
# be detected from the system, and defaulting to stereo. The available values
-# are: mono, stereo, quad, surround51, surround51rear, surround61, surround71
+# are: mono, stereo, quad, surround51, surround51rear, surround61, surround71,
+# ambi1, ambi2, ambi3. Note that the ambi* configurations provide ambisonic
+# channels of the given order (using ACN ordering and SN3D normalization by
+# default), which need to be decoded to play correctly on speakers.
#channels =
## sample-type:
@@ -78,7 +81,7 @@
# which helps protect against skips when the CPU is under load, but increases
# the delay between a sound getting mixed and being heard. Acceptable values
# range between 2 and 16.
-#periods = 4
+#periods = 3
## stereo-mode:
# Specifies if stereo output is treated as being headphones or speakers. With
@@ -86,6 +89,20 @@
# Valid settings are auto, speakers, and headphones.
#stereo-mode = auto
+## stereo-encoding:
+# Specifies the encoding method for non-HRTF stereo output. 'panpot' (default)
+# uses standard amplitude panning (aka pair-wise, stereo pair, etc) between
+# -30 and +30 degrees, while 'uhj' creates stereo-compatible two-channel UHJ
+# output, which encodes some surround sound information into stereo output
+# that can be decoded with a surround sound receiver. If crossfeed filters are
+# used, UHJ is disabled.
+#stereo-encoding = panpot
+
+## ambi-format:
+# Specifies the channel order and normalization for the "ambi*" set of channel
+# configurations. Valid settings are: fuma, acn+sn3d, acn+n3d
+#ambi-format = acn+sn3d
+
## hrtf:
# Controls HRTF processing. These filters provide better spatialization of
# sounds while using headphones, but do require a bit more CPU power. The
@@ -96,21 +113,24 @@
# respectively.
#hrtf = auto
-## hrtf_tables:
-# Specifies a comma-separated list of files containing HRTF data sets. The
-# format of the files are described in hrtf.txt. The filenames may contain
-# these markers, which will be replaced as needed:
-# %r - Device sampling rate
-# %% - Percent sign (%)
-# The listed files are relative to system-dependant data directories. On
-# Windows this is:
+## default-hrtf:
+# Specifies the default HRTF to use. When multiple HRTFs are available, this
+# determines the preferred one to use if none are specifically requested. Note
+# that this is the enumerated HRTF name, not necessarily the filename.
+#default-hrtf =
+
+## hrtf-paths:
+# Specifies a comma-separated list of paths containing HRTF data sets. The
+# format of the files are described in docs/hrtf.txt. The files within the
+# directories must have the .mhr file extension to be recognized. By default,
+# OS-dependent data paths will be used. They will also be used if the list
+# ends with a comma. On Windows this is:
# $AppData\openal\hrtf
# And on other systems, it's (in order):
# $XDG_DATA_HOME/openal/hrtf (defaults to $HOME/.local/share/openal/hrtf)
# $XDG_DATA_DIRS/openal/hrtf (defaults to /usr/local/share/openal/hrtf and
# /usr/share/openal/hrtf)
-# An absolute path may also be specified, if the given file is elsewhere.
-#hrtf_tables = default-%r.mhr
+#hrtf-paths =
## cf_level:
# Sets the crossfeed level for stereo output. Valid values are:
@@ -129,11 +149,11 @@
# Selects the resampler used when mixing sources. Valid values are:
# point - nearest sample, no interpolation
# linear - extrapolates samples using a linear slope between samples
-# sinc4 - extrapolates samples using a 4-point Sinc filter
-# sinc8 - extrapolates samples using an 8-point Sinc filter
-# bsinc - extrapolates samples using a band-limited Sinc filter (varying
-# between 12 and 24 points, with anti-aliasing)
-# Specifying other values will result in using the default (linear).
+# cubic - extrapolates samples using a Catmull-Rom spline
+# bsinc12 - extrapolates samples using a band-limited Sinc filter (varying
+# between 12 and 24 points, with anti-aliasing)
+# bsinc24 - extrapolates samples using a band-limited Sinc filter (varying
+# between 24 and 48 points, with anti-aliasing)
#resampler = linear
## rt-prio: (global)
@@ -155,19 +175,53 @@
# can use a non-negligible amount of CPU time if an effect is set on it even
# if no sources are feeding it, so this may help when apps use more than the
# system can handle.
-#slots = 4
+#slots = 64
## sends:
-# Sets the number of auxiliary sends per source. When not specified (default),
-# it allows the app to request how many it wants. The maximum value currently
-# possible is 4.
-#sends =
+# Limits the number of auxiliary sends allowed per source. Setting this higher
+# than the default has no effect.
+#sends = 16
+
+## front-stablizer:
+# Applies filters to "stablize" front sound imaging. A psychoacoustic method
+# is used to generate a front-center channel signal from the front-left and
+# front-right channels, improving the front response by reducing the combing
+# artifacts and phase errors. Consequently, it will only work with channel
+# configurations that include front-left, front-right, and front-center.
+#front-stablizer = false
+
+## output-limiter:
+# Applies a gain limiter on the final mixed output. This reduces the volume
+# when the output samples would otherwise clamp, avoiding excessive clipping
+# noise.
+#output-limiter = true
+
+## dither:
+# Applies dithering on the final mix, for 8- and 16-bit output by default.
+# This replaces the distortion created by nearest-value quantization with low-
+# level whitenoise.
+#dither = true
+
+## dither-depth:
+# Quantization bit-depth for dithered output. A value of 0 (or less) will
+# match the output sample depth. For int32, uint32, and float32 output, 0 will
+# disable dithering because they're at or beyond the rendered precision. The
+# maximum dither depth is 24.
+#dither-depth = 0
+
+## volume-adjust:
+# A global volume adjustment for source output, expressed in decibels. The
+# value is logarithmic, so +6 will be a scale of (approximately) 2x, +12 will
+# be a scale of 4x, etc. Similarly, -6 will be x1/2, and -12 is about x1/4. A
+# value of 0 means no change.
+#volume-adjust = 0
## excludefx: (global)
# Sets which effects to exclude, preventing apps from using them. This can
# help for apps that try to use effects which are too CPU intensive for the
-# system to handle. Available effects are: eaxreverb,reverb,chorus,compressor,
-# distortion,echo,equalizer,flanger,modulator,dedicated
+# system to handle. Available effects are: eaxreverb,reverb,autowah,chorus,
+# compressor,distortion,echo,equalizer,flanger,modulator,dedicated,pshifter,
+# fshifter
#excludefx =
## default-reverb: (global)
@@ -192,6 +246,69 @@
#trap-al-error = false
##
+## Ambisonic decoder stuff
+##
+[decoder]
+
+## hq-mode:
+# Enables a high-quality ambisonic decoder. This mode is capable of frequency-
+# dependent processing, creating a better reproduction of 3D sound rendering
+# over surround sound speakers. Enabling this also requires specifying decoder
+# configuration files for the appropriate speaker configuration you intend to
+# use (see the quad, surround51, etc options below). Currently, up to third-
+# order decoding is supported.
+hq-mode = false
+
+## distance-comp:
+# Enables compensation for the speakers' relative distances to the listener.
+# This applies the necessary delays and attenuation to make the speakers
+# behave as though they are all equidistant, which is important for proper
+# playback of 3D sound rendering. Requires the proper distances to be
+# specified in the decoder configuration file.
+distance-comp = true
+
+## nfc:
+# Enables near-field control filters. This simulates and compensates for low-
+# frequency effects caused by the curvature of nearby sound-waves, which
+# creates a more realistic perception of sound distance. Note that the effect
+# may be stronger or weaker than intended if the application doesn't use or
+# specify an appropriate unit scale, or if incorrect speaker distances are set
+# in the decoder configuration file. Requires hq-mode to be enabled.
+nfc = true
+
+## nfc-ref-delay
+# Specifies the reference delay value for ambisonic output. When channels is
+# set to one of the ambi* formats, this option enables NFC-HOA output with the
+# specified Reference Delay parameter. The specified value can then be shared
+# with an appropriate NFC-HOA decoder to reproduce correct near-field effects.
+# Keep in mind that despite being designed for higher-order ambisonics, this
+# applies to first-order output all the same. When left unset, normal output
+# is created with no near-field simulation.
+nfc-ref-delay =
+
+## quad:
+# Decoder configuration file for Quadraphonic channel output. See
+# docs/ambdec.txt for a description of the file format.
+quad =
+
+## surround51:
+# Decoder configuration file for 5.1 Surround (Side and Rear) channel output.
+# See docs/ambdec.txt for a description of the file format.
+surround51 =
+
+## surround61:
+# Decoder configuration file for 6.1 Surround channel output. See
+# docs/ambdec.txt for a description of the file format.
+surround61 =
+
+## surround71:
+# Decoder configuration file for 7.1 Surround channel output. See
+# docs/ambdec.txt for a description of the file format. Note: This can be used
+# to enable 3D7.1 with the appropriate configuration and speaker placement,
+# see docs/3D7.1.txt.
+surround71 =
+
+##
## Reverb effect stuff (includes EAX reverb)
##
[reverb]
@@ -203,12 +320,6 @@
# value of 0 means no change.
#boost = 0
-## emulate-eax: (global)
-# Allows the standard reverb effect to be used in place of EAX reverb. EAX
-# reverb processing is a bit more CPU intensive than standard, so this option
-# allows a simpler effect to be used at the loss of some quality.
-#emulate-eax = false
-
##
## PulseAudio backend stuff
##
@@ -334,9 +445,9 @@
#buffer-size = 0
##
-## MMDevApi backend stuff
+## WASAPI backend stuff
##
-[mmdevapi]
+[wasapi]
##
## DirectSound backend stuff
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 00000000..6d826eed
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,19 @@
+version: 1.19.0.{build}
+
+environment:
+ matrix:
+ - GEN: "Visual Studio 14 2015"
+ CFG: Release
+ - GEN: "Visual Studio 14 2015 Win64"
+ CFG: Release
+
+install:
+ # Remove the VS Xamarin targets to reduce AppVeyor specific noise in build
+ # logs. See also http://help.appveyor.com/discussions/problems/4569
+ - del "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets"
+
+build_script:
+ - cd build
+ - cmake -G"%GEN%" -DALSOFT_REQUIRE_WINMM=ON -DALSOFT_REQUIRE_DSOUND=ON -DALSOFT_REQUIRE_WASAPI=ON -DALSOFT_EMBED_HRTF_DATA=YES ..
+ - cmake --build . --config %CFG% --clean-first
+
diff --git a/cmake/CheckSharedFunctionExists.cmake b/cmake/CheckSharedFunctionExists.cmake
index 7975f233..c691fa9c 100644
--- a/cmake/CheckSharedFunctionExists.cmake
+++ b/cmake/CheckSharedFunctionExists.cmake
@@ -34,7 +34,7 @@
# License text for the above reference.)
MACRO(CHECK_SHARED_FUNCTION_EXISTS SYMBOL FILES LIBRARY LOCATION VARIABLE)
- IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
+ IF(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}")
SET(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
SET(MACRO_CHECK_SYMBOL_EXISTS_FLAGS ${CMAKE_REQUIRED_FLAGS})
IF(CMAKE_REQUIRED_LIBRARIES)
@@ -88,5 +88,5 @@ MACRO(CHECK_SHARED_FUNCTION_EXISTS SYMBOL FILES LIBRARY LOCATION VARIABLE)
"${OUTPUT}\nFile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c:\n"
"${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
ENDIF(${VARIABLE})
- ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
+ ENDIF(NOT DEFINED "${VARIABLE}" OR "x${${VARIABLE}}" STREQUAL "x${VARIABLE}")
ENDMACRO(CHECK_SHARED_FUNCTION_EXISTS)
diff --git a/cmake/FindDSound.cmake b/cmake/FindDSound.cmake
index 0ddf98aa..4078deb5 100644
--- a/cmake/FindDSound.cmake
+++ b/cmake/FindDSound.cmake
@@ -8,24 +8,30 @@
# DSOUND_LIBRARY - the dsound library
#
+if (WIN32)
+ include(FindWindowsSDK)
+ if (WINDOWSSDK_FOUND)
+ get_windowssdk_library_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_LIB_DIRS)
+ get_windowssdk_include_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_INCLUDE_DIRS)
+ endif()
+endif()
+
+# DSOUND_INCLUDE_DIR
find_path(DSOUND_INCLUDE_DIR
- NAMES dsound.h
- PATHS "${DXSDK_DIR}"
+ NAMES "dsound.h"
+ PATHS "${DXSDK_DIR}" ${WINSDK_INCLUDE_DIRS}
PATH_SUFFIXES include
- DOC "The DirectSound include directory"
-)
+ DOC "The DirectSound include directory")
+# DSOUND_LIBRARY
find_library(DSOUND_LIBRARY
NAMES dsound
- PATHS "${DXSDK_DIR}"
+ PATHS "${DXSDK_DIR}" ${WINSDK_LIB_DIRS}
PATH_SUFFIXES lib lib/x86 lib/x64
- DOC "The DirectSound library"
-)
+ DOC "The DirectSound library")
include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(DSound
- REQUIRED_VARS DSOUND_LIBRARY DSOUND_INCLUDE_DIR
-)
+find_package_handle_standard_args(DSound REQUIRED_VARS DSOUND_LIBRARY DSOUND_INCLUDE_DIR)
if(DSOUND_FOUND)
set(DSOUND_LIBRARIES ${DSOUND_LIBRARY})
diff --git a/cmake/FindFFmpeg.cmake b/cmake/FindFFmpeg.cmake
index 96cbb6ed..c489c2c3 100644
--- a/cmake/FindFFmpeg.cmake
+++ b/cmake/FindFFmpeg.cmake
@@ -142,6 +142,12 @@ foreach(_component ${FFmpeg_FIND_COMPONENTS})
endif()
endforeach()
+# Add libz if it exists (needed for static ffmpeg builds)
+find_library(_FFmpeg_HAVE_LIBZ NAMES z)
+if(_FFmpeg_HAVE_LIBZ)
+ set(FFMPEG_LIBRARIES ${FFMPEG_LIBRARIES} ${_FFmpeg_HAVE_LIBZ})
+endif()
+
# Build the include path and library list with duplicates removed.
if(FFMPEG_INCLUDE_DIRS)
list(REMOVE_DUPLICATES FFMPEG_INCLUDE_DIRS)
diff --git a/cmake/FindOSS.cmake b/cmake/FindOSS.cmake
index 88ee66ad..feffb451 100644
--- a/cmake/FindOSS.cmake
+++ b/cmake/FindOSS.cmake
@@ -2,8 +2,10 @@
#
# OSS_FOUND - True if OSS_INCLUDE_DIR is found
# OSS_INCLUDE_DIRS - Set when OSS_INCLUDE_DIR is found
+# OSS_LIBRARIES - Set when OSS_LIBRARY is found
#
# OSS_INCLUDE_DIR - where to find sys/soundcard.h, etc.
+# OSS_LIBRARY - where to find libossaudio (optional).
#
find_path(OSS_INCLUDE_DIR
@@ -11,11 +13,21 @@ find_path(OSS_INCLUDE_DIR
DOC "The OSS include directory"
)
+find_library(OSS_LIBRARY
+ NAMES ossaudio
+ DOC "Optional OSS library"
+)
+
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OSS REQUIRED_VARS OSS_INCLUDE_DIR)
if(OSS_FOUND)
set(OSS_INCLUDE_DIRS ${OSS_INCLUDE_DIR})
+ if(OSS_LIBRARY)
+ set(OSS_LIBRARIES ${OSS_LIBRARY})
+ else()
+ unset(OSS_LIBRARIES)
+ endif()
endif()
-mark_as_advanced(OSS_INCLUDE_DIR)
+mark_as_advanced(OSS_INCLUDE_DIR OSS_LIBRARY)
diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake
index 70e607a8..e808d006 100644
--- a/cmake/FindSDL2.cmake
+++ b/cmake/FindSDL2.cmake
@@ -18,10 +18,10 @@
# module will automatically add the -framework Cocoa on your behalf.
#
#
-# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration
+# Additional Note: If you see an empty SDL2_CORE_LIBRARY in your configuration
# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
# (SDL2.dll, libsdl2.so, SDL2.framework, etc).
-# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
+# Set SDL2_CORE_LIBRARY to point to your SDL2 library, and configure again.
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
# as appropriate. These values are used to generate the final SDL2_LIBRARY
# variable, but when these values are unset, SDL2_LIBRARY does not get created.
@@ -87,7 +87,7 @@ FIND_PATH(SDL2_INCLUDE_DIR SDL.h
)
#MESSAGE("SDL2_INCLUDE_DIR is ${SDL2_INCLUDE_DIR}")
-FIND_LIBRARY(SDL2_LIBRARY_TEMP
+FIND_LIBRARY(SDL2_CORE_LIBRARY
NAMES SDL2
HINTS
$ENV{SDL2DIR}
@@ -98,8 +98,7 @@ FIND_LIBRARY(SDL2_LIBRARY_TEMP
/opt/csw
/opt
)
-
-#MESSAGE("SDL2_LIBRARY_TEMP is ${SDL2_LIBRARY_TEMP}")
+#MESSAGE("SDL2_CORE_LIBRARY is ${SDL2_CORE_LIBRARY}")
IF(NOT SDL2_BUILDING_LIBRARY)
IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
@@ -137,7 +136,9 @@ IF(MINGW)
ENDIF(MINGW)
SET(SDL2_FOUND "NO")
-IF(SDL2_LIBRARY_TEMP)
+IF(SDL2_CORE_LIBRARY)
+ SET(SDL2_LIBRARY_TEMP ${SDL2_CORE_LIBRARY})
+
# For SDL2main
IF(NOT SDL2_BUILDING_LIBRARY)
IF(SDL2MAIN_LIBRARY)
@@ -172,15 +173,12 @@ IF(SDL2_LIBRARY_TEMP)
ENDIF(WIN32)
# Set the final string here so the GUI reflects the final state.
- SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
- # Set the temp variable to INTERNAL so it is not seen in the CMake GUI
- SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
+ SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP})
SET(SDL2_FOUND "YES")
-ENDIF(SDL2_LIBRARY_TEMP)
+ENDIF(SDL2_CORE_LIBRARY)
INCLUDE(FindPackageHandleStandardArgs)
-
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2
REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)
diff --git a/cmake/FindWindowsSDK.cmake b/cmake/FindWindowsSDK.cmake
new file mode 100644
index 00000000..e136b897
--- /dev/null
+++ b/cmake/FindWindowsSDK.cmake
@@ -0,0 +1,626 @@
+# - Find the Windows SDK aka Platform SDK
+#
+# Relevant Wikipedia article: http://en.wikipedia.org/wiki/Microsoft_Windows_SDK
+#
+# Pass "COMPONENTS tools" to ignore Visual Studio version checks: in case
+# you just want the tool binaries to run, rather than the libraries and headers
+# for compiling.
+#
+# Variables:
+# WINDOWSSDK_FOUND - if any version of the windows or platform SDK was found that is usable with the current version of visual studio
+# WINDOWSSDK_LATEST_DIR
+# WINDOWSSDK_LATEST_NAME
+# WINDOWSSDK_FOUND_PREFERENCE - if we found an entry indicating a "preferred" SDK listed for this visual studio version
+# WINDOWSSDK_PREFERRED_DIR
+# WINDOWSSDK_PREFERRED_NAME
+#
+# WINDOWSSDK_DIRS - contains no duplicates, ordered most recent first.
+# WINDOWSSDK_PREFERRED_FIRST_DIRS - contains no duplicates, ordered with preferred first, followed by the rest in descending recency
+#
+# Functions:
+# windowssdk_name_lookup(<directory> <output variable>) - Find the name corresponding with the SDK directory you pass in, or
+# NOTFOUND if not recognized. Your directory must be one of WINDOWSSDK_DIRS for this to work.
+#
+# windowssdk_build_lookup(<directory> <output variable>) - Find the build version number corresponding with the SDK directory you pass in, or
+# NOTFOUND if not recognized. Your directory must be one of WINDOWSSDK_DIRS for this to work.
+#
+# get_windowssdk_from_component(<file or dir> <output variable>) - Given a library or include dir,
+# find the Windows SDK root dir corresponding to it, or NOTFOUND if unrecognized.
+#
+# get_windowssdk_library_dirs(<directory> <output variable>) - Find the architecture-appropriate
+# library directories corresponding to the SDK directory you pass in (or NOTFOUND if none)
+#
+# get_windowssdk_library_dirs_multiple(<output variable> <directory> ...) - Find the architecture-appropriate
+# library directories corresponding to the SDK directories you pass in, in order, skipping those not found. NOTFOUND if none at all.
+# Good for passing WINDOWSSDK_DIRS or WINDOWSSDK_DIRS to if you really just want a file and don't care where from.
+#
+# get_windowssdk_include_dirs(<directory> <output variable>) - Find the
+# include directories corresponding to the SDK directory you pass in (or NOTFOUND if none)
+#
+# get_windowssdk_include_dirs_multiple(<output variable> <directory> ...) - Find the
+# include directories corresponding to the SDK directories you pass in, in order, skipping those not found. NOTFOUND if none at all.
+# Good for passing WINDOWSSDK_DIRS or WINDOWSSDK_DIRS to if you really just want a file and don't care where from.
+#
+# Requires these CMake modules:
+# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
+#
+# Original Author:
+# 2012 Ryan Pavlik <[email protected]> <[email protected]>
+# http://academic.cleardefinition.com
+# Iowa State University HCI Graduate Program/VRAC
+#
+# Copyright Iowa State University 2012.
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+set(_preferred_sdk_dirs) # pre-output
+set(_win_sdk_dirs) # pre-output
+set(_win_sdk_versanddirs) # pre-output
+set(_win_sdk_buildsanddirs) # pre-output
+set(_winsdk_vistaonly) # search parameters
+set(_winsdk_kits) # search parameters
+
+
+set(_WINDOWSSDK_ANNOUNCE OFF)
+if(NOT WINDOWSSDK_FOUND AND (NOT WindowsSDK_FIND_QUIETLY))
+ set(_WINDOWSSDK_ANNOUNCE ON)
+endif()
+macro(_winsdk_announce)
+ if(_WINSDK_ANNOUNCE)
+ message(STATUS ${ARGN})
+ endif()
+endmacro()
+
+set(_winsdk_win10vers
+ 10.0.14393.0 # Redstone aka Win10 1607 "Anniversary Update"
+ 10.0.10586.0 # TH2 aka Win10 1511
+ 10.0.10240.0 # Win10 RTM
+ 10.0.10150.0 # just ucrt
+ 10.0.10056.0
+)
+
+if(WindowsSDK_FIND_COMPONENTS MATCHES "tools")
+ set(_WINDOWSSDK_IGNOREMSVC ON)
+ _winsdk_announce("Checking for tools from Windows/Platform SDKs...")
+else()
+ set(_WINDOWSSDK_IGNOREMSVC OFF)
+ _winsdk_announce("Checking for Windows/Platform SDKs...")
+endif()
+
+# Appends to the three main pre-output lists used only if the path exists
+# and is not already in the list.
+function(_winsdk_conditional_append _vername _build _path)
+ if(("${_path}" MATCHES "registry") OR (NOT EXISTS "${_path}"))
+ # Path invalid - do not add
+ return()
+ endif()
+ list(FIND _win_sdk_dirs "${_path}" _win_sdk_idx)
+ if(_win_sdk_idx GREATER -1)
+ # Path already in list - do not add
+ return()
+ endif()
+ _winsdk_announce( " - ${_vername}, Build ${_build} @ ${_path}")
+ # Not yet in the list, so we'll add it
+ list(APPEND _win_sdk_dirs "${_path}")
+ set(_win_sdk_dirs "${_win_sdk_dirs}" CACHE INTERNAL "" FORCE)
+ list(APPEND
+ _win_sdk_versanddirs
+ "${_vername}"
+ "${_path}")
+ set(_win_sdk_versanddirs "${_win_sdk_versanddirs}" CACHE INTERNAL "" FORCE)
+ list(APPEND
+ _win_sdk_buildsanddirs
+ "${_build}"
+ "${_path}")
+ set(_win_sdk_buildsanddirs "${_win_sdk_buildsanddirs}" CACHE INTERNAL "" FORCE)
+endfunction()
+
+# Appends to the "preferred SDK" lists only if the path exists
+function(_winsdk_conditional_append_preferred _info _path)
+ if(("${_path}" MATCHES "registry") OR (NOT EXISTS "${_path}"))
+ # Path invalid - do not add
+ return()
+ endif()
+
+ get_filename_component(_path "${_path}" ABSOLUTE)
+
+ list(FIND _win_sdk_preferred_sdk_dirs "${_path}" _win_sdk_idx)
+ if(_win_sdk_idx GREATER -1)
+ # Path already in list - do not add
+ return()
+ endif()
+ _winsdk_announce( " - Found \"preferred\" SDK ${_info} @ ${_path}")
+ # Not yet in the list, so we'll add it
+ list(APPEND _win_sdk_preferred_sdk_dirs "${_path}")
+ set(_win_sdk_preferred_sdk_dirs "${_win_sdk_dirs}" CACHE INTERNAL "" FORCE)
+
+ # Just in case we somehow missed it:
+ _winsdk_conditional_append("${_info}" "" "${_path}")
+endfunction()
+
+# Given a version like v7.0A, looks for an SDK in the registry under "Microsoft SDKs".
+# If the given version might be in both HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows
+# and HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots aka "Windows Kits",
+# use this macro first, since these registry keys usually have more information.
+#
+# Pass a "default" build number as an extra argument in case we can't find it.
+function(_winsdk_check_microsoft_sdks_registry _winsdkver)
+ set(SDKKEY "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\${_winsdkver}")
+ get_filename_component(_sdkdir
+ "[${SDKKEY};InstallationFolder]"
+ ABSOLUTE)
+
+ set(_sdkname "Windows SDK ${_winsdkver}")
+
+ # Default build number passed as extra argument
+ set(_build ${ARGN})
+ # See if the registry holds a Microsoft-mutilated, err, designated, product name
+ # (just using get_filename_component to execute the registry lookup)
+ get_filename_component(_sdkproductname
+ "[${SDKKEY};ProductName]"
+ NAME)
+ if(NOT "${_sdkproductname}" MATCHES "registry")
+ # Got a product name
+ set(_sdkname "${_sdkname} (${_sdkproductname})")
+ endif()
+
+ # try for a version to augment our name
+ # (just using get_filename_component to execute the registry lookup)
+ get_filename_component(_sdkver
+ "[${SDKKEY};ProductVersion]"
+ NAME)
+ if(NOT "${_sdkver}" MATCHES "registry" AND NOT MATCHES)
+ # Got a version
+ if(NOT "${_sdkver}" MATCHES "\\.\\.")
+ # and it's not an invalid one with two dots in it:
+ # use to override the default build
+ set(_build ${_sdkver})
+ if(NOT "${_sdkname}" MATCHES "${_sdkver}")
+ # Got a version that's not already in the name, let's use it to improve our name.
+ set(_sdkname "${_sdkname} (${_sdkver})")
+ endif()
+ endif()
+ endif()
+ _winsdk_conditional_append("${_sdkname}" "${_build}" "${_sdkdir}")
+endfunction()
+
+# Given a name for identification purposes, the build number, and a key (technically a "value name")
+# corresponding to a Windows SDK packaged as a "Windows Kit", look for it
+# in HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots
+# Note that the key or "value name" tends to be something weird like KitsRoot81 -
+# no easy way to predict, just have to observe them in the wild.
+# Doesn't hurt to also try _winsdk_check_microsoft_sdks_registry for these:
+# sometimes you get keys in both parts of the registry (in the wow64 portion especially),
+# and the non-"Windows Kits" location is often more descriptive.
+function(_winsdk_check_windows_kits_registry _winkit_name _winkit_build _winkit_key)
+ get_filename_component(_sdkdir
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;${_winkit_key}]"
+ ABSOLUTE)
+ _winsdk_conditional_append("${_winkit_name}" "${_winkit_build}" "${_sdkdir}")
+endfunction()
+
+# Given a name for identification purposes and the build number
+# corresponding to a Windows 10 SDK packaged as a "Windows Kit", look for it
+# in HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots
+# Doesn't hurt to also try _winsdk_check_microsoft_sdks_registry for these:
+# sometimes you get keys in both parts of the registry (in the wow64 portion especially),
+# and the non-"Windows Kits" location is often more descriptive.
+function(_winsdk_check_win10_kits _winkit_build)
+ get_filename_component(_sdkdir
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]"
+ ABSOLUTE)
+ if(("${_sdkdir}" MATCHES "registry") OR (NOT EXISTS "${_sdkdir}"))
+ return() # not found
+ endif()
+ if(EXISTS "${_sdkdir}/Include/${_winkit_build}/um")
+ _winsdk_conditional_append("Windows Kits 10 (Build ${_winkit_build})" "${_winkit_build}" "${_sdkdir}")
+ endif()
+endfunction()
+
+# Given a name for indentification purposes, the build number, and the associated package GUID,
+# look in the registry under both HKLM and HKCU in \\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\
+# for that guid and the SDK it points to.
+function(_winsdk_check_platformsdk_registry _platformsdkname _build _platformsdkguid)
+ foreach(_winsdk_hive HKEY_LOCAL_MACHINE HKEY_CURRENT_USER)
+ get_filename_component(_sdkdir
+ "[${_winsdk_hive}\\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\${_platformsdkguid};Install Dir]"
+ ABSOLUTE)
+ _winsdk_conditional_append("${_platformsdkname} (${_build})" "${_build}" "${_sdkdir}")
+ endforeach()
+endfunction()
+
+###
+# Detect toolchain information: to know whether it's OK to use Vista+ only SDKs
+###
+set(_winsdk_vistaonly_ok OFF)
+if(MSVC AND NOT _WINDOWSSDK_IGNOREMSVC)
+ # VC 10 and older has broad target support
+ if(MSVC_VERSION LESS 1700)
+ # VC 11 by default targets Vista and later only, so we can add a few more SDKs that (might?) only work on vista+
+ elseif("${CMAKE_VS_PLATFORM_TOOLSET}" MATCHES "_xp")
+ # This is the XP-compatible v110+ toolset
+ elseif("${CMAKE_VS_PLATFORM_TOOLSET}" STREQUAL "v100" OR "${CMAKE_VS_PLATFORM_TOOLSET}" STREQUAL "v90")
+ # This is the VS2010/VS2008 toolset
+ else()
+ # OK, we're VC11 or newer and not using a backlevel or XP-compatible toolset.
+ # These versions have no XP (and possibly Vista pre-SP1) support
+ set(_winsdk_vistaonly_ok ON)
+ if(_WINDOWSSDK_ANNOUNCE AND NOT _WINDOWSSDK_VISTAONLY_PESTERED)
+ set(_WINDOWSSDK_VISTAONLY_PESTERED ON CACHE INTERNAL "" FORCE)
+ message(STATUS "FindWindowsSDK: Detected Visual Studio 2012 or newer, not using the _xp toolset variant: including SDK versions that drop XP support in search!")
+ endif()
+ endif()
+endif()
+if(_WINDOWSSDK_IGNOREMSVC)
+ set(_winsdk_vistaonly_ok ON)
+endif()
+
+###
+# MSVC version checks - keeps messy conditionals in one place
+# (messy because of _WINDOWSSDK_IGNOREMSVC)
+###
+set(_winsdk_msvc_greater_1200 OFF)
+if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (MSVC_VERSION GREATER 1200)))
+ set(_winsdk_msvc_greater_1200 ON)
+endif()
+# Newer than VS .NET/VS Toolkit 2003
+set(_winsdk_msvc_greater_1310 OFF)
+if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (MSVC_VERSION GREATER 1310)))
+ set(_winsdk_msvc_greater_1310 ON)
+endif()
+
+# VS2005/2008
+set(_winsdk_msvc_less_1600 OFF)
+if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (MSVC_VERSION LESS 1600)))
+ set(_winsdk_msvc_less_1600 ON)
+endif()
+
+# VS2013+
+set(_winsdk_msvc_not_less_1800 OFF)
+if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (NOT MSVC_VERSION LESS 1800)))
+ set(_winsdk_msvc_not_less_1800 ON)
+endif()
+
+###
+# START body of find module
+###
+if(_winsdk_msvc_greater_1310) # Newer than VS .NET/VS Toolkit 2003
+ ###
+ # Look for "preferred" SDKs
+ ###
+
+ # Environment variable for SDK dir
+ if(EXISTS "$ENV{WindowsSDKDir}" AND (NOT "$ENV{WindowsSDKDir}" STREQUAL ""))
+ _winsdk_conditional_append_preferred("WindowsSDKDir environment variable" "$ENV{WindowsSDKDir}")
+ endif()
+
+ if(_winsdk_msvc_less_1600)
+ # Per-user current Windows SDK for VS2005/2008
+ get_filename_component(_sdkdir
+ "[HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
+ ABSOLUTE)
+ _winsdk_conditional_append_preferred("Per-user current Windows SDK" "${_sdkdir}")
+
+ # System-wide current Windows SDK for VS2005/2008
+ get_filename_component(_sdkdir
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
+ ABSOLUTE)
+ _winsdk_conditional_append_preferred("System-wide current Windows SDK" "${_sdkdir}")
+ endif()
+
+ ###
+ # Begin the massive list of SDK searching!
+ ###
+ if(_winsdk_vistaonly_ok AND _winsdk_msvc_not_less_1800)
+ # These require at least Visual Studio 2013 (VC12)
+
+ _winsdk_check_microsoft_sdks_registry(v10.0A)
+
+ # Windows Software Development Kit (SDK) for Windows 10
+ # Several different versions living in the same directory - if nothing else we can assume RTM (10240)
+ _winsdk_check_microsoft_sdks_registry(v10.0 10.0.10240.0)
+ foreach(_win10build ${_winsdk_win10vers})
+ _winsdk_check_win10_kits(${_win10build})
+ endforeach()
+ endif() # vista-only and 2013+
+
+ # Included in Visual Studio 2013
+ # Includes the v120_xp toolset
+ _winsdk_check_microsoft_sdks_registry(v8.1A 8.1.51636)
+
+ if(_winsdk_vistaonly_ok AND _winsdk_msvc_not_less_1800)
+ # Windows Software Development Kit (SDK) for Windows 8.1
+ # http://msdn.microsoft.com/en-gb/windows/desktop/bg162891
+ _winsdk_check_microsoft_sdks_registry(v8.1 8.1.25984.0)
+ _winsdk_check_windows_kits_registry("Windows Kits 8.1" 8.1.25984.0 KitsRoot81)
+ endif() # vista-only and 2013+
+
+ if(_winsdk_vistaonly_ok)
+ # Included in Visual Studio 2012
+ _winsdk_check_microsoft_sdks_registry(v8.0A 8.0.50727)
+
+ # Microsoft Windows SDK for Windows 8 and .NET Framework 4.5
+ # This is the first version to also include the DirectX SDK
+ # http://msdn.microsoft.com/en-US/windows/desktop/hh852363.aspx
+ _winsdk_check_microsoft_sdks_registry(v8.0 6.2.9200.16384)
+ _winsdk_check_windows_kits_registry("Windows Kits 8.0" 6.2.9200.16384 KitsRoot)
+ endif() # vista-only
+
+ # Included with VS 2012 Update 1 or later
+ # Introduces v110_xp toolset
+ _winsdk_check_microsoft_sdks_registry(v7.1A 7.1.51106)
+ if(_winsdk_vistaonly_ok)
+ # Microsoft Windows SDK for Windows 7 and .NET Framework 4
+ # http://www.microsoft.com/downloads/en/details.aspx?FamilyID=6b6c21d2-2006-4afa-9702-529fa782d63b
+ _winsdk_check_microsoft_sdks_registry(v7.1 7.1.7600.0.30514)
+ endif() # vista-only
+
+ # Included with VS 2010
+ _winsdk_check_microsoft_sdks_registry(v7.0A 6.1.7600.16385)
+
+ # Windows SDK for Windows 7 and .NET Framework 3.5 SP1
+ # Works with VC9
+ # http://www.microsoft.com/en-us/download/details.aspx?id=18950
+ _winsdk_check_microsoft_sdks_registry(v7.0 6.1.7600.16385)
+
+ # Two versions call themselves "v6.1":
+ # Older:
+ # Windows Vista Update & .NET 3.0 SDK
+ # http://www.microsoft.com/en-us/download/details.aspx?id=14477
+
+ # Newer:
+ # Windows Server 2008 & .NET 3.5 SDK
+ # may have broken VS9SP1? they recommend v7.0 instead, or a KB...
+ # http://www.microsoft.com/en-us/download/details.aspx?id=24826
+ _winsdk_check_microsoft_sdks_registry(v6.1 6.1.6000.16384.10)
+
+ # Included in VS 2008
+ _winsdk_check_microsoft_sdks_registry(v6.0A 6.1.6723.1)
+
+ # Microsoft Windows Software Development Kit for Windows Vista and .NET Framework 3.0 Runtime Components
+ # http://blogs.msdn.com/b/stanley/archive/2006/11/08/microsoft-windows-software-development-kit-for-windows-vista-and-net-framework-3-0-runtime-components.aspx
+ _winsdk_check_microsoft_sdks_registry(v6.0 6.0.6000.16384)
+endif()
+
+# Let's not forget the Platform SDKs, which sometimes are useful!
+if(_winsdk_msvc_greater_1200)
+ _winsdk_check_platformsdk_registry("Microsoft Platform SDK for Windows Server 2003 R2" "5.2.3790.2075.51" "D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1")
+ _winsdk_check_platformsdk_registry("Microsoft Platform SDK for Windows Server 2003 SP1" "5.2.3790.1830.15" "8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3")
+endif()
+###
+# Finally, look for "preferred" SDKs
+###
+if(_winsdk_msvc_greater_1310) # Newer than VS .NET/VS Toolkit 2003
+
+
+ # Environment variable for SDK dir
+ if(EXISTS "$ENV{WindowsSDKDir}" AND (NOT "$ENV{WindowsSDKDir}" STREQUAL ""))
+ _winsdk_conditional_append_preferred("WindowsSDKDir environment variable" "$ENV{WindowsSDKDir}")
+ endif()
+
+ if(_winsdk_msvc_less_1600)
+ # Per-user current Windows SDK for VS2005/2008
+ get_filename_component(_sdkdir
+ "[HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
+ ABSOLUTE)
+ _winsdk_conditional_append_preferred("Per-user current Windows SDK" "${_sdkdir}")
+
+ # System-wide current Windows SDK for VS2005/2008
+ get_filename_component(_sdkdir
+ "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
+ ABSOLUTE)
+ _winsdk_conditional_append_preferred("System-wide current Windows SDK" "${_sdkdir}")
+ endif()
+endif()
+
+
+function(windowssdk_name_lookup _dir _outvar)
+ list(FIND _win_sdk_versanddirs "${_dir}" _diridx)
+ math(EXPR _idx "${_diridx} - 1")
+ if(${_idx} GREATER -1)
+ list(GET _win_sdk_versanddirs ${_idx} _ret)
+ else()
+ set(_ret "NOTFOUND")
+ endif()
+ set(${_outvar} "${_ret}" PARENT_SCOPE)
+endfunction()
+
+function(windowssdk_build_lookup _dir _outvar)
+ list(FIND _win_sdk_buildsanddirs "${_dir}" _diridx)
+ math(EXPR _idx "${_diridx} - 1")
+ if(${_idx} GREATER -1)
+ list(GET _win_sdk_buildsanddirs ${_idx} _ret)
+ else()
+ set(_ret "NOTFOUND")
+ endif()
+ set(${_outvar} "${_ret}" PARENT_SCOPE)
+endfunction()
+
+# If we found something...
+if(_win_sdk_dirs)
+ list(GET _win_sdk_dirs 0 WINDOWSSDK_LATEST_DIR)
+ windowssdk_name_lookup("${WINDOWSSDK_LATEST_DIR}"
+ WINDOWSSDK_LATEST_NAME)
+ set(WINDOWSSDK_DIRS ${_win_sdk_dirs})
+
+ # Fallback, in case no preference found.
+ set(WINDOWSSDK_PREFERRED_DIR "${WINDOWSSDK_LATEST_DIR}")
+ set(WINDOWSSDK_PREFERRED_NAME "${WINDOWSSDK_LATEST_NAME}")
+ set(WINDOWSSDK_PREFERRED_FIRST_DIRS ${WINDOWSSDK_DIRS})
+ set(WINDOWSSDK_FOUND_PREFERENCE OFF)
+endif()
+
+# If we found indications of a user preference...
+if(_win_sdk_preferred_sdk_dirs)
+ list(GET _win_sdk_preferred_sdk_dirs 0 WINDOWSSDK_PREFERRED_DIR)
+ windowssdk_name_lookup("${WINDOWSSDK_PREFERRED_DIR}"
+ WINDOWSSDK_PREFERRED_NAME)
+ set(WINDOWSSDK_PREFERRED_FIRST_DIRS
+ ${_win_sdk_preferred_sdk_dirs}
+ ${_win_sdk_dirs})
+ list(REMOVE_DUPLICATES WINDOWSSDK_PREFERRED_FIRST_DIRS)
+ set(WINDOWSSDK_FOUND_PREFERENCE ON)
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(WindowsSDK
+ "No compatible version of the Windows SDK or Platform SDK found."
+ WINDOWSSDK_DIRS)
+
+if(WINDOWSSDK_FOUND)
+ # Internal: Architecture-appropriate library directory names.
+ if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM")
+ if(CMAKE_SIZEOF_VOID_P MATCHES "8")
+ # Only supported in Win10 SDK and up.
+ set(_winsdk_arch8 arm64) # what the WDK for Win8+ calls this architecture
+ else()
+ set(_winsdk_archbare /arm) # what the architecture used to be called in oldest SDKs
+ set(_winsdk_arch arm) # what the architecture used to be called
+ set(_winsdk_arch8 arm) # what the WDK for Win8+ calls this architecture
+ endif()
+ else()
+ if(CMAKE_SIZEOF_VOID_P MATCHES "8")
+ set(_winsdk_archbare /x64) # what the architecture used to be called in oldest SDKs
+ set(_winsdk_arch amd64) # what the architecture used to be called
+ set(_winsdk_arch8 x64) # what the WDK for Win8+ calls this architecture
+ else()
+ set(_winsdk_archbare ) # what the architecture used to be called in oldest SDKs
+ set(_winsdk_arch i386) # what the architecture used to be called
+ set(_winsdk_arch8 x86) # what the WDK for Win8+ calls this architecture
+ endif()
+ endif()
+
+ function(get_windowssdk_from_component _component _var)
+ get_filename_component(_component "${_component}" ABSOLUTE)
+ file(TO_CMAKE_PATH "${_component}" _component)
+ foreach(_sdkdir ${WINDOWSSDK_DIRS})
+ get_filename_component(_sdkdir "${_sdkdir}" ABSOLUTE)
+ string(LENGTH "${_sdkdir}" _sdklen)
+ file(RELATIVE_PATH _rel "${_sdkdir}" "${_component}")
+ # If we don't have any "parent directory" items...
+ if(NOT "${_rel}" MATCHES "[.][.]")
+ set(${_var} "${_sdkdir}" PARENT_SCOPE)
+ return()
+ endif()
+ endforeach()
+ # Fail.
+ set(${_var} "NOTFOUND" PARENT_SCOPE)
+ endfunction()
+ function(get_windowssdk_library_dirs _winsdk_dir _var)
+ set(_dirs)
+ set(_suffixes
+ "lib${_winsdk_archbare}" # SDKs like 7.1A
+ "lib/${_winsdk_arch}" # just because some SDKs have x86 dir and root dir
+ "lib/w2k/${_winsdk_arch}" # Win2k min requirement
+ "lib/wxp/${_winsdk_arch}" # WinXP min requirement
+ "lib/wnet/${_winsdk_arch}" # Win Server 2003 min requirement
+ "lib/wlh/${_winsdk_arch}"
+ "lib/wlh/um/${_winsdk_arch8}" # Win Vista ("Long Horn") min requirement
+ "lib/win7/${_winsdk_arch}"
+ "lib/win7/um/${_winsdk_arch8}" # Win 7 min requirement
+ )
+ foreach(_ver
+ wlh # Win Vista ("Long Horn") min requirement
+ win7 # Win 7 min requirement
+ win8 # Win 8 min requirement
+ winv6.3 # Win 8.1 min requirement
+ )
+
+ list(APPEND _suffixes
+ "lib/${_ver}/${_winsdk_arch}"
+ "lib/${_ver}/um/${_winsdk_arch8}"
+ "lib/${_ver}/km/${_winsdk_arch8}"
+ )
+ endforeach()
+
+ # Look for WDF libraries in Win10+ SDK
+ foreach(_mode umdf kmdf)
+ file(GLOB _wdfdirs RELATIVE "${_winsdk_dir}" "${_winsdk_dir}/lib/wdf/${_mode}/${_winsdk_arch8}/*")
+ if(_wdfdirs)
+ list(APPEND _suffixes ${_wdfdirs})
+ endif()
+ endforeach()
+
+ # Look in each Win10+ SDK version for the components
+ foreach(_win10ver ${_winsdk_win10vers})
+ foreach(_component um km ucrt mmos)
+ list(APPEND _suffixes "lib/${_win10ver}/${_component}/${_winsdk_arch8}")
+ endforeach()
+ endforeach()
+
+ foreach(_suffix ${_suffixes})
+ # Check to see if a library actually exists here.
+ file(GLOB _libs "${_winsdk_dir}/${_suffix}/*.lib")
+ if(_libs)
+ list(APPEND _dirs "${_winsdk_dir}/${_suffix}")
+ endif()
+ endforeach()
+ if("${_dirs}" STREQUAL "")
+ set(_dirs NOTFOUND)
+ else()
+ list(REMOVE_DUPLICATES _dirs)
+ endif()
+ set(${_var} ${_dirs} PARENT_SCOPE)
+ endfunction()
+ function(get_windowssdk_include_dirs _winsdk_dir _var)
+ set(_dirs)
+
+ set(_subdirs shared um winrt km wdf mmos ucrt)
+ set(_suffixes Include)
+
+ foreach(_dir ${_subdirs})
+ list(APPEND _suffixes "Include/${_dir}")
+ endforeach()
+
+ foreach(_ver ${_winsdk_win10vers})
+ foreach(_dir ${_subdirs})
+ list(APPEND _suffixes "Include/${_ver}/${_dir}")
+ endforeach()
+ endforeach()
+
+ foreach(_suffix ${_suffixes})
+ # Check to see if a header file actually exists here.
+ file(GLOB _headers "${_winsdk_dir}/${_suffix}/*.h")
+ if(_headers)
+ list(APPEND _dirs "${_winsdk_dir}/${_suffix}")
+ endif()
+ endforeach()
+ if("${_dirs}" STREQUAL "")
+ set(_dirs NOTFOUND)
+ else()
+ list(REMOVE_DUPLICATES _dirs)
+ endif()
+ set(${_var} ${_dirs} PARENT_SCOPE)
+ endfunction()
+ function(get_windowssdk_library_dirs_multiple _var)
+ set(_dirs)
+ foreach(_sdkdir ${ARGN})
+ get_windowssdk_library_dirs("${_sdkdir}" _current_sdk_libdirs)
+ if(_current_sdk_libdirs)
+ list(APPEND _dirs ${_current_sdk_libdirs})
+ endif()
+ endforeach()
+ if("${_dirs}" STREQUAL "")
+ set(_dirs NOTFOUND)
+ else()
+ list(REMOVE_DUPLICATES _dirs)
+ endif()
+ set(${_var} ${_dirs} PARENT_SCOPE)
+ endfunction()
+ function(get_windowssdk_include_dirs_multiple _var)
+ set(_dirs)
+ foreach(_sdkdir ${ARGN})
+ get_windowssdk_include_dirs("${_sdkdir}" _current_sdk_incdirs)
+ if(_current_sdk_libdirs)
+ list(APPEND _dirs ${_current_sdk_incdirs})
+ endif()
+ endforeach()
+ if("${_dirs}" STREQUAL "")
+ set(_dirs NOTFOUND)
+ else()
+ list(REMOVE_DUPLICATES _dirs)
+ endif()
+ set(${_var} ${_dirs} PARENT_SCOPE)
+ endfunction()
+endif()
diff --git a/common/alcomplex.c b/common/alcomplex.c
new file mode 100644
index 00000000..d4045aeb
--- /dev/null
+++ b/common/alcomplex.c
@@ -0,0 +1,92 @@
+
+#include "config.h"
+
+#include "alcomplex.h"
+#include "math_defs.h"
+
+
+extern inline ALcomplex complex_add(ALcomplex a, ALcomplex b);
+extern inline ALcomplex complex_sub(ALcomplex a, ALcomplex b);
+extern inline ALcomplex complex_mult(ALcomplex a, ALcomplex b);
+
+void complex_fft(ALcomplex *FFTBuffer, ALsizei FFTSize, ALdouble Sign)
+{
+ ALsizei i, j, k, mask, step, step2;
+ ALcomplex temp, u, w;
+ ALdouble arg;
+
+ /* Bit-reversal permutation applied to a sequence of FFTSize items */
+ for(i = 1;i < FFTSize-1;i++)
+ {
+ for(mask = 0x1, j = 0;mask < FFTSize;mask <<= 1)
+ {
+ if((i&mask) != 0)
+ j++;
+ j <<= 1;
+ }
+ j >>= 1;
+
+ if(i < j)
+ {
+ temp = FFTBuffer[i];
+ FFTBuffer[i] = FFTBuffer[j];
+ FFTBuffer[j] = temp;
+ }
+ }
+
+ /* Iterative form of Danielson–Lanczos lemma */
+ for(i = 1, step = 2;i < FFTSize;i<<=1, step<<=1)
+ {
+ step2 = step >> 1;
+ arg = M_PI / step2;
+
+ w.Real = cos(arg);
+ w.Imag = sin(arg) * Sign;
+
+ u.Real = 1.0;
+ u.Imag = 0.0;
+
+ for(j = 0;j < step2;j++)
+ {
+ for(k = j;k < FFTSize;k+=step)
+ {
+ temp = complex_mult(FFTBuffer[k+step2], u);
+ FFTBuffer[k+step2] = complex_sub(FFTBuffer[k], temp);
+ FFTBuffer[k] = complex_add(FFTBuffer[k], temp);
+ }
+
+ u = complex_mult(u, w);
+ }
+ }
+}
+
+void complex_hilbert(ALcomplex *Buffer, ALsizei size)
+{
+ const ALdouble inverse_size = 1.0/(ALdouble)size;
+ ALsizei todo, i;
+
+ for(i = 0;i < size;i++)
+ Buffer[i].Imag = 0.0;
+
+ complex_fft(Buffer, size, 1.0);
+
+ todo = size >> 1;
+ Buffer[0].Real *= inverse_size;
+ Buffer[0].Imag *= inverse_size;
+ for(i = 1;i < todo;i++)
+ {
+ Buffer[i].Real *= 2.0*inverse_size;
+ Buffer[i].Imag *= 2.0*inverse_size;
+ }
+ Buffer[i].Real *= inverse_size;
+ Buffer[i].Imag *= inverse_size;
+ i++;
+
+ for(;i < size;i++)
+ {
+ Buffer[i].Real = 0.0;
+ Buffer[i].Imag = 0.0;
+ }
+
+ complex_fft(Buffer, size, -1.0);
+}
diff --git a/common/alcomplex.h b/common/alcomplex.h
new file mode 100644
index 00000000..2418ce78
--- /dev/null
+++ b/common/alcomplex.h
@@ -0,0 +1,71 @@
+#ifndef ALCOMPLEX_H
+#define ALCOMPLEX_H
+
+#include "AL/al.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct ALcomplex {
+ ALdouble Real;
+ ALdouble Imag;
+} ALcomplex;
+
+/** Addition of two complex numbers. */
+inline ALcomplex complex_add(ALcomplex a, ALcomplex b)
+{
+ ALcomplex result;
+
+ result.Real = a.Real + b.Real;
+ result.Imag = a.Imag + b.Imag;
+
+ return result;
+}
+
+/** Subtraction of two complex numbers. */
+inline ALcomplex complex_sub(ALcomplex a, ALcomplex b)
+{
+ ALcomplex result;
+
+ result.Real = a.Real - b.Real;
+ result.Imag = a.Imag - b.Imag;
+
+ return result;
+}
+
+/** Multiplication of two complex numbers. */
+inline ALcomplex complex_mult(ALcomplex a, ALcomplex b)
+{
+ ALcomplex result;
+
+ result.Real = a.Real*b.Real - a.Imag*b.Imag;
+ result.Imag = a.Imag*b.Real + a.Real*b.Imag;
+
+ return result;
+}
+
+/**
+ * Iterative implementation of 2-radix FFT (In-place algorithm). Sign = -1 is
+ * FFT and 1 is iFFT (inverse). Fills FFTBuffer[0...FFTSize-1] with the
+ * Discrete Fourier Transform (DFT) of the time domain data stored in
+ * FFTBuffer[0...FFTSize-1]. FFTBuffer is an array of complex numbers, FFTSize
+ * MUST BE power of two.
+ */
+void complex_fft(ALcomplex *FFTBuffer, ALsizei FFTSize, ALdouble Sign);
+
+/**
+ * Calculate the complex helical sequence (discrete-time analytical signal) of
+ * the given input using the discrete Hilbert transform (In-place algorithm).
+ * Fills Buffer[0...size-1] with the discrete-time analytical signal stored in
+ * Buffer[0...size-1]. Buffer is an array of complex numbers, size MUST BE
+ * power of two.
+ */
+void complex_hilbert(ALcomplex *Buffer, ALsizei size);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif /* ALCOMPLEX_H */
diff --git a/include/align.h b/common/align.h
index e2dc81df..e2dc81df 100644
--- a/include/align.h
+++ b/common/align.h
diff --git a/common/almalloc.c b/common/almalloc.c
new file mode 100644
index 00000000..0d982ca1
--- /dev/null
+++ b/common/almalloc.c
@@ -0,0 +1,110 @@
+
+#include "config.h"
+
+#include "almalloc.h"
+
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#else
+#include <unistd.h>
+#endif
+
+
+#ifdef __GNUC__
+#define LIKELY(x) __builtin_expect(!!(x), !0)
+#define UNLIKELY(x) __builtin_expect(!!(x), 0)
+#else
+#define LIKELY(x) (!!(x))
+#define UNLIKELY(x) (!!(x))
+#endif
+
+
+void *al_malloc(size_t alignment, size_t size)
+{
+#if defined(HAVE_ALIGNED_ALLOC)
+ size = (size+(alignment-1))&~(alignment-1);
+ return aligned_alloc(alignment, size);
+#elif defined(HAVE_POSIX_MEMALIGN)
+ void *ret;
+ if(posix_memalign(&ret, alignment, size) == 0)
+ return ret;
+ return NULL;
+#elif defined(HAVE__ALIGNED_MALLOC)
+ return _aligned_malloc(size, alignment);
+#else
+ char *ret = malloc(size+alignment);
+ if(ret != NULL)
+ {
+ *(ret++) = 0x00;
+ while(((ptrdiff_t)ret&(alignment-1)) != 0)
+ *(ret++) = 0x55;
+ }
+ return ret;
+#endif
+}
+
+void *al_calloc(size_t alignment, size_t size)
+{
+ void *ret = al_malloc(alignment, size);
+ if(ret) memset(ret, 0, size);
+ return ret;
+}
+
+void al_free(void *ptr)
+{
+#if defined(HAVE_ALIGNED_ALLOC) || defined(HAVE_POSIX_MEMALIGN)
+ free(ptr);
+#elif defined(HAVE__ALIGNED_MALLOC)
+ _aligned_free(ptr);
+#else
+ if(ptr != NULL)
+ {
+ char *finder = ptr;
+ do {
+ --finder;
+ } while(*finder == 0x55);
+ free(finder);
+ }
+#endif
+}
+
+size_t al_get_page_size(void)
+{
+ static size_t psize = 0;
+ if(UNLIKELY(!psize))
+ {
+#ifdef HAVE_SYSCONF
+#if defined(_SC_PAGESIZE)
+ if(!psize) psize = sysconf(_SC_PAGESIZE);
+#elif defined(_SC_PAGE_SIZE)
+ if(!psize) psize = sysconf(_SC_PAGE_SIZE);
+#endif
+#endif /* HAVE_SYSCONF */
+#ifdef _WIN32
+ if(!psize)
+ {
+ SYSTEM_INFO sysinfo;
+ memset(&sysinfo, 0, sizeof(sysinfo));
+
+ GetSystemInfo(&sysinfo);
+ psize = sysinfo.dwPageSize;
+ }
+#endif
+ if(!psize) psize = DEF_ALIGN;
+ }
+ return psize;
+}
+
+int al_is_sane_alignment_allocator(void)
+{
+#if defined(HAVE_ALIGNED_ALLOC) || defined(HAVE_POSIX_MEMALIGN) || defined(HAVE__ALIGNED_MALLOC)
+ return 1;
+#else
+ return 0;
+#endif
+}
diff --git a/common/almalloc.h b/common/almalloc.h
new file mode 100644
index 00000000..a4297cf5
--- /dev/null
+++ b/common/almalloc.h
@@ -0,0 +1,30 @@
+#ifndef AL_MALLOC_H
+#define AL_MALLOC_H
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Minimum alignment required by posix_memalign. */
+#define DEF_ALIGN sizeof(void*)
+
+void *al_malloc(size_t alignment, size_t size);
+void *al_calloc(size_t alignment, size_t size);
+void al_free(void *ptr);
+
+size_t al_get_page_size(void);
+
+/**
+ * Returns non-0 if the allocation function has direct alignment handling.
+ * Otherwise, the standard malloc is used with an over-allocation and pointer
+ * offset strategy.
+ */
+int al_is_sane_alignment_allocator(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AL_MALLOC_H */
diff --git a/common/atomic.c b/common/atomic.c
index 3cdb77f4..7a8fe6d8 100644
--- a/common/atomic.c
+++ b/common/atomic.c
@@ -8,6 +8,3 @@ extern inline void InitRef(RefCount *ptr, uint value);
extern inline uint ReadRef(RefCount *ptr);
extern inline uint IncrementRef(RefCount *ptr);
extern inline uint DecrementRef(RefCount *ptr);
-
-extern inline int ExchangeInt(volatile int *ptr, int newval);
-extern inline void *ExchangePtr(XchgPtr *ptr, void *newval);
diff --git a/common/atomic.h b/common/atomic.h
new file mode 100644
index 00000000..39daa1dc
--- /dev/null
+++ b/common/atomic.h
@@ -0,0 +1,439 @@
+#ifndef AL_ATOMIC_H
+#define AL_ATOMIC_H
+
+#include "static_assert.h"
+#include "bool.h"
+
+#ifdef __GNUC__
+/* This helps cast away the const-ness of a pointer without accidentally
+ * changing the pointer type. This is necessary due to Clang's inability to use
+ * atomic_load on a const _Atomic variable.
+ */
+#define CONST_CAST(T, V) __extension__({ \
+ const T _tmp = (V); \
+ (T)_tmp; \
+})
+#else
+#define CONST_CAST(T, V) ((T)(V))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Atomics using C11 */
+#ifdef HAVE_C11_ATOMIC
+
+#include <stdatomic.h>
+
+#define almemory_order memory_order
+#define almemory_order_relaxed memory_order_relaxed
+#define almemory_order_consume memory_order_consume
+#define almemory_order_acquire memory_order_acquire
+#define almemory_order_release memory_order_release
+#define almemory_order_acq_rel memory_order_acq_rel
+#define almemory_order_seq_cst memory_order_seq_cst
+
+#define ATOMIC(T) T _Atomic
+#define ATOMIC_FLAG atomic_flag
+
+#define ATOMIC_INIT atomic_init
+#define ATOMIC_INIT_STATIC ATOMIC_VAR_INIT
+/*#define ATOMIC_FLAG_INIT ATOMIC_FLAG_INIT*/
+
+#define ATOMIC_LOAD atomic_load_explicit
+#define ATOMIC_STORE atomic_store_explicit
+
+#define ATOMIC_ADD atomic_fetch_add_explicit
+#define ATOMIC_SUB atomic_fetch_sub_explicit
+
+#define ATOMIC_EXCHANGE atomic_exchange_explicit
+#define ATOMIC_COMPARE_EXCHANGE_STRONG atomic_compare_exchange_strong_explicit
+#define ATOMIC_COMPARE_EXCHANGE_WEAK atomic_compare_exchange_weak_explicit
+
+#define ATOMIC_FLAG_TEST_AND_SET atomic_flag_test_and_set_explicit
+#define ATOMIC_FLAG_CLEAR atomic_flag_clear_explicit
+
+#define ATOMIC_THREAD_FENCE atomic_thread_fence
+
+/* Atomics using GCC intrinsics */
+#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && !defined(__QNXNTO__)
+
+enum almemory_order {
+ almemory_order_relaxed,
+ almemory_order_consume,
+ almemory_order_acquire,
+ almemory_order_release,
+ almemory_order_acq_rel,
+ almemory_order_seq_cst
+};
+
+#define ATOMIC(T) struct { T volatile value; }
+#define ATOMIC_FLAG ATOMIC(int)
+
+#define ATOMIC_INIT(_val, _newval) do { (_val)->value = (_newval); } while(0)
+#define ATOMIC_INIT_STATIC(_newval) {(_newval)}
+#define ATOMIC_FLAG_INIT ATOMIC_INIT_STATIC(0)
+
+#define ATOMIC_LOAD(_val, _MO) __extension__({ \
+ __typeof((_val)->value) _r = (_val)->value; \
+ __asm__ __volatile__("" ::: "memory"); \
+ _r; \
+})
+#define ATOMIC_STORE(_val, _newval, _MO) do { \
+ __asm__ __volatile__("" ::: "memory"); \
+ (_val)->value = (_newval); \
+} while(0)
+
+#define ATOMIC_ADD(_val, _incr, _MO) __sync_fetch_and_add(&(_val)->value, (_incr))
+#define ATOMIC_SUB(_val, _decr, _MO) __sync_fetch_and_sub(&(_val)->value, (_decr))
+
+#define ATOMIC_EXCHANGE(_val, _newval, _MO) __extension__({ \
+ __asm__ __volatile__("" ::: "memory"); \
+ __sync_lock_test_and_set(&(_val)->value, (_newval)); \
+})
+#define ATOMIC_COMPARE_EXCHANGE_STRONG(_val, _oldval, _newval, _MO1, _MO2) __extension__({ \
+ __typeof(*(_oldval)) _o = *(_oldval); \
+ *(_oldval) = __sync_val_compare_and_swap(&(_val)->value, _o, (_newval)); \
+ *(_oldval) == _o; \
+})
+
+#define ATOMIC_FLAG_TEST_AND_SET(_val, _MO) __extension__({ \
+ __asm__ __volatile__("" ::: "memory"); \
+ __sync_lock_test_and_set(&(_val)->value, 1); \
+})
+#define ATOMIC_FLAG_CLEAR(_val, _MO) __extension__({ \
+ __sync_lock_release(&(_val)->value); \
+ __asm__ __volatile__("" ::: "memory"); \
+})
+
+
+#define ATOMIC_THREAD_FENCE(order) do { \
+ enum { must_be_constant = (order) }; \
+ const int _o = must_be_constant; \
+ if(_o > almemory_order_relaxed) \
+ __asm__ __volatile__("" ::: "memory"); \
+} while(0)
+
+/* Atomics using x86/x86-64 GCC inline assembly */
+#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+
+#define WRAP_ADD(S, ret, dest, incr) __asm__ __volatile__( \
+ "lock; xadd"S" %0,(%1)" \
+ : "=r" (ret) \
+ : "r" (dest), "0" (incr) \
+ : "memory" \
+)
+#define WRAP_SUB(S, ret, dest, decr) __asm__ __volatile__( \
+ "lock; xadd"S" %0,(%1)" \
+ : "=r" (ret) \
+ : "r" (dest), "0" (-(decr)) \
+ : "memory" \
+)
+
+#define WRAP_XCHG(S, ret, dest, newval) __asm__ __volatile__( \
+ "lock; xchg"S" %0,(%1)" \
+ : "=r" (ret) \
+ : "r" (dest), "0" (newval) \
+ : "memory" \
+)
+#define WRAP_CMPXCHG(S, ret, dest, oldval, newval) __asm__ __volatile__( \
+ "lock; cmpxchg"S" %2,(%1)" \
+ : "=a" (ret) \
+ : "r" (dest), "r" (newval), "0" (oldval) \
+ : "memory" \
+)
+
+
+enum almemory_order {
+ almemory_order_relaxed,
+ almemory_order_consume,
+ almemory_order_acquire,
+ almemory_order_release,
+ almemory_order_acq_rel,
+ almemory_order_seq_cst
+};
+
+#define ATOMIC(T) struct { T volatile value; }
+
+#define ATOMIC_INIT(_val, _newval) do { (_val)->value = (_newval); } while(0)
+#define ATOMIC_INIT_STATIC(_newval) {(_newval)}
+
+#define ATOMIC_LOAD(_val, _MO) __extension__({ \
+ __typeof((_val)->value) _r = (_val)->value; \
+ __asm__ __volatile__("" ::: "memory"); \
+ _r; \
+})
+#define ATOMIC_STORE(_val, _newval, _MO) do { \
+ __asm__ __volatile__("" ::: "memory"); \
+ (_val)->value = (_newval); \
+} while(0)
+
+#define ATOMIC_ADD(_val, _incr, _MO) __extension__({ \
+ static_assert(sizeof((_val)->value)==4 || sizeof((_val)->value)==8, "Unsupported size!"); \
+ __typeof((_val)->value) _r; \
+ if(sizeof((_val)->value) == 4) WRAP_ADD("l", _r, &(_val)->value, _incr); \
+ else if(sizeof((_val)->value) == 8) WRAP_ADD("q", _r, &(_val)->value, _incr); \
+ _r; \
+})
+#define ATOMIC_SUB(_val, _decr, _MO) __extension__({ \
+ static_assert(sizeof((_val)->value)==4 || sizeof((_val)->value)==8, "Unsupported size!"); \
+ __typeof((_val)->value) _r; \
+ if(sizeof((_val)->value) == 4) WRAP_SUB("l", _r, &(_val)->value, _decr); \
+ else if(sizeof((_val)->value) == 8) WRAP_SUB("q", _r, &(_val)->value, _decr); \
+ _r; \
+})
+
+#define ATOMIC_EXCHANGE(_val, _newval, _MO) __extension__({ \
+ __typeof((_val)->value) _r; \
+ if(sizeof((_val)->value) == 4) WRAP_XCHG("l", _r, &(_val)->value, (_newval)); \
+ else if(sizeof((_val)->value) == 8) WRAP_XCHG("q", _r, &(_val)->value, (_newval)); \
+ _r; \
+})
+#define ATOMIC_COMPARE_EXCHANGE_STRONG(_val, _oldval, _newval, _MO1, _MO2) __extension__({ \
+ __typeof(*(_oldval)) _old = *(_oldval); \
+ if(sizeof((_val)->value) == 4) WRAP_CMPXCHG("l", *(_oldval), &(_val)->value, _old, (_newval)); \
+ else if(sizeof((_val)->value) == 8) WRAP_CMPXCHG("q", *(_oldval), &(_val)->value, _old, (_newval)); \
+ *(_oldval) == _old; \
+})
+
+#define ATOMIC_EXCHANGE_PTR(_val, _newval, _MO) __extension__({ \
+ void *_r; \
+ if(sizeof(void*) == 4) WRAP_XCHG("l", _r, &(_val)->value, (_newval)); \
+ else if(sizeof(void*) == 8) WRAP_XCHG("q", _r, &(_val)->value, (_newval));\
+ _r; \
+})
+#define ATOMIC_COMPARE_EXCHANGE_PTR_STRONG(_val, _oldval, _newval, _MO1, _MO2) __extension__({ \
+ void *_old = *(_oldval); \
+ if(sizeof(void*) == 4) WRAP_CMPXCHG("l", *(_oldval), &(_val)->value, _old, (_newval)); \
+ else if(sizeof(void*) == 8) WRAP_CMPXCHG("q", *(_oldval), &(_val)->value, _old, (_newval)); \
+ *(_oldval) == _old; \
+})
+
+#define ATOMIC_THREAD_FENCE(order) do { \
+ enum { must_be_constant = (order) }; \
+ const int _o = must_be_constant; \
+ if(_o > almemory_order_relaxed) \
+ __asm__ __volatile__("" ::: "memory"); \
+} while(0)
+
+/* Atomics using Windows methods */
+#elif defined(_WIN32)
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+/* NOTE: This mess is *extremely* touchy. It lacks quite a bit of safety
+ * checking due to the lack of multi-statement expressions, typeof(), and C99
+ * compound literals. It is incapable of properly exchanging floats, which get
+ * casted to LONG/int, and could cast away potential warnings.
+ *
+ * Unfortunately, it's the only semi-safe way that doesn't rely on C99 (because
+ * MSVC).
+ */
+
+inline LONG AtomicAdd32(volatile LONG *dest, LONG incr)
+{
+ return InterlockedExchangeAdd(dest, incr);
+}
+inline LONGLONG AtomicAdd64(volatile LONGLONG *dest, LONGLONG incr)
+{
+ return InterlockedExchangeAdd64(dest, incr);
+}
+inline LONG AtomicSub32(volatile LONG *dest, LONG decr)
+{
+ return InterlockedExchangeAdd(dest, -decr);
+}
+inline LONGLONG AtomicSub64(volatile LONGLONG *dest, LONGLONG decr)
+{
+ return InterlockedExchangeAdd64(dest, -decr);
+}
+
+inline LONG AtomicSwap32(volatile LONG *dest, LONG newval)
+{
+ return InterlockedExchange(dest, newval);
+}
+inline LONGLONG AtomicSwap64(volatile LONGLONG *dest, LONGLONG newval)
+{
+ return InterlockedExchange64(dest, newval);
+}
+inline void *AtomicSwapPtr(void *volatile *dest, void *newval)
+{
+ return InterlockedExchangePointer(dest, newval);
+}
+
+inline bool CompareAndSwap32(volatile LONG *dest, LONG newval, LONG *oldval)
+{
+ LONG old = *oldval;
+ *oldval = InterlockedCompareExchange(dest, newval, *oldval);
+ return old == *oldval;
+}
+inline bool CompareAndSwap64(volatile LONGLONG *dest, LONGLONG newval, LONGLONG *oldval)
+{
+ LONGLONG old = *oldval;
+ *oldval = InterlockedCompareExchange64(dest, newval, *oldval);
+ return old == *oldval;
+}
+inline bool CompareAndSwapPtr(void *volatile *dest, void *newval, void **oldval)
+{
+ void *old = *oldval;
+ *oldval = InterlockedCompareExchangePointer(dest, newval, *oldval);
+ return old == *oldval;
+}
+
+#define WRAP_ADDSUB(T, _func, _ptr, _amnt) _func((T volatile*)(_ptr), (_amnt))
+#define WRAP_XCHG(T, _func, _ptr, _newval) _func((T volatile*)(_ptr), (_newval))
+#define WRAP_CMPXCHG(T, _func, _ptr, _newval, _oldval) _func((T volatile*)(_ptr), (_newval), (T*)(_oldval))
+
+
+enum almemory_order {
+ almemory_order_relaxed,
+ almemory_order_consume,
+ almemory_order_acquire,
+ almemory_order_release,
+ almemory_order_acq_rel,
+ almemory_order_seq_cst
+};
+
+#define ATOMIC(T) struct { T volatile value; }
+
+#define ATOMIC_INIT(_val, _newval) do { (_val)->value = (_newval); } while(0)
+#define ATOMIC_INIT_STATIC(_newval) {(_newval)}
+
+#define ATOMIC_LOAD(_val, _MO) ((_val)->value)
+#define ATOMIC_STORE(_val, _newval, _MO) do { \
+ (_val)->value = (_newval); \
+} while(0)
+
+int _al_invalid_atomic_size(); /* not defined */
+void *_al_invalid_atomic_ptr_size(); /* not defined */
+
+#define ATOMIC_ADD(_val, _incr, _MO) \
+ ((sizeof((_val)->value)==4) ? WRAP_ADDSUB(LONG, AtomicAdd32, &(_val)->value, (_incr)) : \
+ (sizeof((_val)->value)==8) ? WRAP_ADDSUB(LONGLONG, AtomicAdd64, &(_val)->value, (_incr)) : \
+ _al_invalid_atomic_size())
+#define ATOMIC_SUB(_val, _decr, _MO) \
+ ((sizeof((_val)->value)==4) ? WRAP_ADDSUB(LONG, AtomicSub32, &(_val)->value, (_decr)) : \
+ (sizeof((_val)->value)==8) ? WRAP_ADDSUB(LONGLONG, AtomicSub64, &(_val)->value, (_decr)) : \
+ _al_invalid_atomic_size())
+
+#define ATOMIC_EXCHANGE(_val, _newval, _MO) \
+ ((sizeof((_val)->value)==4) ? WRAP_XCHG(LONG, AtomicSwap32, &(_val)->value, (_newval)) : \
+ (sizeof((_val)->value)==8) ? WRAP_XCHG(LONGLONG, AtomicSwap64, &(_val)->value, (_newval)) : \
+ (LONG)_al_invalid_atomic_size())
+#define ATOMIC_COMPARE_EXCHANGE_STRONG(_val, _oldval, _newval, _MO1, _MO2) \
+ ((sizeof((_val)->value)==4) ? WRAP_CMPXCHG(LONG, CompareAndSwap32, &(_val)->value, (_newval), (_oldval)) : \
+ (sizeof((_val)->value)==8) ? WRAP_CMPXCHG(LONGLONG, CompareAndSwap64, &(_val)->value, (_newval), (_oldval)) : \
+ (bool)_al_invalid_atomic_size())
+
+#define ATOMIC_EXCHANGE_PTR(_val, _newval, _MO) \
+ ((sizeof((_val)->value)==sizeof(void*)) ? AtomicSwapPtr((void*volatile*)&(_val)->value, (_newval)) : \
+ _al_invalid_atomic_ptr_size())
+#define ATOMIC_COMPARE_EXCHANGE_PTR_STRONG(_val, _oldval, _newval, _MO1, _MO2)\
+ ((sizeof((_val)->value)==sizeof(void*)) ? CompareAndSwapPtr((void*volatile*)&(_val)->value, (_newval), (void**)(_oldval)) : \
+ (bool)_al_invalid_atomic_size())
+
+#define ATOMIC_THREAD_FENCE(order) do { \
+ enum { must_be_constant = (order) }; \
+ const int _o = must_be_constant; \
+ if(_o > almemory_order_relaxed) \
+ _ReadWriteBarrier(); \
+} while(0)
+
+#else
+
+#error "No atomic functions available on this platform!"
+
+#define ATOMIC(T) T
+
+#define ATOMIC_INIT(_val, _newval) ((void)0)
+#define ATOMIC_INIT_STATIC(_newval) (0)
+
+#define ATOMIC_LOAD(...) (0)
+#define ATOMIC_STORE(...) ((void)0)
+
+#define ATOMIC_ADD(...) (0)
+#define ATOMIC_SUB(...) (0)
+
+#define ATOMIC_EXCHANGE(...) (0)
+#define ATOMIC_COMPARE_EXCHANGE_STRONG(...) (0)
+
+#define ATOMIC_THREAD_FENCE(...) ((void)0)
+#endif
+
+/* If no PTR xchg variants are provided, the normal ones can handle it. */
+#ifndef ATOMIC_EXCHANGE_PTR
+#define ATOMIC_EXCHANGE_PTR ATOMIC_EXCHANGE
+#define ATOMIC_COMPARE_EXCHANGE_PTR_STRONG ATOMIC_COMPARE_EXCHANGE_STRONG
+#define ATOMIC_COMPARE_EXCHANGE_PTR_WEAK ATOMIC_COMPARE_EXCHANGE_WEAK
+#endif
+
+/* If no weak cmpxchg is provided (not all systems will have one), substitute a
+ * strong cmpxchg. */
+#ifndef ATOMIC_COMPARE_EXCHANGE_WEAK
+#define ATOMIC_COMPARE_EXCHANGE_WEAK ATOMIC_COMPARE_EXCHANGE_STRONG
+#endif
+#ifndef ATOMIC_COMPARE_EXCHANGE_PTR_WEAK
+#define ATOMIC_COMPARE_EXCHANGE_PTR_WEAK ATOMIC_COMPARE_EXCHANGE_PTR_STRONG
+#endif
+
+/* If no ATOMIC_FLAG is defined, simulate one with an atomic int using exchange
+ * and store ops.
+ */
+#ifndef ATOMIC_FLAG
+#define ATOMIC_FLAG ATOMIC(int)
+#define ATOMIC_FLAG_INIT ATOMIC_INIT_STATIC(0)
+#define ATOMIC_FLAG_TEST_AND_SET(_val, _MO) ATOMIC_EXCHANGE(_val, 1, _MO)
+#define ATOMIC_FLAG_CLEAR(_val, _MO) ATOMIC_STORE(_val, 0, _MO)
+#endif
+
+
+#define ATOMIC_LOAD_SEQ(_val) ATOMIC_LOAD(_val, almemory_order_seq_cst)
+#define ATOMIC_STORE_SEQ(_val, _newval) ATOMIC_STORE(_val, _newval, almemory_order_seq_cst)
+
+#define ATOMIC_ADD_SEQ(_val, _incr) ATOMIC_ADD(_val, _incr, almemory_order_seq_cst)
+#define ATOMIC_SUB_SEQ(_val, _decr) ATOMIC_SUB(_val, _decr, almemory_order_seq_cst)
+
+#define ATOMIC_EXCHANGE_SEQ(_val, _newval) ATOMIC_EXCHANGE(_val, _newval, almemory_order_seq_cst)
+#define ATOMIC_COMPARE_EXCHANGE_STRONG_SEQ(_val, _oldval, _newval) \
+ ATOMIC_COMPARE_EXCHANGE_STRONG(_val, _oldval, _newval, almemory_order_seq_cst, almemory_order_seq_cst)
+#define ATOMIC_COMPARE_EXCHANGE_WEAK_SEQ(_val, _oldval, _newval) \
+ ATOMIC_COMPARE_EXCHANGE_WEAK(_val, _oldval, _newval, almemory_order_seq_cst, almemory_order_seq_cst)
+
+#define ATOMIC_EXCHANGE_PTR_SEQ(_val, _newval) ATOMIC_EXCHANGE_PTR(_val, _newval, almemory_order_seq_cst)
+#define ATOMIC_COMPARE_EXCHANGE_PTR_STRONG_SEQ(_val, _oldval, _newval) \
+ ATOMIC_COMPARE_EXCHANGE_PTR_STRONG(_val, _oldval, _newval, almemory_order_seq_cst, almemory_order_seq_cst)
+#define ATOMIC_COMPARE_EXCHANGE_PTR_WEAK_SEQ(_val, _oldval, _newval) \
+ ATOMIC_COMPARE_EXCHANGE_PTR_WEAK(_val, _oldval, _newval, almemory_order_seq_cst, almemory_order_seq_cst)
+
+
+typedef unsigned int uint;
+typedef ATOMIC(uint) RefCount;
+
+inline void InitRef(RefCount *ptr, uint value)
+{ ATOMIC_INIT(ptr, value); }
+inline uint ReadRef(RefCount *ptr)
+{ return ATOMIC_LOAD(ptr, almemory_order_acquire); }
+inline uint IncrementRef(RefCount *ptr)
+{ return ATOMIC_ADD(ptr, 1, almemory_order_acq_rel)+1; }
+inline uint DecrementRef(RefCount *ptr)
+{ return ATOMIC_SUB(ptr, 1, almemory_order_acq_rel)-1; }
+
+
+/* WARNING: A livelock is theoretically possible if another thread keeps
+ * changing the head without giving this a chance to actually swap in the new
+ * one (practically impossible with this little code, but...).
+ */
+#define ATOMIC_REPLACE_HEAD(T, _head, _entry) do { \
+ T _first = ATOMIC_LOAD(_head, almemory_order_acquire); \
+ do { \
+ ATOMIC_STORE(&(_entry)->next, _first, almemory_order_relaxed); \
+ } while(ATOMIC_COMPARE_EXCHANGE_PTR_WEAK(_head, &_first, _entry, \
+ almemory_order_acq_rel, almemory_order_acquire) == 0); \
+} while(0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AL_ATOMIC_H */
diff --git a/include/bool.h b/common/bool.h
index 6f714d09..6f714d09 100644
--- a/include/bool.h
+++ b/common/bool.h
diff --git a/common/math_defs.h b/common/math_defs.h
new file mode 100644
index 00000000..aa79b695
--- /dev/null
+++ b/common/math_defs.h
@@ -0,0 +1,65 @@
+#ifndef AL_MATH_DEFS_H
+#define AL_MATH_DEFS_H
+
+#include <math.h>
+#ifdef HAVE_FLOAT_H
+#include <float.h>
+#endif
+
+#ifndef M_PI
+#define M_PI (3.14159265358979323846)
+#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 SQRT_2 1.41421356237309504880
+#define SQRT_3 1.73205080756887719318
+
+#define SQRTF_2 1.41421356237309504880f
+#define SQRTF_3 1.73205080756887719318f
+
+#ifndef HUGE_VALF
+static const union msvc_inf_hack {
+ unsigned char b[4];
+ float f;
+} msvc_inf_union = {{ 0x00, 0x00, 0x80, 0x7F }};
+#define HUGE_VALF (msvc_inf_union.f)
+#endif
+
+#ifndef HAVE_LOG2F
+static inline float log2f(float f)
+{
+ return logf(f) / logf(2.0f);
+}
+#endif
+
+#ifndef HAVE_CBRTF
+static inline float cbrtf(float f)
+{
+ return powf(f, 1.0f/3.0f);
+}
+#endif
+
+#ifndef HAVE_COPYSIGNF
+static inline float copysignf(float x, float y)
+{
+ union {
+ float f;
+ unsigned int u;
+ } ux = { x }, uy = { y };
+ ux.u &= 0x7fffffffu;
+ ux.u |= (uy.u&0x80000000u);
+ return ux.f;
+}
+#endif
+
+#define DEG2RAD(x) ((float)(x) * (float)(M_PI/180.0))
+#define RAD2DEG(x) ((float)(x) * (float)(180.0/M_PI))
+
+#endif /* AL_MATH_DEFS_H */
diff --git a/common/rwlock.c b/common/rwlock.c
index cfa3aee4..67cf3acf 100644
--- a/common/rwlock.c
+++ b/common/rwlock.c
@@ -11,26 +11,27 @@
/* A simple spinlock. Yield the thread while the given integer is set by
* another. Could probably be improved... */
#define LOCK(l) do { \
- while(ATOMIC_EXCHANGE(int, &(l), true) == true) \
+ while(ATOMIC_FLAG_TEST_AND_SET(&(l), almemory_order_acq_rel) == true) \
althrd_yield(); \
} while(0)
-#define UNLOCK(l) ATOMIC_STORE(&(l), false)
+#define UNLOCK(l) ATOMIC_FLAG_CLEAR(&(l), almemory_order_release)
void RWLockInit(RWLock *lock)
{
InitRef(&lock->read_count, 0);
InitRef(&lock->write_count, 0);
- ATOMIC_INIT(&lock->read_lock, false);
- ATOMIC_INIT(&lock->read_entry_lock, false);
- ATOMIC_INIT(&lock->write_lock, false);
+ ATOMIC_FLAG_CLEAR(&lock->read_lock, almemory_order_relaxed);
+ ATOMIC_FLAG_CLEAR(&lock->read_entry_lock, almemory_order_relaxed);
+ ATOMIC_FLAG_CLEAR(&lock->write_lock, almemory_order_relaxed);
}
void ReadLock(RWLock *lock)
{
LOCK(lock->read_entry_lock);
LOCK(lock->read_lock);
- if(IncrementRef(&lock->read_count) == 1)
+ /* NOTE: ATOMIC_ADD returns the *old* value! */
+ if(ATOMIC_ADD(&lock->read_count, 1, almemory_order_acq_rel) == 0)
LOCK(lock->write_lock);
UNLOCK(lock->read_lock);
UNLOCK(lock->read_entry_lock);
@@ -38,13 +39,14 @@ void ReadLock(RWLock *lock)
void ReadUnlock(RWLock *lock)
{
- if(DecrementRef(&lock->read_count) == 0)
+ /* NOTE: ATOMIC_SUB returns the *old* value! */
+ if(ATOMIC_SUB(&lock->read_count, 1, almemory_order_acq_rel) == 1)
UNLOCK(lock->write_lock);
}
void WriteLock(RWLock *lock)
{
- if(IncrementRef(&lock->write_count) == 1)
+ if(ATOMIC_ADD(&lock->write_count, 1, almemory_order_acq_rel) == 0)
LOCK(lock->read_lock);
LOCK(lock->write_lock);
}
@@ -52,6 +54,6 @@ void WriteLock(RWLock *lock)
void WriteUnlock(RWLock *lock)
{
UNLOCK(lock->write_lock);
- if(DecrementRef(&lock->write_count) == 0)
+ if(ATOMIC_SUB(&lock->write_count, 1, almemory_order_acq_rel) == 1)
UNLOCK(lock->read_lock);
}
diff --git a/include/rwlock.h b/common/rwlock.h
index 158a0670..8e36fa1a 100644
--- a/include/rwlock.h
+++ b/common/rwlock.h
@@ -11,13 +11,12 @@ extern "C" {
typedef struct {
RefCount read_count;
RefCount write_count;
- ATOMIC(int) read_lock;
- ATOMIC(int) read_entry_lock;
- ATOMIC(int) write_lock;
+ ATOMIC_FLAG read_lock;
+ ATOMIC_FLAG read_entry_lock;
+ ATOMIC_FLAG 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) }
+ ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT, ATOMIC_FLAG_INIT }
void RWLockInit(RWLock *lock);
void ReadLock(RWLock *lock);
diff --git a/include/static_assert.h b/common/static_assert.h
index bf0ce065..bf0ce065 100644
--- a/include/static_assert.h
+++ b/common/static_assert.h
diff --git a/common/threads.c b/common/threads.c
index 71fa6ab9..e8301297 100644
--- a/common/threads.c
+++ b/common/threads.c
@@ -55,7 +55,7 @@ extern inline int altss_set(altss_t tss_id, void *val);
#endif
-#define THREAD_STACK_SIZE (1*1024*1024) /* 1MB */
+#define THREAD_STACK_SIZE (2*1024*1024) /* 2MB */
#ifdef _WIN32
@@ -64,6 +64,22 @@ extern inline int altss_set(altss_t tss_id, void *val);
#include <mmsystem.h>
+/* An associative map of uint:void* pairs. The key is the unique Thread ID and
+ * the value is the thread HANDLE. The thread ID is passed around as the
+ * althrd_t since there is only one ID per thread, whereas a thread may be
+ * referenced by multiple different HANDLEs. This map allows retrieving the
+ * original handle which is needed to join the thread and get its return value.
+ */
+static UIntMap ThrdIdHandle = UINTMAP_STATIC_INITIALIZE;
+
+/* An associative map of uint:void* pairs. The key is the TLS index (given by
+ * TlsAlloc), and the value is the altss_dtor_t callback. When a thread exits,
+ * we iterate over the TLS indices for their thread-local value and call the
+ * destructor function with it if they're both not NULL.
+ */
+static UIntMap TlsDestructors = UINTMAP_STATIC_INITIALIZE;
+
+
void althrd_setname(althrd_t thr, const char *name)
{
#if defined(_MSC_VER)
@@ -94,23 +110,6 @@ void althrd_setname(althrd_t thr, const char *name)
}
-static UIntMap ThrdIdHandle = UINTMAP_STATIC_INITIALIZE;
-
-static void NTAPI althrd_callback(void* UNUSED(handle), DWORD reason, void* UNUSED(reserved))
-{
- if(reason == DLL_PROCESS_DETACH)
- ResetUIntMap(&ThrdIdHandle);
-}
-#ifdef _MSC_VER
-#pragma section(".CRT$XLC",read)
-__declspec(allocate(".CRT$XLC")) PIMAGE_TLS_CALLBACK althrd_callback_ = althrd_callback;
-#elif defined(__GNUC__)
-PIMAGE_TLS_CALLBACK althrd_callback_ __attribute__((section(".CRT$XLC"))) = althrd_callback;
-#else
-PIMAGE_TLS_CALLBACK althrd_callback_ = althrd_callback;
-#endif
-
-
typedef struct thread_cntr {
althrd_start_t func;
void *arg;
@@ -194,7 +193,8 @@ int althrd_sleep(const struct timespec *ts, struct timespec* UNUSED(rem))
int almtx_init(almtx_t *mtx, int type)
{
if(!mtx) return althrd_error;
- type &= ~(almtx_recursive|almtx_timed);
+
+ type &= ~almtx_recursive;
if(type != almtx_plain)
return althrd_error;
@@ -207,29 +207,6 @@ void almtx_destroy(almtx_t *mtx)
DeleteCriticalSection(mtx);
}
-int almtx_timedlock(almtx_t *mtx, const struct timespec *ts)
-{
- int ret;
-
- if(!mtx || !ts)
- return althrd_error;
-
- while((ret=almtx_trylock(mtx)) == althrd_busy)
- {
- struct timespec now;
-
- if(ts->tv_sec < 0 || ts->tv_nsec < 0 || ts->tv_nsec >= 1000000000 ||
- altimespec_get(&now, AL_TIME_UTC) != AL_TIME_UTC)
- return althrd_error;
- if(now.tv_sec > ts->tv_sec || (now.tv_sec == ts->tv_sec && now.tv_nsec >= ts->tv_nsec))
- return althrd_timedout;
-
- althrd_yield();
- }
-
- return ret;
-}
-
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600
int alcnd_init(alcnd_t *cond)
{
@@ -256,21 +233,6 @@ int alcnd_wait(alcnd_t *cond, almtx_t *mtx)
return althrd_error;
}
-int alcnd_timedwait(alcnd_t *cond, almtx_t *mtx, const struct timespec *time_point)
-{
- struct timespec curtime;
- DWORD sleeptime;
-
- if(altimespec_get(&curtime, AL_TIME_UTC) != AL_TIME_UTC)
- return althrd_error;
-
- sleeptime = (time_point->tv_nsec - curtime.tv_nsec + 999999)/1000000;
- sleeptime += (time_point->tv_sec - curtime.tv_sec)*1000;
- if(SleepConditionVariableCS(cond, mtx, sleeptime) != 0)
- return althrd_success;
- return (GetLastError()==ERROR_TIMEOUT) ? althrd_timedout : althrd_error;
-}
-
void alcnd_destroy(alcnd_t* UNUSED(cond))
{
/* Nothing to delete? */
@@ -306,8 +268,8 @@ int alcnd_init(alcnd_t *cond)
InitRef(&icond->wait_count, 0);
- icond->events[SIGNAL] = CreateEvent(NULL, FALSE, FALSE, NULL);
- icond->events[BROADCAST] = CreateEvent(NULL, TRUE, FALSE, NULL);
+ icond->events[SIGNAL] = CreateEventW(NULL, FALSE, FALSE, NULL);
+ icond->events[BROADCAST] = CreateEventW(NULL, TRUE, FALSE, NULL);
if(!icond->events[SIGNAL] || !icond->events[BROADCAST])
{
if(icond->events[SIGNAL])
@@ -355,30 +317,6 @@ int alcnd_wait(alcnd_t *cond, almtx_t *mtx)
return althrd_success;
}
-int alcnd_timedwait(alcnd_t *cond, almtx_t *mtx, const struct timespec *time_point)
-{
- _int_alcnd_t *icond = cond->Ptr;
- struct timespec curtime;
- DWORD sleeptime;
- int res;
-
- if(altimespec_get(&curtime, AL_TIME_UTC) != AL_TIME_UTC)
- return althrd_error;
- sleeptime = (time_point->tv_nsec - curtime.tv_nsec + 999999)/1000000;
- sleeptime += (time_point->tv_sec - curtime.tv_sec)*1000;
-
- IncrementRef(&icond->wait_count);
- LeaveCriticalSection(mtx);
-
- res = WaitForMultipleObjects(2, icond->events, FALSE, sleeptime);
-
- if(DecrementRef(&icond->wait_count) == 0 && res == WAIT_OBJECT_0+BROADCAST)
- ResetEvent(icond->events[BROADCAST]);
- EnterCriticalSection(mtx);
-
- return (res == WAIT_TIMEOUT) ? althrd_timedout : althrd_success;
-}
-
void alcnd_destroy(alcnd_t *cond)
{
_int_alcnd_t *icond = cond->Ptr;
@@ -389,46 +327,40 @@ void alcnd_destroy(alcnd_t *cond)
#endif /* defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600 */
-/* An associative map of uint:void* pairs. The key is the TLS index (given by
- * TlsAlloc), and the value is the altss_dtor_t callback. When a thread exits,
- * we iterate over the TLS indices for their thread-local value and call the
- * destructor function with it if they're both not NULL. To avoid using
- * DllMain, a PIMAGE_TLS_CALLBACK function pointer is placed in a ".CRT$XLx"
- * section (where x is a character A to Z) which will be called by the CRT.
- */
-static UIntMap TlsDestructors = UINTMAP_STATIC_INITIALIZE;
+int alsem_init(alsem_t *sem, unsigned int initial)
+{
+ *sem = CreateSemaphore(NULL, initial, INT_MAX, NULL);
+ if(*sem != NULL) return althrd_success;
+ return althrd_error;
+}
-static void NTAPI altss_callback(void* UNUSED(handle), DWORD reason, void* UNUSED(reserved))
+void alsem_destroy(alsem_t *sem)
{
- ALsizei i;
+ CloseHandle(*sem);
+}
- if(reason == DLL_PROCESS_DETACH)
- {
- ResetUIntMap(&TlsDestructors);
- return;
- }
- if(reason != DLL_THREAD_DETACH)
- return;
+int alsem_post(alsem_t *sem)
+{
+ DWORD ret = ReleaseSemaphore(*sem, 1, NULL);
+ if(ret) return althrd_success;
+ return althrd_error;
+}
- LockUIntMapRead(&TlsDestructors);
- for(i = 0;i < TlsDestructors.size;i++)
- {
- void *ptr = altss_get(TlsDestructors.array[i].key);
- altss_dtor_t callback = (altss_dtor_t)TlsDestructors.array[i].value;
- if(ptr && callback)
- callback(ptr);
- }
- UnlockUIntMapRead(&TlsDestructors);
+int alsem_wait(alsem_t *sem)
+{
+ DWORD ret = WaitForSingleObject(*sem, INFINITE);
+ if(ret == WAIT_OBJECT_0) return althrd_success;
+ return althrd_error;
}
-#ifdef _MSC_VER
-#pragma section(".CRT$XLB",read)
-__declspec(allocate(".CRT$XLB")) PIMAGE_TLS_CALLBACK altss_callback_ = altss_callback;
-#elif defined(__GNUC__)
-PIMAGE_TLS_CALLBACK altss_callback_ __attribute__((section(".CRT$XLB"))) = altss_callback;
-#else
-#warning "No TLS callback support, thread-local contexts may leak references on poorly written applications."
-PIMAGE_TLS_CALLBACK altss_callback_ = altss_callback;
-#endif
+
+int alsem_trywait(alsem_t *sem)
+{
+ DWORD ret = WaitForSingleObject(*sem, 0);
+ if(ret == WAIT_OBJECT_0) return althrd_success;
+ if(ret == WAIT_TIMEOUT) return althrd_busy;
+ return althrd_error;
+}
+
int altss_create(altss_t *tss_id, altss_dtor_t callback)
{
@@ -480,6 +412,31 @@ void alcall_once(alonce_flag *once, void (*callback)(void))
InterlockedExchange(once, 2);
}
+
+void althrd_deinit(void)
+{
+ ResetUIntMap(&ThrdIdHandle);
+ ResetUIntMap(&TlsDestructors);
+}
+
+void althrd_thread_detach(void)
+{
+ ALsizei i;
+
+ LockUIntMapRead(&TlsDestructors);
+ for(i = 0;i < TlsDestructors.size;i++)
+ {
+ void *ptr = altss_get(TlsDestructors.keys[i]);
+ altss_dtor_t callback = (altss_dtor_t)TlsDestructors.values[i];
+ if(ptr)
+ {
+ if(callback) callback(ptr);
+ altss_set(TlsDestructors.keys[i], NULL);
+ }
+ }
+ UnlockUIntMapRead(&TlsDestructors);
+}
+
#else
#include <sys/time.h>
@@ -493,15 +450,19 @@ void alcall_once(alonce_flag *once, void (*callback)(void))
extern inline int althrd_sleep(const struct timespec *ts, struct timespec *rem);
extern inline void alcall_once(alonce_flag *once, void (*callback)(void));
+extern inline void althrd_deinit(void);
+extern inline void althrd_thread_detach(void);
void althrd_setname(althrd_t thr, const char *name)
{
#if defined(HAVE_PTHREAD_SETNAME_NP)
-#if defined(__GNUC__)
- pthread_setname_np(thr, name);
-#elif defined(__APPLE__)
- if(althrd_equal(thr, althrd_current())
+#if defined(PTHREAD_SETNAME_NP_ONE_PARAM)
+ if(althrd_equal(thr, althrd_current()))
pthread_setname_np(name);
+#elif defined(PTHREAD_SETNAME_NP_THREE_PARAMS)
+ pthread_setname_np(thr, "%s", (void*)name);
+#else
+ pthread_setname_np(thr, name);
#endif
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(thr, name);
@@ -531,6 +492,8 @@ int althrd_create(althrd_t *thr, althrd_start_t func, void *arg)
{
thread_cntr *cntr;
pthread_attr_t attr;
+ size_t stackmult = 1;
+ int err;
cntr = malloc(sizeof(*cntr));
if(!cntr) return althrd_nomem;
@@ -540,7 +503,8 @@ int althrd_create(althrd_t *thr, althrd_start_t func, void *arg)
free(cntr);
return althrd_error;
}
- if(pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE) != 0)
+retry_stacksize:
+ if(pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE*stackmult) != 0)
{
pthread_attr_destroy(&attr);
free(cntr);
@@ -549,15 +513,30 @@ int althrd_create(althrd_t *thr, althrd_start_t func, void *arg)
cntr->func = func;
cntr->arg = arg;
- if(pthread_create(thr, &attr, althrd_starter, cntr) != 0)
+ if((err=pthread_create(thr, &attr, althrd_starter, cntr)) == 0)
{
pthread_attr_destroy(&attr);
- free(cntr);
- return althrd_error;
+ return althrd_success;
}
- pthread_attr_destroy(&attr);
- return althrd_success;
+ if(err == EINVAL)
+ {
+ /* If an invalid stack size, try increasing it (limit x4, 8MB). */
+ if(stackmult < 4)
+ {
+ stackmult *= 2;
+ goto retry_stacksize;
+ }
+ /* If still nothing, try defaults and hope they're good enough. */
+ if(pthread_create(thr, NULL, althrd_starter, cntr) == 0)
+ {
+ pthread_attr_destroy(&attr);
+ return althrd_success;
+ }
+ }
+ pthread_attr_destroy(&attr);
+ free(cntr);
+ return althrd_error;
}
int althrd_detach(althrd_t thr)
@@ -584,10 +563,9 @@ int almtx_init(almtx_t *mtx, int type)
int ret;
if(!mtx) return althrd_error;
- if((type&~(almtx_recursive|almtx_timed)) != 0)
+ if((type&~almtx_recursive) != 0)
return althrd_error;
- type &= ~almtx_timed;
if(type == almtx_plain)
ret = pthread_mutex_init(mtx, NULL);
else
@@ -619,40 +597,6 @@ void almtx_destroy(almtx_t *mtx)
pthread_mutex_destroy(mtx);
}
-int almtx_timedlock(almtx_t *mtx, const struct timespec *ts)
-{
- int ret;
-
-#ifdef HAVE_PTHREAD_MUTEX_TIMEDLOCK
- ret = pthread_mutex_timedlock(mtx, ts);
- switch(ret)
- {
- case 0: return althrd_success;
- case ETIMEDOUT: return althrd_timedout;
- case EBUSY: return althrd_busy;
- }
- return althrd_error;
-#else
- if(!mtx || !ts)
- return althrd_error;
-
- while((ret=almtx_trylock(mtx)) == althrd_busy)
- {
- struct timespec now;
-
- if(ts->tv_sec < 0 || ts->tv_nsec < 0 || ts->tv_nsec >= 1000000000 ||
- altimespec_get(&now, AL_TIME_UTC) != AL_TIME_UTC)
- return althrd_error;
- if(now.tv_sec > ts->tv_sec || (now.tv_sec == ts->tv_sec && now.tv_nsec >= ts->tv_nsec))
- return althrd_timedout;
-
- althrd_yield();
- }
-
- return ret;
-#endif
-}
-
int alcnd_init(alcnd_t *cond)
{
if(pthread_cond_init(cond, NULL) == 0)
@@ -681,18 +625,81 @@ int alcnd_wait(alcnd_t *cond, almtx_t *mtx)
return althrd_error;
}
-int alcnd_timedwait(alcnd_t *cond, almtx_t *mtx, const struct timespec *time_point)
+void alcnd_destroy(alcnd_t *cond)
+{
+ pthread_cond_destroy(cond);
+}
+
+
+#ifdef __APPLE__
+
+int alsem_init(alsem_t *sem, unsigned int initial)
+{
+ *sem = dispatch_semaphore_create(initial);
+ return *sem ? althrd_success : althrd_error;
+}
+
+void alsem_destroy(alsem_t *sem)
+{
+ dispatch_release(*sem);
+}
+
+int alsem_post(alsem_t *sem)
+{
+ dispatch_semaphore_signal(*sem);
+ return althrd_success;
+}
+
+int alsem_wait(alsem_t *sem)
+{
+ dispatch_semaphore_wait(*sem, DISPATCH_TIME_FOREVER);
+ return althrd_success;
+}
+
+int alsem_trywait(alsem_t *sem)
+{
+ long value = dispatch_semaphore_wait(*sem, DISPATCH_TIME_NOW);
+ return value == 0 ? althrd_success : althrd_busy;
+}
+
+#else /* !__APPLE__ */
+
+int alsem_init(alsem_t *sem, unsigned int initial)
+{
+ if(sem_init(sem, 0, initial) == 0)
+ return althrd_success;
+ return althrd_error;
+}
+
+void alsem_destroy(alsem_t *sem)
{
- if(pthread_cond_timedwait(cond, mtx, time_point) == 0)
+ sem_destroy(sem);
+}
+
+int alsem_post(alsem_t *sem)
+{
+ if(sem_post(sem) == 0)
return althrd_success;
return althrd_error;
}
-void alcnd_destroy(alcnd_t *cond)
+int alsem_wait(alsem_t *sem)
{
- pthread_cond_destroy(cond);
+ if(sem_wait(sem) == 0) return althrd_success;
+ if(errno == EINTR) return -2;
+ return althrd_error;
}
+int alsem_trywait(alsem_t *sem)
+{
+ if(sem_trywait(sem) == 0) return althrd_success;
+ if(errno == EWOULDBLOCK) return althrd_busy;
+ if(errno == EINTR) return -2;
+ return althrd_error;
+}
+
+#endif /* __APPLE__ */
+
int altss_create(altss_t *tss_id, altss_dtor_t callback)
{
diff --git a/include/threads.h b/common/threads.h
index a11405f7..2d1b4e7f 100644
--- a/include/threads.h
+++ b/common/threads.h
@@ -3,6 +3,16 @@
#include <time.h>
+#if defined(__GNUC__) && defined(__i386__)
+/* force_align_arg_pointer is required for proper function arguments aligning
+ * when SSE code is used. Some systems (Windows, QNX) do not guarantee our
+ * thread functions will be properly aligned on the stack, even though GCC may
+ * generate code with the assumption that it is. */
+#define FORCE_ALIGN __attribute__((force_align_arg_pointer))
+#else
+#define FORCE_ALIGN
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -18,7 +28,6 @@ enum {
enum {
almtx_plain = 0,
almtx_recursive = 1,
- almtx_timed = 2
};
typedef int (*althrd_start_t)(void*);
@@ -33,17 +42,11 @@ typedef void (*altss_dtor_t)(void*);
#include <windows.h>
-#if !defined(_TIMESPEC_DEFINED) && !(defined(_MSC_VER) && (_MSC_VER >= 1900))
-#define _TIMESPEC_DEFINED
+#ifndef HAVE_STRUCT_TIMESPEC
struct timespec {
time_t tv_sec;
long tv_nsec;
};
-
-struct itimerspec {
- struct timespec it_interval;
- struct timespec it_value;
-};
#endif
typedef DWORD althrd_t;
@@ -53,6 +56,7 @@ typedef CONDITION_VARIABLE alcnd_t;
#else
typedef struct { void *Ptr; } alcnd_t;
#endif
+typedef HANDLE alsem_t;
typedef DWORD altss_t;
typedef LONG alonce_flag;
@@ -61,6 +65,9 @@ typedef LONG alonce_flag;
int althrd_sleep(const struct timespec *ts, struct timespec *rem);
void alcall_once(alonce_flag *once, void (*callback)(void));
+void althrd_deinit(void);
+void althrd_thread_detach(void);
+
inline althrd_t althrd_current(void)
{
@@ -123,11 +130,21 @@ inline int altss_set(altss_t tss_id, void *val)
#include <stdint.h>
#include <errno.h>
#include <pthread.h>
+#ifdef __APPLE__
+#include <dispatch/dispatch.h>
+#else /* !__APPLE__ */
+#include <semaphore.h>
+#endif /* __APPLE__ */
typedef pthread_t althrd_t;
typedef pthread_mutex_t almtx_t;
typedef pthread_cond_t alcnd_t;
+#ifdef __APPLE__
+typedef dispatch_semaphore_t alsem_t;
+#else /* !__APPLE__ */
+typedef sem_t alsem_t;
+#endif /* __APPLE__ */
typedef pthread_key_t altss_t;
typedef pthread_once_t alonce_flag;
@@ -210,6 +227,10 @@ inline void alcall_once(alonce_flag *once, void (*callback)(void))
pthread_once(once, callback);
}
+
+inline void althrd_deinit(void) { }
+inline void althrd_thread_detach(void) { }
+
#endif
@@ -220,15 +241,19 @@ 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 alsem_init(alsem_t *sem, unsigned int initial);
+void alsem_destroy(alsem_t *sem);
+int alsem_post(alsem_t *sem);
+int alsem_wait(alsem_t *sem);
+int alsem_trywait(alsem_t *sem);
+
int altss_create(altss_t *tss_id, altss_dtor_t callback);
void altss_delete(altss_t tss_id);
diff --git a/common/uintmap.c b/common/uintmap.c
index b7a9a29c..18d52d64 100644
--- a/common/uintmap.c
+++ b/common/uintmap.c
@@ -6,6 +6,8 @@
#include <stdlib.h>
#include <string.h>
+#include "almalloc.h"
+
extern inline void LockUIntMapRead(UIntMap *map);
extern inline void UnlockUIntMapRead(UIntMap *map);
@@ -15,9 +17,10 @@ extern inline void UnlockUIntMapWrite(UIntMap *map);
void InitUIntMap(UIntMap *map, ALsizei limit)
{
- map->array = NULL;
+ map->keys = NULL;
+ map->values = NULL;
map->size = 0;
- map->maxsize = 0;
+ map->capacity = 0;
map->limit = limit;
RWLockInit(&map->lock);
}
@@ -25,10 +28,11 @@ void InitUIntMap(UIntMap *map, ALsizei limit)
void ResetUIntMap(UIntMap *map)
{
WriteLock(&map->lock);
- free(map->array);
- map->array = NULL;
+ al_free(map->keys);
+ map->keys = NULL;
+ map->values = NULL;
map->size = 0;
- map->maxsize = 0;
+ map->capacity = 0;
WriteUnlock(&map->lock);
}
@@ -39,53 +43,77 @@ ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value)
WriteLock(&map->lock);
if(map->size > 0)
{
- ALsizei low = 0;
- ALsizei high = map->size - 1;
- while(low < high)
- {
- ALsizei mid = low + (high-low)/2;
- if(map->array[mid].key < key)
- low = mid + 1;
+ ALsizei count = map->size;
+ do {
+ ALsizei step = count>>1;
+ ALsizei i = pos+step;
+ if(!(map->keys[i] < key))
+ count = step;
else
- high = mid;
- }
- if(map->array[low].key < key)
- low++;
- pos = low;
+ {
+ pos = i+1;
+ count -= step+1;
+ }
+ } while(count > 0);
}
- if(pos == map->size || map->array[pos].key != key)
+ if(pos == map->size || map->keys[pos] != key)
{
- if(map->size == map->limit)
+ if(map->size >= map->limit)
{
WriteUnlock(&map->lock);
return AL_OUT_OF_MEMORY;
}
- if(map->size == map->maxsize)
+ if(map->size == map->capacity)
{
- ALvoid *temp = NULL;
- ALsizei newsize;
-
- newsize = (map->maxsize ? (map->maxsize<<1) : 4);
- if(newsize >= map->maxsize)
- temp = realloc(map->array, newsize*sizeof(map->array[0]));
- if(!temp)
+ ALuint *keys = NULL;
+ ALvoid **values;
+ ALsizei newcap, keylen;
+
+ newcap = (map->capacity ? (map->capacity<<1) : 4);
+ if(map->limit > 0 && newcap > map->limit)
+ newcap = map->limit;
+ if(newcap > map->capacity)
+ {
+ /* Round the memory size for keys up to a multiple of the
+ * pointer size.
+ */
+ keylen = newcap * sizeof(map->keys[0]);
+ keylen += sizeof(map->values[0]) - 1;
+ keylen -= keylen%sizeof(map->values[0]);
+
+ keys = al_malloc(16, keylen + newcap*sizeof(map->values[0]));
+ }
+ if(!keys)
{
WriteUnlock(&map->lock);
return AL_OUT_OF_MEMORY;
}
- map->array = temp;
- map->maxsize = newsize;
+ values = (ALvoid**)((ALbyte*)keys + keylen);
+
+ if(map->keys)
+ {
+ memcpy(keys, map->keys, map->size*sizeof(map->keys[0]));
+ memcpy(values, map->values, map->size*sizeof(map->values[0]));
+ }
+ al_free(map->keys);
+ map->keys = keys;
+ map->values = values;
+ map->capacity = newcap;
}
if(pos < map->size)
- memmove(&map->array[pos+1], &map->array[pos],
- (map->size-pos)*sizeof(map->array[0]));
+ {
+ memmove(&map->keys[pos+1], &map->keys[pos],
+ (map->size-pos)*sizeof(map->keys[0]));
+ memmove(&map->values[pos+1], &map->values[pos],
+ (map->size-pos)*sizeof(map->values[0]));
+ }
map->size++;
}
- map->array[pos].key = key;
- map->array[pos].value = value;
+ map->keys[pos] = key;
+ map->values[pos] = value;
WriteUnlock(&map->lock);
return AL_NO_ERROR;
@@ -97,22 +125,29 @@ ALvoid *RemoveUIntMapKey(UIntMap *map, ALuint key)
WriteLock(&map->lock);
if(map->size > 0)
{
- ALsizei low = 0;
- ALsizei high = map->size - 1;
- while(low < high)
- {
- ALsizei mid = low + (high-low)/2;
- if(map->array[mid].key < key)
- low = mid + 1;
+ ALsizei pos = 0;
+ ALsizei count = map->size;
+ do {
+ ALsizei step = count>>1;
+ ALsizei i = pos+step;
+ if(!(map->keys[i] < key))
+ count = step;
else
- high = mid;
- }
- if(map->array[low].key == key)
+ {
+ pos = i+1;
+ count -= step+1;
+ }
+ } while(count > 0);
+ if(pos < map->size && map->keys[pos] == key)
{
- ptr = map->array[low].value;
- if(low < map->size-1)
- memmove(&map->array[low], &map->array[low+1],
- (map->size-1-low)*sizeof(map->array[0]));
+ ptr = map->values[pos];
+ if(pos < map->size-1)
+ {
+ memmove(&map->keys[pos], &map->keys[pos+1],
+ (map->size-1-pos)*sizeof(map->keys[0]));
+ memmove(&map->values[pos], &map->values[pos+1],
+ (map->size-1-pos)*sizeof(map->values[0]));
+ }
map->size--;
}
}
@@ -126,18 +161,21 @@ ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key)
ReadLock(&map->lock);
if(map->size > 0)
{
- ALsizei low = 0;
- ALsizei high = map->size - 1;
- while(low < high)
- {
- ALsizei mid = low + (high-low)/2;
- if(map->array[mid].key < key)
- low = mid + 1;
+ ALsizei pos = 0;
+ ALsizei count = map->size;
+ do {
+ ALsizei step = count>>1;
+ ALsizei i = pos+step;
+ if(!(map->keys[i] < key))
+ count = step;
else
- high = mid;
- }
- if(map->array[low].key == key)
- ptr = map->array[low].value;
+ {
+ pos = i+1;
+ count -= step+1;
+ }
+ } while(count > 0);
+ if(pos < map->size && map->keys[pos] == key)
+ ptr = map->values[pos];
}
ReadUnlock(&map->lock);
return ptr;
diff --git a/common/uintmap.h b/common/uintmap.h
new file mode 100644
index 00000000..32868653
--- /dev/null
+++ b/common/uintmap.h
@@ -0,0 +1,41 @@
+#ifndef AL_UINTMAP_H
+#define AL_UINTMAP_H
+
+#include <limits.h>
+
+#include "AL/al.h"
+#include "rwlock.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct UIntMap {
+ ALuint *keys;
+ /* Shares memory with keys. */
+ ALvoid **values;
+
+ ALsizei size;
+ ALsizei capacity;
+ ALsizei limit;
+ RWLock lock;
+} UIntMap;
+#define UINTMAP_STATIC_INITIALIZE_N(_n) { NULL, NULL, 0, 0, (_n), RWLOCK_STATIC_INITIALIZE }
+#define UINTMAP_STATIC_INITIALIZE UINTMAP_STATIC_INITIALIZE_N(INT_MAX)
+
+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);
+
+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 */
diff --git a/common/win_main_utf8.h b/common/win_main_utf8.h
new file mode 100644
index 00000000..faddc257
--- /dev/null
+++ b/common/win_main_utf8.h
@@ -0,0 +1,97 @@
+#ifndef WIN_MAIN_UTF8_H
+#define WIN_MAIN_UTF8_H
+
+/* For Windows systems this provides a way to get UTF-8 encoded argv strings,
+ * and also overrides fopen to accept UTF-8 filenames. Working with wmain
+ * directly complicates cross-platform compatibility, while normal main() in
+ * Windows uses the current codepage (which has limited availability of
+ * characters).
+ *
+ * For MinGW, you must link with -municode
+ */
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <shellapi.h>
+
+static FILE *my_fopen(const char *fname, const char *mode)
+{
+ WCHAR *wname=NULL, *wmode=NULL;
+ int namelen, modelen;
+ FILE *file = NULL;
+ errno_t err;
+
+ namelen = MultiByteToWideChar(CP_UTF8, 0, fname, -1, NULL, 0);
+ modelen = MultiByteToWideChar(CP_UTF8, 0, mode, -1, NULL, 0);
+
+ if(namelen <= 0 || modelen <= 0)
+ {
+ fprintf(stderr, "Failed to convert UTF-8 fname \"%s\", mode \"%s\"\n", fname, mode);
+ return NULL;
+ }
+
+ wname = calloc(sizeof(WCHAR), namelen+modelen);
+ wmode = wname + namelen;
+ MultiByteToWideChar(CP_UTF8, 0, fname, -1, wname, namelen);
+ MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode, modelen);
+
+ err = _wfopen_s(&file, wname, wmode);
+ if(err)
+ {
+ errno = err;
+ file = NULL;
+ }
+
+ free(wname);
+
+ return file;
+}
+#define fopen my_fopen
+
+
+static char **arglist;
+static void cleanup_arglist(void)
+{
+ free(arglist);
+}
+
+static void GetUnicodeArgs(int *argc, char ***argv)
+{
+ size_t total;
+ wchar_t **args;
+ int nargs, i;
+
+ args = CommandLineToArgvW(GetCommandLineW(), &nargs);
+ if(!args)
+ {
+ fprintf(stderr, "Failed to get command line args: %ld\n", GetLastError());
+ exit(EXIT_FAILURE);
+ }
+
+ total = sizeof(**argv) * nargs;
+ for(i = 0;i < nargs;i++)
+ total += WideCharToMultiByte(CP_UTF8, 0, args[i], -1, NULL, 0, NULL, NULL);
+
+ atexit(cleanup_arglist);
+ arglist = *argv = calloc(1, total);
+ (*argv)[0] = (char*)(*argv + nargs);
+ for(i = 0;i < nargs-1;i++)
+ {
+ int len = WideCharToMultiByte(CP_UTF8, 0, args[i], -1, (*argv)[i], 65535, NULL, NULL);
+ (*argv)[i+1] = (*argv)[i] + len;
+ }
+ WideCharToMultiByte(CP_UTF8, 0, args[i], -1, (*argv)[i], 65535, NULL, NULL);
+ *argc = nargs;
+
+ LocalFree(args);
+}
+#define GET_UNICODE_ARGS(argc, argv) GetUnicodeArgs(argc, argv)
+
+#else
+
+/* Do nothing. */
+#define GET_UNICODE_ARGS(argc, argv)
+
+#endif
+
+#endif /* WIN_MAIN_UTF8_H */
diff --git a/config.h.in b/config.h.in
index e66b1fe8..9cc6c16b 100644
--- a/config.h.in
+++ b/config.h.in
@@ -2,18 +2,18 @@
#define AL_API ${EXPORT_DECL}
#define ALC_API ${EXPORT_DECL}
-/* Define to the library version */
-#define ALSOFT_VERSION "${LIB_VERSION}"
-
-#ifdef IN_IDE_PARSER
-/* KDevelop's parser doesn't recognize the C99-standard restrict keyword, but
- * recent versions (at least 4.5.1) do recognize GCC's __restrict. */
-#define restrict __restrict
-#endif
-
/* Define any available alignment declaration */
#define ALIGN(x) ${ALIGN_DECL}
+/* Define a built-in call indicating an aligned data pointer */
+#define ASSUME_ALIGNED(x, y) ${ASSUME_ALIGNED_DECL}
+
+/* Define if HRTF data is embedded in the library */
+#cmakedefine ALSOFT_EMBED_HRTF_DATA
+
+/* Define if we have the sysconf function */
+#cmakedefine HAVE_SYSCONF
+
/* Define if we have the C11 aligned_alloc function */
#cmakedefine HAVE_ALIGNED_ALLOC
@@ -23,6 +23,12 @@
/* Define if we have the _aligned_malloc function */
#cmakedefine HAVE__ALIGNED_MALLOC
+/* Define if we have the proc_pidpath function */
+#cmakedefine HAVE_PROC_PIDPATH
+
+/* Define if we have the getopt function */
+#cmakedefine HAVE_GETOPT
+
/* Define if we have SSE CPU extensions */
#cmakedefine HAVE_SSE
#cmakedefine HAVE_SSE2
@@ -47,8 +53,8 @@
/* Define if we have the QSA backend */
#cmakedefine HAVE_QSA
-/* Define if we have the MMDevApi backend */
-#cmakedefine HAVE_MMDEVAPI
+/* Define if we have the WASAPI backend */
+#cmakedefine HAVE_WASAPI
/* Define if we have the DSound backend */
#cmakedefine HAVE_DSOUND
@@ -74,6 +80,9 @@
/* Define if we have the Wave Writer backend */
#cmakedefine HAVE_WAVE
+/* Define if we have the SDL2 backend */
+#cmakedefine HAVE_SDL2
+
/* Define if we have the stat function */
#cmakedefine HAVE_STAT
@@ -83,9 +92,21 @@
/* Define if we have the modff function */
#cmakedefine HAVE_MODFF
+/* Define if we have the log2f function */
+#cmakedefine HAVE_LOG2F
+
+/* Define if we have the cbrtf function */
+#cmakedefine HAVE_CBRTF
+
+/* Define if we have the copysignf function */
+#cmakedefine HAVE_COPYSIGNF
+
/* Define if we have the strtof function */
#cmakedefine HAVE_STRTOF
+/* Define if we have the strnlen function */
+#cmakedefine HAVE_STRNLEN
+
/* Define if we have the __int64 type */
#cmakedefine HAVE___INT64
@@ -95,9 +116,6 @@
/* Define to the size of a long long int type */
#cmakedefine SIZEOF_LONG_LONG ${SIZEOF_LONG_LONG}
-/* Define if we have C99 variable-length array support */
-#cmakedefine HAVE_C99_VLA
-
/* Define if we have C99 _Bool support */
#cmakedefine HAVE_C99_BOOL
@@ -134,18 +152,12 @@
/* Define if we have pthread_np.h */
#cmakedefine HAVE_PTHREAD_NP_H
-/* Define if we have alloca.h */
-#cmakedefine HAVE_ALLOCA_H
-
/* Define if we have malloc.h */
#cmakedefine HAVE_MALLOC_H
/* Define if we have dirent.h */
#cmakedefine HAVE_DIRENT_H
-/* Define if we have io.h */
-#cmakedefine HAVE_IO_H
-
/* Define if we have strings.h */
#cmakedefine HAVE_STRINGS_H
@@ -179,6 +191,12 @@
/* Define if we have the __cpuid() intrinsic */
#cmakedefine HAVE_CPUID_INTRINSIC
+/* Define if we have the _BitScanForward64() intrinsic */
+#cmakedefine HAVE_BITSCANFORWARD64_INTRINSIC
+
+/* Define if we have the _BitScanForward() intrinsic */
+#cmakedefine HAVE_BITSCANFORWARD_INTRINSIC
+
/* Define if we have _controlfp() */
#cmakedefine HAVE__CONTROLFP
@@ -191,6 +209,12 @@
/* Define if we have pthread_setname_np() */
#cmakedefine HAVE_PTHREAD_SETNAME_NP
+/* Define if pthread_setname_np() only accepts one parameter */
+#cmakedefine PTHREAD_SETNAME_NP_ONE_PARAM
+
+/* Define if pthread_setname_np() accepts three parameters */
+#cmakedefine PTHREAD_SETNAME_NP_THREE_PARAMS
+
/* Define if we have pthread_set_name_np() */
#cmakedefine HAVE_PTHREAD_SET_NAME_NP
diff --git a/docs/3D7.1.txt b/docs/3D7.1.txt
new file mode 100644
index 00000000..1d40bec6
--- /dev/null
+++ b/docs/3D7.1.txt
@@ -0,0 +1,82 @@
+Overview
+========
+
+3D7.1 is a custom speaker layout designed by Simon Goodwin at Codemasters[1].
+Typical surround sound setups, like quad, 5.1, 6.1, and 7.1, only produce audio
+on a 2D horizontal plane with no verticality, which means the envelopment of
+"surround" sound is limited to left, right, front, and back panning. Sounds
+that should come from above or below will still only play in 2D since there is
+no height difference in the speaker array.
+
+To work around this, 3D7.1 was designed so that some speakers are placed higher
+than the listener while others are lower, in a particular configuration that
+tries to provide balanced output and maintain some compatibility with existing
+audio content and software. Software that recognizes this setup, or can be
+configured for it, can then take advantage of the height difference and
+increase the perception of verticality for true 3D audio. The result is that
+sounds can be perceived as coming from left, right, front, and back, as well as
+up and down.
+
+[1] http://www.codemasters.com/research/3D_sound_for_3D_games.pdf
+
+
+Hardware Setup
+==============
+
+Setting up 3D7.1 requires an audio device capable of raw 8-channel or 7.1
+output, along with a 7.1 speaker kit. The speakers should be hooked up to the
+device in the usual way, with front-left and front-right output going to the
+front-left and front-right speakers, etc. The placement of the speakers should
+be set up according to the table below. Azimuth is the horizontal angle in
+degrees, with 0 directly in front and positive values go /left/, and elevation
+is the vertical angle in degrees, with 0 at head level and positive values go
+/up/.
+
+------------------------------------------------------------
+- Speaker label | Azimuth | Elevation | New label -
+------------------------------------------------------------
+- Front left | 51 | 24 | Upper front left -
+- Front right | -51 | 24 | Upper front right -
+- Front center | 0 | 0 | Front center -
+- Subwoofer/LFE | N/A | N/A | Subwoofer/LFE -
+- Side left | 129 | -24 | Lower back left -
+- Side right | -129 | -24 | Lower back right -
+- Back left | 180 | 55 | Upper back center -
+- Back right | 0 | -55 | Lower front center -
+------------------------------------------------------------
+
+Note that this speaker layout *IS NOT* compatible with standard 7.1 content.
+Audio that should be played from the back will come out at the wrong location
+since the back speakers are placed in the lower front and upper back positions.
+However, this speaker layout *IS* more or less compatible with standard 5.1
+content. Though slightly tilted, to a listener sitting a bit further back from
+the center, the front and side speakers will be close enough to their intended
+locations that the output won't be too off.
+
+
+Software Setup
+==============
+
+To enable 3D7.1 on OpenAL Soft, first make sure the audio device is configured
+for 7.1 output. Then in the alsoft-config utility, under the Renderer tab,
+select the 3D7.1.ambdec preset for the 7.1 Surround decoder configuration. And
+that's it. Any applications using OpenAL Soft can take advantage of fully 3D
+audio, and multi-channel sounds will be properly remixed for the speaker
+layout.
+
+Playback can be improved by (copying and) modifying the 3D7.1.ambdec preset,
+changing the specified speaker distances to match the the real distance (in
+meters) from the center of the speaker array, then enable High Quality Mode in
+alsoft-config. That will improve the quality when the speakers are not all
+equidistant.
+
+Note that care must be taken that the audio device is not treated as a "true"
+7.1 device by non-3D7.1-capable applications. In particular, the audio server
+should not try to upmix stereo and 5.1 content to "fill out" the back speakers,
+and non-3D7.1 apps should be set to either stereo or 5.1 output.
+
+As such, if your system is capable of it, it may be useful to define a virtual
+5.1 device that maps the front, side, and LFE channels to the main device for
+output and disables upmixing, then use that virtual 5.1 device for apps that do
+normal stereo or surround sound output, and use the main device for apps that
+understand 3D7.1 output.
diff --git a/docs/ambdec.txt b/docs/ambdec.txt
new file mode 100644
index 00000000..1f328937
--- /dev/null
+++ b/docs/ambdec.txt
@@ -0,0 +1,189 @@
+AmbDec Configuration Files
+==========================
+
+AmbDec configuration files were developed by Fons Adriaensen as part of the
+AmbDec program <http://kokkinizita.linuxaudio.org/linuxaudio/index.html>.
+
+The file works by specifying a decoder matrix or matrices which transform
+ambisonic channels into speaker feeds. Single-band decoders specify a single
+matrix that transforms all frequencies, while dual-band decoders specifies two
+matrices where one transforms low frequency sounds and the other transforms
+high frequency sounds. See docs/ambisonics.txt for more general information
+about ambisonics.
+
+Starting with OpenAL Soft 1.18, version 3 of the file format is supported as a
+means of specifying custom surround sound speaker layouts. These configuration
+files are also used to enable the high-quality ambisonic decoder.
+
+
+File Format
+===========
+
+As of this writing, there is no official documentation of the .ambdec file
+format. However, the format as OpenAL Soft sees it is as follows:
+
+The file is plain text. Comments start with a hash/pound character (#). There
+may be any amount of whitespace in between the option and parameter values.
+Strings are *not* enclosed in quotation marks.
+
+/description <desc:string>
+Specifies a text description of the configuration. Ignored by OpenAL Soft.
+
+/version <ver:int>
+Declares the format version used by the configuration file. OpenAL Soft
+currently only supports version 3.
+
+/dec/chan_mask <mask:hex>
+Specifies a hexadecimal mask value of ambisonic input channels used by this
+decoder. Counting up from the least significant bit, bit 0 maps to Ambisonic
+Channel Number (ACN) 0, bit 1 maps to ACN 1, etc. As an example, a value of 'b'
+enables bits 0, 1, and 3 (1011 in binary), which correspond to ACN 0, 1, and 3
+(first-order horizontal).
+
+/dec/freq_bands <count:int>
+Specifies the number of frequency bands used by the decoder. This must be 1 for
+single-band or 2 for dual-band.
+
+/dec/speakers <count:int>
+Specifies the number of output speakers to decode to.
+
+/dec/coeff_scale <type:string>
+Specifies the scaling used by the decoder coefficients. Currently recognized
+types are fuma, sn3d, and n3d, for Furse-Malham (FuMa), semi-normalized (SN3D),
+and fully normalized (N3D) scaling, respectively.
+
+/opt/input_scale <name:string>
+Specifies the scaling used by the ambisonic input data. As OpenAL Soft renders
+the data itself and knows the scaling, this is ignored.
+
+/opt/nfeff_comp <dir:string>
+Specifies whether near-field effect compensation is off (not applied at all),
+applied on input (faster, less accurate with varying speaker distances) or
+output (slower, more accurate with varying speaker distances). Ignored by
+OpenAL Soft.
+
+/opt/delay_comp <onoff:bool>
+Specifies whether delay compensation is applied for output. This is used to
+correct for time variations caused by different speaker distances. As OpenAL
+Soft has its own config option for this, this is ignored.
+
+/opt/level_comp <onoff:bool>
+Specifies whether gain compensation is applied for output. This is used to
+correct for volume variations caused by different speaker distances. As OpenAL
+Soft has its own config option for this, this is ignored.
+
+/opt/xover_freq <freq:float>
+Specifies the crossover frequency for dual-band decoders. Frequencies less than
+this are fed to the low-frequency matrix, and frequencies greater than this are
+fed to the high-frequency matrix. Unused for single-band decoders.
+
+/opt/xover_ratio <decibels:float>
+Specifies the volume ratio between the frequency bands. Values greater than 0
+decrease the low-frequency output by half the specified value and increase the
+high-frequency output by half the specified value, while values less than 0
+increase the low-frequency output and decrease the high-frequency output to
+similar effect. Unused for single-band decoders.
+
+/speakers/{
+Begins the output speaker definitions. A speaker is defined using the add_spkr
+command, and there must be a matching number of speaker definitions as the
+specified speaker count. The definitions are ended with a "/}".
+
+add_spkr <id:string> <dist:float> <azi:float> <elev:float> <connection:string>
+Defines an output speaker. The ID is a string identifier for the output speaker
+(see Speaker IDs below). The distance is in meters from the center-point of the
+physical speaker array. The azimuth is the horizontal angle of the speaker, in
+degrees, where 0 is directly front and positive values go left. The elevation
+is the vertical angle of the speaker, in degrees, where 0 is directly front and
+positive goes upward. The connection string is the JACK port name the speaker
+should connect to. Currently, OpenAL Soft uses the ID and distance, and ignores
+the rest.
+
+/lfmatrix/{
+Begins the low-frequency decoder matrix definition. The definition should
+include an order_gain command to specify the base gain for the ambisonic
+orders. Each matrix row is defined using the add_row command, and there must be
+a matching number of rows as the number of speakers. Additionally the row
+definitions are in the same order as the speaker definitions. The definitions
+are ended with a "/}". Only valid for dual-band decoders.
+
+/hfmatrix/{
+Begins the high-frequency decoder matrix definition. The definition should
+include an order_gain command to specify the base gain for the ambisonic
+orders. Each matrix row is defined using the add_row command, and there must be
+a matching number of rows as the number of speakers, Additionally the row
+definitions are in the same order as the speaker definitions. The definitions
+are ended with a "/}". Only valid for dual-band decoders.
+
+/matrix/{
+Begins the decoder matrix definition. The definition should include an
+order_gain command to specify the base gain for the ambisonic orders. Each
+matrix row is defined using the add_row command, and there must be a matching
+number of rows as the number of speakers. Additionally the row definitions are
+in the same order as the speaker definitions. The definitions are ended with a
+"/}". Only valid for single-band decoders.
+
+order_gain <gain:float> <gain:float> <gain:float> <gain:float>
+Specifies the base gain for the zeroth-, first-, second-, and third-order
+coefficients in the given matrix, automatically scaling the related
+coefficients. This should be specified at the beginning of the matrix
+definition.
+
+add_row <coefficient:float> ...
+Specifies a row of coefficients for the matrix. There should be one coefficient
+for each enabled bit in the channel mask, and corresponds to the matching ACN
+channel.
+
+/end
+Marks the end of the configuration file.
+
+
+Speaker IDs
+===========
+
+The AmbDec program uses the speaker ID as a label to display in its config
+dialog, but does not otherwise use it for any particular purpose. However,
+since OpenAL Soft needs to match a speaker definition to an output channel, the
+speaker ID is used to identify what output channel it correspond to. Therefore,
+OpenAL Soft requires these channel labels to be recognized:
+
+LF = Front left
+RF = Front right
+LS = Side left
+RS = Side right
+LB = Back left
+RB = Back right
+CE = Front center
+CB = Back center
+
+Additionally, configuration files for surround51 will acknowledge back speakers
+for side channels, and surround51rear will acknowledge side speakers for back
+channels, to avoid issues with a configuration expecting 5.1 to use the side
+channels when the device is configured for back, or vice-versa.
+
+Furthermore, OpenAL Soft does not require a speaker definition for each output
+channel the configuration is used with. So for example a 5.1 configuration may
+omit a front center speaker definition, in which case the front center output
+channel will not contribute to the ambisonic decode (though OpenAL Soft will
+still use it in certain scenarios, such as the AL_EFFECT_DEDICATED_DIALOGUE
+effect).
+
+
+Creating Configuration Files
+============================
+
+Configuration files can be created or modified by hand in a text editor. The
+AmbDec program also has a GUI for creating and editing them. However, these
+methods rely on you having the coefficients to fill in... they won't be
+generated for you.
+
+Another option is to use the Ambisonic Decoder Toolbox
+<https://bitbucket.org/ambidecodertoolbox/adt.git>. This is a collection of
+MATLAB and GNU Octave scripts that can generate AmbDec configuration files from
+an array of speaker definitions (labels and positions). If you're familiar with
+using MATLAB or GNU Octave, this may be a good option.
+
+There are plans for OpenAL Soft to include a utility to generate coefficients
+and make configuration files. However, calculating proper coefficients for
+anything other than regular or semi-regular speaker setups is somewhat of a
+black art, so may take some time.
diff --git a/docs/ambisonics.txt b/docs/ambisonics.txt
new file mode 100644
index 00000000..2d94427e
--- /dev/null
+++ b/docs/ambisonics.txt
@@ -0,0 +1,126 @@
+OpenAL Soft's renderer has advanced quite a bit since its start with panned
+stereo output. Among these advancements is support for surround sound output,
+using psychoacoustic modeling and more accurate plane wave reconstruction. The
+concepts in use may not be immediately obvious to people just getting into 3D
+audio, or people who only have more indirect experience through the use of 3D
+audio APIs, so this document aims to introduce the ideas and purpose of
+Ambisonics as used by OpenAL Soft.
+
+
+What Is It?
+===========
+
+Originally developed in the 1970s by Michael Gerzon and a team others,
+Ambisonics was created as a means of recording and playing back 3D sound.
+Taking advantage of the way sound waves propogate, it is possible to record a
+fully 3D soundfield using as few as 4 channels (or even just 3, if you don't
+mind dropping down to 2 dimensions like many surround sound systems are). This
+representation is called B-Format. It was designed to handle audio independent
+of any specific speaker layout, so with a proper decoder the same recording can
+be played back on a variety of speaker setups, from quadraphonic and hexagonal
+to cubic and other periphonic (with height) layouts.
+
+Although it was developed decades ago, various factors held ambisonics back
+from really taking hold in the consumer market. However, given the solid
+theories backing it, as well as the potential and practical benefits on offer,
+it continued to be a topic of research over the years, with improvements being
+made over the original design. One of the improvements made is the use of
+Spherical Harmonics to increase the number of channels for greater spatial
+definition. Where the original 4-channel design is termed as "First-Order
+Ambisonics", or FOA, the increased channel count through the use of Spherical
+Harmonics is termed as "Higher-Order Ambisonics", or HOA. The details of higher
+order ambisonics are out of the scope of this document, but know that the added
+channels are still independent of any speaker layout, and aim to further
+improve the spatial detail for playback.
+
+Today, the processing power available on even low-end computers means real-time
+Ambisonics processing is possible. Not only can decoders be implemented in
+software, but so can encoders, synthesizing a soundfield using multiple panned
+sources, thus taking advantage of what ambisonics offers in a virtual audio
+environment.
+
+
+How Does It Help?
+=================
+
+Positional sound has come a long way from pan-pot stereo (aka pair-wise).
+Although useful at the time, the issues became readily apparent when trying to
+extend it for surround sound. Pan-pot doesn't work as well for depth (front-
+back) or vertical panning, it has a rather small "sweet spot" (the area the
+head needs to be in to perceive the sound in its intended direction), and it
+misses key distance-related details of sound waves.
+
+Ambisonics takes a different approach. It uses all available speakers to help
+localize a sound, and it also takes into account how the brain localizes low
+frequency sounds compared to high frequency ones -- a so-called psychoacoustic
+model. It may seem counter-intuitive (if a sound is coming from the front-left,
+surely just play it on the front-left speaker?), but to properly model a sound
+coming from where a speaker doesn't exist, more needs to be done to construct a
+proper sound wave that's perceived to come from the intended direction. Doing
+this creates a larger sweet spot, allowing the perceived sound direction to
+remain correct over a larger area around the center of the speakers.
+
+In addition, Ambisonics can encode the near-field effect of sounds, effectively
+capturing the sound distance. The near-field effect is a subtle low-frequency
+boost as a result of wave-front curvature, and properly compensating for this
+occuring with the output speakers (as well as emulating it with a synthesized
+soundfield) can create an improved sense of distance for sounds that move near
+or far.
+
+
+How Is It Used?
+===============
+
+As a 3D audio API, OpenAL is tasked with playing 3D sound as best it can with
+the speaker setup the user has. Since the OpenAL API does not explicitly handle
+the output channel configuration, it has a lot of leeway in how to deal with
+the audio before it's played back for the user to hear. Consequently, OpenAL
+Soft (or any other OpenAL implementation that wishes to) can render using
+Ambisonics and decode the ambisonic mix for a high level of accuracy over what
+simple pan-pot could provide.
+
+This is effectively what the high-quality mode option does, when given an
+appropriate decoder configuation for the playback channel layout. 3D rendering
+and effect mixing is done to an ambisonic buffer, which is later decoded for
+output utilizing the benefits available to ambisonic processing.
+
+The basic, non-high-quality, renderer uses similar principles, however it skips
+the frequency-dependent processing (so low frequency sounds are treated the
+same as high frequency sounds) and does some creative manipulation of the
+involved math to skip the intermediate ambisonic buffer, rendering more
+directly to the output while still taking advantage of all the available
+speakers to reconstruct the sound wave. This method trades away some playback
+quality for less memory and processor usage.
+
+In addition to providing good support for surround sound playback, Ambisonics
+also has benefits with stereo output. 2-channel UHJ is a stereo-compatible
+format that encodes some surround sound information using a wide-band 90-degree
+phase shift filter. It works by taking a B-Format signal, and deriving a
+frontal stereo mix with the rear sounds attenuated and filtered in with it.
+Although the result is not as good as 3-channel (2D) B-Format, it has the
+distinct advantage of only using 2 channels and being compatible with stereo
+output. This means it will sound just fine when played as-is through a normal
+stereo device, or it may optionally be fed to a properly configured surround
+sound receiver which can extract the encoded information and restore some of
+the original surround sound signal.
+
+
+What Are Its Limitations?
+=========================
+
+As good as Ambisonics is, it's not a magic bullet that can overcome all
+problems. One of the bigger issues it has is dealing with irregular speaker
+setups, such as 5.1 surround sound. The problem mainly lies in the imbalanced
+speaker positioning -- there are three speakers within the front 60-degree area
+(meaning only 30-degree gaps in between each of the three speakers), while only
+two speakers cover the back 140-degree area, leaving 80-degree gaps on the
+sides. It should be noted that this problem is inherent to the speaker layout
+itself; there isn't much that can be done to get an optimal surround sound
+response, with ambisonics or not. It will do the best it can, but there are
+trade-offs between detail and accuracy.
+
+Another issue lies with HRTF. While it's certainly possible to play an
+ambisonic mix using HRTF and retain a sense of 3D sound, doing so with a high
+degree of spatial detail requires a fair amount of resources, in both memory
+and processing time. And even with it, mixing sounds with HRTF directly will
+still be better for positional accuracy.
diff --git a/env-vars.txt b/docs/env-vars.txt
index b2268643..a973ee81 100644
--- a/env-vars.txt
+++ b/docs/env-vars.txt
@@ -79,3 +79,13 @@ which some applications make use of to protect against partial updates. In an
attempt to standardize on that behavior, OpenAL Soft has changed those methods
accordingly. Setting this to "ignore" restores the previous no-op behavior for
applications that interact poorly with the new behavior.
+
+__ALSOFT_REVERB_IGNORES_SOUND_SPEED
+Older versions of OpenAL Soft ignored the app-specified speed of sound when
+calculating distance-related reverb decays and always assumed the default
+343.3m/s. Now, both of the AL_SPEED_OF_SOUND and AL_METERS_PER_UNIT properties
+are taken into account for speed of sound adjustments to have an appropriate
+affect on the reverb decay. Consequently, applications that use reverb but
+don't set these properties properly may find the reverb decay too strong.
+Setting this to "true" or "1" will revert to the old behavior for those apps
+and assume the default speed of sound for reverb.
diff --git a/docs/hrtf.txt b/docs/hrtf.txt
new file mode 100644
index 00000000..ba8cd8fa
--- /dev/null
+++ b/docs/hrtf.txt
@@ -0,0 +1,84 @@
+HRTF Support
+============
+
+Starting with OpenAL Soft 1.14, HRTFs can be used to enable enhanced
+spatialization for both 3D (mono) and multi-channel sources, when used with
+headphones/stereo output. This can be enabled using the 'hrtf' config option.
+
+For multi-channel sources this creates a virtual speaker effect, making it
+sound as if speakers provide a discrete position for each channel around the
+listener. For mono sources this provides much more versatility in the perceived
+placement of sounds, making it seem as though they are coming from all around,
+including above and below the listener, instead of just to the front, back, and
+sides.
+
+The default data set is based on the KEMAR HRTF data provided by MIT, which can
+be found at <http://sound.media.mit.edu/resources/KEMAR.html>. It's only
+available when using 44100hz or 48000hz playback.
+
+
+Custom HRTF Data Sets
+=====================
+
+OpenAL Soft also provides an option to use user-specified data sets, in
+addition to or in place of the default set. This allows users to provide their
+own data sets, which could be better suited for their heads, or to work with
+stereo speakers instead of headphones, or to support more playback sample
+rates, for example.
+
+The file format is specified below. It uses little-endian byte order.
+
+==
+ALchar magic[8] = "MinPHR02";
+ALuint sampleRate;
+ALubyte sampleType; /* Can be 0 (16-bit) or 1 (24-bit). */
+ALubyte channelType; /* Can be 0 (mono) or 1 (stereo). */
+ALubyte hrirSize; /* Can be 8 to 128 in steps of 8. */
+ALubyte fdCount; /* Can be 1 to 16. */
+
+struct {
+ ALushort distance; /* Can be 50mm to 2500mm. */
+ ALubyte evCount; /* Can be 5 to 128. */
+ ALubyte azCount[evCount]; /* Each can be 1 to 128. */
+} fields[fdCount];
+
+/* NOTE: ALtype can be ALshort (16-bit) or ALbyte[3] (24-bit) depending on
+ * sampleType,
+ * hrirCount is the sum of all azCounts.
+ * channels can be 1 (mono) or 2 (stereo) depending on channelType.
+ */
+ALtype coefficients[hrirCount][hrirSize][channels];
+ALubyte delays[hrirCount][channels]; /* Each can be 0 to 63. */
+==
+
+The data is described as thus:
+
+The file first starts with the 8-byte marker, "MinPHR02", to identify it as an
+HRTF data set. This is followed by an unsigned 32-bit integer, specifying the
+sample rate the data set is designed for (OpenAL Soft will not use it if the
+output device's playback rate doesn't match).
+
+Afterward, an unsigned 8-bit integer specifies how many sample points (or
+finite impulse response filter coefficients) make up each HRIR.
+
+The following unsigned 8-bit integer specifies the number of fields used by the
+data set. Then for each field an unsigned 16-bit short specifies the distance
+for that field (in millimeters), followed by an 8-bit integer for the number of
+elevations. These elevations start at the bottom (-90 degrees), and increment
+upwards. Following this is an array of unsigned 8-bit integers, one for each
+elevation which specifies the number of azimuths (and thus HRIRs) that make up
+each elevation. Azimuths start clockwise from the front, constructing a full
+circle. Mono HRTFs use the same HRIRs for both ears by reversing the azimuth
+calculation (ie. left = angle, right = 360-angle).
+
+The actual coefficients follow. Each coefficient is a signed 16-bit or 24-bit
+sample. Stereo HRTFs interleave left/right ear coefficients. The HRIRs must
+be minimum-phase. This allows the use of a smaller filter length, reducing
+computation. For reference, the default data set uses a 32-point filter while
+even the smallest data set provided by MIT used a 128-sample filter (a 4x
+reduction by applying minimum-phase reconstruction).
+
+After the coefficients is an array of unsigned 8-bit delay values, one for
+each HRIR (with stereo HRTFs interleaving left/right ear delays). This is the
+propagation delay (in samples) a signal must wait before being convolved with
+the corresponding minimum-phase HRIR filter.
diff --git a/examples/alffplay.c b/examples/alffplay.c
deleted file mode 100644
index 17f6d3bc..00000000
--- a/examples/alffplay.c
+++ /dev/null
@@ -1,1533 +0,0 @@
-/*
- * alffplay.c
- *
- * A pedagogical video player that really works! Now with seeking features.
- *
- * Code based on FFplay, Copyright (c) 2003 Fabrice Bellard, and a tutorial by
- * Martin Bohme <[email protected]>.
- *
- * Requires C99.
- */
-
-#include <stdio.h>
-#include <math.h>
-
-#include <libavcodec/avcodec.h>
-#include <libavformat/avformat.h>
-#include <libavformat/avio.h>
-#include <libavutil/time.h>
-#include <libavutil/avstring.h>
-#include <libavutil/channel_layout.h>
-#include <libswscale/swscale.h>
-#include <libswresample/swresample.h>
-
-#include <SDL.h>
-#include <SDL_thread.h>
-#include <SDL_video.h>
-
-#include "threads.h"
-#include "bool.h"
-
-#include "AL/al.h"
-#include "AL/alc.h"
-#include "AL/alext.h"
-
-
-static bool has_latency_check = false;
-static LPALGETSOURCEDVSOFT alGetSourcedvSOFT;
-
-#define AUDIO_BUFFER_TIME 100 /* In milliseconds, per-buffer */
-#define AUDIO_BUFFER_QUEUE_SIZE 8 /* Number of buffers to queue */
-#define MAX_AUDIOQ_SIZE (5 * 16 * 1024) /* Bytes of compressed audio data to keep queued */
-#define MAX_VIDEOQ_SIZE (5 * 256 * 1024) /* Bytes of compressed video data to keep queued */
-#define AV_SYNC_THRESHOLD 0.01
-#define AV_NOSYNC_THRESHOLD 10.0
-#define SAMPLE_CORRECTION_MAX_DIFF 0.1
-#define AUDIO_DIFF_AVG_NB 20
-#define VIDEO_PICTURE_QUEUE_SIZE 16
-
-enum {
- FF_UPDATE_EVENT = SDL_USEREVENT,
- FF_REFRESH_EVENT,
- FF_QUIT_EVENT
-};
-
-
-typedef struct PacketQueue {
- AVPacketList *first_pkt, *last_pkt;
- volatile int nb_packets;
- volatile int size;
- volatile bool flushing;
- almtx_t mutex;
- alcnd_t cond;
-} PacketQueue;
-
-typedef struct VideoPicture {
- SDL_Texture *bmp;
- int width, height; /* Logical image size (actual size may be larger) */
- volatile bool updated;
- double pts;
-} VideoPicture;
-
-typedef struct AudioState {
- AVStream *st;
-
- PacketQueue q;
- AVPacket pkt;
-
- /* Used for clock difference average computation */
- double diff_accum;
- double diff_avg_coef;
- double diff_threshold;
-
- /* Time (in seconds) of the next sample to be buffered */
- double current_pts;
-
- /* Decompressed sample frame, and swresample context for conversion */
- AVFrame *decoded_aframe;
- struct SwrContext *swres_ctx;
-
- /* Conversion format, for what gets fed to OpenAL */
- int dst_ch_layout;
- enum AVSampleFormat dst_sample_fmt;
-
- /* Storage of converted samples */
- uint8_t *samples;
- ssize_t samples_len; /* In samples */
- ssize_t samples_pos;
- int samples_max;
-
- /* OpenAL format */
- ALenum format;
- ALint frame_size;
-
- ALuint source;
- ALuint buffer[AUDIO_BUFFER_QUEUE_SIZE];
- ALuint buffer_idx;
- almtx_t src_mutex;
-
- althrd_t thread;
-} AudioState;
-
-typedef struct VideoState {
- AVStream *st;
-
- PacketQueue q;
-
- double clock;
- double frame_timer;
- double frame_last_pts;
- double frame_last_delay;
- double current_pts;
- /* time (av_gettime) at which we updated current_pts - used to have running video pts */
- int64_t current_pts_time;
-
- /* Decompressed video frame, and swscale context for conversion */
- AVFrame *decoded_vframe;
- struct SwsContext *swscale_ctx;
-
- VideoPicture pictq[VIDEO_PICTURE_QUEUE_SIZE];
- int pictq_size, pictq_rindex, pictq_windex;
- almtx_t pictq_mutex;
- alcnd_t pictq_cond;
-
- althrd_t thread;
-} VideoState;
-
-typedef struct MovieState {
- AVFormatContext *pFormatCtx;
- int videoStream, audioStream;
-
- volatile bool seek_req;
- int64_t seek_pos;
-
- int av_sync_type;
-
- int64_t external_clock_base;
-
- AudioState audio;
- VideoState video;
-
- althrd_t parse_thread;
-
- char filename[1024];
-
- volatile bool quit;
-} MovieState;
-
-enum {
- AV_SYNC_AUDIO_MASTER,
- AV_SYNC_VIDEO_MASTER,
- AV_SYNC_EXTERNAL_MASTER,
-
- DEFAULT_AV_SYNC_TYPE = AV_SYNC_EXTERNAL_MASTER
-};
-
-static AVPacket flush_pkt = { .data = (uint8_t*)"FLUSH" };
-
-static void packet_queue_init(PacketQueue *q)
-{
- memset(q, 0, sizeof(PacketQueue));
- almtx_init(&q->mutex, almtx_plain);
- alcnd_init(&q->cond);
-}
-static int packet_queue_put(PacketQueue *q, AVPacket *pkt)
-{
- AVPacketList *pkt1;
- if(pkt != &flush_pkt && !pkt->buf && av_dup_packet(pkt) < 0)
- return -1;
-
- pkt1 = av_malloc(sizeof(AVPacketList));
- if(!pkt1) return -1;
- pkt1->pkt = *pkt;
- pkt1->next = NULL;
-
- almtx_lock(&q->mutex);
- if(!q->last_pkt)
- q->first_pkt = pkt1;
- else
- q->last_pkt->next = pkt1;
- q->last_pkt = pkt1;
- q->nb_packets++;
- q->size += pkt1->pkt.size;
- almtx_unlock(&q->mutex);
-
- alcnd_signal(&q->cond);
- return 0;
-}
-static int packet_queue_get(PacketQueue *q, AVPacket *pkt, MovieState *state)
-{
- AVPacketList *pkt1;
- int ret = -1;
-
- almtx_lock(&q->mutex);
- while(!state->quit)
- {
- pkt1 = q->first_pkt;
- if(pkt1)
- {
- q->first_pkt = pkt1->next;
- if(!q->first_pkt)
- q->last_pkt = NULL;
- q->nb_packets--;
- q->size -= pkt1->pkt.size;
- *pkt = pkt1->pkt;
- av_free(pkt1);
- ret = 1;
- break;
- }
-
- if(q->flushing)
- {
- ret = 0;
- break;
- }
- alcnd_wait(&q->cond, &q->mutex);
- }
- almtx_unlock(&q->mutex);
- return ret;
-}
-static void packet_queue_clear(PacketQueue *q)
-{
- AVPacketList *pkt, *pkt1;
-
- almtx_lock(&q->mutex);
- for(pkt = q->first_pkt;pkt != NULL;pkt = pkt1)
- {
- pkt1 = pkt->next;
- if(pkt->pkt.data != flush_pkt.data)
- av_free_packet(&pkt->pkt);
- av_freep(&pkt);
- }
- q->last_pkt = NULL;
- q->first_pkt = NULL;
- q->nb_packets = 0;
- q->size = 0;
- almtx_unlock(&q->mutex);
-}
-static void packet_queue_flush(PacketQueue *q)
-{
- almtx_lock(&q->mutex);
- q->flushing = true;
- almtx_unlock(&q->mutex);
- alcnd_signal(&q->cond);
-}
-static void packet_queue_deinit(PacketQueue *q)
-{
- packet_queue_clear(q);
- alcnd_destroy(&q->cond);
- almtx_destroy(&q->mutex);
-}
-
-
-static double get_audio_clock(AudioState *state)
-{
- double pts;
-
- almtx_lock(&state->src_mutex);
- /* The audio clock is the timestamp of the sample currently being heard.
- * It's based on 4 components:
- * 1 - The timestamp of the next sample to buffer (state->current_pts)
- * 2 - The length of the source's buffer queue (AL_SEC_LENGTH_SOFT)
- * 3 - The offset OpenAL is currently at in the source (the first value
- * from AL_SEC_OFFSET_LATENCY_SOFT)
- * 4 - The latency between OpenAL and the DAC (the second value from
- * AL_SEC_OFFSET_LATENCY_SOFT)
- *
- * Subtracting the length of the source queue from the next sample's
- * timestamp gives the timestamp of the sample at start of the source
- * queue. Adding the source offset to that results in the timestamp for
- * OpenAL's current position, and subtracting the source latency from that
- * gives the timestamp of the sample currently at the DAC.
- */
- pts = state->current_pts;
- if(state->source)
- {
- ALdouble offset[2] = { 0.0, 0.0 };
- ALdouble queue_len = 0.0;
- ALint status;
-
- /* NOTE: The source state must be checked last, in case an underrun
- * occurs and the source stops between retrieving the offset+latency
- * and getting the state. */
- if(has_latency_check)
- {
- alGetSourcedvSOFT(state->source, AL_SEC_OFFSET_LATENCY_SOFT, offset);
- alGetSourcedvSOFT(state->source, AL_SEC_LENGTH_SOFT, &queue_len);
- }
- else
- {
- ALint ioffset, ilen;
- alGetSourcei(state->source, AL_SAMPLE_OFFSET, &ioffset);
- alGetSourcei(state->source, AL_SAMPLE_LENGTH_SOFT, &ilen);
- offset[0] = (double)ioffset / state->st->codec->sample_rate;
- queue_len = (double)ilen / state->st->codec->sample_rate;
- }
- alGetSourcei(state->source, AL_SOURCE_STATE, &status);
-
- /* If the source is AL_STOPPED, then there was an underrun and all
- * buffers are processed, so ignore the source queue. The audio thread
- * will put the source into an AL_INITIAL state and clear the queue
- * when it starts recovery. */
- if(status != AL_STOPPED)
- pts = pts - queue_len + offset[0];
- if(status == AL_PLAYING)
- pts = pts - offset[1];
- }
- almtx_unlock(&state->src_mutex);
-
- return (pts >= 0.0) ? pts : 0.0;
-}
-static double get_video_clock(VideoState *state)
-{
- double delta = (av_gettime() - state->current_pts_time) / 1000000.0;
- return state->current_pts + delta;
-}
-static double get_external_clock(MovieState *movState)
-{
- return (av_gettime()-movState->external_clock_base) / 1000000.0;
-}
-
-double get_master_clock(MovieState *movState)
-{
- if(movState->av_sync_type == AV_SYNC_VIDEO_MASTER)
- return get_video_clock(&movState->video);
- if(movState->av_sync_type == AV_SYNC_AUDIO_MASTER)
- return get_audio_clock(&movState->audio);
- return get_external_clock(movState);
-}
-
-/* Return how many samples to skip to maintain sync (negative means to
- * duplicate samples). */
-static int synchronize_audio(MovieState *movState)
-{
- double diff, avg_diff;
- double ref_clock;
-
- if(movState->av_sync_type == AV_SYNC_AUDIO_MASTER)
- return 0;
-
- ref_clock = get_master_clock(movState);
- diff = ref_clock - get_audio_clock(&movState->audio);
-
- if(!(diff < AV_NOSYNC_THRESHOLD))
- {
- /* Difference is TOO big; reset diff stuff */
- movState->audio.diff_accum = 0.0;
- return 0;
- }
-
- /* Accumulate the diffs */
- movState->audio.diff_accum = movState->audio.diff_accum*movState->audio.diff_avg_coef + diff;
- avg_diff = movState->audio.diff_accum*(1.0 - movState->audio.diff_avg_coef);
- if(fabs(avg_diff) < movState->audio.diff_threshold)
- return 0;
-
- /* Constrain the per-update difference to avoid exceedingly large skips */
- if(!(diff <= SAMPLE_CORRECTION_MAX_DIFF))
- diff = SAMPLE_CORRECTION_MAX_DIFF;
- else if(!(diff >= -SAMPLE_CORRECTION_MAX_DIFF))
- diff = -SAMPLE_CORRECTION_MAX_DIFF;
- return (int)(diff*movState->audio.st->codec->sample_rate);
-}
-
-static int audio_decode_frame(MovieState *movState)
-{
- AVPacket *pkt = &movState->audio.pkt;
-
- while(!movState->quit)
- {
- while(!movState->quit && pkt->size == 0)
- {
- av_free_packet(pkt);
-
- /* Get the next packet */
- int err;
- if((err=packet_queue_get(&movState->audio.q, pkt, movState)) <= 0)
- {
- if(err == 0)
- break;
- return err;
- }
- if(pkt->data == flush_pkt.data)
- {
- avcodec_flush_buffers(movState->audio.st->codec);
- movState->audio.diff_accum = 0.0;
- movState->audio.current_pts = av_q2d(movState->audio.st->time_base)*pkt->pts;
-
- alSourceRewind(movState->audio.source);
- alSourcei(movState->audio.source, AL_BUFFER, 0);
-
- av_new_packet(pkt, 0);
-
- return -1;
- }
-
- /* If provided, update w/ pts */
- if(pkt->pts != AV_NOPTS_VALUE)
- movState->audio.current_pts = av_q2d(movState->audio.st->time_base)*pkt->pts;
- }
-
- AVFrame *frame = movState->audio.decoded_aframe;
- int got_frame = 0;
- int len1 = avcodec_decode_audio4(movState->audio.st->codec, frame,
- &got_frame, pkt);
- if(len1 < 0) break;
-
- if(len1 <= pkt->size)
- {
- /* Move the unread data to the front and clear the end bits */
- int remaining = pkt->size - len1;
- memmove(pkt->data, &pkt->data[len1], remaining);
- av_shrink_packet(pkt, remaining);
- }
-
- if(!got_frame || frame->nb_samples <= 0)
- {
- av_frame_unref(frame);
- continue;
- }
-
- if(frame->nb_samples > movState->audio.samples_max)
- {
- av_freep(&movState->audio.samples);
- av_samples_alloc(
- &movState->audio.samples, NULL, movState->audio.st->codec->channels,
- frame->nb_samples, movState->audio.dst_sample_fmt, 0
- );
- movState->audio.samples_max = frame->nb_samples;
- }
- /* Return the amount of sample frames converted */
- int data_size = swr_convert(movState->audio.swres_ctx,
- &movState->audio.samples, frame->nb_samples,
- (const uint8_t**)frame->data, frame->nb_samples
- );
-
- av_frame_unref(frame);
- return data_size;
- }
-
- return -1;
-}
-
-static int read_audio(MovieState *movState, uint8_t *samples, int length)
-{
- int sample_skip = synchronize_audio(movState);
- int audio_size = 0;
-
- /* Read the next chunk of data, refill the buffer, and queue it
- * on the source */
- length /= movState->audio.frame_size;
- while(audio_size < length)
- {
- if(movState->audio.samples_len <= 0 || movState->audio.samples_pos >= movState->audio.samples_len)
- {
- int frame_len = audio_decode_frame(movState);
- if(frame_len < 0) return -1;
-
- movState->audio.samples_len = frame_len;
- if(movState->audio.samples_len == 0)
- break;
-
- movState->audio.samples_pos = (movState->audio.samples_len < sample_skip) ?
- movState->audio.samples_len : sample_skip;
- sample_skip -= movState->audio.samples_pos;
-
- movState->audio.current_pts += (double)movState->audio.samples_pos /
- (double)movState->audio.st->codec->sample_rate;
- continue;
- }
-
- int rem = length - audio_size;
- if(movState->audio.samples_pos >= 0)
- {
- int n = movState->audio.frame_size;
- int len = movState->audio.samples_len - movState->audio.samples_pos;
- if(rem > len) rem = len;
- memcpy(samples + audio_size*n,
- movState->audio.samples + movState->audio.samples_pos*n,
- rem*n);
- }
- else
- {
- int n = movState->audio.frame_size;
- int len = -movState->audio.samples_pos;
- if(rem > len) rem = len;
-
- /* Add samples by copying the first sample */
- if(n == 1)
- {
- uint8_t sample = ((uint8_t*)movState->audio.samples)[0];
- uint8_t *q = (uint8_t*)samples + audio_size;
- for(int i = 0;i < rem;i++)
- *(q++) = sample;
- }
- else if(n == 2)
- {
- uint16_t sample = ((uint16_t*)movState->audio.samples)[0];
- uint16_t *q = (uint16_t*)samples + audio_size;
- for(int i = 0;i < rem;i++)
- *(q++) = sample;
- }
- else if(n == 4)
- {
- uint32_t sample = ((uint32_t*)movState->audio.samples)[0];
- uint32_t *q = (uint32_t*)samples + audio_size;
- for(int i = 0;i < rem;i++)
- *(q++) = sample;
- }
- else if(n == 8)
- {
- uint64_t sample = ((uint64_t*)movState->audio.samples)[0];
- uint64_t *q = (uint64_t*)samples + audio_size;
- for(int i = 0;i < rem;i++)
- *(q++) = sample;
- }
- else
- {
- uint8_t *sample = movState->audio.samples;
- uint8_t *q = samples + audio_size*n;
- for(int i = 0;i < rem;i++)
- {
- memcpy(q, sample, n);
- q += n;
- }
- }
- }
-
- movState->audio.samples_pos += rem;
- movState->audio.current_pts += (double)rem / movState->audio.st->codec->sample_rate;
- audio_size += rem;
- }
-
- return audio_size * movState->audio.frame_size;
-}
-
-static int audio_thread(void *userdata)
-{
- MovieState *movState = (MovieState*)userdata;
- uint8_t *samples = NULL;
- ALsizei buffer_len;
- ALenum fmt;
-
- alGenBuffers(AUDIO_BUFFER_QUEUE_SIZE, movState->audio.buffer);
- alGenSources(1, &movState->audio.source);
-
- alSourcei(movState->audio.source, AL_SOURCE_RELATIVE, AL_TRUE);
- alSourcei(movState->audio.source, AL_ROLLOFF_FACTOR, 0);
-
- av_new_packet(&movState->audio.pkt, 0);
-
- /* Find a suitable format for OpenAL. */
- movState->audio.format = AL_NONE;
- if(movState->audio.st->codec->sample_fmt == AV_SAMPLE_FMT_U8 ||
- movState->audio.st->codec->sample_fmt == AV_SAMPLE_FMT_U8P)
- {
- movState->audio.dst_sample_fmt = AV_SAMPLE_FMT_U8;
- movState->audio.frame_size = 1;
- if(movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_7POINT1 &&
- alIsExtensionPresent("AL_EXT_MCFORMATS") &&
- (fmt=alGetEnumValue("AL_FORMAT_71CHN8")) != AL_NONE && fmt != -1)
- {
- movState->audio.dst_ch_layout = movState->audio.st->codec->channel_layout;
- movState->audio.frame_size *= 8;
- movState->audio.format = fmt;
- }
- if((movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_5POINT1 ||
- movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) &&
- alIsExtensionPresent("AL_EXT_MCFORMATS") &&
- (fmt=alGetEnumValue("AL_FORMAT_51CHN8")) != AL_NONE && fmt != -1)
- {
- movState->audio.dst_ch_layout = movState->audio.st->codec->channel_layout;
- movState->audio.frame_size *= 6;
- movState->audio.format = fmt;
- }
- if(movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_MONO)
- {
- movState->audio.dst_ch_layout = AV_CH_LAYOUT_MONO;
- movState->audio.frame_size *= 1;
- movState->audio.format = AL_FORMAT_MONO8;
- }
- if(movState->audio.format == AL_NONE)
- {
- movState->audio.dst_ch_layout = AV_CH_LAYOUT_STEREO;
- movState->audio.frame_size *= 2;
- movState->audio.format = AL_FORMAT_STEREO8;
- }
- }
- if((movState->audio.st->codec->sample_fmt == AV_SAMPLE_FMT_FLT ||
- movState->audio.st->codec->sample_fmt == AV_SAMPLE_FMT_FLTP) &&
- alIsExtensionPresent("AL_EXT_FLOAT32"))
- {
- movState->audio.dst_sample_fmt = AV_SAMPLE_FMT_FLT;
- movState->audio.frame_size = 4;
- if(movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_7POINT1 &&
- alIsExtensionPresent("AL_EXT_MCFORMATS") &&
- (fmt=alGetEnumValue("AL_FORMAT_71CHN32")) != AL_NONE && fmt != -1)
- {
- movState->audio.dst_ch_layout = movState->audio.st->codec->channel_layout;
- movState->audio.frame_size *= 8;
- movState->audio.format = fmt;
- }
- if((movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_5POINT1 ||
- movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) &&
- alIsExtensionPresent("AL_EXT_MCFORMATS") &&
- (fmt=alGetEnumValue("AL_FORMAT_51CHN32")) != AL_NONE && fmt != -1)
- {
- movState->audio.dst_ch_layout = movState->audio.st->codec->channel_layout;
- movState->audio.frame_size *= 6;
- movState->audio.format = fmt;
- }
- if(movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_MONO)
- {
- movState->audio.dst_ch_layout = AV_CH_LAYOUT_MONO;
- movState->audio.frame_size *= 1;
- movState->audio.format = AL_FORMAT_MONO_FLOAT32;
- }
- if(movState->audio.format == AL_NONE)
- {
- movState->audio.dst_ch_layout = AV_CH_LAYOUT_STEREO;
- movState->audio.frame_size *= 2;
- movState->audio.format = AL_FORMAT_STEREO_FLOAT32;
- }
- }
- if(movState->audio.format == AL_NONE)
- {
- movState->audio.dst_sample_fmt = AV_SAMPLE_FMT_S16;
- movState->audio.frame_size = 2;
- if(movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_7POINT1 &&
- alIsExtensionPresent("AL_EXT_MCFORMATS") &&
- (fmt=alGetEnumValue("AL_FORMAT_71CHN16")) != AL_NONE && fmt != -1)
- {
- movState->audio.dst_ch_layout = movState->audio.st->codec->channel_layout;
- movState->audio.frame_size *= 8;
- movState->audio.format = fmt;
- }
- if((movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_5POINT1 ||
- movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) &&
- alIsExtensionPresent("AL_EXT_MCFORMATS") &&
- (fmt=alGetEnumValue("AL_FORMAT_51CHN16")) != AL_NONE && fmt != -1)
- {
- movState->audio.dst_ch_layout = movState->audio.st->codec->channel_layout;
- movState->audio.frame_size *= 6;
- movState->audio.format = fmt;
- }
- if(movState->audio.st->codec->channel_layout == AV_CH_LAYOUT_MONO)
- {
- movState->audio.dst_ch_layout = AV_CH_LAYOUT_MONO;
- movState->audio.frame_size *= 1;
- movState->audio.format = AL_FORMAT_MONO16;
- }
- if(movState->audio.format == AL_NONE)
- {
- movState->audio.dst_ch_layout = AV_CH_LAYOUT_STEREO;
- movState->audio.frame_size *= 2;
- movState->audio.format = AL_FORMAT_STEREO16;
- }
- }
- buffer_len = AUDIO_BUFFER_TIME * movState->audio.st->codec->sample_rate / 1000 *
- movState->audio.frame_size;
- samples = av_malloc(buffer_len);
-
- movState->audio.samples = NULL;
- movState->audio.samples_max = 0;
- movState->audio.samples_pos = 0;
- movState->audio.samples_len = 0;
-
- if(!(movState->audio.decoded_aframe=av_frame_alloc()))
- {
- fprintf(stderr, "Failed to allocate audio frame\n");
- goto finish;
- }
-
- movState->audio.swres_ctx = swr_alloc_set_opts(NULL,
- movState->audio.dst_ch_layout,
- movState->audio.dst_sample_fmt,
- movState->audio.st->codec->sample_rate,
- movState->audio.st->codec->channel_layout ?
- movState->audio.st->codec->channel_layout :
- av_get_default_channel_layout(movState->audio.st->codec->channels),
- movState->audio.st->codec->sample_fmt,
- movState->audio.st->codec->sample_rate,
- 0, NULL
- );
- if(!movState->audio.swres_ctx || swr_init(movState->audio.swres_ctx) != 0)
- {
- fprintf(stderr, "Failed to initialize audio converter\n");
- goto finish;
- }
-
- almtx_lock(&movState->audio.src_mutex);
- while(alGetError() == AL_NO_ERROR && !movState->quit)
- {
- /* First remove any processed buffers. */
- ALint processed;
- alGetSourcei(movState->audio.source, AL_BUFFERS_PROCESSED, &processed);
- alSourceUnqueueBuffers(movState->audio.source, processed, (ALuint[AUDIO_BUFFER_QUEUE_SIZE]){});
-
- /* Refill the buffer queue. */
- ALint queued;
- alGetSourcei(movState->audio.source, AL_BUFFERS_QUEUED, &queued);
- while(queued < AUDIO_BUFFER_QUEUE_SIZE)
- {
- int audio_size;
-
- /* Read the next chunk of data, fill the buffer, and queue it on
- * the source */
- audio_size = read_audio(movState, samples, buffer_len);
- if(audio_size < 0) break;
-
- ALuint bufid = movState->audio.buffer[movState->audio.buffer_idx++];
- movState->audio.buffer_idx %= AUDIO_BUFFER_QUEUE_SIZE;
-
- alBufferData(bufid, movState->audio.format, samples, audio_size,
- movState->audio.st->codec->sample_rate);
- alSourceQueueBuffers(movState->audio.source, 1, &bufid);
- queued++;
- }
-
- /* Check that the source is playing. */
- ALint state;
- alGetSourcei(movState->audio.source, AL_SOURCE_STATE, &state);
- if(state == AL_STOPPED)
- {
- /* AL_STOPPED means there was an underrun. Double-check that all
- * processed buffers are removed, then rewind the source to get it
- * back into an AL_INITIAL state. */
- alGetSourcei(movState->audio.source, AL_BUFFERS_PROCESSED, &processed);
- alSourceUnqueueBuffers(movState->audio.source, processed, (ALuint[AUDIO_BUFFER_QUEUE_SIZE]){});
- alSourceRewind(movState->audio.source);
- continue;
- }
-
- almtx_unlock(&movState->audio.src_mutex);
-
- /* (re)start the source if needed, and wait for a buffer to finish */
- if(state != AL_PLAYING && state != AL_PAUSED)
- {
- alGetSourcei(movState->audio.source, AL_BUFFERS_QUEUED, &queued);
- if(queued > 0) alSourcePlay(movState->audio.source);
- }
- SDL_Delay(AUDIO_BUFFER_TIME);
-
- almtx_lock(&movState->audio.src_mutex);
- }
- almtx_unlock(&movState->audio.src_mutex);
-
-finish:
- av_frame_free(&movState->audio.decoded_aframe);
- swr_free(&movState->audio.swres_ctx);
-
- av_freep(&samples);
- av_freep(&movState->audio.samples);
-
- alDeleteSources(1, &movState->audio.source);
- alDeleteBuffers(AUDIO_BUFFER_QUEUE_SIZE, movState->audio.buffer);
-
- return 0;
-}
-
-
-static Uint32 sdl_refresh_timer_cb(Uint32 interval, void *opaque)
-{
- (void)interval;
-
- SDL_PushEvent(&(SDL_Event){ .user={.type=FF_REFRESH_EVENT, .data1=opaque} });
- return 0; /* 0 means stop timer */
-}
-
-/* Schedule a video refresh in 'delay' ms */
-static void schedule_refresh(MovieState *movState, int delay)
-{
- SDL_AddTimer(delay, sdl_refresh_timer_cb, movState);
-}
-
-static void video_display(MovieState *movState, SDL_Window *screen, SDL_Renderer *renderer)
-{
- VideoPicture *vp = &movState->video.pictq[movState->video.pictq_rindex];
-
- if(!vp->bmp)
- return;
-
- float aspect_ratio;
- int win_w, win_h;
- int w, h, x, y;
-
- if(movState->video.st->codec->sample_aspect_ratio.num == 0)
- aspect_ratio = 0.0f;
- else
- {
- aspect_ratio = av_q2d(movState->video.st->codec->sample_aspect_ratio) *
- movState->video.st->codec->width /
- movState->video.st->codec->height;
- }
- if(aspect_ratio <= 0.0f)
- {
- aspect_ratio = (float)movState->video.st->codec->width /
- (float)movState->video.st->codec->height;
- }
-
- SDL_GetWindowSize(screen, &win_w, &win_h);
- h = win_h;
- w = ((int)rint(h * aspect_ratio) + 3) & ~3;
- if(w > win_w)
- {
- w = win_w;
- h = ((int)rint(w / aspect_ratio) + 3) & ~3;
- }
- x = (win_w - w) / 2;
- y = (win_h - h) / 2;
-
- SDL_RenderCopy(renderer, vp->bmp,
- &(SDL_Rect){ .x=0, .y=0, .w=vp->width, .h=vp->height },
- &(SDL_Rect){ .x=x, .y=y, .w=w, .h=h }
- );
- SDL_RenderPresent(renderer);
-}
-
-static void video_refresh_timer(MovieState *movState, SDL_Window *screen, SDL_Renderer *renderer)
-{
- if(!movState->video.st)
- {
- schedule_refresh(movState, 100);
- return;
- }
-
- almtx_lock(&movState->video.pictq_mutex);
-retry:
- if(movState->video.pictq_size == 0)
- schedule_refresh(movState, 1);
- else
- {
- VideoPicture *vp = &movState->video.pictq[movState->video.pictq_rindex];
- double actual_delay, delay, sync_threshold, ref_clock, diff;
-
- movState->video.current_pts = vp->pts;
- movState->video.current_pts_time = av_gettime();
-
- delay = vp->pts - movState->video.frame_last_pts; /* the pts from last time */
- if(delay <= 0 || delay >= 1.0)
- {
- /* if incorrect delay, use previous one */
- delay = movState->video.frame_last_delay;
- }
- /* save for next time */
- movState->video.frame_last_delay = delay;
- movState->video.frame_last_pts = vp->pts;
-
- /* Update delay to sync to clock if not master source. */
- if(movState->av_sync_type != AV_SYNC_VIDEO_MASTER)
- {
- ref_clock = get_master_clock(movState);
- diff = vp->pts - ref_clock;
-
- /* Skip or repeat the frame. Take delay into account. */
- sync_threshold = (delay > AV_SYNC_THRESHOLD) ? delay : AV_SYNC_THRESHOLD;
- if(fabs(diff) < AV_NOSYNC_THRESHOLD)
- {
- if(diff <= -sync_threshold)
- delay = 0;
- else if(diff >= sync_threshold)
- delay = 2 * delay;
- }
- }
-
- movState->video.frame_timer += delay;
- /* Compute the REAL delay. */
- actual_delay = movState->video.frame_timer - (av_gettime() / 1000000.0);
- if(!(actual_delay >= 0.010))
- {
- /* We don't have time to handle this picture, just skip to the next one. */
- movState->video.pictq_rindex = (movState->video.pictq_rindex+1)%VIDEO_PICTURE_QUEUE_SIZE;
- movState->video.pictq_size--;
- alcnd_signal(&movState->video.pictq_cond);
- goto retry;
- }
- schedule_refresh(movState, (int)(actual_delay*1000.0 + 0.5));
-
- /* Show the picture! */
- video_display(movState, screen, renderer);
-
- /* Update queue for next picture. */
- movState->video.pictq_rindex = (movState->video.pictq_rindex+1)%VIDEO_PICTURE_QUEUE_SIZE;
- movState->video.pictq_size--;
- alcnd_signal(&movState->video.pictq_cond);
- }
- almtx_unlock(&movState->video.pictq_mutex);
-}
-
-
-static void update_picture(MovieState *movState, bool *first_update, SDL_Window *screen, SDL_Renderer *renderer)
-{
- VideoPicture *vp = &movState->video.pictq[movState->video.pictq_windex];
-
- /* allocate or resize the buffer! */
- if(!vp->bmp || vp->width != movState->video.st->codec->width ||
- vp->height != movState->video.st->codec->height)
- {
- if(vp->bmp)
- SDL_DestroyTexture(vp->bmp);
- vp->bmp = SDL_CreateTexture(
- renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING,
- movState->video.st->codec->coded_width, movState->video.st->codec->coded_height
- );
- if(!vp->bmp)
- fprintf(stderr, "Failed to create YV12 texture!\n");
- vp->width = movState->video.st->codec->width;
- vp->height = movState->video.st->codec->height;
-
- if(*first_update && vp->width > 0 && vp->height > 0)
- {
- /* For the first update, set the window size to the video size. */
- *first_update = false;
-
- int w = vp->width;
- int h = vp->height;
- if(movState->video.st->codec->sample_aspect_ratio.num != 0 &&
- movState->video.st->codec->sample_aspect_ratio.den != 0)
- {
- double aspect_ratio = av_q2d(movState->video.st->codec->sample_aspect_ratio);
- if(aspect_ratio >= 1.0)
- w = (int)(w*aspect_ratio + 0.5);
- else if(aspect_ratio > 0.0)
- h = (int)(h/aspect_ratio + 0.5);
- }
- SDL_SetWindowSize(screen, w, h);
- }
- }
-
- if(vp->bmp)
- {
- AVFrame *frame = movState->video.decoded_vframe;
- void *pixels = NULL;
- int pitch = 0;
-
- if(movState->video.st->codec->pix_fmt == PIX_FMT_YUV420P)
- SDL_UpdateYUVTexture(vp->bmp, NULL,
- frame->data[0], frame->linesize[0],
- frame->data[1], frame->linesize[1],
- frame->data[2], frame->linesize[2]
- );
- else if(SDL_LockTexture(vp->bmp, NULL, &pixels, &pitch) != 0)
- fprintf(stderr, "Failed to lock texture\n");
- else
- {
- // Convert the image into YUV format that SDL uses
- int coded_w = movState->video.st->codec->coded_width;
- int coded_h = movState->video.st->codec->coded_height;
- int w = movState->video.st->codec->width;
- int h = movState->video.st->codec->height;
- if(!movState->video.swscale_ctx)
- movState->video.swscale_ctx = sws_getContext(
- w, h, movState->video.st->codec->pix_fmt,
- w, h, PIX_FMT_YUV420P, SWS_X, NULL, NULL, NULL
- );
-
- /* point pict at the queue */
- AVPicture pict;
- pict.data[0] = pixels;
- pict.data[2] = pict.data[0] + coded_w*coded_h;
- pict.data[1] = pict.data[2] + coded_w*coded_h/4;
-
- pict.linesize[0] = pitch;
- pict.linesize[2] = pitch / 2;
- pict.linesize[1] = pitch / 2;
-
- sws_scale(movState->video.swscale_ctx, (const uint8_t**)frame->data,
- frame->linesize, 0, h, pict.data, pict.linesize);
- SDL_UnlockTexture(vp->bmp);
- }
- }
-
- almtx_lock(&movState->video.pictq_mutex);
- vp->updated = true;
- almtx_unlock(&movState->video.pictq_mutex);
- alcnd_signal(&movState->video.pictq_cond);
-}
-
-static int queue_picture(MovieState *movState, double pts)
-{
- /* Wait until we have space for a new pic */
- almtx_lock(&movState->video.pictq_mutex);
- while(movState->video.pictq_size >= VIDEO_PICTURE_QUEUE_SIZE && !movState->quit)
- alcnd_wait(&movState->video.pictq_cond, &movState->video.pictq_mutex);
- almtx_unlock(&movState->video.pictq_mutex);
-
- if(movState->quit)
- return -1;
-
- VideoPicture *vp = &movState->video.pictq[movState->video.pictq_windex];
-
- /* We have to create/update the picture in the main thread */
- vp->updated = false;
- SDL_PushEvent(&(SDL_Event){ .user={.type=FF_UPDATE_EVENT, .data1=movState} });
-
- /* Wait until the picture is updated. */
- almtx_lock(&movState->video.pictq_mutex);
- while(!vp->updated && !movState->quit)
- alcnd_wait(&movState->video.pictq_cond, &movState->video.pictq_mutex);
- almtx_unlock(&movState->video.pictq_mutex);
- if(movState->quit)
- return -1;
- vp->pts = pts;
-
- movState->video.pictq_windex = (movState->video.pictq_windex+1)%VIDEO_PICTURE_QUEUE_SIZE;
- almtx_lock(&movState->video.pictq_mutex);
- movState->video.pictq_size++;
- almtx_unlock(&movState->video.pictq_mutex);
-
- return 0;
-}
-
-static double synchronize_video(MovieState *movState, double pts)
-{
- double frame_delay;
-
- if(pts == 0.0) /* if we aren't given a pts, set it to the clock */
- pts = movState->video.clock;
- else /* if we have pts, set video clock to it */
- movState->video.clock = pts;
-
- /* update the video clock */
- frame_delay = av_q2d(movState->video.st->codec->time_base);
- /* if we are repeating a frame, adjust clock accordingly */
- frame_delay += movState->video.decoded_vframe->repeat_pict * (frame_delay * 0.5);
- movState->video.clock += frame_delay;
- return pts;
-}
-
-int video_thread(void *arg)
-{
- MovieState *movState = (MovieState*)arg;
- AVPacket *packet = (AVPacket[1]){};
- int64_t saved_pts, pkt_pts;
- int frameFinished;
-
- movState->video.decoded_vframe = av_frame_alloc();
- while(packet_queue_get(&movState->video.q, packet, movState) >= 0)
- {
- if(packet->data == flush_pkt.data)
- {
- avcodec_flush_buffers(movState->video.st->codec);
-
- almtx_lock(&movState->video.pictq_mutex);
- movState->video.pictq_size = 0;
- movState->video.pictq_rindex = 0;
- movState->video.pictq_windex = 0;
- almtx_unlock(&movState->video.pictq_mutex);
-
- movState->video.clock = av_q2d(movState->video.st->time_base)*packet->pts;
- movState->video.current_pts = movState->video.clock;
- movState->video.current_pts_time = av_gettime();
- continue;
- }
-
- pkt_pts = packet->pts;
-
- /* Decode video frame */
- avcodec_decode_video2(movState->video.st->codec, movState->video.decoded_vframe,
- &frameFinished, packet);
- if(pkt_pts != AV_NOPTS_VALUE && !movState->video.decoded_vframe->opaque)
- {
- /* Store the packet's original pts in the frame, in case the frame
- * is not finished decoding yet. */
- saved_pts = pkt_pts;
- movState->video.decoded_vframe->opaque = &saved_pts;
- }
-
- av_free_packet(packet);
-
- if(frameFinished)
- {
- double pts = av_q2d(movState->video.st->time_base);
- if(packet->dts != AV_NOPTS_VALUE)
- pts *= packet->dts;
- else if(movState->video.decoded_vframe->opaque)
- pts *= *(int64_t*)movState->video.decoded_vframe->opaque;
- else
- pts *= 0.0;
- movState->video.decoded_vframe->opaque = NULL;
-
- pts = synchronize_video(movState, pts);
- if(queue_picture(movState, pts) < 0)
- break;
- }
- }
-
- sws_freeContext(movState->video.swscale_ctx);
- movState->video.swscale_ctx = NULL;
- av_frame_free(&movState->video.decoded_vframe);
- return 0;
-}
-
-
-static int stream_component_open(MovieState *movState, int stream_index)
-{
- AVFormatContext *pFormatCtx = movState->pFormatCtx;
- AVCodecContext *codecCtx;
- AVCodec *codec;
-
- if(stream_index < 0 || (unsigned int)stream_index >= pFormatCtx->nb_streams)
- return -1;
-
- /* Get a pointer to the codec context for the video stream, and open the
- * associated codec */
- codecCtx = pFormatCtx->streams[stream_index]->codec;
-
- codec = avcodec_find_decoder(codecCtx->codec_id);
- if(!codec || avcodec_open2(codecCtx, codec, NULL) < 0)
- {
- fprintf(stderr, "Unsupported codec!\n");
- return -1;
- }
-
- /* Initialize and start the media type handler */
- switch(codecCtx->codec_type)
- {
- case AVMEDIA_TYPE_AUDIO:
- movState->audioStream = stream_index;
- movState->audio.st = pFormatCtx->streams[stream_index];
-
- /* Averaging filter for audio sync */
- movState->audio.diff_avg_coef = exp(log(0.01) / AUDIO_DIFF_AVG_NB);
- /* Correct audio only if larger error than this */
- movState->audio.diff_threshold = 2.0 * 0.050/* 50 ms */;
-
- memset(&movState->audio.pkt, 0, sizeof(movState->audio.pkt));
- if(althrd_create(&movState->audio.thread, audio_thread, movState) != althrd_success)
- {
- movState->audioStream = -1;
- movState->audio.st = NULL;
- }
- break;
-
- case AVMEDIA_TYPE_VIDEO:
- movState->videoStream = stream_index;
- movState->video.st = pFormatCtx->streams[stream_index];
-
- movState->video.current_pts_time = av_gettime();
- movState->video.frame_timer = (double)movState->video.current_pts_time /
- 1000000.0;
- movState->video.frame_last_delay = 40e-3;
-
- if(althrd_create(&movState->video.thread, video_thread, movState) != althrd_success)
- {
- movState->videoStream = -1;
- movState->video.st = NULL;
- }
- break;
-
- default:
- break;
- }
-
- return 0;
-}
-
-static int decode_interrupt_cb(void *ctx)
-{
- return ((MovieState*)ctx)->quit;
-}
-
-int decode_thread(void *arg)
-{
- MovieState *movState = (MovieState *)arg;
- AVFormatContext *fmtCtx = movState->pFormatCtx;
- AVPacket *packet = (AVPacket[1]){};
- int video_index = -1;
- int audio_index = -1;
-
- movState->videoStream = -1;
- movState->audioStream = -1;
-
- /* Dump information about file onto standard error */
- av_dump_format(fmtCtx, 0, movState->filename, 0);
-
- /* Find the first video and audio streams */
- for(unsigned int i = 0;i < fmtCtx->nb_streams;i++)
- {
- if(fmtCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO && video_index < 0)
- video_index = i;
- else if(fmtCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO && audio_index < 0)
- audio_index = i;
- }
- movState->external_clock_base = av_gettime();
- if(audio_index >= 0)
- stream_component_open(movState, audio_index);
- if(video_index >= 0)
- stream_component_open(movState, video_index);
-
- if(movState->videoStream < 0 && movState->audioStream < 0)
- {
- fprintf(stderr, "%s: could not open codecs\n", movState->filename);
- goto fail;
- }
-
- /* Main packet handling loop */
- while(!movState->quit)
- {
- if(movState->seek_req)
- {
- int64_t seek_target = movState->seek_pos;
- int stream_index= -1;
-
- /* Prefer seeking on the video stream. */
- if(movState->videoStream >= 0)
- stream_index = movState->videoStream;
- else if(movState->audioStream >= 0)
- stream_index = movState->audioStream;
-
- /* Get a seek timestamp for the appropriate stream. */
- int64_t timestamp = seek_target;
- if(stream_index >= 0)
- timestamp = av_rescale_q(seek_target, AV_TIME_BASE_Q, fmtCtx->streams[stream_index]->time_base);
-
- if(av_seek_frame(movState->pFormatCtx, stream_index, timestamp, 0) < 0)
- fprintf(stderr, "%s: error while seeking\n", movState->pFormatCtx->filename);
- else
- {
- /* Seek successful, clear the packet queues and send a special
- * 'flush' packet with the new stream clock time. */
- if(movState->audioStream >= 0)
- {
- packet_queue_clear(&movState->audio.q);
- flush_pkt.pts = av_rescale_q(seek_target, AV_TIME_BASE_Q,
- fmtCtx->streams[movState->audioStream]->time_base
- );
- packet_queue_put(&movState->audio.q, &flush_pkt);
- }
- if(movState->videoStream >= 0)
- {
- packet_queue_clear(&movState->video.q);
- flush_pkt.pts = av_rescale_q(seek_target, AV_TIME_BASE_Q,
- fmtCtx->streams[movState->videoStream]->time_base
- );
- packet_queue_put(&movState->video.q, &flush_pkt);
- }
- movState->external_clock_base = av_gettime() - seek_target;
- }
- movState->seek_req = false;
- }
-
- if(movState->audio.q.size >= MAX_AUDIOQ_SIZE ||
- movState->video.q.size >= MAX_VIDEOQ_SIZE)
- {
- SDL_Delay(10);
- continue;
- }
-
- if(av_read_frame(movState->pFormatCtx, packet) < 0)
- {
- packet_queue_flush(&movState->video.q);
- packet_queue_flush(&movState->audio.q);
- break;
- }
-
- /* Place the packet in the queue it's meant for, or discard it. */
- if(packet->stream_index == movState->videoStream)
- packet_queue_put(&movState->video.q, packet);
- else if(packet->stream_index == movState->audioStream)
- packet_queue_put(&movState->audio.q, packet);
- else
- av_free_packet(packet);
- }
-
- /* all done - wait for it */
- while(!movState->quit)
- {
- if(movState->audio.q.nb_packets == 0 && movState->video.q.nb_packets == 0)
- break;
- SDL_Delay(100);
- }
-
-fail:
- movState->quit = true;
- packet_queue_flush(&movState->video.q);
- packet_queue_flush(&movState->audio.q);
-
- if(movState->videoStream >= 0)
- althrd_join(movState->video.thread, NULL);
- if(movState->audioStream >= 0)
- althrd_join(movState->audio.thread, NULL);
-
- SDL_PushEvent(&(SDL_Event){ .user={.type=FF_QUIT_EVENT, .data1=movState} });
-
- return 0;
-}
-
-
-static void stream_seek(MovieState *movState, double incr)
-{
- if(!movState->seek_req)
- {
- double newtime = get_master_clock(movState)+incr;
- if(newtime <= 0.0) movState->seek_pos = 0;
- else movState->seek_pos = (int64_t)(newtime * AV_TIME_BASE);
- movState->seek_req = true;
- }
-}
-
-int main(int argc, char *argv[])
-{
- SDL_Event event;
- MovieState *movState;
- bool first_update = true;
- SDL_Window *screen;
- SDL_Renderer *renderer;
- ALCdevice *device;
- ALCcontext *context;
-
- if(argc < 2)
- {
- fprintf(stderr, "Usage: %s <file>\n", argv[0]);
- return 1;
- }
- /* Register all formats and codecs */
- av_register_all();
- /* Initialize networking protocols */
- avformat_network_init();
-
- if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER))
- {
- fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
- return 1;
- }
-
- /* Make a window to put our video */
- screen = SDL_CreateWindow("alffplay", 0, 0, 640, 480, SDL_WINDOW_RESIZABLE);
- if(!screen)
- {
- fprintf(stderr, "SDL: could not set video mode - exiting\n");
- return 1;
- }
- /* Make a renderer to handle the texture image surface and rendering. */
- renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_ACCELERATED);
- if(renderer)
- {
- SDL_RendererInfo rinf;
- bool ok = false;
-
- /* Make sure the renderer supports YV12 textures. If not, fallback to a
- * software renderer. */
- if(SDL_GetRendererInfo(renderer, &rinf) == 0)
- {
- for(Uint32 i = 0;!ok && i < rinf.num_texture_formats;i++)
- ok = (rinf.texture_formats[i] == SDL_PIXELFORMAT_YV12);
- }
- if(!ok)
- {
- fprintf(stderr, "YV12 pixelformat textures not supported on renderer %s\n", rinf.name);
- SDL_DestroyRenderer(renderer);
- renderer = NULL;
- }
- }
- if(!renderer)
- renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_SOFTWARE);
- if(!renderer)
- {
- fprintf(stderr, "SDL: could not create renderer - exiting\n");
- return 1;
- }
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- SDL_RenderFillRect(renderer, NULL);
- SDL_RenderPresent(renderer);
-
- /* Open an audio device */
- device = alcOpenDevice(NULL);
- if(!device)
- {
- fprintf(stderr, "OpenAL: could not open device - exiting\n");
- return 1;
- }
- context = alcCreateContext(device, NULL);
- if(!context)
- {
- fprintf(stderr, "OpenAL: could not create context - exiting\n");
- return 1;
- }
- if(alcMakeContextCurrent(context) == ALC_FALSE)
- {
- fprintf(stderr, "OpenAL: could not make context current - exiting\n");
- return 1;
- }
-
- if(!alIsExtensionPresent("AL_SOFT_source_length"))
- {
- fprintf(stderr, "Required AL_SOFT_source_length not supported - exiting\n");
- return 1;
- }
-
- if(!alIsExtensionPresent("AL_SOFT_source_latency"))
- fprintf(stderr, "AL_SOFT_source_latency not supported, audio may be a bit laggy.\n");
- else
- {
- alGetSourcedvSOFT = alGetProcAddress("alGetSourcedvSOFT");
- has_latency_check = true;
- }
-
-
- movState = av_mallocz(sizeof(MovieState));
-
- av_strlcpy(movState->filename, argv[1], sizeof(movState->filename));
-
- packet_queue_init(&movState->audio.q);
- packet_queue_init(&movState->video.q);
-
- almtx_init(&movState->video.pictq_mutex, almtx_plain);
- alcnd_init(&movState->video.pictq_cond);
- almtx_init(&movState->audio.src_mutex, almtx_recursive);
-
- movState->av_sync_type = DEFAULT_AV_SYNC_TYPE;
-
- movState->pFormatCtx = avformat_alloc_context();
- movState->pFormatCtx->interrupt_callback = (AVIOInterruptCB){.callback=decode_interrupt_cb, .opaque=movState};
-
- if(avio_open2(&movState->pFormatCtx->pb, movState->filename, AVIO_FLAG_READ,
- &movState->pFormatCtx->interrupt_callback, NULL))
- {
- fprintf(stderr, "Failed to open %s\n", movState->filename);
- return 1;
- }
-
- /* Open movie file */
- if(avformat_open_input(&movState->pFormatCtx, movState->filename, NULL, NULL) != 0)
- {
- fprintf(stderr, "Failed to open %s\n", movState->filename);
- return 1;
- }
-
- /* Retrieve stream information */
- if(avformat_find_stream_info(movState->pFormatCtx, NULL) < 0)
- {
- fprintf(stderr, "%s: failed to find stream info\n", movState->filename);
- return 1;
- }
-
- schedule_refresh(movState, 40);
-
-
- if(althrd_create(&movState->parse_thread, decode_thread, movState) != althrd_success)
- {
- fprintf(stderr, "Failed to create parse thread!\n");
- return 1;
- }
- while(SDL_WaitEvent(&event) == 1)
- {
- switch(event.type)
- {
- case SDL_KEYDOWN:
- switch(event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- movState->quit = true;
- break;
-
- case SDLK_LEFT:
- stream_seek(movState, -10.0);
- break;
- case SDLK_RIGHT:
- stream_seek(movState, 10.0);
- break;
- case SDLK_UP:
- stream_seek(movState, 30.0);
- break;
- case SDLK_DOWN:
- stream_seek(movState, -30.0);
- break;
-
- default:
- break;
- }
- break;
-
- case SDL_WINDOWEVENT:
- switch(event.window.event)
- {
- case SDL_WINDOWEVENT_RESIZED:
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- SDL_RenderFillRect(renderer, NULL);
- break;
-
- default:
- break;
- }
- break;
-
- case SDL_QUIT:
- movState->quit = true;
- break;
-
- case FF_UPDATE_EVENT:
- update_picture(event.user.data1, &first_update, screen, renderer);
- break;
-
- case FF_REFRESH_EVENT:
- video_refresh_timer(event.user.data1, screen, renderer);
- break;
-
- case FF_QUIT_EVENT:
- althrd_join(movState->parse_thread, NULL);
-
- avformat_close_input(&movState->pFormatCtx);
-
- almtx_destroy(&movState->audio.src_mutex);
- almtx_destroy(&movState->video.pictq_mutex);
- alcnd_destroy(&movState->video.pictq_cond);
- packet_queue_deinit(&movState->video.q);
- packet_queue_deinit(&movState->audio.q);
-
- alcMakeContextCurrent(NULL);
- alcDestroyContext(context);
- alcCloseDevice(device);
-
- SDL_Quit();
- exit(0);
-
- default:
- break;
- }
- }
-
- fprintf(stderr, "SDL_WaitEvent error - %s\n", SDL_GetError());
- return 1;
-}
diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp
new file mode 100644
index 00000000..27520a6d
--- /dev/null
+++ b/examples/alffplay.cpp
@@ -0,0 +1,1915 @@
+/*
+ * An example showing how to play a stream sync'd to video, using ffmpeg.
+ *
+ * Requires C++11.
+ */
+
+#include <condition_variable>
+#include <functional>
+#include <algorithm>
+#include <iostream>
+#include <iomanip>
+#include <cstring>
+#include <limits>
+#include <thread>
+#include <chrono>
+#include <atomic>
+#include <vector>
+#include <mutex>
+#include <deque>
+#include <array>
+#include <cmath>
+#include <string>
+
+extern "C" {
+#include "libavcodec/avcodec.h"
+#include "libavformat/avformat.h"
+#include "libavformat/avio.h"
+#include "libavutil/time.h"
+#include "libavutil/pixfmt.h"
+#include "libavutil/avstring.h"
+#include "libavutil/channel_layout.h"
+#include "libswscale/swscale.h"
+#include "libswresample/swresample.h"
+}
+
+#include "SDL.h"
+
+#include "AL/alc.h"
+#include "AL/al.h"
+#include "AL/alext.h"
+
+#include "common/alhelpers.h"
+
+extern "C" {
+/* Undefine this to disable use of experimental extensions. Don't use for
+ * production code! Interfaces and behavior may change prior to being
+ * finalized.
+ */
+#define ALLOW_EXPERIMENTAL_EXTS
+
+#ifdef ALLOW_EXPERIMENTAL_EXTS
+#ifndef AL_SOFT_map_buffer
+#define AL_SOFT_map_buffer 1
+typedef unsigned int ALbitfieldSOFT;
+#define AL_MAP_READ_BIT_SOFT 0x00000001
+#define AL_MAP_WRITE_BIT_SOFT 0x00000002
+#define AL_MAP_PERSISTENT_BIT_SOFT 0x00000004
+#define AL_PRESERVE_DATA_BIT_SOFT 0x00000008
+typedef void (AL_APIENTRY*LPALBUFFERSTORAGESOFT)(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq, ALbitfieldSOFT flags);
+typedef void* (AL_APIENTRY*LPALMAPBUFFERSOFT)(ALuint buffer, ALsizei offset, ALsizei length, ALbitfieldSOFT access);
+typedef void (AL_APIENTRY*LPALUNMAPBUFFERSOFT)(ALuint buffer);
+typedef void (AL_APIENTRY*LPALFLUSHMAPPEDBUFFERSOFT)(ALuint buffer, ALsizei offset, ALsizei length);
+#endif
+
+#ifndef AL_SOFT_events
+#define AL_SOFT_events 1
+#define AL_EVENT_CALLBACK_FUNCTION_SOFT 0x1220
+#define AL_EVENT_CALLBACK_USER_PARAM_SOFT 0x1221
+#define AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT 0x1222
+#define AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT 0x1223
+#define AL_EVENT_TYPE_ERROR_SOFT 0x1224
+#define AL_EVENT_TYPE_PERFORMANCE_SOFT 0x1225
+#define AL_EVENT_TYPE_DEPRECATED_SOFT 0x1226
+#define AL_EVENT_TYPE_DISCONNECTED_SOFT 0x1227
+typedef void (AL_APIENTRY*ALEVENTPROCSOFT)(ALenum eventType, ALuint object, ALuint param,
+ ALsizei length, const ALchar *message,
+ void *userParam);
+typedef void (AL_APIENTRY*LPALEVENTCONTROLSOFT)(ALsizei count, const ALenum *types, ALboolean enable);
+typedef void (AL_APIENTRY*LPALEVENTCALLBACKSOFT)(ALEVENTPROCSOFT callback, void *userParam);
+typedef void* (AL_APIENTRY*LPALGETPOINTERSOFT)(ALenum pname);
+typedef void (AL_APIENTRY*LPALGETPOINTERVSOFT)(ALenum pname, void **values);
+#endif
+#endif /* ALLOW_EXPERIMENTAL_EXTS */
+}
+
+namespace {
+
+#ifndef M_PI
+#define M_PI (3.14159265358979323846)
+#endif
+
+using nanoseconds = std::chrono::nanoseconds;
+using microseconds = std::chrono::microseconds;
+using milliseconds = std::chrono::milliseconds;
+using seconds = std::chrono::seconds;
+using seconds_d64 = std::chrono::duration<double>;
+
+const std::string AppName("alffplay");
+
+bool EnableDirectOut = false;
+bool EnableWideStereo = false;
+LPALGETSOURCEI64VSOFT alGetSourcei64vSOFT;
+LPALCGETINTEGER64VSOFT alcGetInteger64vSOFT;
+
+#ifdef AL_SOFT_map_buffer
+LPALBUFFERSTORAGESOFT alBufferStorageSOFT;
+LPALMAPBUFFERSOFT alMapBufferSOFT;
+LPALUNMAPBUFFERSOFT alUnmapBufferSOFT;
+#endif
+
+#ifdef AL_SOFT_events
+LPALEVENTCONTROLSOFT alEventControlSOFT;
+LPALEVENTCALLBACKSOFT alEventCallbackSOFT;
+#endif
+
+const seconds AVNoSyncThreshold(10);
+
+const milliseconds VideoSyncThreshold(10);
+#define VIDEO_PICTURE_QUEUE_SIZE 16
+
+const seconds_d64 AudioSyncThreshold(0.03);
+const milliseconds AudioSampleCorrectionMax(50);
+/* Averaging filter coefficient for audio sync. */
+#define AUDIO_DIFF_AVG_NB 20
+const double AudioAvgFilterCoeff = std::pow(0.01, 1.0/AUDIO_DIFF_AVG_NB);
+/* Per-buffer size, in time */
+const milliseconds AudioBufferTime(20);
+/* Buffer total size, in time (should be divisible by the buffer time) */
+const milliseconds AudioBufferTotalTime(800);
+
+#define MAX_QUEUE_SIZE (15 * 1024 * 1024) /* Bytes of compressed data to keep queued */
+
+enum {
+ FF_UPDATE_EVENT = SDL_USEREVENT,
+ FF_REFRESH_EVENT,
+ FF_MOVIE_DONE_EVENT
+};
+
+enum class SyncMaster {
+ Audio,
+ Video,
+ External,
+
+ Default = External
+};
+
+
+inline microseconds get_avtime()
+{ return microseconds(av_gettime()); }
+
+/* Define unique_ptrs to auto-cleanup associated ffmpeg objects. */
+struct AVIOContextDeleter {
+ void operator()(AVIOContext *ptr) { avio_closep(&ptr); }
+};
+using AVIOContextPtr = std::unique_ptr<AVIOContext,AVIOContextDeleter>;
+
+struct AVFormatCtxDeleter {
+ void operator()(AVFormatContext *ptr) { avformat_close_input(&ptr); }
+};
+using AVFormatCtxPtr = std::unique_ptr<AVFormatContext,AVFormatCtxDeleter>;
+
+struct AVCodecCtxDeleter {
+ void operator()(AVCodecContext *ptr) { avcodec_free_context(&ptr); }
+};
+using AVCodecCtxPtr = std::unique_ptr<AVCodecContext,AVCodecCtxDeleter>;
+
+struct AVFrameDeleter {
+ void operator()(AVFrame *ptr) { av_frame_free(&ptr); }
+};
+using AVFramePtr = std::unique_ptr<AVFrame,AVFrameDeleter>;
+
+struct SwrContextDeleter {
+ void operator()(SwrContext *ptr) { swr_free(&ptr); }
+};
+using SwrContextPtr = std::unique_ptr<SwrContext,SwrContextDeleter>;
+
+struct SwsContextDeleter {
+ void operator()(SwsContext *ptr) { sws_freeContext(ptr); }
+};
+using SwsContextPtr = std::unique_ptr<SwsContext,SwsContextDeleter>;
+
+
+class PacketQueue {
+ std::deque<AVPacket> mPackets;
+ size_t mTotalSize{0};
+
+public:
+ ~PacketQueue() { clear(); }
+
+ bool empty() const noexcept { return mPackets.empty(); }
+ size_t totalSize() const noexcept { return mTotalSize; }
+
+ void put(const AVPacket *pkt)
+ {
+ mPackets.push_back(AVPacket{});
+ if(av_packet_ref(&mPackets.back(), pkt) != 0)
+ mPackets.pop_back();
+ else
+ mTotalSize += mPackets.back().size;
+ }
+
+ AVPacket *front() noexcept
+ { return &mPackets.front(); }
+
+ void pop()
+ {
+ AVPacket *pkt = &mPackets.front();
+ mTotalSize -= pkt->size;
+ av_packet_unref(pkt);
+ mPackets.pop_front();
+ }
+
+ void clear()
+ {
+ for(AVPacket &pkt : mPackets)
+ av_packet_unref(&pkt);
+ mPackets.clear();
+ mTotalSize = 0;
+ }
+};
+
+
+struct MovieState;
+
+struct AudioState {
+ MovieState &mMovie;
+
+ AVStream *mStream{nullptr};
+ AVCodecCtxPtr mCodecCtx;
+
+ std::mutex mQueueMtx;
+ std::condition_variable mQueueCond;
+
+ /* Used for clock difference average computation */
+ seconds_d64 mClockDiffAvg{0};
+
+ /* Time of the next sample to be buffered */
+ nanoseconds mCurrentPts{0};
+
+ /* Device clock time that the stream started at. */
+ nanoseconds mDeviceStartTime{nanoseconds::min()};
+
+ /* Decompressed sample frame, and swresample context for conversion */
+ AVFramePtr mDecodedFrame;
+ SwrContextPtr mSwresCtx;
+
+ /* Conversion format, for what gets fed to OpenAL */
+ int mDstChanLayout{0};
+ AVSampleFormat mDstSampleFmt{AV_SAMPLE_FMT_NONE};
+
+ /* Storage of converted samples */
+ uint8_t *mSamples{nullptr};
+ int mSamplesLen{0}; /* In samples */
+ int mSamplesPos{0};
+ int mSamplesMax{0};
+
+ /* OpenAL format */
+ ALenum mFormat{AL_NONE};
+ ALsizei mFrameSize{0};
+
+ std::mutex mSrcMutex;
+ std::condition_variable mSrcCond;
+ std::atomic_flag mConnected;
+ ALuint mSource{0};
+ std::vector<ALuint> mBuffers;
+ ALsizei mBufferIdx{0};
+
+ AudioState(MovieState &movie) : mMovie(movie)
+ { mConnected.test_and_set(std::memory_order_relaxed); }
+ ~AudioState()
+ {
+ if(mSource)
+ alDeleteSources(1, &mSource);
+ if(!mBuffers.empty())
+ alDeleteBuffers(mBuffers.size(), mBuffers.data());
+
+ av_freep(&mSamples);
+ }
+
+#ifdef AL_SOFT_events
+ static void AL_APIENTRY EventCallback(ALenum eventType, ALuint object, ALuint param,
+ ALsizei length, const ALchar *message,
+ void *userParam);
+#endif
+
+ nanoseconds getClockNoLock();
+ nanoseconds getClock()
+ {
+ std::lock_guard<std::mutex> lock(mSrcMutex);
+ return getClockNoLock();
+ }
+
+ bool isBufferFilled();
+ void startPlayback();
+
+ int getSync();
+ int decodeFrame();
+ bool readAudio(uint8_t *samples, int length);
+
+ int handler();
+};
+
+struct VideoState {
+ MovieState &mMovie;
+
+ AVStream *mStream{nullptr};
+ AVCodecCtxPtr mCodecCtx;
+
+ std::mutex mQueueMtx;
+ std::condition_variable mQueueCond;
+
+ nanoseconds mClock{0};
+ nanoseconds mFrameTimer{0};
+ nanoseconds mFrameLastPts{0};
+ nanoseconds mFrameLastDelay{0};
+ nanoseconds mCurrentPts{0};
+ /* time (av_gettime) at which we updated mCurrentPts - used to have running video pts */
+ microseconds mCurrentPtsTime{0};
+
+ /* Decompressed video frame, and swscale context for conversion */
+ AVFramePtr mDecodedFrame;
+ SwsContextPtr mSwscaleCtx;
+
+ struct Picture {
+ SDL_Texture *mImage{nullptr};
+ int mWidth{0}, mHeight{0}; /* Logical image size (actual size may be larger) */
+ std::atomic<bool> mUpdated{false};
+ nanoseconds mPts{0};
+
+ ~Picture()
+ {
+ if(mImage)
+ SDL_DestroyTexture(mImage);
+ mImage = nullptr;
+ }
+ };
+ std::array<Picture,VIDEO_PICTURE_QUEUE_SIZE> mPictQ;
+ size_t mPictQSize{0}, mPictQRead{0}, mPictQWrite{0};
+ std::mutex mPictQMutex;
+ std::condition_variable mPictQCond;
+ bool mFirstUpdate{true};
+ std::atomic<bool> mEOS{false};
+ std::atomic<bool> mFinalUpdate{false};
+
+ VideoState(MovieState &movie) : mMovie(movie) { }
+
+ nanoseconds getClock();
+ bool isBufferFilled();
+
+ static Uint32 SDLCALL sdl_refresh_timer_cb(Uint32 interval, void *opaque);
+ void schedRefresh(milliseconds delay);
+ void display(SDL_Window *screen, SDL_Renderer *renderer);
+ void refreshTimer(SDL_Window *screen, SDL_Renderer *renderer);
+ void updatePicture(SDL_Window *screen, SDL_Renderer *renderer);
+ int queuePicture(nanoseconds pts);
+ int handler();
+};
+
+struct MovieState {
+ AVIOContextPtr mIOContext;
+ AVFormatCtxPtr mFormatCtx;
+
+ SyncMaster mAVSyncType{SyncMaster::Default};
+
+ microseconds mClockBase{0};
+ std::atomic<bool> mPlaying{false};
+
+ std::mutex mSendMtx;
+ std::condition_variable mSendCond;
+ /* NOTE: false/clear = need data, true/set = no data needed */
+ std::atomic_flag mSendDataGood;
+
+ std::atomic<bool> mQuit{false};
+
+ AudioState mAudio;
+ VideoState mVideo;
+
+ std::thread mParseThread;
+ std::thread mAudioThread;
+ std::thread mVideoThread;
+
+ std::string mFilename;
+
+ MovieState(std::string fname)
+ : mAudio(*this), mVideo(*this), mFilename(std::move(fname))
+ { }
+ ~MovieState()
+ {
+ mQuit = true;
+ if(mParseThread.joinable())
+ mParseThread.join();
+ }
+
+ static int decode_interrupt_cb(void *ctx);
+ bool prepare();
+ void setTitle(SDL_Window *window);
+
+ nanoseconds getClock();
+
+ nanoseconds getMasterClock();
+
+ nanoseconds getDuration();
+
+ int streamComponentOpen(int stream_index);
+ int parse_handler();
+};
+
+
+nanoseconds AudioState::getClockNoLock()
+{
+ // The audio clock is the timestamp of the sample currently being heard.
+ if(alcGetInteger64vSOFT)
+ {
+ // If device start time = min, we aren't playing yet.
+ if(mDeviceStartTime == nanoseconds::min())
+ return nanoseconds::zero();
+
+ // Get the current device clock time and latency.
+ auto device = alcGetContextsDevice(alcGetCurrentContext());
+ ALCint64SOFT devtimes[2] = {0,0};
+ alcGetInteger64vSOFT(device, ALC_DEVICE_CLOCK_LATENCY_SOFT, 2, devtimes);
+ auto latency = nanoseconds(devtimes[1]);
+ auto device_time = nanoseconds(devtimes[0]);
+
+ // The clock is simply the current device time relative to the recorded
+ // start time. We can also subtract the latency to get more a accurate
+ // position of where the audio device actually is in the output stream.
+ return device_time - mDeviceStartTime - latency;
+ }
+
+ /* The source-based clock is based on 4 components:
+ * 1 - The timestamp of the next sample to buffer (mCurrentPts)
+ * 2 - The length of the source's buffer queue
+ * (AudioBufferTime*AL_BUFFERS_QUEUED)
+ * 3 - The offset OpenAL is currently at in the source (the first value
+ * from AL_SAMPLE_OFFSET_LATENCY_SOFT)
+ * 4 - The latency between OpenAL and the DAC (the second value from
+ * AL_SAMPLE_OFFSET_LATENCY_SOFT)
+ *
+ * Subtracting the length of the source queue from the next sample's
+ * timestamp gives the timestamp of the sample at the start of the source
+ * queue. Adding the source offset to that results in the timestamp for the
+ * sample at OpenAL's current position, and subtracting the source latency
+ * from that gives the timestamp of the sample currently at the DAC.
+ */
+ nanoseconds pts = mCurrentPts;
+ if(mSource)
+ {
+ ALint64SOFT offset[2];
+ ALint queued;
+ ALint status;
+
+ /* NOTE: The source state must be checked last, in case an underrun
+ * occurs and the source stops between retrieving the offset+latency
+ * and getting the state. */
+ if(alGetSourcei64vSOFT)
+ alGetSourcei64vSOFT(mSource, AL_SAMPLE_OFFSET_LATENCY_SOFT, offset);
+ else
+ {
+ ALint ioffset;
+ alGetSourcei(mSource, AL_SAMPLE_OFFSET, &ioffset);
+ offset[0] = (ALint64SOFT)ioffset << 32;
+ offset[1] = 0;
+ }
+ alGetSourcei(mSource, AL_BUFFERS_QUEUED, &queued);
+ alGetSourcei(mSource, AL_SOURCE_STATE, &status);
+
+ /* If the source is AL_STOPPED, then there was an underrun and all
+ * buffers are processed, so ignore the source queue. The audio thread
+ * will put the source into an AL_INITIAL state and clear the queue
+ * when it starts recovery. */
+ if(status != AL_STOPPED)
+ {
+ using fixed32 = std::chrono::duration<int64_t,std::ratio<1,(1ll<<32)>>;
+
+ pts -= AudioBufferTime*queued;
+ pts += std::chrono::duration_cast<nanoseconds>(
+ fixed32(offset[0] / mCodecCtx->sample_rate)
+ );
+ }
+ /* Don't offset by the latency if the source isn't playing. */
+ if(status == AL_PLAYING)
+ pts -= nanoseconds(offset[1]);
+ }
+
+ return std::max(pts, nanoseconds::zero());
+}
+
+bool AudioState::isBufferFilled()
+{
+ /* All of OpenAL's buffer queueing happens under the mSrcMutex lock, as
+ * does the source gen. So when we're able to grab the lock and the source
+ * is valid, the queue must be full.
+ */
+ std::lock_guard<std::mutex> lock(mSrcMutex);
+ return mSource != 0;
+}
+
+void AudioState::startPlayback()
+{
+ alSourcePlay(mSource);
+ if(alcGetInteger64vSOFT)
+ {
+ using fixed32 = std::chrono::duration<int64_t,std::ratio<1,(1ll<<32)>>;
+
+ // Subtract the total buffer queue time from the current pts to get the
+ // pts of the start of the queue.
+ nanoseconds startpts = mCurrentPts - AudioBufferTotalTime;
+ int64_t srctimes[2]={0,0};
+ alGetSourcei64vSOFT(mSource, AL_SAMPLE_OFFSET_CLOCK_SOFT, srctimes);
+ auto device_time = nanoseconds(srctimes[1]);
+ auto src_offset = std::chrono::duration_cast<nanoseconds>(fixed32(srctimes[0])) /
+ mCodecCtx->sample_rate;
+
+ // The mixer may have ticked and incremented the device time and sample
+ // offset, so subtract the source offset from the device time to get
+ // the device time the source started at. Also subtract startpts to get
+ // the device time the stream would have started at to reach where it
+ // is now.
+ mDeviceStartTime = device_time - src_offset - startpts;
+ }
+}
+
+int AudioState::getSync()
+{
+ if(mMovie.mAVSyncType == SyncMaster::Audio)
+ return 0;
+
+ auto ref_clock = mMovie.getMasterClock();
+ auto diff = ref_clock - getClockNoLock();
+
+ if(!(diff < AVNoSyncThreshold && diff > -AVNoSyncThreshold))
+ {
+ /* Difference is TOO big; reset accumulated average */
+ mClockDiffAvg = seconds_d64::zero();
+ return 0;
+ }
+
+ /* Accumulate the diffs */
+ mClockDiffAvg = mClockDiffAvg*AudioAvgFilterCoeff + diff;
+ auto avg_diff = mClockDiffAvg*(1.0 - AudioAvgFilterCoeff);
+ if(avg_diff < AudioSyncThreshold/2.0 && avg_diff > -AudioSyncThreshold)
+ return 0;
+
+ /* Constrain the per-update difference to avoid exceedingly large skips */
+ diff = std::min<nanoseconds>(std::max<nanoseconds>(diff, -AudioSampleCorrectionMax),
+ AudioSampleCorrectionMax);
+ return (int)std::chrono::duration_cast<seconds>(diff*mCodecCtx->sample_rate).count();
+}
+
+int AudioState::decodeFrame()
+{
+ while(!mMovie.mQuit.load(std::memory_order_relaxed))
+ {
+ std::unique_lock<std::mutex> lock(mQueueMtx);
+ int ret = avcodec_receive_frame(mCodecCtx.get(), mDecodedFrame.get());
+ if(ret == AVERROR(EAGAIN))
+ {
+ mMovie.mSendDataGood.clear(std::memory_order_relaxed);
+ std::unique_lock<std::mutex>(mMovie.mSendMtx).unlock();
+ mMovie.mSendCond.notify_one();
+ do {
+ mQueueCond.wait(lock);
+ ret = avcodec_receive_frame(mCodecCtx.get(), mDecodedFrame.get());
+ } while(ret == AVERROR(EAGAIN));
+ }
+ lock.unlock();
+ if(ret == AVERROR_EOF) break;
+ mMovie.mSendDataGood.clear(std::memory_order_relaxed);
+ mMovie.mSendCond.notify_one();
+ if(ret < 0)
+ {
+ std::cerr<< "Failed to decode frame: "<<ret <<std::endl;
+ return 0;
+ }
+
+ if(mDecodedFrame->nb_samples <= 0)
+ {
+ av_frame_unref(mDecodedFrame.get());
+ continue;
+ }
+
+ /* If provided, update w/ pts */
+ if(mDecodedFrame->best_effort_timestamp != AV_NOPTS_VALUE)
+ mCurrentPts = std::chrono::duration_cast<nanoseconds>(
+ seconds_d64(av_q2d(mStream->time_base)*mDecodedFrame->best_effort_timestamp)
+ );
+
+ if(mDecodedFrame->nb_samples > mSamplesMax)
+ {
+ av_freep(&mSamples);
+ av_samples_alloc(
+ &mSamples, nullptr, mCodecCtx->channels,
+ mDecodedFrame->nb_samples, mDstSampleFmt, 0
+ );
+ mSamplesMax = mDecodedFrame->nb_samples;
+ }
+ /* Return the amount of sample frames converted */
+ int data_size = swr_convert(mSwresCtx.get(), &mSamples, mDecodedFrame->nb_samples,
+ (const uint8_t**)mDecodedFrame->data, mDecodedFrame->nb_samples
+ );
+
+ av_frame_unref(mDecodedFrame.get());
+ return data_size;
+ }
+
+ return 0;
+}
+
+/* Duplicates the sample at in to out, count times. The frame size is a
+ * multiple of the template type size.
+ */
+template<typename T>
+static void sample_dup(uint8_t *out, const uint8_t *in, int count, int frame_size)
+{
+ const T *sample = reinterpret_cast<const T*>(in);
+ T *dst = reinterpret_cast<T*>(out);
+ if(frame_size == sizeof(T))
+ std::fill_n(dst, count, *sample);
+ else
+ {
+ /* NOTE: frame_size is a multiple of sizeof(T). */
+ int type_mult = frame_size / sizeof(T);
+ int i = 0;
+ std::generate_n(dst, count*type_mult,
+ [sample,type_mult,&i]() -> T
+ {
+ T ret = sample[i];
+ i = (i+1)%type_mult;
+ return ret;
+ }
+ );
+ }
+}
+
+
+bool AudioState::readAudio(uint8_t *samples, int length)
+{
+ int sample_skip = getSync();
+ int audio_size = 0;
+
+ /* Read the next chunk of data, refill the buffer, and queue it
+ * on the source */
+ length /= mFrameSize;
+ while(audio_size < length)
+ {
+ if(mSamplesLen <= 0 || mSamplesPos >= mSamplesLen)
+ {
+ int frame_len = decodeFrame();
+ if(frame_len <= 0) break;
+
+ mSamplesLen = frame_len;
+ mSamplesPos = std::min(mSamplesLen, sample_skip);
+ sample_skip -= mSamplesPos;
+
+ // Adjust the device start time and current pts by the amount we're
+ // skipping/duplicating, so that the clock remains correct for the
+ // current stream position.
+ auto skip = nanoseconds(seconds(mSamplesPos)) / mCodecCtx->sample_rate;
+ mDeviceStartTime -= skip;
+ mCurrentPts += skip;
+ continue;
+ }
+
+ int rem = length - audio_size;
+ if(mSamplesPos >= 0)
+ {
+ int len = mSamplesLen - mSamplesPos;
+ if(rem > len) rem = len;
+ memcpy(samples, mSamples + mSamplesPos*mFrameSize, rem*mFrameSize);
+ }
+ else
+ {
+ rem = std::min(rem, -mSamplesPos);
+
+ /* Add samples by copying the first sample */
+ if((mFrameSize&7) == 0)
+ sample_dup<uint64_t>(samples, mSamples, rem, mFrameSize);
+ else if((mFrameSize&3) == 0)
+ sample_dup<uint32_t>(samples, mSamples, rem, mFrameSize);
+ else if((mFrameSize&1) == 0)
+ sample_dup<uint16_t>(samples, mSamples, rem, mFrameSize);
+ else
+ sample_dup<uint8_t>(samples, mSamples, rem, mFrameSize);
+ }
+
+ mSamplesPos += rem;
+ mCurrentPts += nanoseconds(seconds(rem)) / mCodecCtx->sample_rate;
+ samples += rem*mFrameSize;
+ audio_size += rem;
+ }
+ if(audio_size <= 0)
+ return false;
+
+ if(audio_size < length)
+ {
+ int rem = length - audio_size;
+ std::fill_n(samples, rem*mFrameSize,
+ (mDstSampleFmt == AV_SAMPLE_FMT_U8) ? 0x80 : 0x00);
+ mCurrentPts += nanoseconds(seconds(rem)) / mCodecCtx->sample_rate;
+ audio_size += rem;
+ }
+ return true;
+}
+
+
+#ifdef AL_SOFT_events
+void AL_APIENTRY AudioState::EventCallback(ALenum eventType, ALuint object, ALuint param,
+ ALsizei length, const ALchar *message,
+ void *userParam)
+{
+ AudioState *self = reinterpret_cast<AudioState*>(userParam);
+
+ if(eventType == AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT)
+ {
+ /* Temporarily lock the source mutex to ensure it's not between
+ * checking the processed count and going to sleep.
+ */
+ std::unique_lock<std::mutex>(self->mSrcMutex).unlock();
+ self->mSrcCond.notify_one();
+ return;
+ }
+
+ std::cout<< "\n---- AL Event on AudioState "<<self<<" ----\nEvent: ";
+ switch(eventType)
+ {
+ case AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT: std::cout<< "Buffer completed"; break;
+ case AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT: std::cout<< "Source state changed"; break;
+ case AL_EVENT_TYPE_ERROR_SOFT: std::cout<< "API error"; break;
+ case AL_EVENT_TYPE_PERFORMANCE_SOFT: std::cout<< "Performance"; break;
+ case AL_EVENT_TYPE_DEPRECATED_SOFT: std::cout<< "Deprecated"; break;
+ case AL_EVENT_TYPE_DISCONNECTED_SOFT: std::cout<< "Disconnected"; break;
+ default: std::cout<< "0x"<<std::hex<<std::setw(4)<<std::setfill('0')<<eventType<<
+ std::dec<<std::setw(0)<<std::setfill(' '); break;
+ }
+ std::cout<< "\n"
+ "Object ID: "<<object<<"\n"
+ "Parameter: "<<param<<"\n"
+ "Message: "<<std::string(message, length)<<"\n----"<<
+ std::endl;
+
+ if(eventType == AL_EVENT_TYPE_DISCONNECTED_SOFT)
+ {
+ { std::lock_guard<std::mutex> lock(self->mSrcMutex);
+ self->mConnected.clear(std::memory_order_release);
+ }
+ std::unique_lock<std::mutex>(self->mSrcMutex).unlock();
+ self->mSrcCond.notify_one();
+ }
+}
+#endif
+
+int AudioState::handler()
+{
+ std::unique_lock<std::mutex> lock(mSrcMutex);
+ milliseconds sleep_time = AudioBufferTime / 3;
+ ALenum fmt;
+
+#ifdef AL_SOFT_events
+ const std::array<ALenum,6> evt_types{{
+ AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT, AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT,
+ AL_EVENT_TYPE_ERROR_SOFT, AL_EVENT_TYPE_PERFORMANCE_SOFT, AL_EVENT_TYPE_DEPRECATED_SOFT,
+ AL_EVENT_TYPE_DISCONNECTED_SOFT
+ }};
+ if(alEventControlSOFT)
+ {
+ alEventControlSOFT(evt_types.size(), evt_types.data(), AL_TRUE);
+ alEventCallbackSOFT(EventCallback, this);
+ sleep_time = AudioBufferTotalTime;
+ }
+#endif
+
+ /* Find a suitable format for OpenAL. */
+ mDstChanLayout = 0;
+ if(mCodecCtx->sample_fmt == AV_SAMPLE_FMT_U8 || mCodecCtx->sample_fmt == AV_SAMPLE_FMT_U8P)
+ {
+ mDstSampleFmt = AV_SAMPLE_FMT_U8;
+ mFrameSize = 1;
+ if(mCodecCtx->channel_layout == AV_CH_LAYOUT_7POINT1 &&
+ alIsExtensionPresent("AL_EXT_MCFORMATS") &&
+ (fmt=alGetEnumValue("AL_FORMAT_71CHN8")) != AL_NONE && fmt != -1)
+ {
+ mDstChanLayout = mCodecCtx->channel_layout;
+ mFrameSize *= 8;
+ mFormat = fmt;
+ }
+ if((mCodecCtx->channel_layout == AV_CH_LAYOUT_5POINT1 ||
+ mCodecCtx->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) &&
+ alIsExtensionPresent("AL_EXT_MCFORMATS") &&
+ (fmt=alGetEnumValue("AL_FORMAT_51CHN8")) != AL_NONE && fmt != -1)
+ {
+ mDstChanLayout = mCodecCtx->channel_layout;
+ mFrameSize *= 6;
+ mFormat = fmt;
+ }
+ if(mCodecCtx->channel_layout == AV_CH_LAYOUT_MONO)
+ {
+ mDstChanLayout = mCodecCtx->channel_layout;
+ mFrameSize *= 1;
+ mFormat = AL_FORMAT_MONO8;
+ }
+ if(!mDstChanLayout)
+ {
+ mDstChanLayout = AV_CH_LAYOUT_STEREO;
+ mFrameSize *= 2;
+ mFormat = AL_FORMAT_STEREO8;
+ }
+ }
+ if((mCodecCtx->sample_fmt == AV_SAMPLE_FMT_FLT || mCodecCtx->sample_fmt == AV_SAMPLE_FMT_FLTP) &&
+ alIsExtensionPresent("AL_EXT_FLOAT32"))
+ {
+ mDstSampleFmt = AV_SAMPLE_FMT_FLT;
+ mFrameSize = 4;
+ if(mCodecCtx->channel_layout == AV_CH_LAYOUT_7POINT1 &&
+ alIsExtensionPresent("AL_EXT_MCFORMATS") &&
+ (fmt=alGetEnumValue("AL_FORMAT_71CHN32")) != AL_NONE && fmt != -1)
+ {
+ mDstChanLayout = mCodecCtx->channel_layout;
+ mFrameSize *= 8;
+ mFormat = fmt;
+ }
+ if((mCodecCtx->channel_layout == AV_CH_LAYOUT_5POINT1 ||
+ mCodecCtx->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) &&
+ alIsExtensionPresent("AL_EXT_MCFORMATS") &&
+ (fmt=alGetEnumValue("AL_FORMAT_51CHN32")) != AL_NONE && fmt != -1)
+ {
+ mDstChanLayout = mCodecCtx->channel_layout;
+ mFrameSize *= 6;
+ mFormat = fmt;
+ }
+ if(mCodecCtx->channel_layout == AV_CH_LAYOUT_MONO)
+ {
+ mDstChanLayout = mCodecCtx->channel_layout;
+ mFrameSize *= 1;
+ mFormat = AL_FORMAT_MONO_FLOAT32;
+ }
+ if(!mDstChanLayout)
+ {
+ mDstChanLayout = AV_CH_LAYOUT_STEREO;
+ mFrameSize *= 2;
+ mFormat = AL_FORMAT_STEREO_FLOAT32;
+ }
+ }
+ if(!mDstChanLayout)
+ {
+ mDstSampleFmt = AV_SAMPLE_FMT_S16;
+ mFrameSize = 2;
+ if(mCodecCtx->channel_layout == AV_CH_LAYOUT_7POINT1 &&
+ alIsExtensionPresent("AL_EXT_MCFORMATS") &&
+ (fmt=alGetEnumValue("AL_FORMAT_71CHN16")) != AL_NONE && fmt != -1)
+ {
+ mDstChanLayout = mCodecCtx->channel_layout;
+ mFrameSize *= 8;
+ mFormat = fmt;
+ }
+ if((mCodecCtx->channel_layout == AV_CH_LAYOUT_5POINT1 ||
+ mCodecCtx->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) &&
+ alIsExtensionPresent("AL_EXT_MCFORMATS") &&
+ (fmt=alGetEnumValue("AL_FORMAT_51CHN16")) != AL_NONE && fmt != -1)
+ {
+ mDstChanLayout = mCodecCtx->channel_layout;
+ mFrameSize *= 6;
+ mFormat = fmt;
+ }
+ if(mCodecCtx->channel_layout == AV_CH_LAYOUT_MONO)
+ {
+ mDstChanLayout = mCodecCtx->channel_layout;
+ mFrameSize *= 1;
+ mFormat = AL_FORMAT_MONO16;
+ }
+ if(!mDstChanLayout)
+ {
+ mDstChanLayout = AV_CH_LAYOUT_STEREO;
+ mFrameSize *= 2;
+ mFormat = AL_FORMAT_STEREO16;
+ }
+ }
+ void *samples = nullptr;
+ ALsizei buffer_len = std::chrono::duration_cast<std::chrono::duration<int>>(
+ mCodecCtx->sample_rate * AudioBufferTime).count() * mFrameSize;
+
+ mSamples = NULL;
+ mSamplesMax = 0;
+ mSamplesPos = 0;
+ mSamplesLen = 0;
+
+ mDecodedFrame.reset(av_frame_alloc());
+ if(!mDecodedFrame)
+ {
+ std::cerr<< "Failed to allocate audio frame" <<std::endl;
+ goto finish;
+ }
+
+ mSwresCtx.reset(swr_alloc_set_opts(nullptr,
+ mDstChanLayout, mDstSampleFmt, mCodecCtx->sample_rate,
+ mCodecCtx->channel_layout ? mCodecCtx->channel_layout :
+ (uint64_t)av_get_default_channel_layout(mCodecCtx->channels),
+ mCodecCtx->sample_fmt, mCodecCtx->sample_rate,
+ 0, nullptr
+ ));
+ if(!mSwresCtx || swr_init(mSwresCtx.get()) != 0)
+ {
+ std::cerr<< "Failed to initialize audio converter" <<std::endl;
+ goto finish;
+ }
+
+ mBuffers.assign(AudioBufferTotalTime / AudioBufferTime, 0);
+ alGenBuffers(mBuffers.size(), mBuffers.data());
+ alGenSources(1, &mSource);
+
+ if(EnableDirectOut)
+ alSourcei(mSource, AL_DIRECT_CHANNELS_SOFT, AL_TRUE);
+ if(EnableWideStereo)
+ {
+ ALfloat angles[2] = { (ALfloat)(M_PI/3.0), (ALfloat)(-M_PI/3.0) };
+ alSourcefv(mSource, AL_STEREO_ANGLES, angles);
+ }
+
+ if(alGetError() != AL_NO_ERROR)
+ goto finish;
+
+#ifdef AL_SOFT_map_buffer
+ if(alBufferStorageSOFT)
+ {
+ for(ALuint bufid : mBuffers)
+ alBufferStorageSOFT(bufid, mFormat, nullptr, buffer_len, mCodecCtx->sample_rate,
+ AL_MAP_WRITE_BIT_SOFT);
+ if(alGetError() != AL_NO_ERROR)
+ {
+ fprintf(stderr, "Failed to use mapped buffers\n");
+ samples = av_malloc(buffer_len);
+ }
+ }
+ else
+#endif
+ samples = av_malloc(buffer_len);
+
+ while(alGetError() == AL_NO_ERROR && !mMovie.mQuit.load(std::memory_order_relaxed) &&
+ mConnected.test_and_set(std::memory_order_relaxed))
+ {
+ /* First remove any processed buffers. */
+ ALint processed;
+ alGetSourcei(mSource, AL_BUFFERS_PROCESSED, &processed);
+ while(processed > 0)
+ {
+ std::array<ALuint,4> bids;
+ alSourceUnqueueBuffers(mSource, std::min<ALsizei>(bids.size(), processed),
+ bids.data());
+ processed -= std::min<ALsizei>(bids.size(), processed);
+ }
+
+ /* Refill the buffer queue. */
+ ALint queued;
+ alGetSourcei(mSource, AL_BUFFERS_QUEUED, &queued);
+ while((ALuint)queued < mBuffers.size())
+ {
+ ALuint bufid = mBuffers[mBufferIdx];
+
+ uint8_t *ptr = reinterpret_cast<uint8_t*>(samples
+#ifdef AL_SOFT_map_buffer
+ ? samples : alMapBufferSOFT(bufid, 0, buffer_len, AL_MAP_WRITE_BIT_SOFT)
+#endif
+ );
+ if(!ptr) break;
+
+ /* Read the next chunk of data, filling the buffer, and queue it on
+ * the source */
+ bool got_audio = readAudio(ptr, buffer_len);
+#ifdef AL_SOFT_map_buffer
+ if(!samples) alUnmapBufferSOFT(bufid);
+#endif
+ if(!got_audio) break;
+
+ if(samples)
+ alBufferData(bufid, mFormat, samples, buffer_len, mCodecCtx->sample_rate);
+
+ alSourceQueueBuffers(mSource, 1, &bufid);
+ mBufferIdx = (mBufferIdx+1) % mBuffers.size();
+ ++queued;
+ }
+ if(queued == 0)
+ break;
+
+ /* Check that the source is playing. */
+ ALint state;
+ alGetSourcei(mSource, AL_SOURCE_STATE, &state);
+ if(state == AL_STOPPED)
+ {
+ /* AL_STOPPED means there was an underrun. Clear the buffer queue
+ * since this likely means we're late, and rewind the source to get
+ * it back into an AL_INITIAL state.
+ */
+ alSourceRewind(mSource);
+ alSourcei(mSource, AL_BUFFER, 0);
+ continue;
+ }
+
+ /* (re)start the source if needed, and wait for a buffer to finish */
+ if(state != AL_PLAYING && state != AL_PAUSED &&
+ mMovie.mPlaying.load(std::memory_order_relaxed))
+ startPlayback();
+
+ mSrcCond.wait_for(lock, sleep_time);
+ }
+
+ alSourceRewind(mSource);
+ alSourcei(mSource, AL_BUFFER, 0);
+
+finish:
+ av_freep(&samples);
+
+#ifdef AL_SOFT_events
+ if(alEventControlSOFT)
+ {
+ alEventControlSOFT(evt_types.size(), evt_types.data(), AL_FALSE);
+ alEventCallbackSOFT(nullptr, nullptr);
+ }
+#endif
+
+ return 0;
+}
+
+
+nanoseconds VideoState::getClock()
+{
+ /* NOTE: This returns incorrect times while not playing. */
+ auto delta = get_avtime() - mCurrentPtsTime;
+ return mCurrentPts + delta;
+}
+
+bool VideoState::isBufferFilled()
+{
+ std::unique_lock<std::mutex> lock(mPictQMutex);
+ return mPictQSize >= mPictQ.size();
+}
+
+Uint32 SDLCALL VideoState::sdl_refresh_timer_cb(Uint32 /*interval*/, void *opaque)
+{
+ SDL_Event evt{};
+ evt.user.type = FF_REFRESH_EVENT;
+ evt.user.data1 = opaque;
+ SDL_PushEvent(&evt);
+ return 0; /* 0 means stop timer */
+}
+
+/* Schedules an FF_REFRESH_EVENT event to occur in 'delay' ms. */
+void VideoState::schedRefresh(milliseconds delay)
+{
+ SDL_AddTimer(delay.count(), sdl_refresh_timer_cb, this);
+}
+
+/* Called by VideoState::refreshTimer to display the next video frame. */
+void VideoState::display(SDL_Window *screen, SDL_Renderer *renderer)
+{
+ Picture *vp = &mPictQ[mPictQRead];
+
+ if(!vp->mImage)
+ return;
+
+ float aspect_ratio;
+ int win_w, win_h;
+ int w, h, x, y;
+
+ if(mCodecCtx->sample_aspect_ratio.num == 0)
+ aspect_ratio = 0.0f;
+ else
+ {
+ aspect_ratio = av_q2d(mCodecCtx->sample_aspect_ratio) * mCodecCtx->width /
+ mCodecCtx->height;
+ }
+ if(aspect_ratio <= 0.0f)
+ aspect_ratio = (float)mCodecCtx->width / (float)mCodecCtx->height;
+
+ SDL_GetWindowSize(screen, &win_w, &win_h);
+ h = win_h;
+ w = ((int)rint(h * aspect_ratio) + 3) & ~3;
+ if(w > win_w)
+ {
+ w = win_w;
+ h = ((int)rint(w / aspect_ratio) + 3) & ~3;
+ }
+ x = (win_w - w) / 2;
+ y = (win_h - h) / 2;
+
+ SDL_Rect src_rect{ 0, 0, vp->mWidth, vp->mHeight };
+ SDL_Rect dst_rect{ x, y, w, h };
+ SDL_RenderCopy(renderer, vp->mImage, &src_rect, &dst_rect);
+ SDL_RenderPresent(renderer);
+}
+
+/* FF_REFRESH_EVENT handler called on the main thread where the SDL_Renderer
+ * was created. It handles the display of the next decoded video frame (if not
+ * falling behind), and sets up the timer for the following video frame.
+ */
+void VideoState::refreshTimer(SDL_Window *screen, SDL_Renderer *renderer)
+{
+ if(!mStream)
+ {
+ if(mEOS)
+ {
+ mFinalUpdate = true;
+ std::unique_lock<std::mutex>(mPictQMutex).unlock();
+ mPictQCond.notify_all();
+ return;
+ }
+ schedRefresh(milliseconds(100));
+ return;
+ }
+ if(!mMovie.mPlaying.load(std::memory_order_relaxed))
+ {
+ schedRefresh(milliseconds(1));
+ return;
+ }
+
+ std::unique_lock<std::mutex> lock(mPictQMutex);
+retry:
+ if(mPictQSize == 0)
+ {
+ if(mEOS)
+ mFinalUpdate = true;
+ else
+ schedRefresh(milliseconds(1));
+ lock.unlock();
+ mPictQCond.notify_all();
+ return;
+ }
+
+ Picture *vp = &mPictQ[mPictQRead];
+ mCurrentPts = vp->mPts;
+ mCurrentPtsTime = get_avtime();
+
+ /* Get delay using the frame pts and the pts from last frame. */
+ auto delay = vp->mPts - mFrameLastPts;
+ if(delay <= seconds::zero() || delay >= seconds(1))
+ {
+ /* If incorrect delay, use previous one. */
+ delay = mFrameLastDelay;
+ }
+ /* Save for next frame. */
+ mFrameLastDelay = delay;
+ mFrameLastPts = vp->mPts;
+
+ /* Update delay to sync to clock if not master source. */
+ if(mMovie.mAVSyncType != SyncMaster::Video)
+ {
+ auto ref_clock = mMovie.getMasterClock();
+ auto diff = vp->mPts - ref_clock;
+
+ /* Skip or repeat the frame. Take delay into account. */
+ auto sync_threshold = std::min<nanoseconds>(delay, VideoSyncThreshold);
+ if(!(diff < AVNoSyncThreshold && diff > -AVNoSyncThreshold))
+ {
+ if(diff <= -sync_threshold)
+ delay = nanoseconds::zero();
+ else if(diff >= sync_threshold)
+ delay *= 2;
+ }
+ }
+
+ mFrameTimer += delay;
+ /* Compute the REAL delay. */
+ auto actual_delay = mFrameTimer - get_avtime();
+ if(!(actual_delay >= VideoSyncThreshold))
+ {
+ /* We don't have time to handle this picture, just skip to the next one. */
+ mPictQRead = (mPictQRead+1)%mPictQ.size();
+ mPictQSize--;
+ goto retry;
+ }
+ schedRefresh(std::chrono::duration_cast<milliseconds>(actual_delay));
+
+ /* Show the picture! */
+ display(screen, renderer);
+
+ /* Update queue for next picture. */
+ mPictQRead = (mPictQRead+1)%mPictQ.size();
+ mPictQSize--;
+ lock.unlock();
+ mPictQCond.notify_all();
+}
+
+/* FF_UPDATE_EVENT handler, updates the picture's texture. It's called on the
+ * main thread where the renderer was created.
+ */
+void VideoState::updatePicture(SDL_Window *screen, SDL_Renderer *renderer)
+{
+ Picture *vp = &mPictQ[mPictQWrite];
+ bool fmt_updated = false;
+
+ /* allocate or resize the buffer! */
+ if(!vp->mImage || vp->mWidth != mCodecCtx->width || vp->mHeight != mCodecCtx->height)
+ {
+ fmt_updated = true;
+ if(vp->mImage)
+ SDL_DestroyTexture(vp->mImage);
+ vp->mImage = SDL_CreateTexture(
+ renderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING,
+ mCodecCtx->coded_width, mCodecCtx->coded_height
+ );
+ if(!vp->mImage)
+ std::cerr<< "Failed to create YV12 texture!" <<std::endl;
+ vp->mWidth = mCodecCtx->width;
+ vp->mHeight = mCodecCtx->height;
+
+ if(mFirstUpdate && vp->mWidth > 0 && vp->mHeight > 0)
+ {
+ /* For the first update, set the window size to the video size. */
+ mFirstUpdate = false;
+
+ int w = vp->mWidth;
+ int h = vp->mHeight;
+ if(mCodecCtx->sample_aspect_ratio.den != 0)
+ {
+ double aspect_ratio = av_q2d(mCodecCtx->sample_aspect_ratio);
+ if(aspect_ratio >= 1.0)
+ w = (int)(w*aspect_ratio + 0.5);
+ else if(aspect_ratio > 0.0)
+ h = (int)(h/aspect_ratio + 0.5);
+ }
+ SDL_SetWindowSize(screen, w, h);
+ }
+ }
+
+ if(vp->mImage)
+ {
+ AVFrame *frame = mDecodedFrame.get();
+ void *pixels = nullptr;
+ int pitch = 0;
+
+ if(mCodecCtx->pix_fmt == AV_PIX_FMT_YUV420P)
+ SDL_UpdateYUVTexture(vp->mImage, nullptr,
+ frame->data[0], frame->linesize[0],
+ frame->data[1], frame->linesize[1],
+ frame->data[2], frame->linesize[2]
+ );
+ else if(SDL_LockTexture(vp->mImage, nullptr, &pixels, &pitch) != 0)
+ std::cerr<< "Failed to lock texture" <<std::endl;
+ else
+ {
+ // Convert the image into YUV format that SDL uses
+ int coded_w = mCodecCtx->coded_width;
+ int coded_h = mCodecCtx->coded_height;
+ int w = mCodecCtx->width;
+ int h = mCodecCtx->height;
+ if(!mSwscaleCtx || fmt_updated)
+ {
+ mSwscaleCtx.reset(sws_getContext(
+ w, h, mCodecCtx->pix_fmt,
+ w, h, AV_PIX_FMT_YUV420P, 0,
+ nullptr, nullptr, nullptr
+ ));
+ }
+
+ /* point pict at the queue */
+ uint8_t *pict_data[3];
+ pict_data[0] = reinterpret_cast<uint8_t*>(pixels);
+ pict_data[1] = pict_data[0] + coded_w*coded_h;
+ pict_data[2] = pict_data[1] + coded_w*coded_h/4;
+
+ int pict_linesize[3];
+ pict_linesize[0] = pitch;
+ pict_linesize[1] = pitch / 2;
+ pict_linesize[2] = pitch / 2;
+
+ sws_scale(mSwscaleCtx.get(), (const uint8_t**)frame->data,
+ frame->linesize, 0, h, pict_data, pict_linesize);
+ SDL_UnlockTexture(vp->mImage);
+ }
+ }
+
+ vp->mUpdated.store(true, std::memory_order_release);
+ std::unique_lock<std::mutex>(mPictQMutex).unlock();
+ mPictQCond.notify_one();
+}
+
+int VideoState::queuePicture(nanoseconds pts)
+{
+ /* Wait until we have space for a new pic */
+ std::unique_lock<std::mutex> lock(mPictQMutex);
+ while(mPictQSize >= mPictQ.size() && !mMovie.mQuit.load(std::memory_order_relaxed))
+ mPictQCond.wait(lock);
+ lock.unlock();
+
+ if(mMovie.mQuit.load(std::memory_order_relaxed))
+ return -1;
+
+ Picture *vp = &mPictQ[mPictQWrite];
+
+ /* We have to create/update the picture in the main thread */
+ vp->mUpdated.store(false, std::memory_order_relaxed);
+ SDL_Event evt{};
+ evt.user.type = FF_UPDATE_EVENT;
+ evt.user.data1 = this;
+ SDL_PushEvent(&evt);
+
+ /* Wait until the picture is updated. */
+ lock.lock();
+ while(!vp->mUpdated.load(std::memory_order_relaxed))
+ {
+ if(mMovie.mQuit.load(std::memory_order_relaxed))
+ return -1;
+ mPictQCond.wait(lock);
+ }
+ if(mMovie.mQuit.load(std::memory_order_relaxed))
+ return -1;
+ vp->mPts = pts;
+
+ mPictQWrite = (mPictQWrite+1)%mPictQ.size();
+ mPictQSize++;
+ lock.unlock();
+
+ return 0;
+}
+
+int VideoState::handler()
+{
+ mDecodedFrame.reset(av_frame_alloc());
+ while(!mMovie.mQuit.load(std::memory_order_relaxed))
+ {
+ std::unique_lock<std::mutex> lock(mQueueMtx);
+ /* Decode video frame */
+ int ret = avcodec_receive_frame(mCodecCtx.get(), mDecodedFrame.get());
+ if(ret == AVERROR(EAGAIN))
+ {
+ mMovie.mSendDataGood.clear(std::memory_order_relaxed);
+ std::unique_lock<std::mutex>(mMovie.mSendMtx).unlock();
+ mMovie.mSendCond.notify_one();
+ do {
+ mQueueCond.wait(lock);
+ ret = avcodec_receive_frame(mCodecCtx.get(), mDecodedFrame.get());
+ } while(ret == AVERROR(EAGAIN));
+ }
+ lock.unlock();
+ if(ret == AVERROR_EOF) break;
+ mMovie.mSendDataGood.clear(std::memory_order_relaxed);
+ mMovie.mSendCond.notify_one();
+ if(ret < 0)
+ {
+ std::cerr<< "Failed to decode frame: "<<ret <<std::endl;
+ continue;
+ }
+
+ /* Get the PTS for this frame. */
+ nanoseconds pts;
+ if(mDecodedFrame->best_effort_timestamp != AV_NOPTS_VALUE)
+ mClock = std::chrono::duration_cast<nanoseconds>(
+ seconds_d64(av_q2d(mStream->time_base)*mDecodedFrame->best_effort_timestamp)
+ );
+ pts = mClock;
+
+ /* Update the video clock to the next expected PTS. */
+ auto frame_delay = av_q2d(mCodecCtx->time_base);
+ frame_delay += mDecodedFrame->repeat_pict * (frame_delay * 0.5);
+ mClock += std::chrono::duration_cast<nanoseconds>(seconds_d64(frame_delay));
+
+ if(queuePicture(pts) < 0)
+ break;
+ av_frame_unref(mDecodedFrame.get());
+ }
+ mEOS = true;
+
+ std::unique_lock<std::mutex> lock(mPictQMutex);
+ if(mMovie.mQuit.load(std::memory_order_relaxed))
+ {
+ mPictQRead = 0;
+ mPictQWrite = 0;
+ mPictQSize = 0;
+ }
+ while(!mFinalUpdate)
+ mPictQCond.wait(lock);
+
+ return 0;
+}
+
+
+int MovieState::decode_interrupt_cb(void *ctx)
+{
+ return reinterpret_cast<MovieState*>(ctx)->mQuit.load(std::memory_order_relaxed);
+}
+
+bool MovieState::prepare()
+{
+ AVIOContext *avioctx = nullptr;
+ AVIOInterruptCB intcb = { decode_interrupt_cb, this };
+ if(avio_open2(&avioctx, mFilename.c_str(), AVIO_FLAG_READ, &intcb, nullptr))
+ {
+ std::cerr<< "Failed to open "<<mFilename <<std::endl;
+ return false;
+ }
+ mIOContext.reset(avioctx);
+
+ /* Open movie file. If avformat_open_input fails it will automatically free
+ * this context, so don't set it onto a smart pointer yet.
+ */
+ AVFormatContext *fmtctx = avformat_alloc_context();
+ fmtctx->pb = mIOContext.get();
+ fmtctx->interrupt_callback = intcb;
+ if(avformat_open_input(&fmtctx, mFilename.c_str(), nullptr, nullptr) != 0)
+ {
+ std::cerr<< "Failed to open "<<mFilename <<std::endl;
+ return false;
+ }
+ mFormatCtx.reset(fmtctx);
+
+ /* Retrieve stream information */
+ if(avformat_find_stream_info(mFormatCtx.get(), nullptr) < 0)
+ {
+ std::cerr<< mFilename<<": failed to find stream info" <<std::endl;
+ return false;
+ }
+
+ mVideo.schedRefresh(milliseconds(40));
+
+ mParseThread = std::thread(std::mem_fn(&MovieState::parse_handler), this);
+ return true;
+}
+
+void MovieState::setTitle(SDL_Window *window)
+{
+ auto pos1 = mFilename.rfind('/');
+ auto pos2 = mFilename.rfind('\\');
+ auto fpos = ((pos1 == std::string::npos) ? pos2 :
+ (pos2 == std::string::npos) ? pos1 :
+ std::max(pos1, pos2)) + 1;
+ SDL_SetWindowTitle(window, (mFilename.substr(fpos)+" - "+AppName).c_str());
+}
+
+nanoseconds MovieState::getClock()
+{
+ if(!mPlaying.load(std::memory_order_relaxed))
+ return nanoseconds::zero();
+ return get_avtime() - mClockBase;
+}
+
+nanoseconds MovieState::getMasterClock()
+{
+ if(mAVSyncType == SyncMaster::Video)
+ return mVideo.getClock();
+ if(mAVSyncType == SyncMaster::Audio)
+ return mAudio.getClock();
+ return getClock();
+}
+
+nanoseconds MovieState::getDuration()
+{ return std::chrono::duration<int64_t,std::ratio<1,AV_TIME_BASE>>(mFormatCtx->duration); }
+
+int MovieState::streamComponentOpen(int stream_index)
+{
+ if(stream_index < 0 || (unsigned int)stream_index >= mFormatCtx->nb_streams)
+ return -1;
+
+ /* Get a pointer to the codec context for the stream, and open the
+ * associated codec.
+ */
+ AVCodecCtxPtr avctx(avcodec_alloc_context3(nullptr));
+ if(!avctx) return -1;
+
+ if(avcodec_parameters_to_context(avctx.get(), mFormatCtx->streams[stream_index]->codecpar))
+ return -1;
+
+ AVCodec *codec = avcodec_find_decoder(avctx->codec_id);
+ if(!codec || avcodec_open2(avctx.get(), codec, nullptr) < 0)
+ {
+ std::cerr<< "Unsupported codec: "<<avcodec_get_name(avctx->codec_id)
+ << " (0x"<<std::hex<<avctx->codec_id<<std::dec<<")" <<std::endl;
+ return -1;
+ }
+
+ /* Initialize and start the media type handler */
+ switch(avctx->codec_type)
+ {
+ case AVMEDIA_TYPE_AUDIO:
+ mAudio.mStream = mFormatCtx->streams[stream_index];
+ mAudio.mCodecCtx = std::move(avctx);
+
+ mAudioThread = std::thread(std::mem_fn(&AudioState::handler), &mAudio);
+ break;
+
+ case AVMEDIA_TYPE_VIDEO:
+ mVideo.mStream = mFormatCtx->streams[stream_index];
+ mVideo.mCodecCtx = std::move(avctx);
+
+ mVideoThread = std::thread(std::mem_fn(&VideoState::handler), &mVideo);
+ break;
+
+ default:
+ return -1;
+ }
+
+ return stream_index;
+}
+
+int MovieState::parse_handler()
+{
+ int video_index = -1;
+ int audio_index = -1;
+
+ /* Dump information about file onto standard error */
+ av_dump_format(mFormatCtx.get(), 0, mFilename.c_str(), 0);
+
+ /* Find the first video and audio streams */
+ for(unsigned int i = 0;i < mFormatCtx->nb_streams;i++)
+ {
+ auto codecpar = mFormatCtx->streams[i]->codecpar;
+ if(codecpar->codec_type == AVMEDIA_TYPE_VIDEO && video_index < 0)
+ video_index = streamComponentOpen(i);
+ else if(codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audio_index < 0)
+ audio_index = streamComponentOpen(i);
+ }
+
+ if(video_index < 0 && audio_index < 0)
+ {
+ std::cerr<< mFilename<<": could not open codecs" <<std::endl;
+ mQuit = true;
+ }
+
+ PacketQueue audio_queue, video_queue;
+ bool input_finished = false;
+
+ /* Main packet reading/dispatching loop */
+ while(!mQuit.load(std::memory_order_relaxed) && !input_finished)
+ {
+ AVPacket packet;
+ if(av_read_frame(mFormatCtx.get(), &packet) < 0)
+ input_finished = true;
+ else
+ {
+ /* Copy the packet into the queue it's meant for. */
+ if(packet.stream_index == video_index)
+ video_queue.put(&packet);
+ else if(packet.stream_index == audio_index)
+ audio_queue.put(&packet);
+ av_packet_unref(&packet);
+ }
+
+ do {
+ /* Send whatever queued packets we have. */
+ if(!audio_queue.empty())
+ {
+ std::unique_lock<std::mutex> lock(mAudio.mQueueMtx);
+ int ret;
+ do {
+ ret = avcodec_send_packet(mAudio.mCodecCtx.get(), audio_queue.front());
+ if(ret != AVERROR(EAGAIN)) audio_queue.pop();
+ } while(ret != AVERROR(EAGAIN) && !audio_queue.empty());
+ lock.unlock();
+ mAudio.mQueueCond.notify_one();
+ }
+ if(!video_queue.empty())
+ {
+ std::unique_lock<std::mutex> lock(mVideo.mQueueMtx);
+ int ret;
+ do {
+ ret = avcodec_send_packet(mVideo.mCodecCtx.get(), video_queue.front());
+ if(ret != AVERROR(EAGAIN)) video_queue.pop();
+ } while(ret != AVERROR(EAGAIN) && !video_queue.empty());
+ lock.unlock();
+ mVideo.mQueueCond.notify_one();
+ }
+ /* If the queues are completely empty, or it's not full and there's
+ * more input to read, go get more.
+ */
+ size_t queue_size = audio_queue.totalSize() + video_queue.totalSize();
+ if(queue_size == 0 || (queue_size < MAX_QUEUE_SIZE && !input_finished))
+ break;
+
+ if(!mPlaying.load(std::memory_order_relaxed))
+ {
+ if((!mAudio.mCodecCtx || mAudio.isBufferFilled()) &&
+ (!mVideo.mCodecCtx || mVideo.isBufferFilled()))
+ {
+ /* Set the base time 50ms ahead of the current av time. */
+ mClockBase = get_avtime() + milliseconds(50);
+ mVideo.mCurrentPtsTime = mClockBase;
+ mVideo.mFrameTimer = mVideo.mCurrentPtsTime;
+ mAudio.startPlayback();
+ mPlaying.store(std::memory_order_release);
+ }
+ }
+ /* Nothing to send or get for now, wait a bit and try again. */
+ { std::unique_lock<std::mutex> lock(mSendMtx);
+ if(mSendDataGood.test_and_set(std::memory_order_relaxed))
+ mSendCond.wait_for(lock, milliseconds(10));
+ }
+ } while(!mQuit.load(std::memory_order_relaxed));
+ }
+ /* Pass a null packet to finish the send buffers (the receive functions
+ * will get AVERROR_EOF when emptied).
+ */
+ if(mVideo.mCodecCtx)
+ {
+ { std::lock_guard<std::mutex> lock(mVideo.mQueueMtx);
+ avcodec_send_packet(mVideo.mCodecCtx.get(), nullptr);
+ }
+ mVideo.mQueueCond.notify_one();
+ }
+ if(mAudio.mCodecCtx)
+ {
+ { std::lock_guard<std::mutex> lock(mAudio.mQueueMtx);
+ avcodec_send_packet(mAudio.mCodecCtx.get(), nullptr);
+ }
+ mAudio.mQueueCond.notify_one();
+ }
+ video_queue.clear();
+ audio_queue.clear();
+
+ /* all done - wait for it */
+ if(mVideoThread.joinable())
+ mVideoThread.join();
+ if(mAudioThread.joinable())
+ mAudioThread.join();
+
+ mVideo.mEOS = true;
+ std::unique_lock<std::mutex> lock(mVideo.mPictQMutex);
+ while(!mVideo.mFinalUpdate)
+ mVideo.mPictQCond.wait(lock);
+ lock.unlock();
+
+ SDL_Event evt{};
+ evt.user.type = FF_MOVIE_DONE_EVENT;
+ SDL_PushEvent(&evt);
+
+ return 0;
+}
+
+
+// Helper class+method to print the time with human-readable formatting.
+struct PrettyTime {
+ seconds mTime;
+};
+inline std::ostream &operator<<(std::ostream &os, const PrettyTime &rhs)
+{
+ using hours = std::chrono::hours;
+ using minutes = std::chrono::minutes;
+ using std::chrono::duration_cast;
+
+ seconds t = rhs.mTime;
+ if(t.count() < 0)
+ {
+ os << '-';
+ t *= -1;
+ }
+
+ // Only handle up to hour formatting
+ if(t >= hours(1))
+ os << duration_cast<hours>(t).count() << 'h' << std::setfill('0') << std::setw(2)
+ << (duration_cast<minutes>(t).count() % 60) << 'm';
+ else
+ os << duration_cast<minutes>(t).count() << 'm' << std::setfill('0');
+ os << std::setw(2) << (duration_cast<seconds>(t).count() % 60) << 's' << std::setw(0)
+ << std::setfill(' ');
+ return os;
+}
+
+} // namespace
+
+
+int main(int argc, char *argv[])
+{
+ std::unique_ptr<MovieState> movState;
+
+ if(argc < 2)
+ {
+ std::cerr<< "Usage: "<<argv[0]<<" [-device <device name>] [-direct] <files...>" <<std::endl;
+ return 1;
+ }
+ /* Register all formats and codecs */
+ av_register_all();
+ /* Initialize networking protocols */
+ avformat_network_init();
+
+ if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER))
+ {
+ std::cerr<< "Could not initialize SDL - <<"<<SDL_GetError() <<std::endl;
+ return 1;
+ }
+
+ /* Make a window to put our video */
+ SDL_Window *screen = SDL_CreateWindow(AppName.c_str(), 0, 0, 640, 480, SDL_WINDOW_RESIZABLE);
+ if(!screen)
+ {
+ std::cerr<< "SDL: could not set video mode - exiting" <<std::endl;
+ return 1;
+ }
+ /* Make a renderer to handle the texture image surface and rendering. */
+ Uint32 render_flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC;
+ SDL_Renderer *renderer = SDL_CreateRenderer(screen, -1, render_flags);
+ if(renderer)
+ {
+ SDL_RendererInfo rinf{};
+ bool ok = false;
+
+ /* Make sure the renderer supports IYUV textures. If not, fallback to a
+ * software renderer. */
+ if(SDL_GetRendererInfo(renderer, &rinf) == 0)
+ {
+ for(Uint32 i = 0;!ok && i < rinf.num_texture_formats;i++)
+ ok = (rinf.texture_formats[i] == SDL_PIXELFORMAT_IYUV);
+ }
+ if(!ok)
+ {
+ std::cerr<< "IYUV pixelformat textures not supported on renderer "<<rinf.name <<std::endl;
+ SDL_DestroyRenderer(renderer);
+ renderer = nullptr;
+ }
+ }
+ if(!renderer)
+ {
+ render_flags = SDL_RENDERER_SOFTWARE | SDL_RENDERER_PRESENTVSYNC;
+ renderer = SDL_CreateRenderer(screen, -1, render_flags);
+ }
+ if(!renderer)
+ {
+ std::cerr<< "SDL: could not create renderer - exiting" <<std::endl;
+ return 1;
+ }
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
+ SDL_RenderFillRect(renderer, nullptr);
+ SDL_RenderPresent(renderer);
+
+ /* Open an audio device */
+ ++argv; --argc;
+ if(InitAL(&argv, &argc))
+ {
+ std::cerr<< "Failed to set up audio device" <<std::endl;
+ return 1;
+ }
+
+ { auto device = alcGetContextsDevice(alcGetCurrentContext());
+ if(alcIsExtensionPresent(device, "ALC_SOFT_device_clock"))
+ {
+ std::cout<< "Found ALC_SOFT_device_clock" <<std::endl;
+ alcGetInteger64vSOFT = reinterpret_cast<LPALCGETINTEGER64VSOFT>(
+ alcGetProcAddress(device, "alcGetInteger64vSOFT")
+ );
+ }
+ }
+
+ if(alIsExtensionPresent("AL_SOFT_source_latency"))
+ {
+ std::cout<< "Found AL_SOFT_source_latency" <<std::endl;
+ alGetSourcei64vSOFT = reinterpret_cast<LPALGETSOURCEI64VSOFT>(
+ alGetProcAddress("alGetSourcei64vSOFT")
+ );
+ }
+#ifdef AL_SOFT_map_buffer
+ if(alIsExtensionPresent("AL_SOFTX_map_buffer"))
+ {
+ std::cout<< "Found AL_SOFT_map_buffer" <<std::endl;
+ alBufferStorageSOFT = reinterpret_cast<LPALBUFFERSTORAGESOFT>(
+ alGetProcAddress("alBufferStorageSOFT"));
+ alMapBufferSOFT = reinterpret_cast<LPALMAPBUFFERSOFT>(
+ alGetProcAddress("alMapBufferSOFT"));
+ alUnmapBufferSOFT = reinterpret_cast<LPALUNMAPBUFFERSOFT>(
+ alGetProcAddress("alUnmapBufferSOFT"));
+ }
+#endif
+#ifdef AL_SOFT_events
+ if(alIsExtensionPresent("AL_SOFTX_events"))
+ {
+ std::cout<< "Found AL_SOFT_events" <<std::endl;
+ alEventControlSOFT = reinterpret_cast<LPALEVENTCONTROLSOFT>(
+ alGetProcAddress("alEventControlSOFT"));
+ alEventCallbackSOFT = reinterpret_cast<LPALEVENTCALLBACKSOFT>(
+ alGetProcAddress("alEventCallbackSOFT"));
+ }
+#endif
+
+ int fileidx = 0;
+ for(;fileidx < argc;++fileidx)
+ {
+ if(strcmp(argv[fileidx], "-direct") == 0)
+ {
+ if(!alIsExtensionPresent("AL_SOFT_direct_channels"))
+ std::cerr<< "AL_SOFT_direct_channels not supported for direct output" <<std::endl;
+ else
+ {
+ std::cout<< "Found AL_SOFT_direct_channels" <<std::endl;
+ EnableDirectOut = true;
+ }
+ }
+ else if(strcmp(argv[fileidx], "-wide") == 0)
+ {
+ if(!alIsExtensionPresent("AL_EXT_STEREO_ANGLES"))
+ std::cerr<< "AL_EXT_STEREO_ANGLES not supported for wide stereo" <<std::endl;
+ else
+ {
+ std::cout<< "Found AL_EXT_STEREO_ANGLES" <<std::endl;
+ EnableWideStereo = true;
+ }
+ }
+ else
+ break;
+ }
+
+ while(fileidx < argc && !movState)
+ {
+ movState = std::unique_ptr<MovieState>(new MovieState(argv[fileidx++]));
+ if(!movState->prepare()) movState = nullptr;
+ }
+ if(!movState)
+ {
+ std::cerr<< "Could not start a video" <<std::endl;
+ return 1;
+ }
+ movState->setTitle(screen);
+
+ /* Default to going to the next movie at the end of one. */
+ enum class EomAction {
+ Next, Quit
+ } eom_action = EomAction::Next;
+ seconds last_time(-1);
+ SDL_Event event;
+ while(1)
+ {
+ int have_evt = SDL_WaitEventTimeout(&event, 10);
+
+ auto cur_time = std::chrono::duration_cast<seconds>(movState->getMasterClock());
+ if(cur_time != last_time)
+ {
+ auto end_time = std::chrono::duration_cast<seconds>(movState->getDuration());
+ std::cout<< "\r "<<PrettyTime{cur_time}<<" / "<<PrettyTime{end_time} <<std::flush;
+ last_time = cur_time;
+ }
+ if(!have_evt) continue;
+
+ switch(event.type)
+ {
+ case SDL_KEYDOWN:
+ switch(event.key.keysym.sym)
+ {
+ case SDLK_ESCAPE:
+ movState->mQuit = true;
+ eom_action = EomAction::Quit;
+ break;
+
+ case SDLK_n:
+ movState->mQuit = true;
+ eom_action = EomAction::Next;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case SDL_WINDOWEVENT:
+ switch(event.window.event)
+ {
+ case SDL_WINDOWEVENT_RESIZED:
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
+ SDL_RenderFillRect(renderer, nullptr);
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case SDL_QUIT:
+ movState->mQuit = true;
+ eom_action = EomAction::Quit;
+ break;
+
+ case FF_UPDATE_EVENT:
+ reinterpret_cast<VideoState*>(event.user.data1)->updatePicture(
+ screen, renderer
+ );
+ break;
+
+ case FF_REFRESH_EVENT:
+ reinterpret_cast<VideoState*>(event.user.data1)->refreshTimer(
+ screen, renderer
+ );
+ break;
+
+ case FF_MOVIE_DONE_EVENT:
+ std::cout<<'\n';
+ last_time = seconds(-1);
+ if(eom_action != EomAction::Quit)
+ {
+ movState = nullptr;
+ while(fileidx < argc && !movState)
+ {
+ movState = std::unique_ptr<MovieState>(new MovieState(argv[fileidx++]));
+ if(!movState->prepare()) movState = nullptr;
+ }
+ if(movState)
+ {
+ movState->setTitle(screen);
+ break;
+ }
+ }
+
+ /* Nothing more to play. Shut everything down and quit. */
+ movState = nullptr;
+
+ CloseAL();
+
+ SDL_DestroyRenderer(renderer);
+ renderer = nullptr;
+ SDL_DestroyWindow(screen);
+ screen = nullptr;
+
+ SDL_Quit();
+ exit(0);
+
+ default:
+ break;
+ }
+ }
+
+ std::cerr<< "SDL_WaitEvent error - "<<SDL_GetError() <<std::endl;
+ return 1;
+}
diff --git a/examples/alhrtf.c b/examples/alhrtf.c
index 6dac5308..f9150ae1 100644
--- a/examples/alhrtf.c
+++ b/examples/alhrtf.c
@@ -28,12 +28,13 @@
#include <assert.h>
#include <math.h>
+#include <SDL_sound.h>
+
#include "AL/al.h"
#include "AL/alc.h"
#include "AL/alext.h"
#include "common/alhelpers.h"
-#include "common/sdl_sound.h"
#ifndef M_PI
@@ -44,47 +45,63 @@ static LPALCGETSTRINGISOFT alcGetStringiSOFT;
static LPALCRESETDEVICESOFT alcResetDeviceSOFT;
/* LoadBuffer loads the named audio file into an OpenAL buffer object, and
- * returns the new buffer ID. */
+ * returns the new buffer ID.
+ */
static ALuint LoadSound(const char *filename)
{
- ALenum err, format, type, channels;
- ALuint rate, buffer;
- size_t datalen;
- void *data;
- FilePtr sound;
+ Sound_Sample *sample;
+ ALenum err, format;
+ ALuint buffer;
+ Uint32 slen;
/* Open the audio file */
- sound = openAudioFile(filename, 1000);
- if(!sound)
+ sample = Sound_NewSampleFromFile(filename, NULL, 65536);
+ if(!sample)
{
fprintf(stderr, "Could not open audio in %s\n", filename);
- closeAudioFile(sound);
return 0;
}
/* Get the sound format, and figure out the OpenAL format */
- if(getAudioInfo(sound, &rate, &channels, &type) != 0)
+ if(sample->actual.channels == 1)
{
- fprintf(stderr, "Error getting audio info for %s\n", filename);
- closeAudioFile(sound);
- return 0;
+ if(sample->actual.format == AUDIO_U8)
+ format = AL_FORMAT_MONO8;
+ else if(sample->actual.format == AUDIO_S16SYS)
+ format = AL_FORMAT_MONO16;
+ else
+ {
+ fprintf(stderr, "Unsupported sample format: 0x%04x\n", sample->actual.format);
+ Sound_FreeSample(sample);
+ return 0;
+ }
}
-
- format = GetFormat(channels, type, NULL);
- if(format == AL_NONE)
+ else if(sample->actual.channels == 2)
{
- fprintf(stderr, "Unsupported format (%s, %s) for %s\n",
- ChannelsName(channels), TypeName(type), filename);
- closeAudioFile(sound);
+ if(sample->actual.format == AUDIO_U8)
+ format = AL_FORMAT_STEREO8;
+ else if(sample->actual.format == AUDIO_S16SYS)
+ format = AL_FORMAT_STEREO16;
+ else
+ {
+ fprintf(stderr, "Unsupported sample format: 0x%04x\n", sample->actual.format);
+ Sound_FreeSample(sample);
+ return 0;
+ }
+ }
+ else
+ {
+ fprintf(stderr, "Unsupported channel count: %d\n", sample->actual.channels);
+ Sound_FreeSample(sample);
return 0;
}
/* Decode the whole audio stream to a buffer. */
- data = decodeAudioStream(sound, &datalen);
- if(!data)
+ slen = Sound_DecodeAll(sample);
+ if(!sample->buffer || slen == 0)
{
fprintf(stderr, "Failed to read audio from %s\n", filename);
- closeAudioFile(sound);
+ Sound_FreeSample(sample);
return 0;
}
@@ -92,9 +109,8 @@ static ALuint LoadSound(const char *filename)
* close the file. */
buffer = 0;
alGenBuffers(1, &buffer);
- alBufferData(buffer, format, data, datalen, rate);
- free(data);
- closeAudioFile(sound);
+ alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate);
+ Sound_FreeSample(sample);
/* Check if an error occured, and clean up if so. */
err = alGetError();
@@ -113,6 +129,7 @@ static ALuint LoadSound(const char *filename)
int main(int argc, char **argv)
{
ALCdevice *device;
+ ALboolean has_angle_ext;
ALuint source, buffer;
const char *soundname;
const char *hrtfname;
@@ -121,28 +138,18 @@ int main(int argc, char **argv)
ALdouble angle;
ALenum state;
- /* Print out usage if no file was specified */
- if(argc < 2 || (strcmp(argv[1], "-hrtf") == 0 && argc < 4))
+ /* Print out usage if no arguments were specified */
+ if(argc < 2)
{
- fprintf(stderr, "Usage: %s [-hrtf <name>] <soundfile>\n", argv[0]);
+ fprintf(stderr, "Usage: %s [-device <name>] [-hrtf <name>] <soundfile>\n", argv[0]);
return 1;
}
- /* Initialize OpenAL with the default device, and check for HRTF support. */
- if(InitAL() != 0)
+ /* Initialize OpenAL, and check for HRTF support. */
+ argv++; argc--;
+ if(InitAL(&argv, &argc) != 0)
return 1;
- if(strcmp(argv[1], "-hrtf") == 0)
- {
- hrtfname = argv[2];
- soundname = argv[3];
- }
- else
- {
- hrtfname = NULL;
- soundname = argv[1];
- }
-
device = alcGetContextsDevice(alcGetCurrentContext());
if(!alcIsExtensionPresent(device, "ALC_SOFT_HRTF"))
{
@@ -157,6 +164,24 @@ int main(int argc, char **argv)
LOAD_PROC(device, alcResetDeviceSOFT);
#undef LOAD_PROC
+ /* Check for the AL_EXT_STEREO_ANGLES extension to be able to also rotate
+ * stereo sources.
+ */
+ has_angle_ext = alIsExtensionPresent("AL_EXT_STEREO_ANGLES");
+ printf("AL_EXT_STEREO_ANGLES%s found\n", has_angle_ext?"":" not");
+
+ /* Check for user-preferred HRTF */
+ if(strcmp(argv[0], "-hrtf") == 0)
+ {
+ hrtfname = argv[1];
+ soundname = argv[2];
+ }
+ else
+ {
+ hrtfname = NULL;
+ soundname = argv[0];
+ }
+
/* Enumerate available HRTFs, and reset the device using one. */
alcGetIntegerv(device, ALC_NUM_HRTF_SPECIFIERS_SOFT, 1, &num_hrtf);
if(!num_hrtf)
@@ -178,19 +203,22 @@ int main(int argc, char **argv)
index = i;
}
+ i = 0;
+ attr[i++] = ALC_HRTF_SOFT;
+ attr[i++] = ALC_TRUE;
if(index == -1)
{
if(hrtfname)
printf("HRTF \"%s\" not found\n", hrtfname);
- index = 0;
+ printf("Using default HRTF...\n");
}
- printf("Selecting HRTF %d...\n", index);
-
- attr[0] = ALC_HRTF_SOFT;
- attr[1] = ALC_TRUE;
- attr[2] = ALC_HRTF_ID_SOFT;
- attr[3] = index;
- attr[4] = 0;
+ else
+ {
+ printf("Selecting HRTF %d...\n", index);
+ attr[i++] = ALC_HRTF_ID_SOFT;
+ attr[i++] = index;
+ }
+ attr[i] = 0;
if(!alcResetDeviceSOFT(device, attr))
printf("Failed to reset device: %s\n", alcGetString(device, alcGetError(device)));
@@ -207,10 +235,14 @@ int main(int argc, char **argv)
}
fflush(stdout);
+ /* Initialize SDL_sound. */
+ Sound_Init();
+
/* Load the sound into a buffer. */
buffer = LoadSound(soundname);
if(!buffer)
{
+ Sound_Quit();
CloseAL();
return 1;
}
@@ -227,21 +259,35 @@ int main(int argc, char **argv)
angle = 0.0;
alSourcePlay(source);
do {
- Sleep(10);
+ al_nssleep(10000000);
- /* Rotate the source around the listener by about 1/4 cycle per second.
- * Only affects mono sounds.
+ /* Rotate the source around the listener by about 1/4 cycle per second,
+ * and keep it within -pi...+pi.
*/
angle += 0.01 * M_PI * 0.5;
+ if(angle > M_PI)
+ angle -= M_PI*2.0;
+
+ /* This only rotates mono sounds. */
alSource3f(source, AL_POSITION, (ALfloat)sin(angle), 0.0f, -(ALfloat)cos(angle));
+ if(has_angle_ext)
+ {
+ /* This rotates stereo sounds with the AL_EXT_STEREO_ANGLES
+ * extension. Angles are specified counter-clockwise in radians.
+ */
+ ALfloat angles[2] = { (ALfloat)(M_PI/6.0 - angle), (ALfloat)(-M_PI/6.0 - angle) };
+ alSourcefv(source, AL_STEREO_ANGLES, angles);
+ }
+
alGetSourcei(source, AL_SOURCE_STATE, &state);
} while(alGetError() == AL_NO_ERROR && state == AL_PLAYING);
- /* All done. Delete resources, and close OpenAL. */
+ /* All done. Delete resources, and close down SDL_sound and OpenAL. */
alDeleteSources(1, &source);
alDeleteBuffers(1, &buffer);
+ Sound_Quit();
CloseAL();
return 0;
diff --git a/examples/allatency.c b/examples/allatency.c
index deb13d3b..d561373f 100644
--- a/examples/allatency.c
+++ b/examples/allatency.c
@@ -27,16 +27,14 @@
#include <stdio.h>
#include <assert.h>
+#include <SDL_sound.h>
+
#include "AL/al.h"
#include "AL/alc.h"
#include "AL/alext.h"
#include "common/alhelpers.h"
-#include "common/sdl_sound.h"
-
-static LPALBUFFERSAMPLESSOFT alBufferSamplesSOFT = wrap_BufferSamples;
-static LPALISBUFFERFORMATSUPPORTEDSOFT alIsBufferFormatSupportedSOFT;
static LPALSOURCEDSOFT alSourcedSOFT;
static LPALSOURCE3DSOFT alSource3dSOFT;
@@ -52,47 +50,63 @@ static LPALGETSOURCE3I64SOFT alGetSource3i64SOFT;
static LPALGETSOURCEI64VSOFT alGetSourcei64vSOFT;
/* LoadBuffer loads the named audio file into an OpenAL buffer object, and
- * returns the new buffer ID. */
+ * returns the new buffer ID.
+ */
static ALuint LoadSound(const char *filename)
{
- ALenum err, format, type, channels;
- ALuint rate, buffer;
- size_t datalen;
- void *data;
- FilePtr sound;
+ Sound_Sample *sample;
+ ALenum err, format;
+ ALuint buffer;
+ Uint32 slen;
/* Open the audio file */
- sound = openAudioFile(filename, 1000);
- if(!sound)
+ sample = Sound_NewSampleFromFile(filename, NULL, 65536);
+ if(!sample)
{
fprintf(stderr, "Could not open audio in %s\n", filename);
- closeAudioFile(sound);
return 0;
}
/* Get the sound format, and figure out the OpenAL format */
- if(getAudioInfo(sound, &rate, &channels, &type) != 0)
+ if(sample->actual.channels == 1)
{
- fprintf(stderr, "Error getting audio info for %s\n", filename);
- closeAudioFile(sound);
- return 0;
+ if(sample->actual.format == AUDIO_U8)
+ format = AL_FORMAT_MONO8;
+ else if(sample->actual.format == AUDIO_S16SYS)
+ format = AL_FORMAT_MONO16;
+ else
+ {
+ fprintf(stderr, "Unsupported sample format: 0x%04x\n", sample->actual.format);
+ Sound_FreeSample(sample);
+ return 0;
+ }
}
-
- format = GetFormat(channels, type, alIsBufferFormatSupportedSOFT);
- if(format == AL_NONE)
+ else if(sample->actual.channels == 2)
{
- fprintf(stderr, "Unsupported format (%s, %s) for %s\n",
- ChannelsName(channels), TypeName(type), filename);
- closeAudioFile(sound);
+ if(sample->actual.format == AUDIO_U8)
+ format = AL_FORMAT_STEREO8;
+ else if(sample->actual.format == AUDIO_S16SYS)
+ format = AL_FORMAT_STEREO16;
+ else
+ {
+ fprintf(stderr, "Unsupported sample format: 0x%04x\n", sample->actual.format);
+ Sound_FreeSample(sample);
+ return 0;
+ }
+ }
+ else
+ {
+ fprintf(stderr, "Unsupported channel count: %d\n", sample->actual.channels);
+ Sound_FreeSample(sample);
return 0;
}
/* Decode the whole audio stream to a buffer. */
- data = decodeAudioStream(sound, &datalen);
- if(!data)
+ slen = Sound_DecodeAll(sample);
+ if(!sample->buffer || slen == 0)
{
fprintf(stderr, "Failed to read audio from %s\n", filename);
- closeAudioFile(sound);
+ Sound_FreeSample(sample);
return 0;
}
@@ -100,17 +114,15 @@ static ALuint LoadSound(const char *filename)
* close the file. */
buffer = 0;
alGenBuffers(1, &buffer);
- alBufferSamplesSOFT(buffer, rate, format, BytesToFrames(datalen, channels, type),
- channels, type, data);
- free(data);
- closeAudioFile(sound);
+ alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate);
+ Sound_FreeSample(sample);
/* Check if an error occured, and clean up if so. */
err = alGetError();
if(err != AL_NO_ERROR)
{
fprintf(stderr, "OpenAL Error: %s\n", alGetString(err));
- if(alIsBuffer(buffer))
+ if(buffer && alIsBuffer(buffer))
alDeleteBuffers(1, &buffer);
return 0;
}
@@ -125,15 +137,16 @@ int main(int argc, char **argv)
ALdouble offsets[2];
ALenum state;
- /* Print out usage if no file was specified */
+ /* Print out usage if no arguments were specified */
if(argc < 2)
{
- fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
+ fprintf(stderr, "Usage: %s [-device <name>] <filename>\n", argv[0]);
return 1;
}
- /* Initialize OpenAL with the default device, and check for EFX support. */
- if(InitAL() != 0)
+ /* Initialize OpenAL, and check for source_latency support. */
+ argv++; argc--;
+ if(InitAL(&argv, &argc) != 0)
return 1;
if(!alIsExtensionPresent("AL_SOFT_source_latency"))
@@ -157,18 +170,16 @@ int main(int argc, char **argv)
LOAD_PROC(alGetSourcei64SOFT);
LOAD_PROC(alGetSource3i64SOFT);
LOAD_PROC(alGetSourcei64vSOFT);
-
- if(alIsExtensionPresent("AL_SOFT_buffer_samples"))
- {
- LOAD_PROC(alBufferSamplesSOFT);
- LOAD_PROC(alIsBufferFormatSupportedSOFT);
- }
#undef LOAD_PROC
+ /* Initialize SDL_sound. */
+ Sound_Init();
+
/* Load the sound into a buffer. */
- buffer = LoadSound(argv[1]);
+ buffer = LoadSound(argv[0]);
if(!buffer)
{
+ Sound_Quit();
CloseAL();
return 1;
}
@@ -182,7 +193,7 @@ int main(int argc, char **argv)
/* Play the sound until it finishes. */
alSourcePlay(source);
do {
- Sleep(10);
+ al_nssleep(10000000);
alGetSourcei(source, AL_SOURCE_STATE, &state);
/* Get the source offset and latency. AL_SEC_OFFSET_LATENCY_SOFT will
@@ -194,10 +205,11 @@ int main(int argc, char **argv)
} while(alGetError() == AL_NO_ERROR && state == AL_PLAYING);
printf("\n");
- /* All done. Delete resources, and close OpenAL. */
+ /* All done. Delete resources, and close down SDL_sound and OpenAL. */
alDeleteSources(1, &source);
alDeleteBuffers(1, &buffer);
+ Sound_Quit();
CloseAL();
return 0;
diff --git a/examples/alloopback.c b/examples/alloopback.c
index 04c92818..16553f9b 100644
--- a/examples/alloopback.c
+++ b/examples/alloopback.c
@@ -38,6 +38,13 @@
#include "common/alhelpers.h"
+#ifndef SDL_AUDIO_MASK_BITSIZE
+#define SDL_AUDIO_MASK_BITSIZE (0xFF)
+#endif
+#ifndef SDL_AUDIO_BITSIZE
+#define SDL_AUDIO_BITSIZE(x) (x & SDL_AUDIO_MASK_BITSIZE)
+#endif
+
#ifndef M_PI
#define M_PI (3.14159265358979323846)
#endif
@@ -61,6 +68,35 @@ void SDLCALL RenderSDLSamples(void *userdata, Uint8 *stream, int len)
}
+static const char *ChannelsName(ALCenum chans)
+{
+ switch(chans)
+ {
+ case ALC_MONO_SOFT: return "Mono";
+ case ALC_STEREO_SOFT: return "Stereo";
+ case ALC_QUAD_SOFT: return "Quadraphonic";
+ case ALC_5POINT1_SOFT: return "5.1 Surround";
+ case ALC_6POINT1_SOFT: return "6.1 Surround";
+ case ALC_7POINT1_SOFT: return "7.1 Surround";
+ }
+ return "Unknown Channels";
+}
+
+static const char *TypeName(ALCenum type)
+{
+ switch(type)
+ {
+ case ALC_BYTE_SOFT: return "S8";
+ case ALC_UNSIGNED_BYTE_SOFT: return "U8";
+ case ALC_SHORT_SOFT: return "S16";
+ case ALC_UNSIGNED_SHORT_SOFT: return "U16";
+ case ALC_INT_SOFT: return "S32";
+ case ALC_UNSIGNED_INT_SOFT: return "U32";
+ case ALC_FLOAT_SOFT: return "Float32";
+ }
+ return "Unknown Type";
+}
+
/* Creates a one second buffer containing a sine wave, and returns the new
* buffer ID. */
static ALuint CreateSineWave(void)
@@ -169,7 +205,7 @@ int main(int argc, char *argv[])
attrs[6] = 0; /* end of list */
- playback.FrameSize = FramesToBytes(1, attrs[1], attrs[3]);
+ playback.FrameSize = obtained.channels * SDL_AUDIO_BITSIZE(obtained.format) / 8;
/* Initialize OpenAL loopback device, using our format attributes. */
playback.Device = alcLoopbackOpenDeviceSOFT(NULL);
@@ -216,7 +252,7 @@ int main(int argc, char *argv[])
/* Play the sound until it finishes. */
alSourcePlay(source);
do {
- Sleep(10);
+ al_nssleep(10000000);
alGetSourcei(source, AL_SOURCE_STATE, &state);
} while(alGetError() == AL_NO_ERROR && state == AL_PLAYING);
diff --git a/examples/almultireverb.c b/examples/almultireverb.c
new file mode 100644
index 00000000..a2587585
--- /dev/null
+++ b/examples/almultireverb.c
@@ -0,0 +1,696 @@
+/*
+ * OpenAL Multi-Zone Reverb Example
+ *
+ * Copyright (c) 2018 by Chris Robinson <[email protected]>
+ *
+ * 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.
+ */
+
+/* This file contains an example for controlling multiple reverb zones to
+ * smoothly transition between reverb environments. The general concept is to
+ * extend single-reverb by also tracking the closest adjacent environment, and
+ * utilize EAX Reverb's panning vectors to position them relative to the
+ * listener.
+ */
+
+#include <stdio.h>
+#include <assert.h>
+#include <math.h>
+
+#include <SDL_sound.h>
+
+#include "AL/al.h"
+#include "AL/alc.h"
+#include "AL/alext.h"
+#include "AL/efx-presets.h"
+
+#include "common/alhelpers.h"
+
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+
+/* Filter object functions */
+static LPALGENFILTERS alGenFilters;
+static LPALDELETEFILTERS alDeleteFilters;
+static LPALISFILTER alIsFilter;
+static LPALFILTERI alFilteri;
+static LPALFILTERIV alFilteriv;
+static LPALFILTERF alFilterf;
+static LPALFILTERFV alFilterfv;
+static LPALGETFILTERI alGetFilteri;
+static LPALGETFILTERIV alGetFilteriv;
+static LPALGETFILTERF alGetFilterf;
+static LPALGETFILTERFV alGetFilterfv;
+
+/* Effect object functions */
+static LPALGENEFFECTS alGenEffects;
+static LPALDELETEEFFECTS alDeleteEffects;
+static LPALISEFFECT alIsEffect;
+static LPALEFFECTI alEffecti;
+static LPALEFFECTIV alEffectiv;
+static LPALEFFECTF alEffectf;
+static LPALEFFECTFV alEffectfv;
+static LPALGETEFFECTI alGetEffecti;
+static LPALGETEFFECTIV alGetEffectiv;
+static LPALGETEFFECTF alGetEffectf;
+static LPALGETEFFECTFV alGetEffectfv;
+
+/* Auxiliary Effect Slot object functions */
+static LPALGENAUXILIARYEFFECTSLOTS alGenAuxiliaryEffectSlots;
+static LPALDELETEAUXILIARYEFFECTSLOTS alDeleteAuxiliaryEffectSlots;
+static LPALISAUXILIARYEFFECTSLOT alIsAuxiliaryEffectSlot;
+static LPALAUXILIARYEFFECTSLOTI alAuxiliaryEffectSloti;
+static LPALAUXILIARYEFFECTSLOTIV alAuxiliaryEffectSlotiv;
+static LPALAUXILIARYEFFECTSLOTF alAuxiliaryEffectSlotf;
+static LPALAUXILIARYEFFECTSLOTFV alAuxiliaryEffectSlotfv;
+static LPALGETAUXILIARYEFFECTSLOTI alGetAuxiliaryEffectSloti;
+static LPALGETAUXILIARYEFFECTSLOTIV alGetAuxiliaryEffectSlotiv;
+static LPALGETAUXILIARYEFFECTSLOTF alGetAuxiliaryEffectSlotf;
+static LPALGETAUXILIARYEFFECTSLOTFV alGetAuxiliaryEffectSlotfv;
+
+
+/* LoadEffect loads the given initial reverb properties into the given OpenAL
+ * effect object, and returns non-zero on success.
+ */
+static int LoadEffect(ALuint effect, const EFXEAXREVERBPROPERTIES *reverb)
+{
+ ALenum err;
+
+ alGetError();
+
+ /* Prepare the effect for EAX Reverb (standard reverb doesn't contain
+ * the needed panning vectors).
+ */
+ alEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_EAXREVERB);
+ if((err=alGetError()) != AL_NO_ERROR)
+ {
+ fprintf(stderr, "Failed to set EAX Reverb: %s (0x%04x)\n", alGetString(err), err);
+ return 0;
+ }
+
+ /* Load the reverb properties. */
+ alEffectf(effect, AL_EAXREVERB_DENSITY, reverb->flDensity);
+ alEffectf(effect, AL_EAXREVERB_DIFFUSION, reverb->flDiffusion);
+ alEffectf(effect, AL_EAXREVERB_GAIN, reverb->flGain);
+ alEffectf(effect, AL_EAXREVERB_GAINHF, reverb->flGainHF);
+ alEffectf(effect, AL_EAXREVERB_GAINLF, reverb->flGainLF);
+ alEffectf(effect, AL_EAXREVERB_DECAY_TIME, reverb->flDecayTime);
+ alEffectf(effect, AL_EAXREVERB_DECAY_HFRATIO, reverb->flDecayHFRatio);
+ alEffectf(effect, AL_EAXREVERB_DECAY_LFRATIO, reverb->flDecayLFRatio);
+ alEffectf(effect, AL_EAXREVERB_REFLECTIONS_GAIN, reverb->flReflectionsGain);
+ alEffectf(effect, AL_EAXREVERB_REFLECTIONS_DELAY, reverb->flReflectionsDelay);
+ alEffectfv(effect, AL_EAXREVERB_REFLECTIONS_PAN, reverb->flReflectionsPan);
+ alEffectf(effect, AL_EAXREVERB_LATE_REVERB_GAIN, reverb->flLateReverbGain);
+ alEffectf(effect, AL_EAXREVERB_LATE_REVERB_DELAY, reverb->flLateReverbDelay);
+ alEffectfv(effect, AL_EAXREVERB_LATE_REVERB_PAN, reverb->flLateReverbPan);
+ alEffectf(effect, AL_EAXREVERB_ECHO_TIME, reverb->flEchoTime);
+ alEffectf(effect, AL_EAXREVERB_ECHO_DEPTH, reverb->flEchoDepth);
+ alEffectf(effect, AL_EAXREVERB_MODULATION_TIME, reverb->flModulationTime);
+ alEffectf(effect, AL_EAXREVERB_MODULATION_DEPTH, reverb->flModulationDepth);
+ alEffectf(effect, AL_EAXREVERB_AIR_ABSORPTION_GAINHF, reverb->flAirAbsorptionGainHF);
+ alEffectf(effect, AL_EAXREVERB_HFREFERENCE, reverb->flHFReference);
+ alEffectf(effect, AL_EAXREVERB_LFREFERENCE, reverb->flLFReference);
+ alEffectf(effect, AL_EAXREVERB_ROOM_ROLLOFF_FACTOR, reverb->flRoomRolloffFactor);
+ alEffecti(effect, AL_EAXREVERB_DECAY_HFLIMIT, reverb->iDecayHFLimit);
+
+ /* Check if an error occured, and return failure if so. */
+ if((err=alGetError()) != AL_NO_ERROR)
+ {
+ fprintf(stderr, "Error setting up reverb: %s\n", alGetString(err));
+ return 0;
+ }
+
+ return 1;
+}
+
+
+/* LoadBuffer loads the named audio file into an OpenAL buffer object, and
+ * returns the new buffer ID.
+ */
+static ALuint LoadSound(const char *filename)
+{
+ Sound_Sample *sample;
+ ALenum err, format;
+ ALuint buffer;
+ Uint32 slen;
+
+ /* Open the audio file */
+ sample = Sound_NewSampleFromFile(filename, NULL, 65536);
+ if(!sample)
+ {
+ fprintf(stderr, "Could not open audio in %s\n", filename);
+ return 0;
+ }
+
+ /* Get the sound format, and figure out the OpenAL format */
+ if(sample->actual.channels == 1)
+ {
+ if(sample->actual.format == AUDIO_U8)
+ format = AL_FORMAT_MONO8;
+ else if(sample->actual.format == AUDIO_S16SYS)
+ format = AL_FORMAT_MONO16;
+ else
+ {
+ fprintf(stderr, "Unsupported sample format: 0x%04x\n", sample->actual.format);
+ Sound_FreeSample(sample);
+ return 0;
+ }
+ }
+ else if(sample->actual.channels == 2)
+ {
+ if(sample->actual.format == AUDIO_U8)
+ format = AL_FORMAT_STEREO8;
+ else if(sample->actual.format == AUDIO_S16SYS)
+ format = AL_FORMAT_STEREO16;
+ else
+ {
+ fprintf(stderr, "Unsupported sample format: 0x%04x\n", sample->actual.format);
+ Sound_FreeSample(sample);
+ return 0;
+ }
+ }
+ else
+ {
+ fprintf(stderr, "Unsupported channel count: %d\n", sample->actual.channels);
+ Sound_FreeSample(sample);
+ return 0;
+ }
+
+ /* Decode the whole audio stream to a buffer. */
+ slen = Sound_DecodeAll(sample);
+ if(!sample->buffer || slen == 0)
+ {
+ fprintf(stderr, "Failed to read audio from %s\n", filename);
+ Sound_FreeSample(sample);
+ return 0;
+ }
+
+ /* Buffer the audio data into a new buffer object, then free the data and
+ * close the file. */
+ buffer = 0;
+ alGenBuffers(1, &buffer);
+ alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate);
+ Sound_FreeSample(sample);
+
+ /* Check if an error occured, and clean up if so. */
+ err = alGetError();
+ if(err != AL_NO_ERROR)
+ {
+ fprintf(stderr, "OpenAL Error: %s\n", alGetString(err));
+ if(buffer && alIsBuffer(buffer))
+ alDeleteBuffers(1, &buffer);
+ return 0;
+ }
+
+ return buffer;
+}
+
+
+/* Helper to calculate the dot-product of the two given vectors. */
+static ALfloat dot_product(const ALfloat vec0[3], const ALfloat vec1[3])
+{
+ return vec0[0]*vec1[0] + vec0[1]*vec1[1] + vec0[2]*vec1[2];
+}
+
+/* Helper to normalize a given vector. */
+static void normalize(ALfloat vec[3])
+{
+ ALfloat mag = sqrtf(dot_product(vec, vec));
+ if(mag > 0.00001f)
+ {
+ vec[0] /= mag;
+ vec[1] /= mag;
+ vec[2] /= mag;
+ }
+ else
+ {
+ vec[0] = 0.0f;
+ vec[1] = 0.0f;
+ vec[2] = 0.0f;
+ }
+}
+
+
+/* The main update function to update the listener and environment effects. */
+static void UpdateListenerAndEffects(float timediff, const ALuint slots[2], const ALuint effects[2], const EFXEAXREVERBPROPERTIES reverbs[2])
+{
+ static const ALfloat listener_move_scale = 10.0f;
+ /* Individual reverb zones are connected via "portals". Each portal has a
+ * position (center point of the connecting area), a normal (facing
+ * direction), and a radius (approximate size of the connecting area).
+ */
+ const ALfloat portal_pos[3] = { 0.0f, 0.0f, 0.0f };
+ const ALfloat portal_norm[3] = { sqrtf(0.5f), 0.0f, -sqrtf(0.5f) };
+ const ALfloat portal_radius = 2.5f;
+ ALfloat other_dir[3], this_dir[3];
+ ALfloat listener_pos[3];
+ ALfloat local_norm[3];
+ ALfloat local_dir[3];
+ ALfloat near_edge[3];
+ ALfloat far_edge[3];
+ ALfloat dist, edist;
+
+ /* Update the listener position for the amount of time passed. This uses a
+ * simple triangular LFO to offset the position (moves along the X axis
+ * between -listener_move_scale and +listener_move_scale for each
+ * transition).
+ */
+ listener_pos[0] = (fabsf(2.0f - timediff/2.0f) - 1.0f) * listener_move_scale;
+ listener_pos[1] = 0.0f;
+ listener_pos[2] = 0.0f;
+ alListenerfv(AL_POSITION, listener_pos);
+
+ /* Calculate local_dir, which represents the listener-relative point to the
+ * adjacent zone (should also include orientation). Because EAX Reverb uses
+ * left-handed coordinates instead of right-handed like the rest of OpenAL,
+ * negate Z for the local values.
+ */
+ local_dir[0] = portal_pos[0] - listener_pos[0];
+ local_dir[1] = portal_pos[1] - listener_pos[1];
+ local_dir[2] = -(portal_pos[2] - listener_pos[2]);
+ /* A normal application would also rotate the portal's normal given the
+ * listener orientation, to get the listener-relative normal.
+ */
+ local_norm[0] = portal_norm[0];
+ local_norm[1] = portal_norm[1];
+ local_norm[2] = -portal_norm[2];
+
+ /* Calculate the distance from the listener to the portal, and ensure it's
+ * far enough away to not suffer severe floating-point precision issues.
+ */
+ dist = sqrtf(dot_product(local_dir, local_dir));
+ if(dist > 0.00001f)
+ {
+ const EFXEAXREVERBPROPERTIES *other_reverb, *this_reverb;
+ ALuint other_effect, this_effect;
+ ALfloat magnitude, dir_dot_norm;
+
+ /* Normalize the direction to the portal. */
+ local_dir[0] /= dist;
+ local_dir[1] /= dist;
+ local_dir[2] /= dist;
+
+ /* Calculate the dot product of the portal's local direction and local
+ * normal, which is used for angular and side checks later on.
+ */
+ dir_dot_norm = dot_product(local_dir, local_norm);
+
+ /* Figure out which zone we're in. */
+ if(dir_dot_norm <= 0.0f)
+ {
+ /* We're in front of the portal, so we're in Zone 0. */
+ this_effect = effects[0];
+ other_effect = effects[1];
+ this_reverb = &reverbs[0];
+ other_reverb = &reverbs[1];
+ }
+ else
+ {
+ /* We're behind the portal, so we're in Zone 1. */
+ this_effect = effects[1];
+ other_effect = effects[0];
+ this_reverb = &reverbs[1];
+ other_reverb = &reverbs[0];
+ }
+
+ /* Calculate the listener-relative extents of the portal. */
+ /* First, project the listener-to-portal vector onto the portal's plane
+ * to get the portal-relative direction along the plane that goes away
+ * from the listener (toward the farthest edge of the portal).
+ */
+ far_edge[0] = local_dir[0] - local_norm[0]*dir_dot_norm;
+ far_edge[1] = local_dir[1] - local_norm[1]*dir_dot_norm;
+ far_edge[2] = local_dir[2] - local_norm[2]*dir_dot_norm;
+
+ edist = sqrtf(dot_product(far_edge, far_edge));
+ if(edist > 0.0001f)
+ {
+ /* Rescale the portal-relative vector to be at the radius edge. */
+ ALfloat mag = portal_radius / edist;
+ far_edge[0] *= mag;
+ far_edge[1] *= mag;
+ far_edge[2] *= mag;
+
+ /* Calculate the closest edge of the portal by negating the
+ * farthest, and add an offset to make them both relative to the
+ * listener.
+ */
+ near_edge[0] = local_dir[0]*dist - far_edge[0];
+ near_edge[1] = local_dir[1]*dist - far_edge[1];
+ near_edge[2] = local_dir[2]*dist - far_edge[2];
+ far_edge[0] += local_dir[0]*dist;
+ far_edge[1] += local_dir[1]*dist;
+ far_edge[2] += local_dir[2]*dist;
+
+ /* Normalize the listener-relative extents of the portal, then
+ * calculate the panning magnitude for the other zone given the
+ * apparent size of the opening. The panning magnitude affects the
+ * envelopment of the environment, with 1 being a point, 0.5 being
+ * half coverage around the listener, and 0 being full coverage.
+ */
+ normalize(far_edge);
+ normalize(near_edge);
+ magnitude = 1.0f - acosf(dot_product(far_edge, near_edge))/(float)(M_PI*2.0);
+
+ /* Recalculate the panning direction, to be directly between the
+ * direction of the two extents.
+ */
+ local_dir[0] = far_edge[0] + near_edge[0];
+ local_dir[1] = far_edge[1] + near_edge[1];
+ local_dir[2] = far_edge[2] + near_edge[2];
+ normalize(local_dir);
+ }
+ else
+ {
+ /* If we get here, the listener is directly in front of or behind
+ * the center of the portal, making all aperture edges effectively
+ * equidistant. Calculating the panning magnitude is simplified,
+ * using the arctangent of the radius and distance.
+ */
+ magnitude = 1.0f - (atan2f(portal_radius, dist) / (float)M_PI);
+ }
+
+ /* Scale the other zone's panning vector. */
+ other_dir[0] = local_dir[0] * magnitude;
+ other_dir[1] = local_dir[1] * magnitude;
+ other_dir[2] = local_dir[2] * magnitude;
+ /* Pan the current zone to the opposite direction of the portal, and
+ * take the remaining percentage of the portal's magnitude.
+ */
+ this_dir[0] = local_dir[0] * (magnitude-1.0f);
+ this_dir[1] = local_dir[1] * (magnitude-1.0f);
+ this_dir[2] = local_dir[2] * (magnitude-1.0f);
+
+ /* Now set the effects' panning vectors and gain. Energy is shared
+ * between environments, so attenuate according to each zone's
+ * contribution (note: gain^2 = energy).
+ */
+ alEffectf(this_effect, AL_EAXREVERB_REFLECTIONS_GAIN, this_reverb->flReflectionsGain * sqrtf(magnitude));
+ alEffectf(this_effect, AL_EAXREVERB_LATE_REVERB_GAIN, this_reverb->flLateReverbGain * sqrtf(magnitude));
+ alEffectfv(this_effect, AL_EAXREVERB_REFLECTIONS_PAN, this_dir);
+ alEffectfv(this_effect, AL_EAXREVERB_LATE_REVERB_PAN, this_dir);
+
+ alEffectf(other_effect, AL_EAXREVERB_REFLECTIONS_GAIN, other_reverb->flReflectionsGain * sqrtf(1.0f-magnitude));
+ alEffectf(other_effect, AL_EAXREVERB_LATE_REVERB_GAIN, other_reverb->flLateReverbGain * sqrtf(1.0f-magnitude));
+ alEffectfv(other_effect, AL_EAXREVERB_REFLECTIONS_PAN, other_dir);
+ alEffectfv(other_effect, AL_EAXREVERB_LATE_REVERB_PAN, other_dir);
+ }
+ else
+ {
+ /* We're practically in the center of the portal. Give the panning
+ * vectors a 50/50 split, with Zone 0 covering the half in front of
+ * the normal, and Zone 1 covering the half behind.
+ */
+ this_dir[0] = local_norm[0] / 2.0f;
+ this_dir[1] = local_norm[1] / 2.0f;
+ this_dir[2] = local_norm[2] / 2.0f;
+
+ other_dir[0] = local_norm[0] / -2.0f;
+ other_dir[1] = local_norm[1] / -2.0f;
+ other_dir[2] = local_norm[2] / -2.0f;
+
+ alEffectf(effects[0], AL_EAXREVERB_REFLECTIONS_GAIN, reverbs[0].flReflectionsGain * sqrtf(0.5f));
+ alEffectf(effects[0], AL_EAXREVERB_LATE_REVERB_GAIN, reverbs[0].flLateReverbGain * sqrtf(0.5f));
+ alEffectfv(effects[0], AL_EAXREVERB_REFLECTIONS_PAN, this_dir);
+ alEffectfv(effects[0], AL_EAXREVERB_LATE_REVERB_PAN, this_dir);
+
+ alEffectf(effects[1], AL_EAXREVERB_REFLECTIONS_GAIN, reverbs[1].flReflectionsGain * sqrtf(0.5f));
+ alEffectf(effects[1], AL_EAXREVERB_LATE_REVERB_GAIN, reverbs[1].flLateReverbGain * sqrtf(0.5f));
+ alEffectfv(effects[1], AL_EAXREVERB_REFLECTIONS_PAN, other_dir);
+ alEffectfv(effects[1], AL_EAXREVERB_LATE_REVERB_PAN, other_dir);
+ }
+
+ /* Finally, update the effect slots with the updated effect parameters. */
+ alAuxiliaryEffectSloti(slots[0], AL_EFFECTSLOT_EFFECT, effects[0]);
+ alAuxiliaryEffectSloti(slots[1], AL_EFFECTSLOT_EFFECT, effects[1]);
+}
+
+
+int main(int argc, char **argv)
+{
+ static const int MaxTransitions = 8;
+ EFXEAXREVERBPROPERTIES reverbs[2] = {
+ EFX_REVERB_PRESET_CARPETEDHALLWAY,
+ EFX_REVERB_PRESET_BATHROOM
+ };
+ struct timespec basetime;
+ ALCdevice *device = NULL;
+ ALCcontext *context = NULL;
+ ALuint effects[2] = { 0, 0 };
+ ALuint slots[2] = { 0, 0 };
+ ALuint direct_filter = 0;
+ ALuint buffer = 0;
+ ALuint source = 0;
+ ALCint num_sends = 0;
+ ALenum state = AL_INITIAL;
+ ALfloat direct_gain = 1.0f;
+ int loops = 0;
+
+ /* Print out usage if no arguments were specified */
+ if(argc < 2)
+ {
+ fprintf(stderr, "Usage: %s [-device <name>] [options] <filename>\n\n"
+ "Options:\n"
+ "\t-nodirect\tSilence direct path output (easier to hear reverb)\n\n",
+ argv[0]);
+ return 1;
+ }
+
+ /* Initialize OpenAL, and check for EFX support with at least 2 auxiliary
+ * sends (if multiple sends are supported, 2 are provided by default; if
+ * you want more, you have to request it through alcCreateContext).
+ */
+ argv++; argc--;
+ if(InitAL(&argv, &argc) != 0)
+ return 1;
+
+ while(argc > 0)
+ {
+ if(strcmp(argv[0], "-nodirect") == 0)
+ direct_gain = 0.0f;
+ else
+ break;
+ argv++;
+ argc--;
+ }
+ if(argc < 1)
+ {
+ fprintf(stderr, "No filename spacified.\n");
+ CloseAL();
+ return 1;
+ }
+
+ context = alcGetCurrentContext();
+ device = alcGetContextsDevice(context);
+
+ if(!alcIsExtensionPresent(device, "ALC_EXT_EFX"))
+ {
+ fprintf(stderr, "Error: EFX not supported\n");
+ CloseAL();
+ return 1;
+ }
+
+ num_sends = 0;
+ alcGetIntegerv(device, ALC_MAX_AUXILIARY_SENDS, 1, &num_sends);
+ if(alcGetError(device) != ALC_NO_ERROR || num_sends < 2)
+ {
+ fprintf(stderr, "Error: Device does not support multiple sends (got %d, need 2)\n",
+ num_sends);
+ CloseAL();
+ return 1;
+ }
+
+ /* Define a macro to help load the function pointers. */
+#define LOAD_PROC(x) ((x) = alGetProcAddress(#x))
+ LOAD_PROC(alGenFilters);
+ LOAD_PROC(alDeleteFilters);
+ LOAD_PROC(alIsFilter);
+ LOAD_PROC(alFilteri);
+ LOAD_PROC(alFilteriv);
+ LOAD_PROC(alFilterf);
+ LOAD_PROC(alFilterfv);
+ LOAD_PROC(alGetFilteri);
+ LOAD_PROC(alGetFilteriv);
+ LOAD_PROC(alGetFilterf);
+ LOAD_PROC(alGetFilterfv);
+
+ LOAD_PROC(alGenEffects);
+ LOAD_PROC(alDeleteEffects);
+ LOAD_PROC(alIsEffect);
+ LOAD_PROC(alEffecti);
+ LOAD_PROC(alEffectiv);
+ LOAD_PROC(alEffectf);
+ LOAD_PROC(alEffectfv);
+ LOAD_PROC(alGetEffecti);
+ LOAD_PROC(alGetEffectiv);
+ LOAD_PROC(alGetEffectf);
+ LOAD_PROC(alGetEffectfv);
+
+ LOAD_PROC(alGenAuxiliaryEffectSlots);
+ LOAD_PROC(alDeleteAuxiliaryEffectSlots);
+ LOAD_PROC(alIsAuxiliaryEffectSlot);
+ LOAD_PROC(alAuxiliaryEffectSloti);
+ LOAD_PROC(alAuxiliaryEffectSlotiv);
+ LOAD_PROC(alAuxiliaryEffectSlotf);
+ LOAD_PROC(alAuxiliaryEffectSlotfv);
+ LOAD_PROC(alGetAuxiliaryEffectSloti);
+ LOAD_PROC(alGetAuxiliaryEffectSlotiv);
+ LOAD_PROC(alGetAuxiliaryEffectSlotf);
+ LOAD_PROC(alGetAuxiliaryEffectSlotfv);
+#undef LOAD_PROC
+
+ /* Initialize SDL_sound. */
+ Sound_Init();
+
+ /* Load the sound into a buffer. */
+ buffer = LoadSound(argv[0]);
+ if(!buffer)
+ {
+ CloseAL();
+ Sound_Quit();
+ return 1;
+ }
+
+ /* Generate two effects for two "zones", and load a reverb into each one.
+ * Note that unlike single-zone reverb, where you can store one effect per
+ * preset, for multi-zone reverb you should have one effect per environment
+ * instance, or one per audible zone. This is because we'll be changing the
+ * effects' properties in real-time based on the environment instance
+ * relative to the listener.
+ */
+ alGenEffects(2, effects);
+ if(!LoadEffect(effects[0], &reverbs[0]) || !LoadEffect(effects[1], &reverbs[1]))
+ {
+ alDeleteEffects(2, effects);
+ alDeleteBuffers(1, &buffer);
+ Sound_Quit();
+ CloseAL();
+ return 1;
+ }
+
+ /* Create the effect slot objects, one for each "active" effect. */
+ alGenAuxiliaryEffectSlots(2, slots);
+
+ /* Tell the effect slots to use the loaded effect objects, with slot 0 for
+ * Zone 0 and slot 1 for Zone 1. Note that this effectively copies the
+ * effect properties. Modifying or deleting the effect object afterward
+ * won't directly affect the effect slot until they're reapplied like this.
+ */
+ alAuxiliaryEffectSloti(slots[0], AL_EFFECTSLOT_EFFECT, effects[0]);
+ alAuxiliaryEffectSloti(slots[1], AL_EFFECTSLOT_EFFECT, effects[1]);
+ assert(alGetError()==AL_NO_ERROR && "Failed to set effect slot");
+
+ /* For the purposes of this example, prepare a filter that optionally
+ * silences the direct path which allows us to hear just the reverberation.
+ * A filter like this is normally used for obstruction, where the path
+ * directly between the listener and source is blocked (the exact
+ * properties depending on the type and thickness of the obstructing
+ * material).
+ */
+ alGenFilters(1, &direct_filter);
+ alFilteri(direct_filter, AL_FILTER_TYPE, AL_FILTER_LOWPASS);
+ alFilterf(direct_filter, AL_LOWPASS_GAIN, direct_gain);
+ assert(alGetError()==AL_NO_ERROR && "Failed to set direct filter");
+
+ /* Create the source to play the sound with, place it in front of the
+ * listener's path in the left zone.
+ */
+ source = 0;
+ alGenSources(1, &source);
+ alSourcei(source, AL_LOOPING, AL_TRUE);
+ alSource3f(source, AL_POSITION, -5.0f, 0.0f, -2.0f);
+ alSourcei(source, AL_DIRECT_FILTER, direct_filter);
+ alSourcei(source, AL_BUFFER, buffer);
+
+ /* Connect the source to the effect slots. Here, we connect source send 0
+ * to Zone 0's slot, and send 1 to Zone 1's slot. Filters can be specified
+ * to occlude the source from each zone by varying amounts; for example, a
+ * source within a particular zone would be unfiltered, while a source that
+ * can only see a zone through a window or thin wall may be attenuated for
+ * that zone.
+ */
+ alSource3i(source, AL_AUXILIARY_SEND_FILTER, slots[0], 0, AL_FILTER_NULL);
+ alSource3i(source, AL_AUXILIARY_SEND_FILTER, slots[1], 1, AL_FILTER_NULL);
+ assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source");
+
+ /* Get the current time as the base for timing in the main loop. */
+ altimespec_get(&basetime, AL_TIME_UTC);
+ loops = 0;
+ printf("Transition %d of %d...\n", loops+1, MaxTransitions);
+
+ /* Play the sound for a while. */
+ alSourcePlay(source);
+ do {
+ struct timespec curtime;
+ ALfloat timediff;
+
+ /* Start a batch update, to ensure all changes apply simultaneously. */
+ alcSuspendContext(context);
+
+ /* Get the current time to track the amount of time that passed.
+ * Convert the difference to seconds.
+ */
+ altimespec_get(&curtime, AL_TIME_UTC);
+ timediff = (ALfloat)(curtime.tv_sec - basetime.tv_sec);
+ timediff += (ALfloat)(curtime.tv_nsec - basetime.tv_nsec) / 1000000000.0f;
+
+ /* Avoid negative time deltas, in case of non-monotonic clocks. */
+ if(timediff < 0.0f)
+ timediff = 0.0f;
+ else while(timediff >= 4.0f*((loops&1)+1))
+ {
+ /* For this example, each transition occurs over 4 seconds, and
+ * there's 2 transitions per cycle.
+ */
+ if(++loops < MaxTransitions)
+ printf("Transition %d of %d...\n", loops+1, MaxTransitions);
+ if(!(loops&1))
+ {
+ /* Cycle completed. Decrease the delta and increase the base
+ * time to start a new cycle.
+ */
+ timediff -= 8.0f;
+ basetime.tv_sec += 8;
+ }
+ }
+
+ /* Update the listener and effects, and finish the batch. */
+ UpdateListenerAndEffects(timediff, slots, effects, reverbs);
+ alcProcessContext(context);
+
+ al_nssleep(10000000);
+
+ alGetSourcei(source, AL_SOURCE_STATE, &state);
+ } while(alGetError() == AL_NO_ERROR && state == AL_PLAYING && loops < MaxTransitions);
+
+ /* All done. Delete resources, and close down SDL_sound and OpenAL. */
+ alDeleteSources(1, &source);
+ alDeleteAuxiliaryEffectSlots(2, slots);
+ alDeleteEffects(2, effects);
+ alDeleteFilters(1, &direct_filter);
+ alDeleteBuffers(1, &buffer);
+
+ Sound_Quit();
+ CloseAL();
+
+ return 0;
+}
diff --git a/examples/alplay.c b/examples/alplay.c
new file mode 100644
index 00000000..81cb56d5
--- /dev/null
+++ b/examples/alplay.c
@@ -0,0 +1,177 @@
+/*
+ * OpenAL Source Play Example
+ *
+ * Copyright (c) 2017 by Chris Robinson <[email protected]>
+ *
+ * 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.
+ */
+
+/* This file contains an example for playing a sound buffer. */
+
+#include <stdio.h>
+#include <assert.h>
+
+#include <SDL_sound.h>
+
+#include "AL/al.h"
+#include "AL/alc.h"
+
+#include "common/alhelpers.h"
+
+
+/* LoadBuffer loads the named audio file into an OpenAL buffer object, and
+ * returns the new buffer ID.
+ */
+static ALuint LoadSound(const char *filename)
+{
+ Sound_Sample *sample;
+ ALenum err, format;
+ ALuint buffer;
+ Uint32 slen;
+
+ /* Open the audio file */
+ sample = Sound_NewSampleFromFile(filename, NULL, 65536);
+ if(!sample)
+ {
+ fprintf(stderr, "Could not open audio in %s\n", filename);
+ return 0;
+ }
+
+ /* Get the sound format, and figure out the OpenAL format */
+ if(sample->actual.channels == 1)
+ {
+ if(sample->actual.format == AUDIO_U8)
+ format = AL_FORMAT_MONO8;
+ else if(sample->actual.format == AUDIO_S16SYS)
+ format = AL_FORMAT_MONO16;
+ else
+ {
+ fprintf(stderr, "Unsupported sample format: 0x%04x\n", sample->actual.format);
+ Sound_FreeSample(sample);
+ return 0;
+ }
+ }
+ else if(sample->actual.channels == 2)
+ {
+ if(sample->actual.format == AUDIO_U8)
+ format = AL_FORMAT_STEREO8;
+ else if(sample->actual.format == AUDIO_S16SYS)
+ format = AL_FORMAT_STEREO16;
+ else
+ {
+ fprintf(stderr, "Unsupported sample format: 0x%04x\n", sample->actual.format);
+ Sound_FreeSample(sample);
+ return 0;
+ }
+ }
+ else
+ {
+ fprintf(stderr, "Unsupported channel count: %d\n", sample->actual.channels);
+ Sound_FreeSample(sample);
+ return 0;
+ }
+
+ /* Decode the whole audio stream to a buffer. */
+ slen = Sound_DecodeAll(sample);
+ if(!sample->buffer || slen == 0)
+ {
+ fprintf(stderr, "Failed to read audio from %s\n", filename);
+ Sound_FreeSample(sample);
+ return 0;
+ }
+
+ /* Buffer the audio data into a new buffer object, then free the data and
+ * close the file. */
+ buffer = 0;
+ alGenBuffers(1, &buffer);
+ alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate);
+ Sound_FreeSample(sample);
+
+ /* Check if an error occured, and clean up if so. */
+ err = alGetError();
+ if(err != AL_NO_ERROR)
+ {
+ fprintf(stderr, "OpenAL Error: %s\n", alGetString(err));
+ if(buffer && alIsBuffer(buffer))
+ alDeleteBuffers(1, &buffer);
+ return 0;
+ }
+
+ return buffer;
+}
+
+
+int main(int argc, char **argv)
+{
+ ALuint source, buffer;
+ ALfloat offset;
+ ALenum state;
+
+ /* Print out usage if no arguments were specified */
+ if(argc < 2)
+ {
+ fprintf(stderr, "Usage: %s [-device <name>] <filename>\n", argv[0]);
+ return 1;
+ }
+
+ /* Initialize OpenAL. */
+ argv++; argc--;
+ if(InitAL(&argv, &argc) != 0)
+ return 1;
+
+ /* Initialize SDL_sound. */
+ Sound_Init();
+
+ /* Load the sound into a buffer. */
+ buffer = LoadSound(argv[0]);
+ if(!buffer)
+ {
+ Sound_Quit();
+ CloseAL();
+ return 1;
+ }
+
+ /* Create the source to play the sound with. */
+ source = 0;
+ alGenSources(1, &source);
+ alSourcei(source, AL_BUFFER, buffer);
+ assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source");
+
+ /* Play the sound until it finishes. */
+ alSourcePlay(source);
+ do {
+ al_nssleep(10000000);
+ alGetSourcei(source, AL_SOURCE_STATE, &state);
+
+ /* Get the source offset. */
+ alGetSourcef(source, AL_SEC_OFFSET, &offset);
+ printf("\rOffset: %f ", offset);
+ fflush(stdout);
+ } while(alGetError() == AL_NO_ERROR && state == AL_PLAYING);
+ printf("\n");
+
+ /* All done. Delete resources, and close down SDL_sound and OpenAL. */
+ alDeleteSources(1, &source);
+ alDeleteBuffers(1, &buffer);
+
+ Sound_Quit();
+ CloseAL();
+
+ return 0;
+}
diff --git a/examples/alrecord.c b/examples/alrecord.c
new file mode 100644
index 00000000..43b26d35
--- /dev/null
+++ b/examples/alrecord.c
@@ -0,0 +1,394 @@
+/*
+ * OpenAL Recording Example
+ *
+ * Copyright (c) 2017 by Chris Robinson <[email protected]>
+ *
+ * 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.
+ */
+
+/* This file contains a relatively simple recorder. */
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+
+#include "AL/al.h"
+#include "AL/alc.h"
+#include "AL/alext.h"
+
+#include "common/alhelpers.h"
+
+
+#if defined(_WIN64)
+#define SZFMT "%I64u"
+#elif defined(_WIN32)
+#define SZFMT "%u"
+#else
+#define SZFMT "%zu"
+#endif
+
+
+#if defined(_MSC_VER) && (_MSC_VER < 1900)
+static float msvc_strtof(const char *str, char **end)
+{ return (float)strtod(str, end); }
+#define strtof msvc_strtof
+#endif
+
+
+static void fwrite16le(ALushort val, FILE *f)
+{
+ ALubyte data[2] = { val&0xff, (val>>8)&0xff };
+ fwrite(data, 1, 2, f);
+}
+
+static void fwrite32le(ALuint val, FILE *f)
+{
+ ALubyte data[4] = { val&0xff, (val>>8)&0xff, (val>>16)&0xff, (val>>24)&0xff };
+ fwrite(data, 1, 4, f);
+}
+
+
+typedef struct Recorder {
+ ALCdevice *mDevice;
+
+ FILE *mFile;
+ long mDataSizeOffset;
+ ALuint mDataSize;
+ float mRecTime;
+
+ int mChannels;
+ int mBits;
+ int mSampleRate;
+ ALuint mFrameSize;
+ ALbyte *mBuffer;
+ ALsizei mBufferSize;
+} Recorder;
+
+int main(int argc, char **argv)
+{
+ static const char optlist[] =
+" --channels/-c <channels> Set channel count (1 or 2)\n"
+" --bits/-b <bits> Set channel count (8, 16, or 32)\n"
+" --rate/-r <rate> Set sample rate (8000 to 96000)\n"
+" --time/-t <time> Time in seconds to record (1 to 10)\n"
+" --outfile/-o <filename> Output filename (default: record.wav)";
+ const char *fname = "record.wav";
+ const char *devname = NULL;
+ const char *progname;
+ Recorder recorder;
+ long total_size;
+ ALenum format;
+ ALCenum err;
+
+ progname = argv[0];
+ if(argc < 2)
+ {
+ fprintf(stderr, "Record from a device to a wav file.\n\n"
+ "Usage: %s [-device <name>] [options...]\n\n"
+ "Available options:\n%s\n", progname, optlist);
+ return 0;
+ }
+
+ recorder.mDevice = NULL;
+ recorder.mFile = NULL;
+ recorder.mDataSizeOffset = 0;
+ recorder.mDataSize = 0;
+ recorder.mRecTime = 4.0f;
+ recorder.mChannels = 1;
+ recorder.mBits = 16;
+ recorder.mSampleRate = 44100;
+ recorder.mFrameSize = recorder.mChannels * recorder.mBits / 8;
+ recorder.mBuffer = NULL;
+ recorder.mBufferSize = 0;
+
+ argv++; argc--;
+ if(argc > 1 && strcmp(argv[0], "-device") == 0)
+ {
+ devname = argv[1];
+ argv += 2;
+ argc -= 2;
+ }
+
+ while(argc > 0)
+ {
+ char *end;
+ if(strcmp(argv[0], "--") == 0)
+ break;
+ else if(strcmp(argv[0], "--channels") == 0 || strcmp(argv[0], "-c") == 0)
+ {
+ if(!(argc > 1))
+ {
+ fprintf(stderr, "Missing argument for option: %s\n", argv[0]);
+ return 1;
+ }
+
+ recorder.mChannels = strtol(argv[1], &end, 0);
+ if((recorder.mChannels != 1 && recorder.mChannels != 2) || (end && *end != '\0'))
+ {
+ fprintf(stderr, "Invalid channels: %s\n", argv[1]);
+ return 1;
+ }
+ argv += 2;
+ argc -= 2;
+ }
+ else if(strcmp(argv[0], "--bits") == 0 || strcmp(argv[0], "-b") == 0)
+ {
+ if(!(argc > 1))
+ {
+ fprintf(stderr, "Missing argument for option: %s\n", argv[0]);
+ return 1;
+ }
+
+ recorder.mBits = strtol(argv[1], &end, 0);
+ if((recorder.mBits != 8 && recorder.mBits != 16 && recorder.mBits != 32) ||
+ (end && *end != '\0'))
+ {
+ fprintf(stderr, "Invalid bit count: %s\n", argv[1]);
+ return 1;
+ }
+ argv += 2;
+ argc -= 2;
+ }
+ else if(strcmp(argv[0], "--rate") == 0 || strcmp(argv[0], "-r") == 0)
+ {
+ if(!(argc > 1))
+ {
+ fprintf(stderr, "Missing argument for option: %s\n", argv[0]);
+ return 1;
+ }
+
+ recorder.mSampleRate = strtol(argv[1], &end, 0);
+ if(!(recorder.mSampleRate >= 8000 && recorder.mSampleRate <= 96000) || (end && *end != '\0'))
+ {
+ fprintf(stderr, "Invalid sample rate: %s\n", argv[1]);
+ return 1;
+ }
+ argv += 2;
+ argc -= 2;
+ }
+ else if(strcmp(argv[0], "--time") == 0 || strcmp(argv[0], "-t") == 0)
+ {
+ if(!(argc > 1))
+ {
+ fprintf(stderr, "Missing argument for option: %s\n", argv[0]);
+ return 1;
+ }
+
+ recorder.mRecTime = strtof(argv[1], &end);
+ if(!(recorder.mRecTime >= 1.0f && recorder.mRecTime <= 10.0f) || (end && *end != '\0'))
+ {
+ fprintf(stderr, "Invalid record time: %s\n", argv[1]);
+ return 1;
+ }
+ argv += 2;
+ argc -= 2;
+ }
+ else if(strcmp(argv[0], "--outfile") == 0 || strcmp(argv[0], "-o") == 0)
+ {
+ if(!(argc > 1))
+ {
+ fprintf(stderr, "Missing argument for option: %s\n", argv[0]);
+ return 1;
+ }
+
+ fname = argv[1];
+ argv += 2;
+ argc -= 2;
+ }
+ else if(strcmp(argv[0], "--help") == 0 || strcmp(argv[0], "-h") == 0)
+ {
+ fprintf(stderr, "Record from a device to a wav file.\n\n"
+ "Usage: %s [-device <name>] [options...]\n\n"
+ "Available options:\n%s\n", progname, optlist);
+ return 0;
+ }
+ else
+ {
+ fprintf(stderr, "Invalid option '%s'.\n\n"
+ "Usage: %s [-device <name>] [options...]\n\n"
+ "Available options:\n%s\n", argv[0], progname, optlist);
+ return 0;
+ }
+ }
+
+ recorder.mFrameSize = recorder.mChannels * recorder.mBits / 8;
+
+ format = AL_NONE;
+ if(recorder.mChannels == 1)
+ {
+ if(recorder.mBits == 8)
+ format = AL_FORMAT_MONO8;
+ else if(recorder.mBits == 16)
+ format = AL_FORMAT_MONO16;
+ else if(recorder.mBits == 32)
+ format = AL_FORMAT_MONO_FLOAT32;
+ }
+ else if(recorder.mChannels == 2)
+ {
+ if(recorder.mBits == 8)
+ format = AL_FORMAT_STEREO8;
+ else if(recorder.mBits == 16)
+ format = AL_FORMAT_STEREO16;
+ else if(recorder.mBits == 32)
+ format = AL_FORMAT_STEREO_FLOAT32;
+ }
+
+ recorder.mDevice = alcCaptureOpenDevice(devname, recorder.mSampleRate, format, 32768);
+ if(!recorder.mDevice)
+ {
+ fprintf(stderr, "Failed to open %s, %s %d-bit, %s, %dhz (%d samples)\n",
+ devname ? devname : "default device",
+ (recorder.mBits == 32) ? "Float" :
+ (recorder.mBits != 8) ? "Signed" : "Unsigned", recorder.mBits,
+ (recorder.mChannels == 1) ? "Mono" : "Stereo", recorder.mSampleRate,
+ 32768
+ );
+ return 1;
+ }
+ fprintf(stderr, "Opened \"%s\"\n", alcGetString(
+ recorder.mDevice, ALC_CAPTURE_DEVICE_SPECIFIER
+ ));
+
+ recorder.mFile = fopen(fname, "wb");
+ if(!recorder.mFile)
+ {
+ fprintf(stderr, "Failed to open '%s' for writing\n", fname);
+ alcCaptureCloseDevice(recorder.mDevice);
+ return 1;
+ }
+
+ fputs("RIFF", recorder.mFile);
+ fwrite32le(0xFFFFFFFF, recorder.mFile); // 'RIFF' header len; filled in at close
+
+ fputs("WAVE", recorder.mFile);
+
+ fputs("fmt ", recorder.mFile);
+ fwrite32le(18, recorder.mFile); // 'fmt ' header len
+
+ // 16-bit val, format type id (1 = integer PCM, 3 = float PCM)
+ fwrite16le((recorder.mBits == 32) ? 0x0003 : 0x0001, recorder.mFile);
+ // 16-bit val, channel count
+ fwrite16le(recorder.mChannels, recorder.mFile);
+ // 32-bit val, frequency
+ fwrite32le(recorder.mSampleRate, recorder.mFile);
+ // 32-bit val, bytes per second
+ fwrite32le(recorder.mSampleRate * recorder.mFrameSize, recorder.mFile);
+ // 16-bit val, frame size
+ fwrite16le(recorder.mFrameSize, recorder.mFile);
+ // 16-bit val, bits per sample
+ fwrite16le(recorder.mBits, recorder.mFile);
+ // 16-bit val, extra byte count
+ fwrite16le(0, recorder.mFile);
+
+ fputs("data", recorder.mFile);
+ fwrite32le(0xFFFFFFFF, recorder.mFile); // 'data' header len; filled in at close
+
+ recorder.mDataSizeOffset = ftell(recorder.mFile) - 4;
+ if(ferror(recorder.mFile) || recorder.mDataSizeOffset < 0)
+ {
+ fprintf(stderr, "Error writing header: %s\n", strerror(errno));
+ fclose(recorder.mFile);
+ alcCaptureCloseDevice(recorder.mDevice);
+ return 1;
+ }
+
+ fprintf(stderr, "Recording '%s', %s %d-bit, %s, %dhz (%g second%s)\n", fname,
+ (recorder.mBits == 32) ? "Float" :
+ (recorder.mBits != 8) ? "Signed" : "Unsigned", recorder.mBits,
+ (recorder.mChannels == 1) ? "Mono" : "Stereo", recorder.mSampleRate,
+ recorder.mRecTime, (recorder.mRecTime != 1.0f) ? "s" : ""
+ );
+
+ alcCaptureStart(recorder.mDevice);
+ while((double)recorder.mDataSize/(double)recorder.mSampleRate < recorder.mRecTime &&
+ (err=alcGetError(recorder.mDevice)) == ALC_NO_ERROR && !ferror(recorder.mFile))
+ {
+ ALCint count = 0;
+ fprintf(stderr, "\rCaptured %u samples", recorder.mDataSize);
+ alcGetIntegerv(recorder.mDevice, ALC_CAPTURE_SAMPLES, 1, &count);
+ if(count < 1)
+ {
+ al_nssleep(10000000);
+ continue;
+ }
+ if(count > recorder.mBufferSize)
+ {
+ ALbyte *data = calloc(recorder.mFrameSize, count);
+ free(recorder.mBuffer);
+ recorder.mBuffer = data;
+ recorder.mBufferSize = count;
+ }
+ alcCaptureSamples(recorder.mDevice, recorder.mBuffer, count);
+#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
+ /* Byteswap multibyte samples on big-endian systems (wav needs little-
+ * endian, and OpenAL gives the system's native-endian).
+ */
+ if(recorder.mBits == 16)
+ {
+ ALCint i;
+ for(i = 0;i < count*recorder.mChannels;i++)
+ {
+ ALbyte b = recorder.mBuffer[i*2 + 0];
+ recorder.mBuffer[i*2 + 0] = recorder.mBuffer[i*2 + 1];
+ recorder.mBuffer[i*2 + 1] = b;
+ }
+ }
+ else if(recorder.mBits == 32)
+ {
+ ALCint i;
+ for(i = 0;i < count*recorder.mChannels;i++)
+ {
+ ALbyte b0 = recorder.mBuffer[i*4 + 0];
+ ALbyte b1 = recorder.mBuffer[i*4 + 1];
+ recorder.mBuffer[i*4 + 0] = recorder.mBuffer[i*4 + 3];
+ recorder.mBuffer[i*4 + 1] = recorder.mBuffer[i*4 + 2];
+ recorder.mBuffer[i*4 + 2] = b1;
+ recorder.mBuffer[i*4 + 3] = b0;
+ }
+ }
+#endif
+ recorder.mDataSize += (ALuint)fwrite(recorder.mBuffer, recorder.mFrameSize, count,
+ recorder.mFile);
+ }
+ alcCaptureStop(recorder.mDevice);
+ fprintf(stderr, "\rCaptured %u samples\n", recorder.mDataSize);
+ if(err != ALC_NO_ERROR)
+ fprintf(stderr, "Got device error 0x%04x: %s\n", err, alcGetString(recorder.mDevice, err));
+
+ alcCaptureCloseDevice(recorder.mDevice);
+ recorder.mDevice = NULL;
+
+ free(recorder.mBuffer);
+ recorder.mBuffer = NULL;
+ recorder.mBufferSize = 0;
+
+ total_size = ftell(recorder.mFile);
+ if(fseek(recorder.mFile, recorder.mDataSizeOffset, SEEK_SET) == 0)
+ {
+ fwrite32le(recorder.mDataSize*recorder.mFrameSize, recorder.mFile);
+ if(fseek(recorder.mFile, 4, SEEK_SET) == 0)
+ fwrite32le(total_size - 8, recorder.mFile);
+ }
+
+ fclose(recorder.mFile);
+ recorder.mFile = NULL;
+
+ return 0;
+}
diff --git a/examples/alreverb.c b/examples/alreverb.c
index 420b1c55..e6c9e606 100644
--- a/examples/alreverb.c
+++ b/examples/alreverb.c
@@ -27,17 +27,15 @@
#include <stdio.h>
#include <assert.h>
+#include <SDL_sound.h>
+
#include "AL/al.h"
#include "AL/alc.h"
#include "AL/alext.h"
#include "AL/efx-presets.h"
#include "common/alhelpers.h"
-#include "common/sdl_sound.h"
-
-static LPALBUFFERSAMPLESSOFT alBufferSamplesSOFT = wrap_BufferSamples;
-static LPALISBUFFERFORMATSUPPORTEDSOFT alIsBufferFormatSupportedSOFT;
/* Effect object functions */
static LPALGENEFFECTS alGenEffects;
@@ -145,46 +143,63 @@ static ALuint LoadEffect(const EFXEAXREVERBPROPERTIES *reverb)
/* LoadBuffer loads the named audio file into an OpenAL buffer object, and
- * returns the new buffer ID. */
+ * returns the new buffer ID.
+ */
static ALuint LoadSound(const char *filename)
{
- ALenum err, format, type, channels;
- ALuint rate, buffer;
- size_t datalen;
- void *data;
- FilePtr sound;
-
- /* Open the file and get the first stream from it */
- sound = openAudioFile(filename, 1000);
- if(!sound)
+ Sound_Sample *sample;
+ ALenum err, format;
+ ALuint buffer;
+ Uint32 slen;
+
+ /* Open the audio file */
+ sample = Sound_NewSampleFromFile(filename, NULL, 65536);
+ if(!sample)
{
fprintf(stderr, "Could not open audio in %s\n", filename);
return 0;
}
/* Get the sound format, and figure out the OpenAL format */
- if(getAudioInfo(sound, &rate, &channels, &type) != 0)
+ if(sample->actual.channels == 1)
{
- fprintf(stderr, "Error getting audio info for %s\n", filename);
- closeAudioFile(sound);
- return 0;
+ if(sample->actual.format == AUDIO_U8)
+ format = AL_FORMAT_MONO8;
+ else if(sample->actual.format == AUDIO_S16SYS)
+ format = AL_FORMAT_MONO16;
+ else
+ {
+ fprintf(stderr, "Unsupported sample format: 0x%04x\n", sample->actual.format);
+ Sound_FreeSample(sample);
+ return 0;
+ }
}
-
- format = GetFormat(channels, type, alIsBufferFormatSupportedSOFT);
- if(format == AL_NONE)
+ else if(sample->actual.channels == 2)
+ {
+ if(sample->actual.format == AUDIO_U8)
+ format = AL_FORMAT_STEREO8;
+ else if(sample->actual.format == AUDIO_S16SYS)
+ format = AL_FORMAT_STEREO16;
+ else
+ {
+ fprintf(stderr, "Unsupported sample format: 0x%04x\n", sample->actual.format);
+ Sound_FreeSample(sample);
+ return 0;
+ }
+ }
+ else
{
- fprintf(stderr, "Unsupported format (%s, %s) for %s\n",
- ChannelsName(channels), TypeName(type), filename);
- closeAudioFile(sound);
+ fprintf(stderr, "Unsupported channel count: %d\n", sample->actual.channels);
+ Sound_FreeSample(sample);
return 0;
}
/* Decode the whole audio stream to a buffer. */
- data = decodeAudioStream(sound, &datalen);
- if(!data)
+ slen = Sound_DecodeAll(sample);
+ if(!sample->buffer || slen == 0)
{
fprintf(stderr, "Failed to read audio from %s\n", filename);
- closeAudioFile(sound);
+ Sound_FreeSample(sample);
return 0;
}
@@ -192,17 +207,15 @@ static ALuint LoadSound(const char *filename)
* close the file. */
buffer = 0;
alGenBuffers(1, &buffer);
- alBufferSamplesSOFT(buffer, rate, format, BytesToFrames(datalen, channels, type),
- channels, type, data);
- free(data);
- closeAudioFile(sound);
+ alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate);
+ Sound_FreeSample(sample);
/* Check if an error occured, and clean up if so. */
err = alGetError();
if(err != AL_NO_ERROR)
{
fprintf(stderr, "OpenAL Error: %s\n", alGetString(err));
- if(alIsBuffer(buffer))
+ if(buffer && alIsBuffer(buffer))
alDeleteBuffers(1, &buffer);
return 0;
}
@@ -217,15 +230,16 @@ int main(int argc, char **argv)
ALuint source, buffer, effect, slot;
ALenum state;
- /* Print out usage if no file was specified */
+ /* Print out usage if no arguments were specified */
if(argc < 2)
{
- fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
+ fprintf(stderr, "Usage: %s [-device <name] <filename>\n", argv[0]);
return 1;
}
- /* Initialize OpenAL with the default device, and check for EFX support. */
- if(InitAL() != 0)
+ /* Initialize OpenAL, and check for EFX support. */
+ argv++; argc--;
+ if(InitAL(&argv, &argc) != 0)
return 1;
if(!alcIsExtensionPresent(alcGetContextsDevice(alcGetCurrentContext()), "ALC_EXT_EFX"))
@@ -260,19 +274,17 @@ int main(int argc, char **argv)
LOAD_PROC(alGetAuxiliaryEffectSlotiv);
LOAD_PROC(alGetAuxiliaryEffectSlotf);
LOAD_PROC(alGetAuxiliaryEffectSlotfv);
-
- if(alIsExtensionPresent("AL_SOFT_buffer_samples"))
- {
- LOAD_PROC(alBufferSamplesSOFT);
- LOAD_PROC(alIsBufferFormatSupportedSOFT);
- }
#undef LOAD_PROC
+ /* Initialize SDL_sound. */
+ Sound_Init();
+
/* Load the sound into a buffer. */
- buffer = LoadSound(argv[1]);
+ buffer = LoadSound(argv[0]);
if(!buffer)
{
CloseAL();
+ Sound_Quit();
return 1;
}
@@ -281,6 +293,7 @@ int main(int argc, char **argv)
if(!effect)
{
alDeleteBuffers(1, &buffer);
+ Sound_Quit();
CloseAL();
return 1;
}
@@ -311,16 +324,17 @@ int main(int argc, char **argv)
/* Play the sound until it finishes. */
alSourcePlay(source);
do {
- Sleep(10);
+ al_nssleep(10000000);
alGetSourcei(source, AL_SOURCE_STATE, &state);
} while(alGetError() == AL_NO_ERROR && state == AL_PLAYING);
- /* All done. Delete resources, and close OpenAL. */
+ /* All done. Delete resources, and close down SDL_sound and OpenAL. */
alDeleteSources(1, &source);
alDeleteAuxiliaryEffectSlots(1, &slot);
alDeleteEffects(1, &effect);
alDeleteBuffers(1, &buffer);
+ Sound_Quit();
CloseAL();
return 0;
diff --git a/examples/alstream.c b/examples/alstream.c
index 2972d375..68115e8d 100644
--- a/examples/alstream.c
+++ b/examples/alstream.c
@@ -30,17 +30,21 @@
#include <signal.h>
#include <assert.h>
+#include <SDL_sound.h>
+
#include "AL/al.h"
#include "AL/alc.h"
#include "AL/alext.h"
#include "common/alhelpers.h"
-#include "common/sdl_sound.h"
-
-static LPALBUFFERSAMPLESSOFT alBufferSamplesSOFT = wrap_BufferSamples;
-static LPALISBUFFERFORMATSUPPORTEDSOFT alIsBufferFormatSupportedSOFT;
+#ifndef SDL_AUDIO_MASK_BITSIZE
+#define SDL_AUDIO_MASK_BITSIZE (0xFF)
+#endif
+#ifndef SDL_AUDIO_BITSIZE
+#define SDL_AUDIO_BITSIZE(x) (x & SDL_AUDIO_MASK_BITSIZE)
+#endif
/* Define the number of buffers and buffer size (in milliseconds) to use. 4
* buffers with 200ms each gives a nice per-chunk size, and lets the queue last
@@ -54,13 +58,11 @@ typedef struct StreamPlayer {
ALuint source;
/* Handle for the audio file */
- FilePtr file;
+ Sound_Sample *sample;
/* The format of the output stream */
ALenum format;
- ALenum channels;
- ALenum type;
- ALuint rate;
+ ALsizei srate;
} StreamPlayer;
static StreamPlayer *NewPlayer(void);
@@ -77,11 +79,9 @@ static StreamPlayer *NewPlayer(void)
{
StreamPlayer *player;
- player = malloc(sizeof(*player));
+ player = calloc(1, sizeof(*player));
assert(player != NULL);
- memset(player, 0, sizeof(*player));
-
/* Generate the buffers and source */
alGenBuffers(NUM_BUFFERS, player->buffers);
assert(alGetError() == AL_NO_ERROR && "Could not create buffers");
@@ -119,37 +119,63 @@ static void DeletePlayer(StreamPlayer *player)
* it will be closed first. */
static int OpenPlayerFile(StreamPlayer *player, const char *filename)
{
+ Uint32 frame_size;
+
ClosePlayerFile(player);
/* Open the file and get the first stream from it */
- player->file = openAudioFile(filename, BUFFER_TIME_MS);
- if(!player->file)
+ player->sample = Sound_NewSampleFromFile(filename, NULL, 0);
+ if(!player->sample)
{
fprintf(stderr, "Could not open audio in %s\n", filename);
goto error;
}
/* Get the stream format, and figure out the OpenAL format */
- if(getAudioInfo(player->file, &player->rate, &player->channels, &player->type) != 0)
+ if(player->sample->actual.channels == 1)
{
- fprintf(stderr, "Error getting audio info for %s\n", filename);
- goto error;
+ if(player->sample->actual.format == AUDIO_U8)
+ player->format = AL_FORMAT_MONO8;
+ else if(player->sample->actual.format == AUDIO_S16SYS)
+ player->format = AL_FORMAT_MONO16;
+ else
+ {
+ fprintf(stderr, "Unsupported sample format: 0x%04x\n", player->sample->actual.format);
+ goto error;
+ }
}
-
- player->format = GetFormat(player->channels, player->type, alIsBufferFormatSupportedSOFT);
- if(player->format == 0)
+ else if(player->sample->actual.channels == 2)
+ {
+ if(player->sample->actual.format == AUDIO_U8)
+ player->format = AL_FORMAT_STEREO8;
+ else if(player->sample->actual.format == AUDIO_S16SYS)
+ player->format = AL_FORMAT_STEREO16;
+ else
+ {
+ fprintf(stderr, "Unsupported sample format: 0x%04x\n", player->sample->actual.format);
+ goto error;
+ }
+ }
+ else
{
- fprintf(stderr, "Unsupported format (%s, %s) for %s\n",
- ChannelsName(player->channels), TypeName(player->type),
- filename);
+ fprintf(stderr, "Unsupported channel count: %d\n", player->sample->actual.channels);
goto error;
}
+ player->srate = player->sample->actual.rate;
+
+ frame_size = player->sample->actual.channels *
+ SDL_AUDIO_BITSIZE(player->sample->actual.format) / 8;
+
+ /* Set the buffer size, given the desired millisecond length. */
+ Sound_SetBufferSize(player->sample, (Uint32)((Uint64)player->srate*BUFFER_TIME_MS/1000) *
+ frame_size);
return 1;
error:
- closeAudioFile(player->file);
- player->file = NULL;
+ if(player->sample)
+ Sound_FreeSample(player->sample);
+ player->sample = NULL;
return 0;
}
@@ -157,8 +183,9 @@ error:
/* Closes the audio file stream */
static void ClosePlayerFile(StreamPlayer *player)
{
- closeAudioFile(player->file);
- player->file = NULL;
+ if(player->sample)
+ Sound_FreeSample(player->sample);
+ player->sample = NULL;
}
@@ -174,16 +201,12 @@ static int StartPlayer(StreamPlayer *player)
/* Fill the buffer queue */
for(i = 0;i < NUM_BUFFERS;i++)
{
- uint8_t *data;
- size_t got;
-
/* Get some data to give it to the buffer */
- data = getAudioData(player->file, &got);
- if(!data) break;
+ Uint32 slen = Sound_Decode(player->sample);
+ if(slen == 0) break;
- alBufferSamplesSOFT(player->buffers[i], player->rate, player->format,
- BytesToFrames(got, player->channels, player->type),
- player->channels, player->type, data);
+ alBufferData(player->buffers[i], player->format,
+ player->sample->buffer, slen, player->srate);
}
if(alGetError() != AL_NO_ERROR)
{
@@ -220,20 +243,21 @@ static int UpdatePlayer(StreamPlayer *player)
while(processed > 0)
{
ALuint bufid;
- uint8_t *data;
- size_t got;
+ Uint32 slen;
alSourceUnqueueBuffers(player->source, 1, &bufid);
processed--;
+ if((player->sample->flags&(SOUND_SAMPLEFLAG_EOF|SOUND_SAMPLEFLAG_ERROR)))
+ continue;
+
/* Read the next chunk of data, refill the buffer, and queue it
* back on the source */
- data = getAudioData(player->file, &got);
- if(data != NULL)
+ slen = Sound_Decode(player->sample);
+ if(slen > 0)
{
- alBufferSamplesSOFT(bufid, player->rate, player->format,
- BytesToFrames(got, player->channels, player->type),
- player->channels, player->type, data);
+ alBufferData(bufid, player->format, player->sample->buffer, slen,
+ player->srate);
alSourceQueueBuffers(player->source, 1, &bufid);
}
if(alGetError() != AL_NO_ERROR)
@@ -270,29 +294,23 @@ int main(int argc, char **argv)
StreamPlayer *player;
int i;
- /* Print out usage if no file was specified */
+ /* Print out usage if no arguments were specified */
if(argc < 2)
{
- fprintf(stderr, "Usage: %s <filenames...>\n", argv[0]);
+ fprintf(stderr, "Usage: %s [-device <name>] <filenames...>\n", argv[0]);
return 1;
}
- if(InitAL() != 0)
+ argv++; argc--;
+ if(InitAL(&argv, &argc) != 0)
return 1;
- if(alIsExtensionPresent("AL_SOFT_buffer_samples"))
- {
- printf("AL_SOFT_buffer_samples supported!\n");
- alBufferSamplesSOFT = alGetProcAddress("alBufferSamplesSOFT");
- alIsBufferFormatSupportedSOFT = alGetProcAddress("alIsBufferFormatSupportedSOFT");
- }
- else
- printf("AL_SOFT_buffer_samples not supported\n");
+ Sound_Init();
player = NewPlayer();
/* Play each file listed on the command line */
- for(i = 1;i < argc;i++)
+ for(i = 0;i < argc;i++)
{
const char *namepart;
@@ -306,9 +324,8 @@ int main(int argc, char **argv)
else
namepart = argv[i];
- printf("Playing: %s (%s, %s, %dhz)\n", namepart,
- TypeName(player->type), ChannelsName(player->channels),
- player->rate);
+ printf("Playing: %s (%s, %dhz)\n", namepart, FormatName(player->format),
+ player->srate);
fflush(stdout);
if(!StartPlayer(player))
@@ -318,17 +335,18 @@ int main(int argc, char **argv)
}
while(UpdatePlayer(player))
- Sleep(10);
+ al_nssleep(10000000);
/* All done with this file. Close it and go to the next */
ClosePlayerFile(player);
}
printf("Done.\n");
- /* All files done. Delete the player, and close OpenAL */
+ /* All files done. Delete the player, and close down SDL_sound and OpenAL */
DeletePlayer(player);
player = NULL;
+ Sound_Quit();
CloseAL();
return 0;
diff --git a/examples/altonegen.c b/examples/altonegen.c
index 65980529..628e695d 100644
--- a/examples/altonegen.c
+++ b/examples/altonegen.c
@@ -35,6 +35,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <limits.h>
#include <math.h>
#include "AL/al.h"
@@ -53,6 +54,7 @@ enum WaveType {
WT_Sawtooth,
WT_Triangle,
WT_Impulse,
+ WT_WhiteNoise,
};
static const char *GetWaveTypeName(enum WaveType type)
@@ -64,10 +66,17 @@ static const char *GetWaveTypeName(enum WaveType type)
case WT_Sawtooth: return "sawtooth";
case WT_Triangle: return "triangle";
case WT_Impulse: return "impulse";
+ case WT_WhiteNoise: return "noise";
}
return "(unknown)";
}
+static inline ALuint dither_rng(ALuint *seed)
+{
+ *seed = (*seed * 96314165) + 907633515;
+ return *seed;
+}
+
static void ApplySin(ALfloat *data, ALdouble g, ALuint srate, ALuint freq)
{
ALdouble smps_per_cycle = (ALdouble)srate / freq;
@@ -81,6 +90,7 @@ static void ApplySin(ALfloat *data, ALdouble g, ALuint srate, ALuint freq)
*/
static ALuint CreateWave(enum WaveType type, ALuint freq, ALuint srate)
{
+ ALuint seed = 22222;
ALint data_size;
ALfloat *data;
ALuint buffer;
@@ -89,25 +99,44 @@ static ALuint CreateWave(enum WaveType type, ALuint freq, ALuint srate)
data_size = srate * sizeof(ALfloat);
data = calloc(1, data_size);
- if(type == WT_Sine)
- ApplySin(data, 1.0, srate, freq);
- else if(type == WT_Square)
- for(i = 1;freq*i < srate/2;i+=2)
- ApplySin(data, 4.0/M_PI * 1.0/i, srate, freq*i);
- else if(type == WT_Sawtooth)
- for(i = 1;freq*i < srate/2;i++)
- ApplySin(data, 2.0/M_PI * ((i&1)*2 - 1.0) / i, srate, freq*i);
- else if(type == WT_Triangle)
- for(i = 1;freq*i < srate/2;i+=2)
- ApplySin(data, 8.0/(M_PI*M_PI) * (1.0 - (i&2)) / (i*i), srate, freq*i);
- else if(type == WT_Impulse)
+ switch(type)
{
- /* NOTE: Impulse isn't really a waveform, but it can still be useful to
- * test (other than resampling, the ALSOFT_DEFAULT_REVERB environment
- * variable can prove useful here to test the reverb response).
- */
- for(i = 0;i < srate;i++)
- data[i] = (i%(srate/freq)) ? 0.0f : 1.0f;
+ case WT_Sine:
+ ApplySin(data, 1.0, srate, freq);
+ break;
+ case WT_Square:
+ for(i = 1;freq*i < srate/2;i+=2)
+ ApplySin(data, 4.0/M_PI * 1.0/i, srate, freq*i);
+ break;
+ case WT_Sawtooth:
+ for(i = 1;freq*i < srate/2;i++)
+ ApplySin(data, 2.0/M_PI * ((i&1)*2 - 1.0) / i, srate, freq*i);
+ break;
+ case WT_Triangle:
+ for(i = 1;freq*i < srate/2;i+=2)
+ ApplySin(data, 8.0/(M_PI*M_PI) * (1.0 - (i&2)) / (i*i), srate, freq*i);
+ break;
+ case WT_Impulse:
+ /* NOTE: Impulse isn't handled using additive synthesis, and is
+ * instead just a non-0 sample at a given rate. This can still be
+ * useful to test (other than resampling, the ALSOFT_DEFAULT_REVERB
+ * environment variable can prove useful here to test the reverb
+ * response).
+ */
+ for(i = 0;i < srate;i++)
+ data[i] = (i%(srate/freq)) ? 0.0f : 1.0f;
+ break;
+ case WT_WhiteNoise:
+ /* NOTE: WhiteNoise is just uniform set of uncorrelated values, and
+ * is not influenced by the waveform frequency.
+ */
+ for(i = 0;i < srate;i++)
+ {
+ ALuint rng0 = dither_rng(&seed);
+ ALuint rng1 = dither_rng(&seed);
+ data[i] = (ALfloat)(rng0*(1.0/UINT_MAX) - rng1*(1.0/UINT_MAX));
+ }
+ break;
}
/* Buffer the audio data into a new buffer object. */
@@ -133,6 +162,7 @@ static ALuint CreateWave(enum WaveType type, ALuint freq, ALuint srate)
int main(int argc, char *argv[])
{
enum WaveType wavetype = WT_Sine;
+ const char *appname = argv[0];
ALuint source, buffer;
ALint last_pos, num_loops;
ALint max_loops = 4;
@@ -142,23 +172,35 @@ int main(int argc, char *argv[])
ALenum state;
int i;
- for(i = 1;i < argc;i++)
+ argv++; argc--;
+ if(InitAL(&argv, &argc) != 0)
+ return 1;
+
+ if(!alIsExtensionPresent("AL_EXT_FLOAT32"))
+ {
+ fprintf(stderr, "Required AL_EXT_FLOAT32 extension not supported on this device!\n");
+ CloseAL();
+ return 1;
+ }
+
+ for(i = 0;i < argc;i++)
{
if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
{
fprintf(stderr, "OpenAL Tone Generator\n"
"\n"
-"Usage: %s <options>\n"
+"Usage: %s [-device <name>] <options>\n"
"\n"
"Available options:\n"
" --help/-h This help text\n"
" -t <seconds> Time to play a tone (default 5 seconds)\n"
" --waveform/-w <type> Waveform type: sine (default), square, sawtooth,\n"
-" triangle, impulse\n"
+" triangle, impulse, noise\n"
" --freq/-f <hz> Tone frequency (default 1000 hz)\n"
" --srate/-s <sample rate> Sampling rate (default output rate)\n",
- argv[0]
+ appname
);
+ CloseAL();
return 1;
}
else if(i+1 < argc && strcmp(argv[i], "-t") == 0)
@@ -179,6 +221,8 @@ int main(int argc, char *argv[])
wavetype = WT_Triangle;
else if(strcmp(argv[i], "impulse") == 0)
wavetype = WT_Impulse;
+ else if(strcmp(argv[i], "noise") == 0)
+ wavetype = WT_WhiteNoise;
else
fprintf(stderr, "Unhandled waveform: %s\n", argv[i]);
}
@@ -204,15 +248,6 @@ int main(int argc, char *argv[])
}
}
- InitAL();
-
- if(!alIsExtensionPresent("AL_EXT_FLOAT32"))
- {
- fprintf(stderr, "Required AL_EXT_FLOAT32 extension not supported on this device!\n");
- CloseAL();
- return 1;
- }
-
{
ALCdevice *device = alcGetContextsDevice(alcGetCurrentContext());
alcGetIntegerv(device, ALC_FREQUENCY, 1, &dev_rate);
@@ -246,7 +281,7 @@ int main(int argc, char *argv[])
alSourcePlay(source);
do {
ALint pos;
- Sleep(10);
+ al_nssleep(10000000);
alGetSourcei(source, AL_SAMPLE_OFFSET, &pos);
alGetSourcei(source, AL_SOURCE_STATE, &state);
if(pos < last_pos && state == AL_PLAYING)
diff --git a/examples/common/alhelpers.c b/examples/common/alhelpers.c
index 4582321c..fab039e9 100644
--- a/examples/common/alhelpers.c
+++ b/examples/common/alhelpers.c
@@ -29,6 +29,7 @@
* channel configs and sample types. */
#include <stdio.h>
+#include <string.h>
#include "AL/al.h"
#include "AL/alc.h"
@@ -37,15 +38,26 @@
#include "alhelpers.h"
-/* InitAL opens the default device and sets up a context using default
- * attributes, making the program ready to call OpenAL functions. */
-int InitAL(void)
+/* InitAL opens a device and sets up a context using default attributes, making
+ * the program ready to call OpenAL functions. */
+int InitAL(char ***argv, int *argc)
{
+ const ALCchar *name;
ALCdevice *device;
ALCcontext *ctx;
- /* Open and initialize a device with default settings */
- device = alcOpenDevice(NULL);
+ /* Open and initialize a device */
+ device = NULL;
+ if(argc && argv && *argc > 1 && strcmp((*argv)[0], "-device") == 0)
+ {
+ device = alcOpenDevice((*argv)[1]);
+ if(!device)
+ fprintf(stderr, "Failed to open \"%s\", trying default\n", (*argv)[1]);
+ (*argv) += 2;
+ (*argc) -= 2;
+ }
+ if(!device)
+ device = alcOpenDevice(NULL);
if(!device)
{
fprintf(stderr, "Could not open a device!\n");
@@ -62,7 +74,13 @@ int InitAL(void)
return 1;
}
- printf("Opened \"%s\"\n", alcGetString(device, ALC_DEVICE_SPECIFIER));
+ name = NULL;
+ if(alcIsExtensionPresent(device, "ALC_ENUMERATE_ALL_EXT"))
+ name = alcGetString(device, ALC_ALL_DEVICES_SPECIFIER);
+ if(!name || alcGetError(device) != AL_NO_ERROR)
+ name = alcGetString(device, ALC_DEVICE_SPECIFIER);
+ printf("Opened \"%s\"\n", name);
+
return 0;
}
@@ -85,243 +103,14 @@ void CloseAL(void)
}
-/* GetFormat retrieves a compatible buffer format given the channel config 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)
-{
- ALenum format = AL_NONE;
-
- /* If using AL_SOFT_buffer_samples, try looking through its formats */
- if(palIsBufferFormatSupportedSOFT)
- {
- /* AL_SOFT_buffer_samples is more lenient with matching formats. The
- * specified sample type does not need to match the returned format,
- * but it is nice to try to get something close. */
- if(type == AL_UNSIGNED_BYTE_SOFT || type == AL_BYTE_SOFT)
- {
- if(channels == AL_MONO_SOFT) format = AL_MONO8_SOFT;
- else if(channels == AL_STEREO_SOFT) format = AL_STEREO8_SOFT;
- else if(channels == AL_QUAD_SOFT) format = AL_QUAD8_SOFT;
- else if(channels == AL_5POINT1_SOFT) format = AL_5POINT1_8_SOFT;
- else if(channels == AL_6POINT1_SOFT) format = AL_6POINT1_8_SOFT;
- else if(channels == AL_7POINT1_SOFT) format = AL_7POINT1_8_SOFT;
- }
- else if(type == AL_UNSIGNED_SHORT_SOFT || type == AL_SHORT_SOFT)
- {
- if(channels == AL_MONO_SOFT) format = AL_MONO16_SOFT;
- else if(channels == AL_STEREO_SOFT) format = AL_STEREO16_SOFT;
- else if(channels == AL_QUAD_SOFT) format = AL_QUAD16_SOFT;
- else if(channels == AL_5POINT1_SOFT) format = AL_5POINT1_16_SOFT;
- else if(channels == AL_6POINT1_SOFT) format = AL_6POINT1_16_SOFT;
- else if(channels == AL_7POINT1_SOFT) format = AL_7POINT1_16_SOFT;
- }
- else if(type == AL_UNSIGNED_BYTE3_SOFT || type == AL_BYTE3_SOFT ||
- type == AL_UNSIGNED_INT_SOFT || type == AL_INT_SOFT ||
- type == AL_FLOAT_SOFT || type == AL_DOUBLE_SOFT)
- {
- if(channels == AL_MONO_SOFT) format = AL_MONO32F_SOFT;
- else if(channels == AL_STEREO_SOFT) format = AL_STEREO32F_SOFT;
- else if(channels == AL_QUAD_SOFT) format = AL_QUAD32F_SOFT;
- else if(channels == AL_5POINT1_SOFT) format = AL_5POINT1_32F_SOFT;
- else if(channels == AL_6POINT1_SOFT) format = AL_6POINT1_32F_SOFT;
- else if(channels == AL_7POINT1_SOFT) format = AL_7POINT1_32F_SOFT;
- }
-
- if(format != AL_NONE && !palIsBufferFormatSupportedSOFT(format))
- format = AL_NONE;
-
- /* A matching format was not found or supported. Try 32-bit float. */
- if(format == AL_NONE)
- {
- if(channels == AL_MONO_SOFT) format = AL_MONO32F_SOFT;
- else if(channels == AL_STEREO_SOFT) format = AL_STEREO32F_SOFT;
- else if(channels == AL_QUAD_SOFT) format = AL_QUAD32F_SOFT;
- else if(channels == AL_5POINT1_SOFT) format = AL_5POINT1_32F_SOFT;
- else if(channels == AL_6POINT1_SOFT) format = AL_6POINT1_32F_SOFT;
- else if(channels == AL_7POINT1_SOFT) format = AL_7POINT1_32F_SOFT;
-
- if(format != AL_NONE && !palIsBufferFormatSupportedSOFT(format))
- format = AL_NONE;
- }
- /* 32-bit float not supported. Try 16-bit int. */
- if(format == AL_NONE)
- {
- if(channels == AL_MONO_SOFT) format = AL_MONO16_SOFT;
- else if(channels == AL_STEREO_SOFT) format = AL_STEREO16_SOFT;
- else if(channels == AL_QUAD_SOFT) format = AL_QUAD16_SOFT;
- else if(channels == AL_5POINT1_SOFT) format = AL_5POINT1_16_SOFT;
- else if(channels == AL_6POINT1_SOFT) format = AL_6POINT1_16_SOFT;
- else if(channels == AL_7POINT1_SOFT) format = AL_7POINT1_16_SOFT;
-
- if(format != AL_NONE && !palIsBufferFormatSupportedSOFT(format))
- format = AL_NONE;
- }
- /* 16-bit int not supported. Try 8-bit int. */
- if(format == AL_NONE)
- {
- if(channels == AL_MONO_SOFT) format = AL_MONO8_SOFT;
- else if(channels == AL_STEREO_SOFT) format = AL_STEREO8_SOFT;
- else if(channels == AL_QUAD_SOFT) format = AL_QUAD8_SOFT;
- else if(channels == AL_5POINT1_SOFT) format = AL_5POINT1_8_SOFT;
- else if(channels == AL_6POINT1_SOFT) format = AL_6POINT1_8_SOFT;
- else if(channels == AL_7POINT1_SOFT) format = AL_7POINT1_8_SOFT;
-
- if(format != AL_NONE && !palIsBufferFormatSupportedSOFT(format))
- format = AL_NONE;
- }
-
- return format;
- }
-
- /* We use the AL_EXT_MCFORMATS extension to provide output of Quad, 5.1,
- * and 7.1 channel configs, AL_EXT_FLOAT32 for 32-bit float samples, and
- * AL_EXT_DOUBLE for 64-bit float samples. */
- if(type == AL_UNSIGNED_BYTE_SOFT)
- {
- if(channels == AL_MONO_SOFT)
- format = AL_FORMAT_MONO8;
- else if(channels == AL_STEREO_SOFT)
- format = AL_FORMAT_STEREO8;
- else if(alIsExtensionPresent("AL_EXT_MCFORMATS"))
- {
- if(channels == AL_QUAD_SOFT)
- format = alGetEnumValue("AL_FORMAT_QUAD8");
- else if(channels == AL_5POINT1_SOFT)
- format = alGetEnumValue("AL_FORMAT_51CHN8");
- else if(channels == AL_6POINT1_SOFT)
- format = alGetEnumValue("AL_FORMAT_61CHN8");
- else if(channels == AL_7POINT1_SOFT)
- format = alGetEnumValue("AL_FORMAT_71CHN8");
- }
- }
- else if(type == AL_SHORT_SOFT)
- {
- if(channels == AL_MONO_SOFT)
- format = AL_FORMAT_MONO16;
- else if(channels == AL_STEREO_SOFT)
- format = AL_FORMAT_STEREO16;
- else if(alIsExtensionPresent("AL_EXT_MCFORMATS"))
- {
- if(channels == AL_QUAD_SOFT)
- format = alGetEnumValue("AL_FORMAT_QUAD16");
- else if(channels == AL_5POINT1_SOFT)
- format = alGetEnumValue("AL_FORMAT_51CHN16");
- else if(channels == AL_6POINT1_SOFT)
- format = alGetEnumValue("AL_FORMAT_61CHN16");
- else if(channels == AL_7POINT1_SOFT)
- format = alGetEnumValue("AL_FORMAT_71CHN16");
- }
- }
- else if(type == AL_FLOAT_SOFT && alIsExtensionPresent("AL_EXT_FLOAT32"))
- {
- if(channels == AL_MONO_SOFT)
- format = alGetEnumValue("AL_FORMAT_MONO_FLOAT32");
- else if(channels == AL_STEREO_SOFT)
- format = alGetEnumValue("AL_FORMAT_STEREO_FLOAT32");
- else if(alIsExtensionPresent("AL_EXT_MCFORMATS"))
- {
- if(channels == AL_QUAD_SOFT)
- format = alGetEnumValue("AL_FORMAT_QUAD32");
- else if(channels == AL_5POINT1_SOFT)
- format = alGetEnumValue("AL_FORMAT_51CHN32");
- else if(channels == AL_6POINT1_SOFT)
- format = alGetEnumValue("AL_FORMAT_61CHN32");
- else if(channels == AL_7POINT1_SOFT)
- format = alGetEnumValue("AL_FORMAT_71CHN32");
- }
- }
- else if(type == AL_DOUBLE_SOFT && alIsExtensionPresent("AL_EXT_DOUBLE"))
- {
- if(channels == AL_MONO_SOFT)
- format = alGetEnumValue("AL_FORMAT_MONO_DOUBLE");
- else if(channels == AL_STEREO_SOFT)
- format = alGetEnumValue("AL_FORMAT_STEREO_DOUBLE");
- }
-
- /* NOTE: It seems OSX returns -1 from alGetEnumValue for unknown enums, as
- * opposed to 0. Correct it. */
- if(format == -1)
- format = 0;
-
- return format;
-}
-
-
-void AL_APIENTRY wrap_BufferSamples(ALuint buffer, ALuint samplerate,
- ALenum internalformat, ALsizei samples,
- ALenum channels, ALenum type,
- const ALvoid *data)
-{
- alBufferData(buffer, internalformat, data,
- FramesToBytes(samples, channels, type),
- samplerate);
-}
-
-
-const char *ChannelsName(ALenum chans)
+const char *FormatName(ALenum format)
{
- switch(chans)
+ switch(format)
{
- case AL_MONO_SOFT: return "Mono";
- case AL_STEREO_SOFT: return "Stereo";
- case AL_REAR_SOFT: return "Rear";
- case AL_QUAD_SOFT: return "Quadraphonic";
- case AL_5POINT1_SOFT: return "5.1 Surround";
- case AL_6POINT1_SOFT: return "6.1 Surround";
- case AL_7POINT1_SOFT: return "7.1 Surround";
+ case AL_FORMAT_MONO8: return "Mono, U8";
+ case AL_FORMAT_MONO16: return "Mono, S16";
+ case AL_FORMAT_STEREO8: return "Stereo, U8";
+ case AL_FORMAT_STEREO16: return "Stereo, S16";
}
- return "Unknown Channels";
-}
-
-const char *TypeName(ALenum type)
-{
- switch(type)
- {
- case AL_BYTE_SOFT: return "S8";
- case AL_UNSIGNED_BYTE_SOFT: return "U8";
- case AL_SHORT_SOFT: return "S16";
- case AL_UNSIGNED_SHORT_SOFT: return "U16";
- case AL_INT_SOFT: return "S32";
- case AL_UNSIGNED_INT_SOFT: return "U32";
- case AL_FLOAT_SOFT: return "Float32";
- case AL_DOUBLE_SOFT: return "Float64";
- }
- return "Unknown Type";
-}
-
-
-ALsizei FramesToBytes(ALsizei size, ALenum channels, ALenum type)
-{
- switch(channels)
- {
- case AL_MONO_SOFT: size *= 1; break;
- case AL_STEREO_SOFT: size *= 2; break;
- case AL_REAR_SOFT: size *= 2; break;
- case AL_QUAD_SOFT: size *= 4; break;
- case AL_5POINT1_SOFT: size *= 6; break;
- case AL_6POINT1_SOFT: size *= 7; break;
- case AL_7POINT1_SOFT: size *= 8; break;
- }
-
- switch(type)
- {
- case AL_BYTE_SOFT: size *= sizeof(ALbyte); break;
- case AL_UNSIGNED_BYTE_SOFT: size *= sizeof(ALubyte); break;
- case AL_SHORT_SOFT: size *= sizeof(ALshort); break;
- case AL_UNSIGNED_SHORT_SOFT: size *= sizeof(ALushort); break;
- case AL_INT_SOFT: size *= sizeof(ALint); break;
- case AL_UNSIGNED_INT_SOFT: size *= sizeof(ALuint); break;
- case AL_FLOAT_SOFT: size *= sizeof(ALfloat); break;
- case AL_DOUBLE_SOFT: size *= sizeof(ALdouble); break;
- }
-
- return size;
-}
-
-ALsizei BytesToFrames(ALsizei size, ALenum channels, ALenum type)
-{
- return size / FramesToBytes(1, channels, type);
+ return "Unknown Format";
}
diff --git a/examples/common/alhelpers.h b/examples/common/alhelpers.h
index 62ed5be2..41a7ce58 100644
--- a/examples/common/alhelpers.h
+++ b/examples/common/alhelpers.h
@@ -1,47 +1,21 @@
#ifndef ALHELPERS_H
#define ALHELPERS_H
-#ifndef _WIN32
-#include <unistd.h>
-#define Sleep(x) usleep((x)*1000)
-#else
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#endif
-
#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);
+/* Some helper functions to get the name from the format enums. */
+const char *FormatName(ALenum type);
/* Easy device init/deinit functions. InitAL returns 0 on success. */
-int InitAL(void);
+int InitAL(char ***argv, int *argc);
void CloseAL(void);
#ifdef __cplusplus
diff --git a/examples/common/sdl_sound.c b/examples/common/sdl_sound.c
deleted file mode 100644
index 79a5bf32..00000000
--- a/examples/common/sdl_sound.c
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * SDL_sound Decoder Helpers
- *
- * Copyright (c) 2013 by Chris Robinson <[email protected]>
- *
- * 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.
- */
-
-/* This file contains routines for helping to decode audio using SDL_sound.
- * There's very little OpenAL-specific code here.
- */
-#include "sdl_sound.h"
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <signal.h>
-#include <assert.h>
-
-#include <SDL_sound.h>
-
-#include "AL/al.h"
-#include "AL/alc.h"
-#include "AL/alext.h"
-
-#include "alhelpers.h"
-
-
-static int done_init = 0;
-
-FilePtr openAudioFile(const char *fname, size_t buftime_ms)
-{
- FilePtr file;
- ALuint rate;
- Uint32 bufsize;
- ALenum chans, type;
-
- /* We need to make sure SDL_sound is initialized. */
- if(!done_init)
- {
- Sound_Init();
- done_init = 1;
- }
-
- file = Sound_NewSampleFromFile(fname, NULL, 0);
- if(!file)
- {
- fprintf(stderr, "Failed to open %s: %s\n", fname, Sound_GetError());
- return NULL;
- }
-
- if(getAudioInfo(file, &rate, &chans, &type) != 0)
- {
- Sound_FreeSample(file);
- return NULL;
- }
-
- bufsize = FramesToBytes((ALsizei)(buftime_ms/1000.0*rate), chans, type);
- if(Sound_SetBufferSize(file, bufsize) == 0)
- {
- fprintf(stderr, "Failed to set buffer size to %u bytes: %s\n", bufsize, Sound_GetError());
- Sound_FreeSample(file);
- return NULL;
- }
-
- return file;
-}
-
-void closeAudioFile(FilePtr file)
-{
- if(file)
- Sound_FreeSample(file);
-}
-
-
-int getAudioInfo(FilePtr file, ALuint *rate, ALenum *channels, ALenum *type)
-{
- if(file->actual.channels == 1)
- *channels = AL_MONO_SOFT;
- else if(file->actual.channels == 2)
- *channels = AL_STEREO_SOFT;
- else
- {
- fprintf(stderr, "Unsupported channel count: %d\n", file->actual.channels);
- return 1;
- }
-
- if(file->actual.format == AUDIO_U8)
- *type = AL_UNSIGNED_BYTE_SOFT;
- else if(file->actual.format == AUDIO_S8)
- *type = AL_BYTE_SOFT;
- else if(file->actual.format == AUDIO_U16LSB || file->actual.format == AUDIO_U16MSB)
- *type = AL_UNSIGNED_SHORT_SOFT;
- else if(file->actual.format == AUDIO_S16LSB || file->actual.format == AUDIO_S16MSB)
- *type = AL_SHORT_SOFT;
- else
- {
- fprintf(stderr, "Unsupported sample format: 0x%04x\n", file->actual.format);
- return 1;
- }
-
- *rate = file->actual.rate;
-
- return 0;
-}
-
-
-uint8_t *getAudioData(FilePtr file, size_t *length)
-{
- *length = Sound_Decode(file);
- if(*length == 0)
- return NULL;
- if((file->actual.format == AUDIO_U16LSB && AUDIO_U16LSB != AUDIO_U16SYS) ||
- (file->actual.format == AUDIO_U16MSB && AUDIO_U16MSB != AUDIO_U16SYS) ||
- (file->actual.format == AUDIO_S16LSB && AUDIO_S16LSB != AUDIO_S16SYS) ||
- (file->actual.format == AUDIO_S16MSB && AUDIO_S16MSB != AUDIO_S16SYS))
- {
- /* Swap bytes if the decoded endianness doesn't match the system. */
- char *buffer = file->buffer;
- size_t i;
- for(i = 0;i < *length;i+=2)
- {
- char b = buffer[i];
- buffer[i] = buffer[i+1];
- buffer[i+1] = b;
- }
- }
- return file->buffer;
-}
-
-void *decodeAudioStream(FilePtr file, size_t *length)
-{
- Uint32 got;
- char *mem;
-
- got = Sound_DecodeAll(file);
- if(got == 0)
- {
- *length = 0;
- return NULL;
- }
-
- mem = malloc(got);
- memcpy(mem, file->buffer, got);
-
- *length = got;
- return mem;
-}
diff --git a/examples/common/sdl_sound.h b/examples/common/sdl_sound.h
deleted file mode 100644
index e93ab92b..00000000
--- a/examples/common/sdl_sound.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef EXAMPLES_SDL_SOUND_H
-#define EXAMPLES_SDL_SOUND_H
-
-#include "AL/al.h"
-
-#include <SDL_sound.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-/* Opaque handles to files and streams. Apps don't need to concern themselves
- * with the internals */
-typedef Sound_Sample *FilePtr;
-
-/* Opens a file with SDL_sound, and specifies the size of the sample buffer in
- * milliseconds. */
-FilePtr openAudioFile(const char *fname, size_t buftime_ms);
-
-/* Closes/frees an opened file */
-void closeAudioFile(FilePtr file);
-
-/* Returns information about the given audio stream. Returns 0 on success. */
-int getAudioInfo(FilePtr file, ALuint *rate, ALenum *channels, ALenum *type);
-
-/* Returns a pointer to the next available chunk of decoded audio. The size (in
- * bytes) of the returned data buffer is stored in 'length', and the returned
- * pointer is only valid until the next call to getAudioData. */
-uint8_t *getAudioData(FilePtr file, size_t *length);
-
-/* Decodes all remaining data from the stream and returns a buffer containing
- * the audio data, with the size stored in 'length'. The returned pointer must
- * be freed with a call to free(). Note that since this decodes the whole
- * stream, using it on lengthy streams (eg, music) will use a lot of memory.
- * Such streams are better handled using getAudioData to keep smaller chunks in
- * memory at any given time. */
-void *decodeAudioStream(FilePtr, size_t *length);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* EXAMPLES_SDL_SOUND_H */
diff --git a/hrtf.txt b/hrtf.txt
deleted file mode 100644
index 37a329d2..00000000
--- a/hrtf.txt
+++ /dev/null
@@ -1,74 +0,0 @@
-HRTF Support
-============
-
-Starting with OpenAL Soft 1.14, HRTFs can be used to enable enhanced
-spatialization for both 3D (mono) and multi-channel sources, when used with
-headphones/stereo output. This can be enabled using the 'hrtf' config option.
-
-For multi-channel sources this creates a virtual speaker effect, making it
-sound as if speakers provide a discrete position for each channel around the
-listener. For mono sources this provides much more versatility in the perceived
-placement of sounds, making it seem as though they are coming from all around,
-including above and below the listener, instead of just to the front, back, and
-sides.
-
-The default data set is based on the KEMAR HRTF data provided by MIT, which can
-be found at <http://sound.media.mit.edu/resources/KEMAR.html>. It's only
-available when using 44100hz or 48000hz playback.
-
-
-Custom HRTF Data Sets
-=====================
-
-OpenAL Soft also provides an option to use user-specified data sets, in
-addition to or in place of the default set. This allows users to provide their
-own data sets, which could be better suited for their heads, or to work with
-stereo speakers instead of headphones, or to support more playback sample
-rates, for example.
-
-The file format is specified below. It uses little-endian byte order.
-
-==
-ALchar magic[8] = "MinPHR01";
-ALuint sampleRate;
-
-ALubyte hrirSize; /* Can be 8 to 128 in steps of 8. */
-ALubyte evCount; /* Can be 5 to 128. */
-
-ALubyte azCount[evCount]; /* Each can be 1 to 128. */
-
-/* NOTE: hrirCount is the sum of all azCounts */
-ALshort coefficients[hrirCount][hrirSize];
-ALubyte delays[hrirCount]; /* Each can be 0 to 63. */
-==
-
-The data is described as thus:
-
-The file first starts with the 8-byte marker, "MinPHR01", to identify it as an
-HRTF data set. This is followed by an unsigned 32-bit integer, specifying the
-sample rate the data set is designed for (OpenAL Soft will not use it if the
-output device's playback rate doesn't match).
-
-Afterward, an unsigned 8-bit integer specifies how many sample points (or
-finite impulse response filter coefficients) make up each HRIR.
-
-The following unsigned 8-bit integer specifies the number of elevations used
-by the data set. The elevations start at the bottom (-90 degrees), and
-increment upwards. Following this is an array of unsigned 8-bit integers, one
-for each elevation which specifies the number of azimuths (and thus HRIRs) that
-make up each elevation. Azimuths start clockwise from the front, constructing
-a full circle for the left ear only. The right ear uses the same HRIRs but in
-reverse (ie, left = angle, right = 360-angle).
-
-The actual coefficients follow. Each coefficient is a signed 16-bit sample,
-with each HRIR being a consecutive number of sample points. The HRIRs must be
-minimum-phase. This allows the use of a smaller filter length, reducing
-computation. For reference, the built-in data set uses a 32-point filter while
-even the smallest data set provided by MIT used a 128-sample filter (a 4x
-reduction by applying minimum-phase reconstruction). Theoretically, one could
-further reduce the minimum-phase version down to a 16-point filter with only a
-small reduction in quality.
-
-After the coefficients is an array of unsigned 8-bit delay values, one for
-each HRIR. This is the propagation delay (in samples) a signal must wait before
-being convolved with the corresponding minimum-phase HRIR filter.
diff --git a/hrtf/default-44100.mhr b/hrtf/default-44100.mhr
index e0d0bf4b..f7992e13 100644
--- a/hrtf/default-44100.mhr
+++ b/hrtf/default-44100.mhr
Binary files differ
diff --git a/hrtf/default-48000.mhr b/hrtf/default-48000.mhr
index 0ad547ad..66fd4f56 100644
--- a/hrtf/default-48000.mhr
+++ b/hrtf/default-48000.mhr
Binary files differ
diff --git a/include/AL/alext.h b/include/AL/alext.h
index 6af581aa..cd7f2750 100644
--- a/include/AL/alext.h
+++ b/include/AL/alext.h
@@ -97,6 +97,31 @@ extern "C" {
#ifndef AL_EXT_MCFORMATS
#define AL_EXT_MCFORMATS 1
+/* Provides support for surround sound buffer formats with 8, 16, and 32-bit
+ * samples.
+ *
+ * QUAD8: Unsigned 8-bit, Quadraphonic (Front Left, Front Right, Rear Left,
+ * Rear Right).
+ * QUAD16: Signed 16-bit, Quadraphonic.
+ * QUAD32: 32-bit float, Quadraphonic.
+ * REAR8: Unsigned 8-bit, Rear Stereo (Rear Left, Rear Right).
+ * REAR16: Signed 16-bit, Rear Stereo.
+ * REAR32: 32-bit float, Rear Stereo.
+ * 51CHN8: Unsigned 8-bit, 5.1 Surround (Front Left, Front Right, Front Center,
+ * LFE, Side Left, Side Right). Note that some audio systems may label
+ * 5.1's Side channels as Rear or Surround; they are equivalent for the
+ * purposes of this extension.
+ * 51CHN16: Signed 16-bit, 5.1 Surround.
+ * 51CHN32: 32-bit float, 5.1 Surround.
+ * 61CHN8: Unsigned 8-bit, 6.1 Surround (Front Left, Front Right, Front Center,
+ * LFE, Rear Center, Side Left, Side Right).
+ * 61CHN16: Signed 16-bit, 6.1 Surround.
+ * 61CHN32: 32-bit float, 6.1 Surround.
+ * 71CHN8: Unsigned 8-bit, 7.1 Surround (Front Left, Front Right, Front Center,
+ * LFE, Rear Left, Rear Right, Side Left, Side Right).
+ * 71CHN16: Signed 16-bit, 7.1 Surround.
+ * 71CHN32: 32-bit float, 7.1 Surround.
+ */
#define AL_FORMAT_QUAD8 0x1204
#define AL_FORMAT_QUAD16 0x1205
#define AL_FORMAT_QUAD32 0x1206
@@ -395,6 +420,16 @@ ALC_API void ALC_APIENTRY alcDeviceResumeSOFT(ALCdevice *device);
#ifndef AL_EXT_BFORMAT
#define AL_EXT_BFORMAT 1
+/* Provides support for B-Format ambisonic buffers (first-order, FuMa scaling
+ * and layout).
+ *
+ * BFORMAT2D_8: Unsigned 8-bit, 3-channel non-periphonic (WXY).
+ * BFORMAT2D_16: Signed 16-bit, 3-channel non-periphonic (WXY).
+ * BFORMAT2D_FLOAT32: 32-bit float, 3-channel non-periphonic (WXY).
+ * BFORMAT3D_8: Unsigned 8-bit, 4-channel periphonic (WXYZ).
+ * BFORMAT3D_16: Signed 16-bit, 4-channel periphonic (WXYZ).
+ * BFORMAT3D_FLOAT32: 32-bit float, 4-channel periphonic (WXYZ).
+ */
#define AL_FORMAT_BFORMAT2D_8 0x20021
#define AL_FORMAT_BFORMAT2D_16 0x20022
#define AL_FORMAT_BFORMAT2D_FLOAT32 0x20023
@@ -431,6 +466,49 @@ ALC_API ALCboolean ALC_APIENTRY alcResetDeviceSOFT(ALCdevice *device, const ALCi
#endif
#endif
+#ifndef AL_SOFT_gain_clamp_ex
+#define AL_SOFT_gain_clamp_ex 1
+#define AL_GAIN_LIMIT_SOFT 0x200E
+#endif
+
+#ifndef AL_SOFT_source_resampler
+#define AL_SOFT_source_resampler
+#define AL_NUM_RESAMPLERS_SOFT 0x1210
+#define AL_DEFAULT_RESAMPLER_SOFT 0x1211
+#define AL_SOURCE_RESAMPLER_SOFT 0x1212
+#define AL_RESAMPLER_NAME_SOFT 0x1213
+typedef const ALchar* (AL_APIENTRY*LPALGETSTRINGISOFT)(ALenum pname, ALsizei index);
+#ifdef AL_ALEXT_PROTOTYPES
+AL_API const ALchar* AL_APIENTRY alGetStringiSOFT(ALenum pname, ALsizei index);
+#endif
+#endif
+
+#ifndef AL_SOFT_source_spatialize
+#define AL_SOFT_source_spatialize
+#define AL_SOURCE_SPATIALIZE_SOFT 0x1214
+#define AL_AUTO_SOFT 0x0002
+#endif
+
+#ifndef ALC_SOFT_output_limiter
+#define ALC_SOFT_output_limiter
+#define ALC_OUTPUT_LIMITER_SOFT 0x199A
+#endif
+
+#ifndef ALC_SOFT_device_clock
+#define ALC_SOFT_device_clock 1
+typedef int64_t ALCint64SOFT;
+typedef uint64_t ALCuint64SOFT;
+#define ALC_DEVICE_CLOCK_SOFT 0x1600
+#define ALC_DEVICE_LATENCY_SOFT 0x1601
+#define ALC_DEVICE_CLOCK_LATENCY_SOFT 0x1602
+#define AL_SAMPLE_OFFSET_CLOCK_SOFT 0x1202
+#define AL_SEC_OFFSET_CLOCK_SOFT 0x1203
+typedef void (ALC_APIENTRY*LPALCGETINTEGER64VSOFT)(ALCdevice *device, ALCenum pname, ALsizei size, ALCint64SOFT *values);
+#ifdef AL_ALEXT_PROTOTYPES
+ALC_API void ALC_APIENTRY alcGetInteger64vSOFT(ALCdevice *device, ALCenum pname, ALsizei size, ALCint64SOFT *values);
+#endif
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/include/atomic.h b/include/atomic.h
deleted file mode 100644
index 8eb6820b..00000000
--- a/include/atomic.h
+++ /dev/null
@@ -1,334 +0,0 @@
-#ifndef AL_ATOMIC_H
-#define AL_ATOMIC_H
-
-#include "static_assert.h"
-#include "bool.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Atomics using C11 */
-#ifdef HAVE_C11_ATOMIC
-
-#include <stdatomic.h>
-
-#define almemory_order memory_order
-#define almemory_order_relaxed memory_order_relaxed
-#define almemory_order_consume memory_order_consume
-#define almemory_order_acquire memory_order_acquire
-#define almemory_order_release memory_order_release
-#define almemory_order_acq_rel memory_order_acq_rel
-#define almemory_order_seq_cst memory_order_seq_cst
-
-#define ATOMIC(T) T _Atomic
-
-#define ATOMIC_INIT(_val, _newval) atomic_init((_val), (_newval))
-#define ATOMIC_INIT_STATIC(_newval) ATOMIC_VAR_INIT(_newval)
-
-#define PARAM2(f, a, b, ...) (f((a), (b)))
-#define PARAM3(f, a, b, c, ...) (f((a), (b), (c)))
-#define PARAM5(f, a, b, c, d, e, ...) (f((a), (b), (c), (d), (e)))
-
-#define ATOMIC_LOAD(...) PARAM2(atomic_load_explicit, __VA_ARGS__, memory_order_seq_cst)
-#define ATOMIC_STORE(...) PARAM3(atomic_store_explicit, __VA_ARGS__, memory_order_seq_cst)
-
-#define ATOMIC_ADD(T, ...) PARAM3(atomic_fetch_add_explicit, __VA_ARGS__, memory_order_seq_cst)
-#define ATOMIC_SUB(T, ...) PARAM3(atomic_fetch_sub_explicit, __VA_ARGS__, memory_order_seq_cst)
-
-#define ATOMIC_EXCHANGE(T, ...) PARAM3(atomic_exchange_explicit, __VA_ARGS__, memory_order_seq_cst)
-#define ATOMIC_COMPARE_EXCHANGE_STRONG(T, ...) \
- PARAM5(atomic_compare_exchange_strong_explicit, __VA_ARGS__, memory_order_seq_cst, memory_order_seq_cst)
-#define ATOMIC_COMPARE_EXCHANGE_WEAK(T, ...) \
- PARAM5(atomic_compare_exchange_weak_explicit, __VA_ARGS__, memory_order_seq_cst, memory_order_seq_cst)
-
-/* Atomics using GCC intrinsics */
-#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && !defined(__QNXNTO__)
-
-enum almemory_order {
- almemory_order_relaxed,
- almemory_order_consume,
- almemory_order_acquire,
- almemory_order_release,
- almemory_order_acq_rel,
- almemory_order_seq_cst
-};
-
-#define ATOMIC(T) struct { T volatile value; }
-
-#define ATOMIC_INIT(_val, _newval) do { (_val)->value = (_newval); } while(0)
-#define ATOMIC_INIT_STATIC(_newval) {(_newval)}
-
-#define ATOMIC_LOAD(_val, ...) __extension__({ \
- __typeof((_val)->value) _r = (_val)->value; \
- __asm__ __volatile__("" ::: "memory"); \
- _r; \
-})
-#define ATOMIC_STORE(_val, _newval, ...) do { \
- __asm__ __volatile__("" ::: "memory"); \
- (_val)->value = (_newval); \
-} while(0)
-
-#define ATOMIC_ADD(T, _val, _incr, ...) __extension__({ \
- static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
- __sync_fetch_and_add(&(_val)->value, (_incr)); \
-})
-#define ATOMIC_SUB(T, _val, _decr, ...) __extension__({ \
- static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
- __sync_fetch_and_sub(&(_val)->value, (_decr)); \
-})
-
-#define ATOMIC_EXCHANGE(T, _val, _newval, ...) __extension__({ \
- static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
- __sync_lock_test_and_set(&(_val)->value, (_newval)); \
-})
-#define ATOMIC_COMPARE_EXCHANGE_STRONG(T, _val, _oldval, _newval, ...) __extension__({ \
- static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
- T _o = *(_oldval); \
- *(_oldval) = __sync_val_compare_and_swap(&(_val)->value, _o, (_newval)); \
- *(_oldval) == _o; \
-})
-
-/* Atomics using x86/x86-64 GCC inline assembly */
-#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
-
-#define WRAP_ADD(ret, dest, incr) __asm__ __volatile__( \
- "lock; xaddl %0,(%1)" \
- : "=r" (ret) \
- : "r" (dest), "0" (incr) \
- : "memory" \
-)
-#define WRAP_SUB(ret, dest, decr) __asm__ __volatile__( \
- "lock; xaddl %0,(%1)" \
- : "=r" (ret) \
- : "r" (dest), "0" (-(decr)) \
- : "memory" \
-)
-
-#define WRAP_XCHG(S, ret, dest, newval) __asm__ __volatile__( \
- "lock; xchg"S" %0,(%1)" \
- : "=r" (ret) \
- : "r" (dest), "0" (newval) \
- : "memory" \
-)
-#define WRAP_CMPXCHG(S, ret, dest, oldval, newval) __asm__ __volatile__( \
- "lock; cmpxchg"S" %2,(%1)" \
- : "=a" (ret) \
- : "r" (dest), "r" (newval), "0" (oldval) \
- : "memory" \
-)
-
-
-enum almemory_order {
- almemory_order_relaxed,
- almemory_order_consume,
- almemory_order_acquire,
- almemory_order_release,
- almemory_order_acq_rel,
- almemory_order_seq_cst
-};
-
-#define ATOMIC(T) struct { T volatile value; }
-
-#define ATOMIC_INIT(_val, _newval) do { (_val)->value = (_newval); } while(0)
-#define ATOMIC_INIT_STATIC(_newval) {(_newval)}
-
-#define ATOMIC_LOAD(_val, ...) __extension__({ \
- __typeof((_val)->value) _r = (_val)->value; \
- __asm__ __volatile__("" ::: "memory"); \
- _r; \
-})
-#define ATOMIC_STORE(_val, _newval, ...) do { \
- __asm__ __volatile__("" ::: "memory"); \
- (_val)->value = (_newval); \
-} while(0)
-
-#define ATOMIC_ADD(T, _val, _incr, ...) __extension__({ \
- static_assert(sizeof(T)==4, "Type "#T" has incorrect size!"); \
- static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
- T _r; \
- WRAP_ADD(_r, &(_val)->value, (T)(_incr)); \
- _r; \
-})
-#define ATOMIC_SUB(T, _val, _decr, ...) __extension__({ \
- static_assert(sizeof(T)==4, "Type "#T" has incorrect size!"); \
- static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
- T _r; \
- WRAP_SUB(_r, &(_val)->value, (T)(_decr)); \
- _r; \
-})
-
-#define ATOMIC_EXCHANGE(T, _val, _newval, ...) __extension__({ \
- static_assert(sizeof(T)==4 || sizeof(T)==8, "Type "#T" has incorrect size!"); \
- static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
- T _r; \
- if(sizeof(T) == 4) WRAP_XCHG("l", _r, &(_val)->value, (T)(_newval)); \
- else if(sizeof(T) == 8) WRAP_XCHG("q", _r, &(_val)->value, (T)(_newval)); \
- _r; \
-})
-#define ATOMIC_COMPARE_EXCHANGE_STRONG(T, _val, _oldval, _newval, ...) __extension__({ \
- static_assert(sizeof(T)==4 || sizeof(T)==8, "Type "#T" has incorrect size!"); \
- static_assert(sizeof(T)==sizeof((_val)->value), "Type "#T" has incorrect size!"); \
- T _old = *(_oldval); \
- if(sizeof(T) == 4) WRAP_CMPXCHG("l", *(_oldval), &(_val)->value, _old, (T)(_newval)); \
- else if(sizeof(T) == 8) WRAP_CMPXCHG("q", *(_oldval), &(_val)->value, _old, (T)(_newval)); \
- *(_oldval) == _old; \
-})
-
-/* Atomics using Windows methods */
-#elif defined(_WIN32)
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-/* NOTE: This mess is *extremely* noisy, at least on GCC. It works by wrapping
- * Windows' 32-bit and 64-bit atomic methods, which are then casted to use the
- * given type based on its size (e.g. int and float use 32-bit atomics). This
- * is fine for the swap and compare-and-swap methods, although the add and
- * subtract methods only work properly for integer types.
- *
- * Despite how noisy it is, it's unfortunately the only way that doesn't rely
- * on C99 (damn MSVC).
- */
-
-inline LONG AtomicAdd32(volatile LONG *dest, LONG incr)
-{
- return InterlockedExchangeAdd(dest, incr);
-}
-inline LONG AtomicSub32(volatile LONG *dest, LONG decr)
-{
- return InterlockedExchangeAdd(dest, -decr);
-}
-
-inline LONG AtomicSwap32(volatile LONG *dest, LONG newval)
-{
- return InterlockedExchange(dest, newval);
-}
-inline LONGLONG AtomicSwap64(volatile LONGLONG *dest, LONGLONG newval)
-{
- return InterlockedExchange64(dest, newval);
-}
-
-inline bool CompareAndSwap32(volatile LONG *dest, LONG newval, LONG *oldval)
-{
- LONG old = *oldval;
- *oldval = InterlockedCompareExchange(dest, newval, *oldval);
- return old == *oldval;
-}
-inline bool CompareAndSwap64(volatile LONGLONG *dest, LONGLONG newval, LONGLONG *oldval)
-{
- LONGLONG old = *oldval;
- *oldval = InterlockedCompareExchange64(dest, newval, *oldval);
- return old == *oldval;
-}
-
-#define WRAP_ADDSUB(T, _func, _ptr, _amnt) ((T(*)(T volatile*,T))_func)((_ptr), (_amnt))
-#define WRAP_XCHG(T, _func, _ptr, _newval) ((T(*)(T volatile*,T))_func)((_ptr), (_newval))
-#define WRAP_CMPXCHG(T, _func, _ptr, _newval, _oldval) ((bool(*)(T volatile*,T,T*))_func)((_ptr), (_newval), (_oldval))
-
-
-enum almemory_order {
- almemory_order_relaxed,
- almemory_order_consume,
- almemory_order_acquire,
- almemory_order_release,
- almemory_order_acq_rel,
- almemory_order_seq_cst
-};
-
-#define ATOMIC(T) struct { T volatile value; }
-
-#define ATOMIC_INIT(_val, _newval) do { (_val)->value = (_newval); } while(0)
-#define ATOMIC_INIT_STATIC(_newval) {(_newval)}
-
-#define ATOMIC_LOAD(_val, ...) ((_val)->value)
-#define ATOMIC_STORE(_val, _newval, ...) do { \
- (_val)->value = (_newval); \
-} while(0)
-
-int _al_invalid_atomic_size(); /* not defined */
-
-#define ATOMIC_ADD(T, _val, _incr, ...) \
- ((sizeof(T)==4) ? WRAP_ADDSUB(T, AtomicAdd32, &(_val)->value, (_incr)) : \
- (T)_al_invalid_atomic_size())
-#define ATOMIC_SUB(T, _val, _decr, ...) \
- ((sizeof(T)==4) ? WRAP_ADDSUB(T, AtomicSub32, &(_val)->value, (_decr)) : \
- (T)_al_invalid_atomic_size())
-
-#define ATOMIC_EXCHANGE(T, _val, _newval, ...) \
- ((sizeof(T)==4) ? WRAP_XCHG(T, AtomicSwap32, &(_val)->value, (_newval)) : \
- (sizeof(T)==8) ? WRAP_XCHG(T, AtomicSwap64, &(_val)->value, (_newval)) : \
- (T)_al_invalid_atomic_size())
-#define ATOMIC_COMPARE_EXCHANGE_STRONG(T, _val, _oldval, _newval, ...) \
- ((sizeof(T)==4) ? WRAP_CMPXCHG(T, CompareAndSwap32, &(_val)->value, (_newval), (_oldval)) : \
- (sizeof(T)==8) ? WRAP_CMPXCHG(T, CompareAndSwap64, &(_val)->value, (_newval), (_oldval)) : \
- (bool)_al_invalid_atomic_size())
-
-#else
-
-#error "No atomic functions available on this platform!"
-
-#define ATOMIC(T) T
-
-#define ATOMIC_INIT_STATIC(_newval) (0)
-
-#define ATOMIC_LOAD_UNSAFE(_val) (0)
-#define ATOMIC_STORE_UNSAFE(_val, _newval) ((void)0)
-
-#define ATOMIC_LOAD(_val, ...) (0)
-#define ATOMIC_STORE(_val, _newval, ...) ((void)0)
-
-#define ATOMIC_ADD(T, _val, _incr, ...) (0)
-#define ATOMIC_SUB(T, _val, _decr, ...) (0)
-
-#define ATOMIC_EXCHANGE(T, _val, _newval, ...) (0)
-#define ATOMIC_COMPARE_EXCHANGE_STRONG(T, _val, _oldval, _newval, ...) (0)
-#endif
-
-/* If no weak cmpxchg is provided (not all systems will have one), substitute a
- * strong cmpxchg. */
-#ifndef ATOMIC_COMPARE_EXCHANGE_WEAK
-#define ATOMIC_COMPARE_EXCHANGE_WEAK ATOMIC_COMPARE_EXCHANGE_STRONG
-#endif
-
-
-typedef unsigned int uint;
-typedef ATOMIC(uint) RefCount;
-
-inline void InitRef(RefCount *ptr, uint value)
-{ ATOMIC_INIT(ptr, value); }
-inline uint ReadRef(RefCount *ptr)
-{ return ATOMIC_LOAD(ptr); }
-inline uint IncrementRef(RefCount *ptr)
-{ return ATOMIC_ADD(uint, ptr, 1)+1; }
-inline uint DecrementRef(RefCount *ptr)
-{ return ATOMIC_SUB(uint, ptr, 1)-1; }
-
-
-/* NOTE: Not atomic! */
-inline int ExchangeInt(volatile int *ptr, int newval)
-{
- int old = *ptr;
- *ptr = newval;
- return old;
-}
-
-typedef void *volatile XchgPtr;
-/* NOTE: Not atomic! */
-inline void *ExchangePtr(XchgPtr *ptr, void *newval)
-{
- void *old = *ptr;
- *ptr = newval;
- return old;
-}
-
-/* This is *NOT* atomic, but is a handy utility macro to compare-and-swap non-
- * atomic variables. */
-#define COMPARE_EXCHANGE(_val, _oldval, _newval) ((*(_val) == *(_oldval)) ? ((*(_val)=(_newval)),true) : ((*(_oldval)=*(_val)),false))
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* AL_ATOMIC_H */
diff --git a/include/math_defs.h b/include/math_defs.h
deleted file mode 100644
index 149cf80b..00000000
--- a/include/math_defs.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#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 */
diff --git a/include/uintmap.h b/include/uintmap.h
deleted file mode 100644
index 2c4c5e7a..00000000
--- a/include/uintmap.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#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 *LookupUIntMapKey(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 */
diff --git a/native-tools/CMakeLists.txt b/native-tools/CMakeLists.txt
new file mode 100644
index 00000000..5e816bba
--- /dev/null
+++ b/native-tools/CMakeLists.txt
@@ -0,0 +1,29 @@
+cmake_minimum_required(VERSION 3.0.2)
+
+project(native-tools)
+
+include(CheckLibraryExists)
+
+set(CPP_DEFS )
+if(WIN32)
+ set(CPP_DEFS ${CPP_DEFS} _WIN32)
+endif(WIN32)
+
+check_library_exists(m pow "" HAVE_LIBM)
+
+add_executable(bin2h bin2h.c)
+# Enforce no dressing for executable names, so the main script can find it
+set_target_properties(bin2h PROPERTIES OUTPUT_NAME bin2h)
+# Avoid configuration-dependent subdirectories while building with Visual Studio
+set_target_properties(bin2h PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}")
+set_target_properties(bin2h PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}")
+target_compile_definitions(bin2h PRIVATE ${CPP_DEFS})
+
+add_executable(bsincgen bsincgen.c)
+set_target_properties(bsincgen PROPERTIES OUTPUT_NAME bsincgen)
+set_target_properties(bsincgen PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}")
+set_target_properties(bsincgen PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}")
+target_compile_definitions(bsincgen PRIVATE ${CPP_DEFS})
+if(HAVE_LIBM)
+ target_link_libraries(bsincgen m)
+endif(HAVE_LIBM)
diff --git a/native-tools/bin2h.c b/native-tools/bin2h.c
new file mode 100644
index 00000000..92f2b8a5
--- /dev/null
+++ b/native-tools/bin2h.c
@@ -0,0 +1,100 @@
+
+#ifdef _MSC_VER
+#define _CRT_SECURE_NO_WARNINGS
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+int main (int argc, char *argv[])
+{
+ char* input_name;
+ FILE* input_file;
+
+ char* output_name;
+ FILE* output_file;
+
+ char* variable_name;
+
+ if (4 != argc)
+ {
+ puts("Usage: bin2h [input] [output] [variable]");
+ return EXIT_FAILURE;
+ }
+
+ input_name = argv[1];
+ output_name = argv[2];
+ variable_name = argv[3];
+
+ input_file = fopen(input_name, "rb");
+
+ if (NULL == input_file)
+ {
+ printf("Could not open input file '%s': %s\n", input_name, strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ output_file = fopen(output_name, "w");
+
+ if (NULL == output_file)
+ {
+ printf("Could not open output file '%s': %s\n", output_name, strerror(errno));
+ return EXIT_FAILURE;
+ }
+
+ if (fprintf(output_file, "static const unsigned char %s[] = {", variable_name) < 0)
+ {
+ printf("Could not write to output file '%s': %s\n", output_name, strerror(ferror(output_file)));
+ return EXIT_FAILURE;
+ }
+
+ while (0 == feof(input_file))
+ {
+ unsigned char buffer[4096];
+ size_t i, count = fread(buffer, 1, sizeof(buffer), input_file);
+
+ if (sizeof(buffer) != count)
+ {
+ if (0 == feof(input_file) || 0 != ferror(input_file))
+ {
+ printf("Could not read from input file '%s': %s\n", input_name, strerror(ferror(input_file)));
+ return EXIT_FAILURE;
+ }
+ }
+
+ for (i = 0; i < count; ++i)
+ {
+ if ((i & 15) == 0)
+ {
+ if (fprintf(output_file, "\n ") < 0)
+ {
+ printf("Could not write to output file '%s': %s\n", output_name, strerror(ferror(output_file)));
+ return EXIT_FAILURE;
+ }
+ }
+
+ if (fprintf(output_file, "0x%2.2x, ", buffer[i]) < 0)
+ {
+ printf("Could not write to output file '%s': %s\n", output_name, strerror(ferror(output_file)));
+ return EXIT_FAILURE;
+ }
+
+ }
+ }
+
+ if (fprintf(output_file, "\n};\n") < 0)
+ {
+ printf("Could not write to output file '%s': %s\n", output_name, strerror(ferror(output_file)));
+ return EXIT_FAILURE;
+ }
+
+ if (fclose(output_file) < 0)
+ {
+ printf("Could not close output file '%s': %s\n", output_name, strerror(ferror(output_file)));
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/native-tools/bsincgen.c b/native-tools/bsincgen.c
new file mode 100644
index 00000000..72bd8183
--- /dev/null
+++ b/native-tools/bsincgen.c
@@ -0,0 +1,367 @@
+/*
+ * Sinc interpolator coefficient and delta generator for the OpenAL Soft
+ * cross platform audio library.
+ *
+ * Copyright (C) 2015 by Christopher Fitzgerald.
+ *
+ * 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 visit: http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html
+ *
+ * --------------------------------------------------------------------------
+ *
+ * This is a modified version of the bandlimited windowed sinc interpolator
+ * algorithm presented here:
+ *
+ * Smith, J.O. "Windowed Sinc Interpolation", in
+ * Physical Audio Signal Processing,
+ * https://ccrma.stanford.edu/~jos/pasp/Windowed_Sinc_Interpolation.html,
+ * online book,
+ * accessed October 2012.
+ */
+
+#define _UNICODE
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "../common/win_main_utf8.h"
+
+
+#ifndef M_PI
+#define M_PI (3.14159265358979323846)
+#endif
+
+#if !(defined(_ISOC99_SOURCE) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L))
+#define log2(x) (log(x) / log(2.0))
+#endif
+
+/* Same as in alu.h! */
+#define FRACTIONBITS (12)
+#define FRACTIONONE (1<<FRACTIONBITS)
+
+// The number of distinct scale and phase intervals within the filter table.
+// Must be the same as in alu.h!
+#define BSINC_SCALE_COUNT (16)
+#define BSINC_PHASE_COUNT (16)
+
+/* 48 points includes the doubling for downsampling, so the maximum number of
+ * base sample points is 24, which is 23rd order.
+ */
+#define BSINC_POINTS_MAX (48)
+
+static double MinDouble(double a, double b)
+{ return (a <= b) ? a : b; }
+
+static double MaxDouble(double a, double b)
+{ return (a >= b) ? a : b; }
+
+/* NOTE: This is the normalized (instead of just sin(x)/x) cardinal sine
+ * function.
+ * 2 f_t sinc(2 f_t x)
+ * f_t -- normalized transition frequency (0.5 is nyquist)
+ * x -- sample index (-N to N)
+ */
+static double Sinc(const double x)
+{
+ if(fabs(x) < 1e-15)
+ return 1.0;
+ return sin(M_PI * x) / (M_PI * x);
+}
+
+static double BesselI_0(const double x)
+{
+ double term, sum, last_sum, x2, y;
+ int i;
+
+ term = 1.0;
+ sum = 1.0;
+ x2 = x / 2.0;
+ i = 1;
+
+ do {
+ y = x2 / i;
+ i++;
+ last_sum = sum;
+ term *= y * y;
+ sum += term;
+ } while(sum != last_sum);
+
+ return sum;
+}
+
+/* NOTE: k is assumed normalized (-1 to 1)
+ * beta is equivalent to 2 alpha
+ */
+static double Kaiser(const double b, const double k)
+{
+ if(!(k >= -1.0 && k <= 1.0))
+ return 0.0;
+ return BesselI_0(b * sqrt(1.0 - k*k)) / BesselI_0(b);
+}
+
+/* Calculates the (normalized frequency) transition width of the Kaiser window.
+ * Rejection is in dB.
+ */
+static double CalcKaiserWidth(const double rejection, const int order)
+{
+ double w_t = 2.0 * M_PI;
+
+ if(rejection > 21.0)
+ return (rejection - 7.95) / (order * 2.285 * w_t);
+ /* This enforces a minimum rejection of just above 21.18dB */
+ return 5.79 / (order * w_t);
+}
+
+static double CalcKaiserBeta(const double rejection)
+{
+ if(rejection > 50.0)
+ return 0.1102 * (rejection - 8.7);
+ else if(rejection >= 21.0)
+ return (0.5842 * pow(rejection - 21.0, 0.4)) +
+ (0.07886 * (rejection - 21.0));
+ return 0.0;
+}
+
+/* Generates the coefficient, delta, and index tables required by the bsinc resampler */
+static void BsiGenerateTables(FILE *output, const char *tabname, const double rejection, const int order)
+{
+ static double filter[BSINC_SCALE_COUNT][BSINC_PHASE_COUNT + 1][BSINC_POINTS_MAX];
+ static double scDeltas[BSINC_SCALE_COUNT][BSINC_PHASE_COUNT ][BSINC_POINTS_MAX];
+ static double phDeltas[BSINC_SCALE_COUNT][BSINC_PHASE_COUNT + 1][BSINC_POINTS_MAX];
+ static double spDeltas[BSINC_SCALE_COUNT][BSINC_PHASE_COUNT ][BSINC_POINTS_MAX];
+ static int mt[BSINC_SCALE_COUNT];
+ static double at[BSINC_SCALE_COUNT];
+ const int num_points_min = order + 1;
+ double width, beta, scaleBase, scaleRange;
+ int si, pi, i;
+
+ memset(filter, 0, sizeof(filter));
+ memset(scDeltas, 0, sizeof(scDeltas));
+ memset(phDeltas, 0, sizeof(phDeltas));
+ memset(spDeltas, 0, sizeof(spDeltas));
+
+ /* Calculate windowing parameters. The width describes the transition
+ band, but it may vary due to the linear interpolation between scales
+ of the filter.
+ */
+ width = CalcKaiserWidth(rejection, order);
+ beta = CalcKaiserBeta(rejection);
+ scaleBase = width / 2.0;
+ scaleRange = 1.0 - scaleBase;
+
+ // Determine filter scaling.
+ for(si = 0; si < BSINC_SCALE_COUNT; si++)
+ {
+ const double scale = scaleBase + (scaleRange * si / (BSINC_SCALE_COUNT - 1));
+ const double a = MinDouble(floor(num_points_min / (2.0 * scale)), num_points_min);
+ const int m = 2 * (int)a;
+
+ mt[si] = m;
+ at[si] = a;
+ }
+
+ /* Calculate the Kaiser-windowed Sinc filter coefficients for each scale
+ and phase.
+ */
+ for(si = 0; si < BSINC_SCALE_COUNT; si++)
+ {
+ const int m = mt[si];
+ const int o = num_points_min - (m / 2);
+ const int l = (m / 2) - 1;
+ const double a = at[si];
+ const double scale = scaleBase + (scaleRange * si / (BSINC_SCALE_COUNT - 1));
+ const double cutoff = (0.5 * scale) - (scaleBase * MaxDouble(0.5, scale));
+
+ for(pi = 0; pi <= BSINC_PHASE_COUNT; pi++)
+ {
+ const double phase = l + ((double)pi / BSINC_PHASE_COUNT);
+
+ for(i = 0; i < m; i++)
+ {
+ const double x = i - phase;
+ filter[si][pi][o + i] = Kaiser(beta, x / a) * 2.0 * cutoff * Sinc(2.0 * cutoff * x);
+ }
+ }
+ }
+
+ /* Linear interpolation between scales is simplified by pre-calculating
+ the delta (b - a) in: x = a + f (b - a)
+
+ Given a difference in points between scales, the destination points
+ will be 0, thus: x = a + f (-a)
+ */
+ for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++)
+ {
+ const int m = mt[si];
+ const int o = num_points_min - (m / 2);
+
+ for(pi = 0; pi < BSINC_PHASE_COUNT; pi++)
+ {
+ for(i = 0; i < m; i++)
+ scDeltas[si][pi][o + i] = filter[si + 1][pi][o + i] - filter[si][pi][o + i];
+ }
+ }
+
+ // Linear interpolation between phases is also simplified.
+ for(si = 0; si < BSINC_SCALE_COUNT; si++)
+ {
+ const int m = mt[si];
+ const int o = num_points_min - (m / 2);
+
+ for(pi = 0; pi < BSINC_PHASE_COUNT; pi++)
+ {
+ for(i = 0; i < m; i++)
+ phDeltas[si][pi][o + i] = filter[si][pi + 1][o + i] - filter[si][pi][o + i];
+ }
+ }
+
+ /* This last simplification is done to complete the bilinear equation for
+ the combination of scale and phase.
+ */
+ for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++)
+ {
+ const int m = mt[si];
+ const int o = num_points_min - (m / 2);
+
+ for(pi = 0; pi < BSINC_PHASE_COUNT; pi++)
+ {
+ for(i = 0; i < m; i++)
+ spDeltas[si][pi][o + i] = phDeltas[si + 1][pi][o + i] - phDeltas[si][pi][o + i];
+ }
+ }
+
+ // Make sure the number of points is a multiple of 4 (for SIMD).
+ for(si = 0; si < BSINC_SCALE_COUNT; si++)
+ mt[si] = (mt[si]+3) & ~3;
+
+ fprintf(output,
+"/* This %d%s order filter has a rejection of -%.0fdB, yielding a transition width\n"
+" * of ~%.3f (normalized frequency). Order increases when downsampling to a\n"
+" * limit of one octave, after which the quality of the filter (transition\n"
+" * width) suffers to reduce the CPU cost. The bandlimiting will cut all sound\n"
+" * after downsampling by ~%.2f octaves.\n"
+" */\n"
+"const BSincTable %s = {\n",
+ order, (((order%100)/10) == 1) ? "th" :
+ ((order%10) == 1) ? "st" :
+ ((order%10) == 2) ? "nd" :
+ ((order%10) == 3) ? "rd" : "th",
+ rejection, width, log2(1.0/scaleBase), tabname);
+
+ /* The scaleBase is calculated from the Kaiser window transition width.
+ It represents the absolute limit to the filter before it fully cuts
+ the signal. The limit in octaves can be calculated by taking the
+ base-2 logarithm of its inverse: log_2(1 / scaleBase)
+ */
+ fprintf(output, " /* scaleBase */ %.9ef, /* scaleRange */ %.9ef,\n", scaleBase, 1.0 / scaleRange);
+
+ fprintf(output, " /* m */ {");
+ fprintf(output, " %d", mt[0]);
+ for(si = 1; si < BSINC_SCALE_COUNT; si++)
+ fprintf(output, ", %d", mt[si]);
+ fprintf(output, " },\n");
+
+ fprintf(output, " /* filterOffset */ {");
+ fprintf(output, " %d", 0);
+ i = mt[0]*4*BSINC_PHASE_COUNT;
+ for(si = 1; si < BSINC_SCALE_COUNT; si++)
+ {
+ fprintf(output, ", %d", i);
+ i += mt[si]*4*BSINC_PHASE_COUNT;
+ }
+
+ fprintf(output, " },\n");
+
+ // Calculate the table size.
+ i = 0;
+ for(si = 0; si < BSINC_SCALE_COUNT; si++)
+ i += 4 * BSINC_PHASE_COUNT * mt[si];
+
+ fprintf(output, "\n /* Tab (%d entries) */ {\n", i);
+ for(si = 0; si < BSINC_SCALE_COUNT; si++)
+ {
+ const int m = mt[si];
+ const int o = num_points_min - (m / 2);
+
+ for(pi = 0; pi < BSINC_PHASE_COUNT; pi++)
+ {
+ fprintf(output, " /* %2d,%2d (%d) */", si, pi, m);
+ fprintf(output, "\n ");
+ for(i = 0; i < m; i++)
+ fprintf(output, " %+14.9ef,", filter[si][pi][o + i]);
+ fprintf(output, "\n ");
+ for(i = 0; i < m; i++)
+ fprintf(output, " %+14.9ef,", scDeltas[si][pi][o + i]);
+ fprintf(output, "\n ");
+ for(i = 0; i < m; i++)
+ fprintf(output, " %+14.9ef,", phDeltas[si][pi][o + i]);
+ fprintf(output, "\n ");
+ for(i = 0; i < m; i++)
+ fprintf(output, " %+14.9ef,", spDeltas[si][pi][o + i]);
+ fprintf(output, "\n");
+ }
+ }
+ fprintf(output, " }\n};\n\n");
+}
+
+
+int main(int argc, char *argv[])
+{
+ FILE *output;
+
+ GET_UNICODE_ARGS(&argc, &argv);
+
+ if(argc > 2)
+ {
+ fprintf(stderr, "Usage: %s [output file]\n", argv[0]);
+ return 1;
+ }
+
+ if(argc == 2)
+ {
+ output = fopen(argv[1], "wb");
+ if(!output)
+ {
+ fprintf(stderr, "Failed to open %s for writing\n", argv[1]);
+ return 1;
+ }
+ }
+ else
+ output = stdout;
+
+ fprintf(output, "/* Generated by bsincgen, do not edit! */\n\n"
+"static_assert(BSINC_SCALE_COUNT == %d, \"Unexpected BSINC_SCALE_COUNT value!\");\n"
+"static_assert(BSINC_PHASE_COUNT == %d, \"Unexpected BSINC_PHASE_COUNT value!\");\n"
+"static_assert(FRACTIONONE == %d, \"Unexpected FRACTIONONE value!\");\n\n"
+"typedef struct BSincTable {\n"
+" const float scaleBase, scaleRange;\n"
+" const int m[BSINC_SCALE_COUNT];\n"
+" const int filterOffset[BSINC_SCALE_COUNT];\n"
+" alignas(16) const float Tab[];\n"
+"} BSincTable;\n\n", BSINC_SCALE_COUNT, BSINC_PHASE_COUNT, FRACTIONONE);
+ /* A 23rd order filter with a -60dB drop at nyquist. */
+ BsiGenerateTables(output, "bsinc24", 60.0, 23);
+ /* An 11th order filter with a -40dB drop at nyquist. */
+ BsiGenerateTables(output, "bsinc12", 40.0, 11);
+
+ if(output != stdout)
+ fclose(output);
+ output = NULL;
+
+ return 0;
+}
diff --git a/openal.pc.in b/openal.pc.in
index 8bdd4f3b..dfa6f573 100644
--- a/openal.pc.in
+++ b/openal.pc.in
@@ -8,4 +8,5 @@ Description: OpenAL is a cross-platform 3D audio API
Requires: @PKG_CONFIG_REQUIRES@
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -l@LIBNAME@ @PKG_CONFIG_LIBS@
+Libs.private:@PKG_CONFIG_PRIVATE_LIBS@
Cflags: -I${includedir} -I${includedir}/AL @PKG_CONFIG_CFLAGS@
diff --git a/presets/3D7.1.ambdec b/presets/3D7.1.ambdec
new file mode 100644
index 00000000..42b6a0bb
--- /dev/null
+++ b/presets/3D7.1.ambdec
@@ -0,0 +1,43 @@
+# AmbDec configuration
+# Written by Ambisonic Decoder Toolbox, version 8.0
+
+/description 3D7_2h1v_allrad_5200_rE_max_1_band
+
+/version 3
+
+/dec/chan_mask 1bf
+/dec/freq_bands 1
+/dec/speakers 7
+/dec/coeff_scale fuma
+
+/opt/input_scale fuma
+/opt/nfeff_comp output
+/opt/delay_comp on
+/opt/level_comp on
+/opt/xover_freq 400.000000
+/opt/xover_ratio 0.000000
+
+/speakers/{
+# id dist azim elev conn
+#-----------------------------------------------------------------------
+add_spkr LF 1.500000 51.000000 24.000000
+add_spkr RF 1.500000 -51.000000 24.000000
+add_spkr CE 1.500000 0.000000 0.000000
+add_spkr LB 1.500000 180.000000 55.000000
+add_spkr RB 1.500000 0.000000 -55.000000
+add_spkr LS 1.500000 129.000000 -24.000000
+add_spkr RS 1.500000 -129.000000 -24.000000
+/}
+
+/matrix/{
+order_gain 1.000000 0.774597 0.400000 0.000000
+add_row 0.325031 0.357638 0.206500 0.234037 0.202440 0.135692 0.116927 -0.098768
+add_row 0.325036 -0.357619 0.206537 0.234033 -0.202427 -0.135680 0.116934 -0.098768
+add_row 0.080073 -0.000010 -0.000296 0.155843 -0.000016 -0.000011 -0.000623 0.163306
+add_row 0.353556 0.000002 0.408453 -0.288377 -0.000004 -0.000003 -0.221039 0.077297
+add_row 0.325297 0.000008 -0.414018 0.232789 0.000004 0.000003 -0.232940 0.018311
+add_row 0.353558 0.352704 -0.203542 -0.290124 -0.191868 -0.134582 0.110616 -0.038294
+add_row 0.353556 -0.352691 -0.203576 -0.290115 0.191871 0.134585 0.110612 -0.038293
+/}
+
+/end
diff --git a/presets/hexagon.ambdec b/presets/hexagon.ambdec
new file mode 100644
index 00000000..d45f2732
--- /dev/null
+++ b/presets/hexagon.ambdec
@@ -0,0 +1,51 @@
+# AmbDec configuration
+# Written by Ambisonic Decoder Toolbox, version 8.0
+
+/description Hexagon_2h0p_pinv_match_rV_max_rE_2_band
+
+/version 3
+
+/dec/chan_mask 11b
+/dec/freq_bands 2
+/dec/speakers 6
+/dec/coeff_scale fuma
+
+/opt/input_scale fuma
+/opt/nfeff_comp input
+/opt/delay_comp on
+/opt/level_comp on
+/opt/xover_freq 400.000000
+/opt/xover_ratio 0.000000
+
+/speakers/{
+# id dist azim elev conn
+#-----------------------------------------------------------------------
+add_spkr LF 1.000000 30.000000 0.000000
+add_spkr RF 1.000000 -30.000000 0.000000
+add_spkr RS 1.000000 -90.000000 0.000000
+add_spkr RB 1.000000 -150.000000 0.000000
+add_spkr LB 1.000000 150.000000 0.000000
+add_spkr LS 1.000000 90.000000 0.000000
+/}
+
+/lfmatrix/{
+order_gain 1.000000 1.000000 1.000000 0.000000
+add_row 0.235702 0.166667 0.288675 0.288675 0.166667
+add_row 0.235702 -0.166667 0.288675 -0.288675 0.166667
+add_row 0.235702 -0.333333 0.000000 -0.000000 -0.333333
+add_row 0.235702 -0.166667 -0.288675 0.288675 0.166667
+add_row 0.235702 0.166667 -0.288675 -0.288675 0.166667
+add_row 0.235702 0.333333 0.000000 -0.000000 -0.333333
+/}
+
+/hfmatrix/{
+order_gain 1.414214 1.224745 0.707107 0.000000
+add_row 0.235702 0.166667 0.288675 0.288675 0.166667
+add_row 0.235702 -0.166667 0.288675 -0.288675 0.166667
+add_row 0.235702 -0.333333 0.000000 -0.000000 -0.333333
+add_row 0.235702 -0.166667 -0.288675 0.288675 0.166667
+add_row 0.235702 0.166667 -0.288675 -0.288675 0.166667
+add_row 0.235702 0.333333 0.000000 -0.000000 -0.333333
+/}
+
+/end
diff --git a/presets/itu5.1-nocenter.ambdec b/presets/itu5.1-nocenter.ambdec
new file mode 100644
index 00000000..23839d0e
--- /dev/null
+++ b/presets/itu5.1-nocenter.ambdec
@@ -0,0 +1,46 @@
+# AmbDec configuration
+# Written by Ambisonic Decoder Toolbox, version 8.0
+
+# input channel order: WYXVU
+
+/description itu50-noCenter_2h0p_allrad_5200_rE_max_1_band
+
+# Although unused in this configuration, the front-center is declared here so
+# that an appropriate distance may be set (for proper delaying or attenuating
+# of dialog and such which feed it directly). It otherwise does not contribute
+# to positional sound output.
+
+/version 3
+
+/dec/chan_mask 11b
+/dec/freq_bands 1
+/dec/speakers 5
+/dec/coeff_scale fuma
+
+/opt/input_scale fuma
+/opt/nfeff_comp input
+/opt/delay_comp on
+/opt/level_comp on
+/opt/xover_freq 400.000000
+/opt/xover_ratio 0.000000
+
+/speakers/{
+# id dist azim elev conn
+#-----------------------------------------------------------------------
+add_spkr LS 1.000000 110.000000 0.000000 system:playback_3
+add_spkr LF 1.000000 30.000000 0.000000 system:playback_1
+add_spkr CE 1.000000 0.000000 0.000000 system:playback_5
+add_spkr RF 1.000000 -30.000000 0.000000 system:playback_2
+add_spkr RS 1.000000 -110.000000 0.000000 system:playback_4
+/}
+
+/matrix/{
+order_gain 1.00000000e+00 8.66025404e-01 5.00000000e-01 0.000000
+add_row 4.70934222e-01 3.78169605e-01 -4.00084750e-01 -8.22264454e-02 -4.43765986e-02
+add_row 2.66639870e-01 2.55418584e-01 3.32591390e-01 2.82949132e-01 8.16816772e-02
+add_row 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
+add_row 2.66634915e-01 -2.55421639e-01 3.32586482e-01 -2.82947688e-01 8.16782588e-02
+add_row 4.70935891e-01 -3.78173080e-01 -4.00080588e-01 8.22279700e-02 -4.43716394e-02
+/}
+
+/end
diff --git a/presets/itu5.1.ambdec b/presets/itu5.1.ambdec
new file mode 100644
index 00000000..74386034
--- /dev/null
+++ b/presets/itu5.1.ambdec
@@ -0,0 +1,48 @@
+# AmbDec configuration
+# Written by Ambisonic Decoder Toolbox, version 8.0
+
+/description itu50_2h0p_allrad_5200_rE_max_1_band
+
+/version 3
+
+/dec/chan_mask 11b
+/dec/freq_bands 2
+/dec/speakers 5
+/dec/coeff_scale fuma
+
+/opt/input_scale fuma
+/opt/nfeff_comp output
+/opt/delay_comp on
+/opt/level_comp on
+/opt/xover_freq 400.000000
+/opt/xover_ratio 3.000000
+
+/speakers/{
+# id dist azim elev conn
+#-----------------------------------------------------------------------
+add_spkr LS 1.000000 110.000000 0.000000
+add_spkr LF 1.000000 30.000000 0.000000
+add_spkr CE 1.000000 0.000000 0.000000
+add_spkr RF 1.000000 -30.000000 0.000000
+add_spkr RS 1.000000 -110.000000 0.000000
+/}
+
+/lfmatrix/{
+order_gain 1.000000 1.000000 1.000000 0.000000
+add_row 0.420330 0.330200 -0.312250 0.019350 -0.027010
+add_row 0.197700 0.288820 0.287820 0.049110 0.007420
+add_row 0.058030 0.000000 0.205970 0.000000 0.050790
+add_row 0.197700 -0.288820 0.287820 -0.049110 0.007420
+add_row 0.420330 -0.330200 -0.312250 -0.019350 -0.027010
+/}
+
+/hfmatrix/{
+order_gain 1.000000 0.866025 0.500000 0.000000
+add_row 0.470934 0.378170 -0.400085 -0.082226 -0.044377
+add_row 0.208954 0.257988 0.230383 0.288520 -0.025085
+add_row 0.109403 -0.000002 0.194278 -0.000003 0.200863
+add_row 0.208950 -0.257989 0.230379 -0.288516 -0.025088
+add_row 0.470936 -0.378173 -0.400081 0.082228 -0.044372
+/}
+
+/end
diff --git a/presets/presets.txt b/presets/presets.txt
new file mode 100644
index 00000000..541416e2
--- /dev/null
+++ b/presets/presets.txt
@@ -0,0 +1,42 @@
+Ambisonic decoder configuration presets are provided here for common surround
+sound speaker layouts. The presets are prepared to work with OpenAL Soft's high
+quality decoder. By default all of the speaker distances within a preset are
+set to the same value, which results in no effect from distance compensation.
+If this doesn't match your physical speaker setup, it may be worth copying the
+preset and modifying the distance values to match (note that modifying the
+azimuth and elevation values in the presets will not have any effect; the
+specified angles do not change the decoder behavior).
+
+Details of the individual presets are as follows.
+
+square.ambdec
+Specifies a basic square speaker setup for Quadraphonic output, with identical
+width and depth. Front speakers are placed at +45 and -45 degrees, and back
+speakers are placed at +135 and -135 degrees.
+
+rectangle.ambdec
+Specifies a narrower speaker setup for Quadraphonic output, with a little less
+width but a little more depth over a basic square setup. Front speakers are
+placed at +30 and -30 degrees, providing a bit more compatibility for existing
+stereo content, with back speakers at +150 and -150 degrees.
+
+itu5.1.ambdec
+Specifies a standard ITU 5.0/5.1 setup for 5.1 Surround output. The front-
+center speaker is placed directly in front at 0 degrees, with the front-left
+and front-right at +30 and -30 degrees, and the surround speakers (side or
+back) at +110 and -110 degrees.
+
+hexagon.ambdec
+Specifies a flat-front hexagonal speaker setup for 7.1 Surround output. The
+front left and right speakers are placed at +30 and -30 degrees, the side
+speakers are placed at +90 and -90 degrees, and the back speakers are placed at
++150 and -150 degrees. Although this is for 7.1 output, no front-center speaker
+is defined for the decoder, meaning that speaker will be silent for 3D sound
+(however it may still be used with AL_SOFT_direct_channels or ALC_EXT_DEDICATED
+output). A "proper" 7.1 decoder may be provided in the future, but due to the
+nature of the speaker configuration will have trade-offs.
+
+3D7.1.ambdec
+Specifies a 3D7.1 speaker setup for 7.1 Surround output. Although it's for 7.1
+output, the speakers for such a configuration need to be placed in different
+positions for proper results. Please see docs/3D7.1.txt for more information.
diff --git a/presets/rectangle.ambdec b/presets/rectangle.ambdec
new file mode 100644
index 00000000..caf72318
--- /dev/null
+++ b/presets/rectangle.ambdec
@@ -0,0 +1,45 @@
+# AmbDec configuration
+# Written by Ambisonic Decoder Toolbox, version 8.0
+
+/description Rectangle_1h0p_pinv_match_rV_max_rE_2_band
+
+/version 3
+
+/dec/chan_mask b
+/dec/freq_bands 2
+/dec/speakers 4
+/dec/coeff_scale fuma
+
+/opt/input_scale fuma
+/opt/nfeff_comp input
+/opt/delay_comp on
+/opt/level_comp on
+/opt/xover_freq 400.000000
+/opt/xover_ratio 0.000000
+
+/speakers/{
+# id dist azim elev conn
+#-----------------------------------------------------------------------
+add_spkr LF 1.000000 30.000000 0.000000
+add_spkr RF 1.000000 -30.000000 0.000000
+add_spkr RB 1.000000 -150.000000 0.000000
+add_spkr LB 1.000000 150.000000 0.000000
+/}
+
+/lfmatrix/{
+order_gain 1.000000 1.000000 0.000000 0.000000
+add_row 0.353553 0.500000 0.288675
+add_row 0.353553 -0.500000 0.288675
+add_row 0.353553 -0.500000 -0.288675
+add_row 0.353553 0.500000 -0.288675
+/}
+
+/hfmatrix/{
+order_gain 1.414214 1.000000 0.000000 0.000000
+add_row 0.353553 0.500000 0.288675
+add_row 0.353553 -0.500000 0.288675
+add_row 0.353553 -0.500000 -0.288675
+add_row 0.353553 0.500000 -0.288675
+/}
+
+/end
diff --git a/presets/square.ambdec b/presets/square.ambdec
new file mode 100644
index 00000000..547ed367
--- /dev/null
+++ b/presets/square.ambdec
@@ -0,0 +1,45 @@
+# AmbDec configuration
+# Written by Ambisonic Decoder Toolbox, version 8.0
+
+/description Square_1h0p_pinv_match_rV_max_rE_2_band
+
+/version 3
+
+/dec/chan_mask b
+/dec/freq_bands 2
+/dec/speakers 4
+/dec/coeff_scale fuma
+
+/opt/input_scale fuma
+/opt/nfeff_comp input
+/opt/delay_comp on
+/opt/level_comp on
+/opt/xover_freq 400.000000
+/opt/xover_ratio 0.000000
+
+/speakers/{
+# id dist azim elev conn
+#-----------------------------------------------------------------------
+add_spkr LF 1.000000 45.000000 0.000000
+add_spkr RF 1.000000 -45.000000 0.000000
+add_spkr RB 1.000000 -135.000000 0.000000
+add_spkr LB 1.000000 135.000000 0.000000
+/}
+
+/lfmatrix/{
+order_gain 1.000000 1.000000 0.000000 0.000000
+add_row 0.353553 0.353553 0.353553
+add_row 0.353553 -0.353553 0.353553
+add_row 0.353553 -0.353553 -0.353553
+add_row 0.353553 0.353553 -0.353553
+/}
+
+/hfmatrix/{
+order_gain 1.414214 1.000000 0.000000 0.000000
+add_row 0.353553 0.353553 0.353553
+add_row 0.353553 -0.353553 0.353553
+add_row 0.353553 -0.353553 -0.353553
+add_row 0.353553 0.353553 -0.353553
+/}
+
+/end
diff --git a/router/al.c b/router/al.c
new file mode 100644
index 00000000..8dd888d9
--- /dev/null
+++ b/router/al.c
@@ -0,0 +1,132 @@
+
+#include "config.h"
+
+#include <stddef.h>
+
+#include "AL/al.h"
+#include "router.h"
+
+
+atomic_DriverIfacePtr CurrentCtxDriver = ATOMIC_INIT_STATIC(NULL);
+
+#define DECL_THUNK1(R,n,T1) AL_API R AL_APIENTRY n(T1 a) \
+{ \
+ DriverIface *iface = altss_get(ThreadCtxDriver); \
+ if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ return iface->n(a); \
+}
+#define DECL_THUNK2(R,n,T1,T2) AL_API R AL_APIENTRY n(T1 a, T2 b) \
+{ \
+ DriverIface *iface = altss_get(ThreadCtxDriver); \
+ if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ return iface->n(a, b); \
+}
+#define DECL_THUNK3(R,n,T1,T2,T3) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c) \
+{ \
+ DriverIface *iface = altss_get(ThreadCtxDriver); \
+ if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ return iface->n(a, b, c); \
+}
+#define DECL_THUNK4(R,n,T1,T2,T3,T4) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d) \
+{ \
+ DriverIface *iface = altss_get(ThreadCtxDriver); \
+ if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ return iface->n(a, b, c, d); \
+}
+#define DECL_THUNK5(R,n,T1,T2,T3,T4,T5) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d, T5 e) \
+{ \
+ DriverIface *iface = altss_get(ThreadCtxDriver); \
+ if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);\
+ return iface->n(a, b, c, d, e); \
+}
+
+
+/* Ugly hack for some apps calling alGetError without a current context, and
+ * expecting it to be AL_NO_ERROR.
+ */
+AL_API ALenum AL_APIENTRY alGetError(void)
+{
+ DriverIface *iface = altss_get(ThreadCtxDriver);
+ if(!iface) iface = ATOMIC_LOAD(&CurrentCtxDriver, almemory_order_acquire);
+ return iface ? iface->alGetError() : AL_NO_ERROR;
+}
+
+
+DECL_THUNK1(void, alDopplerFactor, ALfloat)
+DECL_THUNK1(void, alDopplerVelocity, ALfloat)
+DECL_THUNK1(void, alSpeedOfSound, ALfloat)
+DECL_THUNK1(void, alDistanceModel, ALenum)
+
+DECL_THUNK1(void, alEnable, ALenum)
+DECL_THUNK1(void, alDisable, ALenum)
+DECL_THUNK1(ALboolean, alIsEnabled, ALenum)
+
+DECL_THUNK1(const ALchar*, alGetString, ALenum)
+DECL_THUNK2(void, alGetBooleanv, ALenum, ALboolean*)
+DECL_THUNK2(void, alGetIntegerv, ALenum, ALint*)
+DECL_THUNK2(void, alGetFloatv, ALenum, ALfloat*)
+DECL_THUNK2(void, alGetDoublev, ALenum, ALdouble*)
+DECL_THUNK1(ALboolean, alGetBoolean, ALenum)
+DECL_THUNK1(ALint, alGetInteger, ALenum)
+DECL_THUNK1(ALfloat, alGetFloat, ALenum)
+DECL_THUNK1(ALdouble, alGetDouble, ALenum)
+
+DECL_THUNK1(ALboolean, alIsExtensionPresent, const ALchar*)
+DECL_THUNK1(void*, alGetProcAddress, const ALchar*)
+DECL_THUNK1(ALenum, alGetEnumValue, const ALchar*)
+
+DECL_THUNK2(void, alListenerf, ALenum, ALfloat)
+DECL_THUNK4(void, alListener3f, ALenum, ALfloat, ALfloat, ALfloat)
+DECL_THUNK2(void, alListenerfv, ALenum, const ALfloat*)
+DECL_THUNK2(void, alListeneri, ALenum, ALint)
+DECL_THUNK4(void, alListener3i, ALenum, ALint, ALint, ALint)
+DECL_THUNK2(void, alListeneriv, ALenum, const ALint*)
+DECL_THUNK2(void, alGetListenerf, ALenum, ALfloat*)
+DECL_THUNK4(void, alGetListener3f, ALenum, ALfloat*, ALfloat*, ALfloat*)
+DECL_THUNK2(void, alGetListenerfv, ALenum, ALfloat*)
+DECL_THUNK2(void, alGetListeneri, ALenum, ALint*)
+DECL_THUNK4(void, alGetListener3i, ALenum, ALint*, ALint*, ALint*)
+DECL_THUNK2(void, alGetListeneriv, ALenum, ALint*)
+
+DECL_THUNK2(void, alGenSources, ALsizei, ALuint*)
+DECL_THUNK2(void, alDeleteSources, ALsizei, const ALuint*)
+DECL_THUNK1(ALboolean, alIsSource, ALuint)
+DECL_THUNK3(void, alSourcef, ALuint, ALenum, ALfloat)
+DECL_THUNK5(void, alSource3f, ALuint, ALenum, ALfloat, ALfloat, ALfloat)
+DECL_THUNK3(void, alSourcefv, ALuint, ALenum, const ALfloat*)
+DECL_THUNK3(void, alSourcei, ALuint, ALenum, ALint)
+DECL_THUNK5(void, alSource3i, ALuint, ALenum, ALint, ALint, ALint)
+DECL_THUNK3(void, alSourceiv, ALuint, ALenum, const ALint*)
+DECL_THUNK3(void, alGetSourcef, ALuint, ALenum, ALfloat*)
+DECL_THUNK5(void, alGetSource3f, ALuint, ALenum, ALfloat*, ALfloat*, ALfloat*)
+DECL_THUNK3(void, alGetSourcefv, ALuint, ALenum, ALfloat*)
+DECL_THUNK3(void, alGetSourcei, ALuint, ALenum, ALint*)
+DECL_THUNK5(void, alGetSource3i, ALuint, ALenum, ALint*, ALint*, ALint*)
+DECL_THUNK3(void, alGetSourceiv, ALuint, ALenum, ALint*)
+DECL_THUNK2(void, alSourcePlayv, ALsizei, const ALuint*)
+DECL_THUNK2(void, alSourceStopv, ALsizei, const ALuint*)
+DECL_THUNK2(void, alSourceRewindv, ALsizei, const ALuint*)
+DECL_THUNK2(void, alSourcePausev, ALsizei, const ALuint*)
+DECL_THUNK1(void, alSourcePlay, ALuint)
+DECL_THUNK1(void, alSourceStop, ALuint)
+DECL_THUNK1(void, alSourceRewind, ALuint)
+DECL_THUNK1(void, alSourcePause, ALuint)
+DECL_THUNK3(void, alSourceQueueBuffers, ALuint, ALsizei, const ALuint*)
+DECL_THUNK3(void, alSourceUnqueueBuffers, ALuint, ALsizei, ALuint*)
+
+DECL_THUNK2(void, alGenBuffers, ALsizei, ALuint*)
+DECL_THUNK2(void, alDeleteBuffers, ALsizei, const ALuint*)
+DECL_THUNK1(ALboolean, alIsBuffer, ALuint)
+DECL_THUNK3(void, alBufferf, ALuint, ALenum, ALfloat)
+DECL_THUNK5(void, alBuffer3f, ALuint, ALenum, ALfloat, ALfloat, ALfloat)
+DECL_THUNK3(void, alBufferfv, ALuint, ALenum, const ALfloat*)
+DECL_THUNK3(void, alBufferi, ALuint, ALenum, ALint)
+DECL_THUNK5(void, alBuffer3i, ALuint, ALenum, ALint, ALint, ALint)
+DECL_THUNK3(void, alBufferiv, ALuint, ALenum, const ALint*)
+DECL_THUNK3(void, alGetBufferf, ALuint, ALenum, ALfloat*)
+DECL_THUNK5(void, alGetBuffer3f, ALuint, ALenum, ALfloat*, ALfloat*, ALfloat*)
+DECL_THUNK3(void, alGetBufferfv, ALuint, ALenum, ALfloat*)
+DECL_THUNK3(void, alGetBufferi, ALuint, ALenum, ALint*)
+DECL_THUNK5(void, alGetBuffer3i, ALuint, ALenum, ALint*, ALint*, ALint*)
+DECL_THUNK3(void, alGetBufferiv, ALuint, ALenum, ALint*)
+DECL_THUNK5(void, alBufferData, ALuint, ALenum, const ALvoid*, ALsizei, ALsizei)
diff --git a/router/alc.c b/router/alc.c
new file mode 100644
index 00000000..946c7d4c
--- /dev/null
+++ b/router/alc.c
@@ -0,0 +1,956 @@
+
+#include "config.h"
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "AL/alc.h"
+#include "router.h"
+#include "almalloc.h"
+
+
+#define COUNTOF(x) (sizeof(x)/sizeof(x[0]))
+
+#define DECL(x) { #x, (ALCvoid*)(x) }
+static const struct {
+ const ALCchar *funcName;
+ ALCvoid *address;
+} alcFunctions[] = {
+ DECL(alcCreateContext),
+ DECL(alcMakeContextCurrent),
+ DECL(alcProcessContext),
+ DECL(alcSuspendContext),
+ DECL(alcDestroyContext),
+ DECL(alcGetCurrentContext),
+ DECL(alcGetContextsDevice),
+ DECL(alcOpenDevice),
+ DECL(alcCloseDevice),
+ DECL(alcGetError),
+ DECL(alcIsExtensionPresent),
+ DECL(alcGetProcAddress),
+ DECL(alcGetEnumValue),
+ DECL(alcGetString),
+ DECL(alcGetIntegerv),
+ DECL(alcCaptureOpenDevice),
+ DECL(alcCaptureCloseDevice),
+ DECL(alcCaptureStart),
+ DECL(alcCaptureStop),
+ DECL(alcCaptureSamples),
+
+ DECL(alcSetThreadContext),
+ DECL(alcGetThreadContext),
+
+ DECL(alEnable),
+ DECL(alDisable),
+ DECL(alIsEnabled),
+ DECL(alGetString),
+ DECL(alGetBooleanv),
+ DECL(alGetIntegerv),
+ DECL(alGetFloatv),
+ DECL(alGetDoublev),
+ DECL(alGetBoolean),
+ DECL(alGetInteger),
+ DECL(alGetFloat),
+ DECL(alGetDouble),
+ DECL(alGetError),
+ DECL(alIsExtensionPresent),
+ DECL(alGetProcAddress),
+ DECL(alGetEnumValue),
+ DECL(alListenerf),
+ DECL(alListener3f),
+ DECL(alListenerfv),
+ DECL(alListeneri),
+ DECL(alListener3i),
+ DECL(alListeneriv),
+ DECL(alGetListenerf),
+ DECL(alGetListener3f),
+ DECL(alGetListenerfv),
+ DECL(alGetListeneri),
+ DECL(alGetListener3i),
+ DECL(alGetListeneriv),
+ DECL(alGenSources),
+ DECL(alDeleteSources),
+ DECL(alIsSource),
+ DECL(alSourcef),
+ DECL(alSource3f),
+ DECL(alSourcefv),
+ DECL(alSourcei),
+ DECL(alSource3i),
+ DECL(alSourceiv),
+ DECL(alGetSourcef),
+ DECL(alGetSource3f),
+ DECL(alGetSourcefv),
+ DECL(alGetSourcei),
+ DECL(alGetSource3i),
+ DECL(alGetSourceiv),
+ DECL(alSourcePlayv),
+ DECL(alSourceStopv),
+ DECL(alSourceRewindv),
+ DECL(alSourcePausev),
+ DECL(alSourcePlay),
+ DECL(alSourceStop),
+ DECL(alSourceRewind),
+ DECL(alSourcePause),
+ DECL(alSourceQueueBuffers),
+ DECL(alSourceUnqueueBuffers),
+ DECL(alGenBuffers),
+ DECL(alDeleteBuffers),
+ DECL(alIsBuffer),
+ DECL(alBufferData),
+ DECL(alBufferf),
+ DECL(alBuffer3f),
+ DECL(alBufferfv),
+ DECL(alBufferi),
+ DECL(alBuffer3i),
+ DECL(alBufferiv),
+ DECL(alGetBufferf),
+ DECL(alGetBuffer3f),
+ DECL(alGetBufferfv),
+ DECL(alGetBufferi),
+ DECL(alGetBuffer3i),
+ DECL(alGetBufferiv),
+ DECL(alDopplerFactor),
+ DECL(alDopplerVelocity),
+ DECL(alSpeedOfSound),
+ DECL(alDistanceModel),
+};
+#undef DECL
+
+#define DECL(x) { #x, (x) }
+static const struct {
+ const ALCchar *enumName;
+ ALCenum value;
+} alcEnumerations[] = {
+ DECL(ALC_INVALID),
+ DECL(ALC_FALSE),
+ DECL(ALC_TRUE),
+
+ DECL(ALC_MAJOR_VERSION),
+ DECL(ALC_MINOR_VERSION),
+ DECL(ALC_ATTRIBUTES_SIZE),
+ DECL(ALC_ALL_ATTRIBUTES),
+ DECL(ALC_DEFAULT_DEVICE_SPECIFIER),
+ DECL(ALC_DEVICE_SPECIFIER),
+ DECL(ALC_ALL_DEVICES_SPECIFIER),
+ DECL(ALC_DEFAULT_ALL_DEVICES_SPECIFIER),
+ DECL(ALC_EXTENSIONS),
+ DECL(ALC_FREQUENCY),
+ DECL(ALC_REFRESH),
+ DECL(ALC_SYNC),
+ DECL(ALC_MONO_SOURCES),
+ DECL(ALC_STEREO_SOURCES),
+ DECL(ALC_CAPTURE_DEVICE_SPECIFIER),
+ DECL(ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER),
+ DECL(ALC_CAPTURE_SAMPLES),
+
+ DECL(ALC_NO_ERROR),
+ DECL(ALC_INVALID_DEVICE),
+ DECL(ALC_INVALID_CONTEXT),
+ DECL(ALC_INVALID_ENUM),
+ DECL(ALC_INVALID_VALUE),
+ DECL(ALC_OUT_OF_MEMORY),
+
+ DECL(AL_INVALID),
+ DECL(AL_NONE),
+ DECL(AL_FALSE),
+ DECL(AL_TRUE),
+
+ DECL(AL_SOURCE_RELATIVE),
+ DECL(AL_CONE_INNER_ANGLE),
+ DECL(AL_CONE_OUTER_ANGLE),
+ DECL(AL_PITCH),
+ DECL(AL_POSITION),
+ DECL(AL_DIRECTION),
+ DECL(AL_VELOCITY),
+ DECL(AL_LOOPING),
+ DECL(AL_BUFFER),
+ DECL(AL_GAIN),
+ DECL(AL_MIN_GAIN),
+ DECL(AL_MAX_GAIN),
+ DECL(AL_ORIENTATION),
+ DECL(AL_REFERENCE_DISTANCE),
+ DECL(AL_ROLLOFF_FACTOR),
+ DECL(AL_CONE_OUTER_GAIN),
+ DECL(AL_MAX_DISTANCE),
+ DECL(AL_SEC_OFFSET),
+ DECL(AL_SAMPLE_OFFSET),
+ DECL(AL_BYTE_OFFSET),
+ DECL(AL_SOURCE_TYPE),
+ DECL(AL_STATIC),
+ DECL(AL_STREAMING),
+ DECL(AL_UNDETERMINED),
+
+ DECL(AL_SOURCE_STATE),
+ DECL(AL_INITIAL),
+ DECL(AL_PLAYING),
+ DECL(AL_PAUSED),
+ DECL(AL_STOPPED),
+
+ DECL(AL_BUFFERS_QUEUED),
+ DECL(AL_BUFFERS_PROCESSED),
+
+ DECL(AL_FORMAT_MONO8),
+ DECL(AL_FORMAT_MONO16),
+ DECL(AL_FORMAT_STEREO8),
+ DECL(AL_FORMAT_STEREO16),
+
+ DECL(AL_FREQUENCY),
+ DECL(AL_BITS),
+ DECL(AL_CHANNELS),
+ DECL(AL_SIZE),
+
+ DECL(AL_UNUSED),
+ DECL(AL_PENDING),
+ DECL(AL_PROCESSED),
+
+ DECL(AL_NO_ERROR),
+ DECL(AL_INVALID_NAME),
+ DECL(AL_INVALID_ENUM),
+ DECL(AL_INVALID_VALUE),
+ DECL(AL_INVALID_OPERATION),
+ DECL(AL_OUT_OF_MEMORY),
+
+ DECL(AL_VENDOR),
+ DECL(AL_VERSION),
+ DECL(AL_RENDERER),
+ DECL(AL_EXTENSIONS),
+
+ DECL(AL_DOPPLER_FACTOR),
+ DECL(AL_DOPPLER_VELOCITY),
+ DECL(AL_DISTANCE_MODEL),
+ DECL(AL_SPEED_OF_SOUND),
+
+ DECL(AL_INVERSE_DISTANCE),
+ DECL(AL_INVERSE_DISTANCE_CLAMPED),
+ DECL(AL_LINEAR_DISTANCE),
+ DECL(AL_LINEAR_DISTANCE_CLAMPED),
+ DECL(AL_EXPONENT_DISTANCE),
+ DECL(AL_EXPONENT_DISTANCE_CLAMPED),
+};
+#undef DECL
+
+static const ALCchar alcNoError[] = "No Error";
+static const ALCchar alcErrInvalidDevice[] = "Invalid Device";
+static const ALCchar alcErrInvalidContext[] = "Invalid Context";
+static const ALCchar alcErrInvalidEnum[] = "Invalid Enum";
+static const ALCchar alcErrInvalidValue[] = "Invalid Value";
+static const ALCchar alcErrOutOfMemory[] = "Out of Memory";
+static const ALCchar alcExtensionList[] =
+ "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
+ "ALC_EXT_thread_local_context";
+
+static const ALCint alcMajorVersion = 1;
+static const ALCint alcMinorVersion = 1;
+
+
+static almtx_t EnumerationLock;
+static almtx_t ContextSwitchLock;
+
+static ATOMIC(ALCenum) LastError = ATOMIC_INIT_STATIC(ALC_NO_ERROR);
+static PtrIntMap DeviceIfaceMap = PTRINTMAP_STATIC_INITIALIZE;
+static PtrIntMap ContextIfaceMap = PTRINTMAP_STATIC_INITIALIZE;
+
+
+typedef struct EnumeratedList {
+ ALCchar *Names;
+ ALCchar *NamesEnd;
+ ALCint *Indicies;
+ ALCsizei IndexSize;
+} EnumeratedList;
+static EnumeratedList DevicesList = { NULL, NULL, NULL, 0 };
+static EnumeratedList AllDevicesList = { NULL, NULL, NULL, 0 };
+static EnumeratedList CaptureDevicesList = { NULL, NULL, NULL, 0 };
+
+static void ClearDeviceList(EnumeratedList *list)
+{
+ al_free(list->Names);
+ list->Names = NULL;
+ list->NamesEnd = NULL;
+
+ al_free(list->Indicies);
+ list->Indicies = NULL;
+ list->IndexSize = 0;
+}
+
+static void AppendDeviceList(EnumeratedList *list, const ALCchar *names, ALint idx)
+{
+ const ALCchar *name_end = names;
+ ALCsizei count = 0;
+ ALCchar *new_list;
+ ALCint *new_indicies;
+ size_t len;
+ ALCsizei i;
+
+ if(!name_end)
+ return;
+ while(*name_end)
+ {
+ TRACE("Enumerated \"%s\", driver %d\n", name_end, idx);
+ count++;
+ name_end += strlen(name_end)+1;
+ }
+ if(names == name_end)
+ return;
+
+ len = (list->NamesEnd - list->Names) + (name_end - names);
+ new_list = al_calloc(DEF_ALIGN, len + 1);
+ memcpy(new_list, list->Names, list->NamesEnd - list->Names);
+ memcpy(new_list + (list->NamesEnd - list->Names), names, name_end - names);
+ al_free(list->Names);
+ list->Names = new_list;
+ list->NamesEnd = list->Names + len;
+
+ new_indicies = al_calloc(16, sizeof(ALCint)*(list->IndexSize + count));
+ for(i = 0;i < list->IndexSize;i++)
+ new_indicies[i] = list->Indicies[i];
+ for(i = 0;i < count;i++)
+ new_indicies[list->IndexSize+i] = idx;
+ al_free(list->Indicies);
+ list->Indicies = new_indicies;
+ list->IndexSize += count;
+}
+
+static ALint GetDriverIndexForName(const EnumeratedList *list, const ALCchar *name)
+{
+ const ALCchar *devnames = list->Names;
+ const ALCint *index = list->Indicies;
+
+ while(devnames && *devnames)
+ {
+ if(strcmp(name, devnames) == 0)
+ return *index;
+ devnames += strlen(devnames)+1;
+ index++;
+ }
+ return -1;
+}
+
+void InitALC(void)
+{
+ almtx_init(&EnumerationLock, almtx_recursive);
+ almtx_init(&ContextSwitchLock, almtx_plain);
+}
+
+void ReleaseALC(void)
+{
+ ClearDeviceList(&DevicesList);
+ ClearDeviceList(&AllDevicesList);
+ ClearDeviceList(&CaptureDevicesList);
+
+ ResetPtrIntMap(&ContextIfaceMap);
+ ResetPtrIntMap(&DeviceIfaceMap);
+
+ almtx_destroy(&ContextSwitchLock);
+ almtx_destroy(&EnumerationLock);
+}
+
+
+ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *devicename)
+{
+ ALCdevice *device = NULL;
+ ALint idx;
+
+ /* Prior to the enumeration extension, apps would hardcode these names as a
+ * quality hint for the wrapper driver. Ignore them since there's no sane
+ * way to map them.
+ */
+ if(devicename && (devicename[0] == '\0' ||
+ strcmp(devicename, "DirectSound3D") == 0 ||
+ strcmp(devicename, "DirectSound") == 0 ||
+ strcmp(devicename, "MMSYSTEM") == 0))
+ devicename = NULL;
+ if(devicename)
+ {
+ almtx_lock(&EnumerationLock);
+ if(!DevicesList.Names)
+ (void)alcGetString(NULL, ALC_DEVICE_SPECIFIER);
+ idx = GetDriverIndexForName(&DevicesList, devicename);
+ if(idx < 0)
+ {
+ if(!AllDevicesList.Names)
+ (void)alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
+ idx = GetDriverIndexForName(&AllDevicesList, devicename);
+ }
+ almtx_unlock(&EnumerationLock);
+ if(idx < 0)
+ {
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_VALUE);
+ TRACE("Failed to find driver for name \"%s\"\n", devicename);
+ return NULL;
+ }
+ TRACE("Found driver %d for name \"%s\"\n", idx, devicename);
+ device = DriverList[idx].alcOpenDevice(devicename);
+ }
+ else
+ {
+ int i;
+ for(i = 0;i < DriverListSize;i++)
+ {
+ if(DriverList[i].ALCVer >= MAKE_ALC_VER(1, 1) ||
+ DriverList[i].alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"))
+ {
+ idx = i;
+ TRACE("Using default device from driver %d\n", idx);
+ device = DriverList[idx].alcOpenDevice(NULL);
+ break;
+ }
+ }
+ }
+
+ if(device)
+ {
+ if(InsertPtrIntMapEntry(&DeviceIfaceMap, device, idx) != ALC_NO_ERROR)
+ {
+ DriverList[idx].alcCloseDevice(device);
+ device = NULL;
+ }
+ }
+
+ return device;
+}
+
+ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *device)
+{
+ ALint idx;
+
+ if(!device || (idx=LookupPtrIntMapKey(&DeviceIfaceMap, device)) < 0)
+ {
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ return ALC_FALSE;
+ }
+ if(!DriverList[idx].alcCloseDevice(device))
+ return ALC_FALSE;
+ RemovePtrIntMapKey(&DeviceIfaceMap, device);
+ return ALC_TRUE;
+}
+
+
+ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrlist)
+{
+ ALCcontext *context;
+ ALint idx;
+
+ if(!device || (idx=LookupPtrIntMapKey(&DeviceIfaceMap, device)) < 0)
+ {
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ return ALC_FALSE;
+ }
+ context = DriverList[idx].alcCreateContext(device, attrlist);
+ if(context)
+ {
+ if(InsertPtrIntMapEntry(&ContextIfaceMap, context, idx) != ALC_NO_ERROR)
+ {
+ DriverList[idx].alcDestroyContext(context);
+ context = NULL;
+ }
+ }
+
+ return context;
+}
+
+ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
+{
+ ALint idx = -1;
+
+ almtx_lock(&ContextSwitchLock);
+ if(context)
+ {
+ idx = LookupPtrIntMapKey(&ContextIfaceMap, context);
+ if(idx < 0)
+ {
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
+ almtx_unlock(&ContextSwitchLock);
+ return ALC_FALSE;
+ }
+ if(!DriverList[idx].alcMakeContextCurrent(context))
+ {
+ almtx_unlock(&ContextSwitchLock);
+ return ALC_FALSE;
+ }
+ }
+
+ /* Unset the context from the old driver if it's different from the new
+ * current one.
+ */
+ if(idx < 0)
+ {
+ DriverIface *oldiface = altss_get(ThreadCtxDriver);
+ if(oldiface) oldiface->alcSetThreadContext(NULL);
+ oldiface = ATOMIC_EXCHANGE_PTR_SEQ(&CurrentCtxDriver, NULL);
+ if(oldiface) oldiface->alcMakeContextCurrent(NULL);
+ }
+ else
+ {
+ DriverIface *oldiface = altss_get(ThreadCtxDriver);
+ if(oldiface && oldiface != &DriverList[idx])
+ oldiface->alcSetThreadContext(NULL);
+ oldiface = ATOMIC_EXCHANGE_PTR_SEQ(&CurrentCtxDriver, &DriverList[idx]);
+ if(oldiface && oldiface != &DriverList[idx])
+ oldiface->alcMakeContextCurrent(NULL);
+ }
+ almtx_unlock(&ContextSwitchLock);
+ altss_set(ThreadCtxDriver, NULL);
+
+ return ALC_TRUE;
+}
+
+ALC_API void ALC_APIENTRY alcProcessContext(ALCcontext *context)
+{
+ if(context)
+ {
+ ALint idx = LookupPtrIntMapKey(&ContextIfaceMap, context);
+ if(idx >= 0)
+ return DriverList[idx].alcProcessContext(context);
+ }
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
+}
+
+ALC_API void ALC_APIENTRY alcSuspendContext(ALCcontext *context)
+{
+ if(context)
+ {
+ ALint idx = LookupPtrIntMapKey(&ContextIfaceMap, context);
+ if(idx >= 0)
+ return DriverList[idx].alcSuspendContext(context);
+ }
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
+}
+
+ALC_API void ALC_APIENTRY alcDestroyContext(ALCcontext *context)
+{
+ ALint idx;
+
+ if(!context || (idx=LookupPtrIntMapKey(&ContextIfaceMap, context)) < 0)
+ {
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
+ return;
+ }
+
+ DriverList[idx].alcDestroyContext(context);
+ RemovePtrIntMapKey(&ContextIfaceMap, context);
+}
+
+ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(void)
+{
+ DriverIface *iface = altss_get(ThreadCtxDriver);
+ if(!iface) iface = ATOMIC_LOAD_SEQ(&CurrentCtxDriver);
+ return iface ? iface->alcGetCurrentContext() : NULL;
+}
+
+ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *context)
+{
+ if(context)
+ {
+ ALint idx = LookupPtrIntMapKey(&ContextIfaceMap, context);
+ if(idx >= 0)
+ return DriverList[idx].alcGetContextsDevice(context);
+ }
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_CONTEXT);
+ return NULL;
+}
+
+
+ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
+{
+ if(device)
+ {
+ ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
+ if(idx < 0) return ALC_INVALID_DEVICE;
+ return DriverList[idx].alcGetError(device);
+ }
+ return ATOMIC_EXCHANGE_SEQ(&LastError, ALC_NO_ERROR);
+}
+
+ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extname)
+{
+ const char *ptr;
+ size_t len;
+
+ if(device)
+ {
+ ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
+ if(idx < 0)
+ {
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ return ALC_FALSE;
+ }
+ return DriverList[idx].alcIsExtensionPresent(device, extname);
+ }
+
+ len = strlen(extname);
+ ptr = alcExtensionList;
+ while(ptr && *ptr)
+ {
+ if(strncasecmp(ptr, extname, len) == 0 && (ptr[len] == '\0' || isspace(ptr[len])))
+ return ALC_TRUE;
+ if((ptr=strchr(ptr, ' ')) != NULL)
+ {
+ do {
+ ++ptr;
+ } while(isspace(*ptr));
+ }
+ }
+ return ALC_FALSE;
+}
+
+ALC_API void* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcname)
+{
+ size_t i;
+
+ if(device)
+ {
+ ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
+ if(idx < 0)
+ {
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ return NULL;
+ }
+ return DriverList[idx].alcGetProcAddress(device, funcname);
+ }
+
+ for(i = 0;i < COUNTOF(alcFunctions);i++)
+ {
+ if(strcmp(funcname, alcFunctions[i].funcName) == 0)
+ return alcFunctions[i].address;
+ }
+ return NULL;
+}
+
+ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumname)
+{
+ size_t i;
+
+ if(device)
+ {
+ ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
+ if(idx < 0)
+ {
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ return 0;
+ }
+ return DriverList[idx].alcGetEnumValue(device, enumname);
+ }
+
+ for(i = 0;i < COUNTOF(alcEnumerations);i++)
+ {
+ if(strcmp(enumname, alcEnumerations[i].enumName) == 0)
+ return alcEnumerations[i].value;
+ }
+ return 0;
+}
+
+ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *device, ALCenum param)
+{
+ ALsizei i = 0;
+
+ if(device)
+ {
+ ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
+ if(idx < 0)
+ {
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ return NULL;
+ }
+ return DriverList[idx].alcGetString(device, param);
+ }
+
+ switch(param)
+ {
+ case ALC_NO_ERROR:
+ return alcNoError;
+ case ALC_INVALID_ENUM:
+ return alcErrInvalidEnum;
+ case ALC_INVALID_VALUE:
+ return alcErrInvalidValue;
+ case ALC_INVALID_DEVICE:
+ return alcErrInvalidDevice;
+ case ALC_INVALID_CONTEXT:
+ return alcErrInvalidContext;
+ case ALC_OUT_OF_MEMORY:
+ return alcErrOutOfMemory;
+ case ALC_EXTENSIONS:
+ return alcExtensionList;
+
+ case ALC_DEVICE_SPECIFIER:
+ almtx_lock(&EnumerationLock);
+ ClearDeviceList(&DevicesList);
+ for(i = 0;i < DriverListSize;i++)
+ {
+ /* Only enumerate names from drivers that support it. */
+ if(DriverList[i].ALCVer >= MAKE_ALC_VER(1, 1) ||
+ DriverList[i].alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"))
+ AppendDeviceList(&DevicesList,
+ DriverList[i].alcGetString(NULL, ALC_DEVICE_SPECIFIER), i
+ );
+ }
+ almtx_unlock(&EnumerationLock);
+ return DevicesList.Names;
+
+ case ALC_ALL_DEVICES_SPECIFIER:
+ almtx_lock(&EnumerationLock);
+ ClearDeviceList(&AllDevicesList);
+ for(i = 0;i < DriverListSize;i++)
+ {
+ /* If the driver doesn't support ALC_ENUMERATE_ALL_EXT, substitute
+ * standard enumeration.
+ */
+ if(DriverList[i].alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT"))
+ AppendDeviceList(&AllDevicesList,
+ DriverList[i].alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER), i
+ );
+ else if(DriverList[i].ALCVer >= MAKE_ALC_VER(1, 1) ||
+ DriverList[i].alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"))
+ AppendDeviceList(&AllDevicesList,
+ DriverList[i].alcGetString(NULL, ALC_DEVICE_SPECIFIER), i
+ );
+ }
+ almtx_unlock(&EnumerationLock);
+ return AllDevicesList.Names;
+
+ case ALC_CAPTURE_DEVICE_SPECIFIER:
+ almtx_lock(&EnumerationLock);
+ ClearDeviceList(&CaptureDevicesList);
+ for(i = 0;i < DriverListSize;i++)
+ {
+ if(DriverList[i].ALCVer >= MAKE_ALC_VER(1, 1) ||
+ DriverList[i].alcIsExtensionPresent(NULL, "ALC_EXT_CAPTURE"))
+ AppendDeviceList(&CaptureDevicesList,
+ DriverList[i].alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER), i
+ );
+ }
+ almtx_unlock(&EnumerationLock);
+ return CaptureDevicesList.Names;
+
+ case ALC_DEFAULT_DEVICE_SPECIFIER:
+ for(i = 0;i < DriverListSize;i++)
+ {
+ if(DriverList[i].ALCVer >= MAKE_ALC_VER(1, 1) ||
+ DriverList[i].alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT"))
+ return DriverList[i].alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
+ }
+ return "";
+
+ case ALC_DEFAULT_ALL_DEVICES_SPECIFIER:
+ for(i = 0;i < DriverListSize;i++)
+ {
+ if(DriverList[i].alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT"))
+ return DriverList[i].alcGetString(NULL, ALC_DEFAULT_ALL_DEVICES_SPECIFIER);
+ }
+ return "";
+
+ case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER:
+ for(i = 0;i < DriverListSize;i++)
+ {
+ if(DriverList[i].ALCVer >= MAKE_ALC_VER(1, 1) ||
+ DriverList[i].alcIsExtensionPresent(NULL, "ALC_EXT_CAPTURE"))
+ return DriverList[i].alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
+ }
+ return "";
+
+ default:
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_ENUM);
+ break;
+ }
+ return NULL;
+}
+
+ALC_API void ALC_APIENTRY alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALCint *values)
+{
+ if(device)
+ {
+ ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
+ if(idx < 0)
+ {
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ return;
+ }
+ return DriverList[idx].alcGetIntegerv(device, param, size, values);
+ }
+
+ if(size <= 0 || values == NULL)
+ {
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_VALUE);
+ return;
+ }
+
+ switch(param)
+ {
+ case ALC_MAJOR_VERSION:
+ if(size >= 1)
+ {
+ values[0] = alcMajorVersion;
+ return;
+ }
+ /*fall-through*/
+ case ALC_MINOR_VERSION:
+ if(size >= 1)
+ {
+ values[0] = alcMinorVersion;
+ return;
+ }
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_VALUE);
+ return;
+
+ case ALC_ATTRIBUTES_SIZE:
+ case ALC_ALL_ATTRIBUTES:
+ case ALC_FREQUENCY:
+ case ALC_REFRESH:
+ case ALC_SYNC:
+ case ALC_MONO_SOURCES:
+ case ALC_STEREO_SOURCES:
+ case ALC_CAPTURE_SAMPLES:
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ return;
+
+ default:
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_ENUM);
+ return;
+ }
+}
+
+
+ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize)
+{
+ ALCdevice *device = NULL;
+ ALint idx;
+
+ if(devicename && devicename[0] == '\0')
+ devicename = NULL;
+ if(devicename)
+ {
+ almtx_lock(&EnumerationLock);
+ if(!CaptureDevicesList.Names)
+ (void)alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
+ idx = GetDriverIndexForName(&CaptureDevicesList, devicename);
+ almtx_unlock(&EnumerationLock);
+ if(idx < 0)
+ {
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_VALUE);
+ TRACE("Failed to find driver for name \"%s\"\n", devicename);
+ return NULL;
+ }
+ TRACE("Found driver %d for name \"%s\"\n", idx, devicename);
+ device = DriverList[idx].alcCaptureOpenDevice(
+ devicename, frequency, format, buffersize
+ );
+ }
+ else
+ {
+ int i;
+ for(i = 0;i < DriverListSize;i++)
+ {
+ if(DriverList[i].ALCVer >= MAKE_ALC_VER(1, 1) ||
+ DriverList[i].alcIsExtensionPresent(NULL, "ALC_EXT_CAPTURE"))
+ {
+ idx = i;
+ TRACE("Using default capture device from driver %d\n", idx);
+ device = DriverList[idx].alcCaptureOpenDevice(
+ NULL, frequency, format, buffersize
+ );
+ break;
+ }
+ }
+ }
+
+ if(device)
+ {
+ if(InsertPtrIntMapEntry(&DeviceIfaceMap, device, idx) != ALC_NO_ERROR)
+ {
+ DriverList[idx].alcCaptureCloseDevice(device);
+ device = NULL;
+ }
+ }
+
+ return device;
+}
+
+ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *device)
+{
+ ALint idx;
+
+ if(!device || (idx=LookupPtrIntMapKey(&DeviceIfaceMap, device)) < 0)
+ {
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+ return ALC_FALSE;
+ }
+ if(!DriverList[idx].alcCaptureCloseDevice(device))
+ return ALC_FALSE;
+ RemovePtrIntMapKey(&DeviceIfaceMap, device);
+ return ALC_TRUE;
+}
+
+ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
+{
+ if(device)
+ {
+ ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
+ if(idx >= 0)
+ return DriverList[idx].alcCaptureStart(device);
+ }
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+}
+
+ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
+{
+ if(device)
+ {
+ ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
+ if(idx >= 0)
+ return DriverList[idx].alcCaptureStop(device);
+ }
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+}
+
+ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
+{
+ if(device)
+ {
+ ALint idx = LookupPtrIntMapKey(&DeviceIfaceMap, device);
+ if(idx >= 0)
+ return DriverList[idx].alcCaptureSamples(device, buffer, samples);
+ }
+ ATOMIC_STORE_SEQ(&LastError, ALC_INVALID_DEVICE);
+}
+
+
+ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context)
+{
+ ALCenum err = ALC_INVALID_CONTEXT;
+ ALint idx;
+
+ if(!context)
+ {
+ DriverIface *oldiface = altss_get(ThreadCtxDriver);
+ if(oldiface && !oldiface->alcSetThreadContext(NULL))
+ return ALC_FALSE;
+ altss_set(ThreadCtxDriver, NULL);
+ return ALC_TRUE;
+ }
+
+ idx = LookupPtrIntMapKey(&ContextIfaceMap, context);
+ if(idx >= 0)
+ {
+ if(DriverList[idx].alcSetThreadContext(context))
+ {
+ DriverIface *oldiface = altss_get(ThreadCtxDriver);
+ if(oldiface != &DriverList[idx])
+ {
+ altss_set(ThreadCtxDriver, &DriverList[idx]);
+ if(oldiface) oldiface->alcSetThreadContext(NULL);
+ }
+ return ALC_TRUE;
+ }
+ err = DriverList[idx].alcGetError(NULL);
+ }
+ ATOMIC_STORE_SEQ(&LastError, err);
+ return ALC_FALSE;
+}
+
+ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void)
+{
+ DriverIface *iface = altss_get(ThreadCtxDriver);
+ if(iface) return iface->alcGetThreadContext();
+ return NULL;
+}
diff --git a/router/router.c b/router/router.c
new file mode 100644
index 00000000..bff73776
--- /dev/null
+++ b/router/router.c
@@ -0,0 +1,537 @@
+
+#include "config.h"
+
+#include "router.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "AL/alc.h"
+#include "AL/al.h"
+#include "almalloc.h"
+
+#include "version.h"
+
+
+DriverIface *DriverList = NULL;
+int DriverListSize = 0;
+static int DriverListSizeMax = 0;
+
+altss_t ThreadCtxDriver;
+
+enum LogLevel LogLevel = LogLevel_Error;
+FILE *LogFile;
+
+static void LoadDriverList(void);
+
+
+BOOL APIENTRY DllMain(HINSTANCE UNUSED(module), DWORD reason, void* UNUSED(reserved))
+{
+ const char *str;
+ int i;
+
+ switch(reason)
+ {
+ case DLL_PROCESS_ATTACH:
+ LogFile = stderr;
+ str = getenv("ALROUTER_LOGFILE");
+ if(str && *str != '\0')
+ {
+ FILE *f = fopen(str, "w");
+ if(f == NULL)
+ ERR("Could not open log file: %s\n", str);
+ else
+ LogFile = f;
+ }
+ str = getenv("ALROUTER_LOGLEVEL");
+ if(str && *str != '\0')
+ {
+ char *end = NULL;
+ long l = strtol(str, &end, 0);
+ if(!end || *end != '\0')
+ ERR("Invalid log level value: %s\n", str);
+ else if(l < LogLevel_None || l > LogLevel_Trace)
+ ERR("Log level out of range: %s\n", str);
+ else
+ LogLevel = l;
+ }
+ TRACE("Initializing router v0.1-%s %s\n", ALSOFT_GIT_COMMIT_HASH, ALSOFT_GIT_BRANCH);
+ LoadDriverList();
+
+ altss_create(&ThreadCtxDriver, NULL);
+ InitALC();
+ break;
+
+ case DLL_THREAD_ATTACH:
+ break;
+ case DLL_THREAD_DETACH:
+ althrd_thread_detach();
+ break;
+
+ case DLL_PROCESS_DETACH:
+ ReleaseALC();
+ altss_delete(ThreadCtxDriver);
+
+ for(i = 0;i < DriverListSize;i++)
+ {
+ if(DriverList[i].Module)
+ FreeLibrary(DriverList[i].Module);
+ }
+ al_free(DriverList);
+ DriverList = NULL;
+ DriverListSize = 0;
+ DriverListSizeMax = 0;
+
+ if(LogFile && LogFile != stderr)
+ fclose(LogFile);
+ LogFile = NULL;
+
+ althrd_deinit();
+ break;
+ }
+ return TRUE;
+}
+
+
+#ifdef __GNUC__
+#define CAST_FUNC(x) (__typeof(x))
+#else
+#define CAST_FUNC(x) (void*)
+#endif
+
+static void AddModule(HMODULE module, const WCHAR *name)
+{
+ DriverIface newdrv;
+ int err = 0;
+ int i;
+
+ for(i = 0;i < DriverListSize;i++)
+ {
+ if(DriverList[i].Module == module)
+ {
+ TRACE("Skipping already-loaded module %p\n", module);
+ FreeLibrary(module);
+ return;
+ }
+ if(wcscmp(DriverList[i].Name, name) == 0)
+ {
+ TRACE("Skipping similarly-named module %ls\n", name);
+ FreeLibrary(module);
+ return;
+ }
+ }
+
+ if(DriverListSize == DriverListSizeMax)
+ {
+ int newmax = DriverListSizeMax ? DriverListSizeMax<<1 : 4;
+ void *newlist = al_calloc(DEF_ALIGN, sizeof(DriverList[0])*newmax);
+ if(!newlist) return;
+
+ memcpy(newlist, DriverList, DriverListSize*sizeof(DriverList[0]));
+ al_free(DriverList);
+ DriverList = newlist;
+ DriverListSizeMax = newmax;
+ }
+
+ memset(&newdrv, 0, sizeof(newdrv));
+ /* Load required functions. */
+#define LOAD_PROC(x) do { \
+ newdrv.x = CAST_FUNC(newdrv.x) GetProcAddress(module, #x); \
+ if(!newdrv.x) \
+ { \
+ ERR("Failed to find entry point for %s in %ls\n", #x, name); \
+ err = 1; \
+ } \
+} while(0)
+ LOAD_PROC(alcCreateContext);
+ LOAD_PROC(alcMakeContextCurrent);
+ LOAD_PROC(alcProcessContext);
+ LOAD_PROC(alcSuspendContext);
+ LOAD_PROC(alcDestroyContext);
+ LOAD_PROC(alcGetCurrentContext);
+ LOAD_PROC(alcGetContextsDevice);
+ LOAD_PROC(alcOpenDevice);
+ LOAD_PROC(alcCloseDevice);
+ LOAD_PROC(alcGetError);
+ LOAD_PROC(alcIsExtensionPresent);
+ LOAD_PROC(alcGetProcAddress);
+ LOAD_PROC(alcGetEnumValue);
+ LOAD_PROC(alcGetString);
+ LOAD_PROC(alcGetIntegerv);
+ LOAD_PROC(alcCaptureOpenDevice);
+ LOAD_PROC(alcCaptureCloseDevice);
+ LOAD_PROC(alcCaptureStart);
+ LOAD_PROC(alcCaptureStop);
+ LOAD_PROC(alcCaptureSamples);
+
+ LOAD_PROC(alEnable);
+ LOAD_PROC(alDisable);
+ LOAD_PROC(alIsEnabled);
+ LOAD_PROC(alGetString);
+ LOAD_PROC(alGetBooleanv);
+ LOAD_PROC(alGetIntegerv);
+ LOAD_PROC(alGetFloatv);
+ LOAD_PROC(alGetDoublev);
+ LOAD_PROC(alGetBoolean);
+ LOAD_PROC(alGetInteger);
+ LOAD_PROC(alGetFloat);
+ LOAD_PROC(alGetDouble);
+ LOAD_PROC(alGetError);
+ LOAD_PROC(alIsExtensionPresent);
+ LOAD_PROC(alGetProcAddress);
+ LOAD_PROC(alGetEnumValue);
+ LOAD_PROC(alListenerf);
+ LOAD_PROC(alListener3f);
+ LOAD_PROC(alListenerfv);
+ LOAD_PROC(alListeneri);
+ LOAD_PROC(alListener3i);
+ LOAD_PROC(alListeneriv);
+ LOAD_PROC(alGetListenerf);
+ LOAD_PROC(alGetListener3f);
+ LOAD_PROC(alGetListenerfv);
+ LOAD_PROC(alGetListeneri);
+ LOAD_PROC(alGetListener3i);
+ LOAD_PROC(alGetListeneriv);
+ LOAD_PROC(alGenSources);
+ LOAD_PROC(alDeleteSources);
+ LOAD_PROC(alIsSource);
+ LOAD_PROC(alSourcef);
+ LOAD_PROC(alSource3f);
+ LOAD_PROC(alSourcefv);
+ LOAD_PROC(alSourcei);
+ LOAD_PROC(alSource3i);
+ LOAD_PROC(alSourceiv);
+ LOAD_PROC(alGetSourcef);
+ LOAD_PROC(alGetSource3f);
+ LOAD_PROC(alGetSourcefv);
+ LOAD_PROC(alGetSourcei);
+ LOAD_PROC(alGetSource3i);
+ LOAD_PROC(alGetSourceiv);
+ LOAD_PROC(alSourcePlayv);
+ LOAD_PROC(alSourceStopv);
+ LOAD_PROC(alSourceRewindv);
+ LOAD_PROC(alSourcePausev);
+ LOAD_PROC(alSourcePlay);
+ LOAD_PROC(alSourceStop);
+ LOAD_PROC(alSourceRewind);
+ LOAD_PROC(alSourcePause);
+ LOAD_PROC(alSourceQueueBuffers);
+ LOAD_PROC(alSourceUnqueueBuffers);
+ LOAD_PROC(alGenBuffers);
+ LOAD_PROC(alDeleteBuffers);
+ LOAD_PROC(alIsBuffer);
+ LOAD_PROC(alBufferf);
+ LOAD_PROC(alBuffer3f);
+ LOAD_PROC(alBufferfv);
+ LOAD_PROC(alBufferi);
+ LOAD_PROC(alBuffer3i);
+ LOAD_PROC(alBufferiv);
+ LOAD_PROC(alGetBufferf);
+ LOAD_PROC(alGetBuffer3f);
+ LOAD_PROC(alGetBufferfv);
+ LOAD_PROC(alGetBufferi);
+ LOAD_PROC(alGetBuffer3i);
+ LOAD_PROC(alGetBufferiv);
+ LOAD_PROC(alBufferData);
+ LOAD_PROC(alDopplerFactor);
+ LOAD_PROC(alDopplerVelocity);
+ LOAD_PROC(alSpeedOfSound);
+ LOAD_PROC(alDistanceModel);
+ if(!err)
+ {
+ ALCint alc_ver[2] = { 0, 0 };
+ wcsncpy(newdrv.Name, name, 32);
+ newdrv.Module = module;
+ newdrv.alcGetIntegerv(NULL, ALC_MAJOR_VERSION, 1, &alc_ver[0]);
+ newdrv.alcGetIntegerv(NULL, ALC_MINOR_VERSION, 1, &alc_ver[1]);
+ if(newdrv.alcGetError(NULL) == ALC_NO_ERROR)
+ newdrv.ALCVer = MAKE_ALC_VER(alc_ver[0], alc_ver[1]);
+ else
+ newdrv.ALCVer = MAKE_ALC_VER(1, 0);
+
+#undef LOAD_PROC
+#define LOAD_PROC(x) do { \
+ newdrv.x = CAST_FUNC(newdrv.x) newdrv.alcGetProcAddress(NULL, #x); \
+ if(!newdrv.x) \
+ { \
+ ERR("Failed to find entry point for %s in %ls\n", #x, name); \
+ err = 1; \
+ } \
+} while(0)
+ if(newdrv.alcIsExtensionPresent(NULL, "ALC_EXT_thread_local_context"))
+ {
+ LOAD_PROC(alcSetThreadContext);
+ LOAD_PROC(alcGetThreadContext);
+ }
+ }
+
+ if(!err)
+ {
+ TRACE("Loaded module %p, %ls, ALC %d.%d\n", module, name,
+ newdrv.ALCVer>>8, newdrv.ALCVer&255);
+ DriverList[DriverListSize++] = newdrv;
+ }
+#undef LOAD_PROC
+}
+
+static void SearchDrivers(WCHAR *path)
+{
+ WCHAR srchPath[MAX_PATH+1] = L"";
+ WIN32_FIND_DATAW fdata;
+ HANDLE srchHdl;
+
+ TRACE("Searching for drivers in %ls...\n", path);
+ wcsncpy(srchPath, path, MAX_PATH);
+ wcsncat(srchPath, L"\\*oal.dll", MAX_PATH - lstrlenW(srchPath));
+ srchHdl = FindFirstFileW(srchPath, &fdata);
+ if(srchHdl != INVALID_HANDLE_VALUE)
+ {
+ do {
+ HMODULE mod;
+
+ wcsncpy(srchPath, path, MAX_PATH);
+ wcsncat(srchPath, L"\\", MAX_PATH - lstrlenW(srchPath));
+ wcsncat(srchPath, fdata.cFileName, MAX_PATH - lstrlenW(srchPath));
+ TRACE("Found %ls\n", srchPath);
+
+ mod = LoadLibraryW(srchPath);
+ if(!mod)
+ WARN("Could not load %ls\n", srchPath);
+ else
+ AddModule(mod, fdata.cFileName);
+ } while(FindNextFileW(srchHdl, &fdata));
+ FindClose(srchHdl);
+ }
+}
+
+static WCHAR *strrchrW(WCHAR *str, WCHAR ch)
+{
+ WCHAR *res = NULL;
+ while(str && *str != '\0')
+ {
+ if(*str == ch)
+ res = str;
+ ++str;
+ }
+ return res;
+}
+
+static int GetLoadedModuleDirectory(const WCHAR *name, WCHAR *moddir, DWORD length)
+{
+ HMODULE module = NULL;
+ WCHAR *sep0, *sep1;
+
+ if(name)
+ {
+ module = GetModuleHandleW(name);
+ if(!module) return 0;
+ }
+
+ if(GetModuleFileNameW(module, moddir, length) == 0)
+ return 0;
+
+ sep0 = strrchrW(moddir, '/');
+ if(sep0) sep1 = strrchrW(sep0+1, '\\');
+ else sep1 = strrchrW(moddir, '\\');
+
+ if(sep1) *sep1 = '\0';
+ else if(sep0) *sep0 = '\0';
+ else *moddir = '\0';
+
+ return 1;
+}
+
+void LoadDriverList(void)
+{
+ WCHAR dll_path[MAX_PATH+1] = L"";
+ WCHAR cwd_path[MAX_PATH+1] = L"";
+ WCHAR proc_path[MAX_PATH+1] = L"";
+ WCHAR sys_path[MAX_PATH+1] = L"";
+ int len;
+
+ if(GetLoadedModuleDirectory(L"OpenAL32.dll", dll_path, MAX_PATH))
+ TRACE("Got DLL path %ls\n", dll_path);
+
+ GetCurrentDirectoryW(MAX_PATH, cwd_path);
+ len = lstrlenW(cwd_path);
+ if(len > 0 && (cwd_path[len-1] == '\\' || cwd_path[len-1] == '/'))
+ cwd_path[len-1] = '\0';
+ TRACE("Got current working directory %ls\n", cwd_path);
+
+ if(GetLoadedModuleDirectory(NULL, proc_path, MAX_PATH))
+ TRACE("Got proc path %ls\n", proc_path);
+
+ GetSystemDirectoryW(sys_path, MAX_PATH);
+ len = lstrlenW(sys_path);
+ if(len > 0 && (sys_path[len-1] == '\\' || sys_path[len-1] == '/'))
+ sys_path[len-1] = '\0';
+ TRACE("Got system path %ls\n", sys_path);
+
+ /* Don't search the DLL's path if it is the same as the current working
+ * directory, app's path, or system path (don't want to do duplicate
+ * searches, or increase the priority of the app or system path).
+ */
+ if(dll_path[0] &&
+ (!cwd_path[0] || wcscmp(dll_path, cwd_path) != 0) &&
+ (!proc_path[0] || wcscmp(dll_path, proc_path) != 0) &&
+ (!sys_path[0] || wcscmp(dll_path, sys_path) != 0))
+ SearchDrivers(dll_path);
+ if(cwd_path[0] &&
+ (!proc_path[0] || wcscmp(cwd_path, proc_path) != 0) &&
+ (!sys_path[0] || wcscmp(cwd_path, sys_path) != 0))
+ SearchDrivers(cwd_path);
+ if(proc_path[0] && (!sys_path[0] || wcscmp(proc_path, sys_path) != 0))
+ SearchDrivers(proc_path);
+ if(sys_path[0])
+ SearchDrivers(sys_path);
+}
+
+
+void InitPtrIntMap(PtrIntMap *map)
+{
+ map->keys = NULL;
+ map->values = NULL;
+ map->size = 0;
+ map->capacity = 0;
+ RWLockInit(&map->lock);
+}
+
+void ResetPtrIntMap(PtrIntMap *map)
+{
+ WriteLock(&map->lock);
+ al_free(map->keys);
+ map->keys = NULL;
+ map->values = NULL;
+ map->size = 0;
+ map->capacity = 0;
+ WriteUnlock(&map->lock);
+}
+
+ALenum InsertPtrIntMapEntry(PtrIntMap *map, ALvoid *key, ALint value)
+{
+ ALsizei pos = 0;
+
+ WriteLock(&map->lock);
+ if(map->size > 0)
+ {
+ ALsizei count = map->size;
+ do {
+ ALsizei step = count>>1;
+ ALsizei i = pos+step;
+ if(!(map->keys[i] < key))
+ count = step;
+ else
+ {
+ pos = i+1;
+ count -= step+1;
+ }
+ } while(count > 0);
+ }
+
+ if(pos == map->size || map->keys[pos] != key)
+ {
+ if(map->size == map->capacity)
+ {
+ ALvoid **keys = NULL;
+ ALint *values;
+ ALsizei newcap;
+
+ newcap = (map->capacity ? (map->capacity<<1) : 4);
+ if(newcap > map->capacity)
+ keys = al_calloc(16, (sizeof(map->keys[0])+sizeof(map->values[0]))*newcap);
+ if(!keys)
+ {
+ WriteUnlock(&map->lock);
+ return AL_OUT_OF_MEMORY;
+ }
+ values = (ALint*)&keys[newcap];
+
+ if(map->keys)
+ {
+ memcpy(keys, map->keys, map->size*sizeof(map->keys[0]));
+ memcpy(values, map->values, map->size*sizeof(map->values[0]));
+ }
+ al_free(map->keys);
+ map->keys = keys;
+ map->values = values;
+ map->capacity = newcap;
+ }
+
+ if(pos < map->size)
+ {
+ memmove(&map->keys[pos+1], &map->keys[pos],
+ (map->size-pos)*sizeof(map->keys[0]));
+ memmove(&map->values[pos+1], &map->values[pos],
+ (map->size-pos)*sizeof(map->values[0]));
+ }
+ map->size++;
+ }
+ map->keys[pos] = key;
+ map->values[pos] = value;
+ WriteUnlock(&map->lock);
+
+ return AL_NO_ERROR;
+}
+
+ALint RemovePtrIntMapKey(PtrIntMap *map, ALvoid *key)
+{
+ ALint ret = -1;
+ WriteLock(&map->lock);
+ if(map->size > 0)
+ {
+ ALsizei pos = 0;
+ ALsizei count = map->size;
+ do {
+ ALsizei step = count>>1;
+ ALsizei i = pos+step;
+ if(!(map->keys[i] < key))
+ count = step;
+ else
+ {
+ pos = i+1;
+ count -= step+1;
+ }
+ } while(count > 0);
+ if(pos < map->size && map->keys[pos] == key)
+ {
+ ret = map->values[pos];
+ if(pos < map->size-1)
+ {
+ memmove(&map->keys[pos], &map->keys[pos+1],
+ (map->size-1-pos)*sizeof(map->keys[0]));
+ memmove(&map->values[pos], &map->values[pos+1],
+ (map->size-1-pos)*sizeof(map->values[0]));
+ }
+ map->size--;
+ }
+ }
+ WriteUnlock(&map->lock);
+ return ret;
+}
+
+ALint LookupPtrIntMapKey(PtrIntMap *map, ALvoid *key)
+{
+ ALint ret = -1;
+ ReadLock(&map->lock);
+ if(map->size > 0)
+ {
+ ALsizei pos = 0;
+ ALsizei count = map->size;
+ do {
+ ALsizei step = count>>1;
+ ALsizei i = pos+step;
+ if(!(map->keys[i] < key))
+ count = step;
+ else
+ {
+ pos = i+1;
+ count -= step+1;
+ }
+ } while(count > 0);
+ if(pos < map->size && map->keys[pos] == key)
+ ret = map->values[pos];
+ }
+ ReadUnlock(&map->lock);
+ return ret;
+}
diff --git a/router/router.h b/router/router.h
new file mode 100644
index 00000000..32a91dcb
--- /dev/null
+++ b/router/router.h
@@ -0,0 +1,197 @@
+#ifndef ROUTER_ROUTER_H
+#define ROUTER_ROUTER_H
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <winnt.h>
+
+#include <stdio.h>
+
+#include "AL/alc.h"
+#include "AL/al.h"
+#include "AL/alext.h"
+#include "atomic.h"
+#include "rwlock.h"
+#include "threads.h"
+
+
+#ifndef UNUSED
+#if defined(__cplusplus)
+#define UNUSED(x)
+#elif defined(__GNUC__)
+#define UNUSED(x) UNUSED_##x __attribute__((unused))
+#elif defined(__LCLINT__)
+#define UNUSED(x) /*@unused@*/ x
+#else
+#define UNUSED(x) x
+#endif
+#endif
+
+#define MAKE_ALC_VER(major, minor) (((major)<<8) | (minor))
+
+typedef struct DriverIface {
+ WCHAR Name[32];
+ HMODULE Module;
+ int ALCVer;
+
+ LPALCCREATECONTEXT alcCreateContext;
+ LPALCMAKECONTEXTCURRENT alcMakeContextCurrent;
+ LPALCPROCESSCONTEXT alcProcessContext;
+ LPALCSUSPENDCONTEXT alcSuspendContext;
+ LPALCDESTROYCONTEXT alcDestroyContext;
+ LPALCGETCURRENTCONTEXT alcGetCurrentContext;
+ LPALCGETCONTEXTSDEVICE alcGetContextsDevice;
+ LPALCOPENDEVICE alcOpenDevice;
+ LPALCCLOSEDEVICE alcCloseDevice;
+ LPALCGETERROR alcGetError;
+ LPALCISEXTENSIONPRESENT alcIsExtensionPresent;
+ LPALCGETPROCADDRESS alcGetProcAddress;
+ LPALCGETENUMVALUE alcGetEnumValue;
+ LPALCGETSTRING alcGetString;
+ LPALCGETINTEGERV alcGetIntegerv;
+ LPALCCAPTUREOPENDEVICE alcCaptureOpenDevice;
+ LPALCCAPTURECLOSEDEVICE alcCaptureCloseDevice;
+ LPALCCAPTURESTART alcCaptureStart;
+ LPALCCAPTURESTOP alcCaptureStop;
+ LPALCCAPTURESAMPLES alcCaptureSamples;
+
+ PFNALCSETTHREADCONTEXTPROC alcSetThreadContext;
+ PFNALCGETTHREADCONTEXTPROC alcGetThreadContext;
+
+ LPALENABLE alEnable;
+ LPALDISABLE alDisable;
+ LPALISENABLED alIsEnabled;
+ LPALGETSTRING alGetString;
+ LPALGETBOOLEANV alGetBooleanv;
+ LPALGETINTEGERV alGetIntegerv;
+ LPALGETFLOATV alGetFloatv;
+ LPALGETDOUBLEV alGetDoublev;
+ LPALGETBOOLEAN alGetBoolean;
+ LPALGETINTEGER alGetInteger;
+ LPALGETFLOAT alGetFloat;
+ LPALGETDOUBLE alGetDouble;
+ LPALGETERROR alGetError;
+ LPALISEXTENSIONPRESENT alIsExtensionPresent;
+ LPALGETPROCADDRESS alGetProcAddress;
+ LPALGETENUMVALUE alGetEnumValue;
+ LPALLISTENERF alListenerf;
+ LPALLISTENER3F alListener3f;
+ LPALLISTENERFV alListenerfv;
+ LPALLISTENERI alListeneri;
+ LPALLISTENER3I alListener3i;
+ LPALLISTENERIV alListeneriv;
+ LPALGETLISTENERF alGetListenerf;
+ LPALGETLISTENER3F alGetListener3f;
+ LPALGETLISTENERFV alGetListenerfv;
+ LPALGETLISTENERI alGetListeneri;
+ LPALGETLISTENER3I alGetListener3i;
+ LPALGETLISTENERIV alGetListeneriv;
+ LPALGENSOURCES alGenSources;
+ LPALDELETESOURCES alDeleteSources;
+ LPALISSOURCE alIsSource;
+ LPALSOURCEF alSourcef;
+ LPALSOURCE3F alSource3f;
+ LPALSOURCEFV alSourcefv;
+ LPALSOURCEI alSourcei;
+ LPALSOURCE3I alSource3i;
+ LPALSOURCEIV alSourceiv;
+ LPALGETSOURCEF alGetSourcef;
+ LPALGETSOURCE3F alGetSource3f;
+ LPALGETSOURCEFV alGetSourcefv;
+ LPALGETSOURCEI alGetSourcei;
+ LPALGETSOURCE3I alGetSource3i;
+ LPALGETSOURCEIV alGetSourceiv;
+ LPALSOURCEPLAYV alSourcePlayv;
+ LPALSOURCESTOPV alSourceStopv;
+ LPALSOURCEREWINDV alSourceRewindv;
+ LPALSOURCEPAUSEV alSourcePausev;
+ LPALSOURCEPLAY alSourcePlay;
+ LPALSOURCESTOP alSourceStop;
+ LPALSOURCEREWIND alSourceRewind;
+ LPALSOURCEPAUSE alSourcePause;
+ LPALSOURCEQUEUEBUFFERS alSourceQueueBuffers;
+ LPALSOURCEUNQUEUEBUFFERS alSourceUnqueueBuffers;
+ LPALGENBUFFERS alGenBuffers;
+ LPALDELETEBUFFERS alDeleteBuffers;
+ LPALISBUFFER alIsBuffer;
+ LPALBUFFERF alBufferf;
+ LPALBUFFER3F alBuffer3f;
+ LPALBUFFERFV alBufferfv;
+ LPALBUFFERI alBufferi;
+ LPALBUFFER3I alBuffer3i;
+ LPALBUFFERIV alBufferiv;
+ LPALGETBUFFERF alGetBufferf;
+ LPALGETBUFFER3F alGetBuffer3f;
+ LPALGETBUFFERFV alGetBufferfv;
+ LPALGETBUFFERI alGetBufferi;
+ LPALGETBUFFER3I alGetBuffer3i;
+ LPALGETBUFFERIV alGetBufferiv;
+ LPALBUFFERDATA alBufferData;
+ LPALDOPPLERFACTOR alDopplerFactor;
+ LPALDOPPLERVELOCITY alDopplerVelocity;
+ LPALSPEEDOFSOUND alSpeedOfSound;
+ LPALDISTANCEMODEL alDistanceModel;
+} DriverIface;
+
+extern DriverIface *DriverList;
+extern int DriverListSize;
+
+extern altss_t ThreadCtxDriver;
+typedef ATOMIC(DriverIface*) atomic_DriverIfacePtr;
+extern atomic_DriverIfacePtr CurrentCtxDriver;
+
+
+typedef struct PtrIntMap {
+ ALvoid **keys;
+ /* Shares memory with keys. */
+ ALint *values;
+
+ ALsizei size;
+ ALsizei capacity;
+ RWLock lock;
+} PtrIntMap;
+#define PTRINTMAP_STATIC_INITIALIZE { NULL, NULL, 0, 0, RWLOCK_STATIC_INITIALIZE }
+
+void InitPtrIntMap(PtrIntMap *map);
+void ResetPtrIntMap(PtrIntMap *map);
+ALenum InsertPtrIntMapEntry(PtrIntMap *map, ALvoid *key, ALint value);
+ALint RemovePtrIntMapKey(PtrIntMap *map, ALvoid *key);
+ALint LookupPtrIntMapKey(PtrIntMap *map, ALvoid *key);
+
+
+void InitALC(void);
+void ReleaseALC(void);
+
+
+enum LogLevel {
+ LogLevel_None = 0,
+ LogLevel_Error = 1,
+ LogLevel_Warn = 2,
+ LogLevel_Trace = 3,
+};
+extern enum LogLevel LogLevel;
+extern FILE *LogFile;
+
+#define TRACE(...) do { \
+ if(LogLevel >= LogLevel_Trace) \
+ { \
+ fprintf(LogFile, "AL Router (II): " __VA_ARGS__); \
+ fflush(LogFile); \
+ } \
+} while(0)
+#define WARN(...) do { \
+ if(LogLevel >= LogLevel_Warn) \
+ { \
+ fprintf(LogFile, "AL Router (WW): " __VA_ARGS__); \
+ fflush(LogFile); \
+ } \
+} while(0)
+#define ERR(...) do { \
+ if(LogLevel >= LogLevel_Error) \
+ { \
+ fprintf(LogFile, "AL Router (EE): " __VA_ARGS__); \
+ fflush(LogFile); \
+ } \
+} while(0)
+
+#endif /* ROUTER_ROUTER_H */
diff --git a/utils/CIAIR.def b/utils/CIAIR.def
index 9589a694..4876dc50 100644
--- a/utils/CIAIR.def
+++ b/utils/CIAIR.def
@@ -1,9 +1,9 @@
# This is a makehrtf HRIR definition file. It is used to define the layout
# and source data to be processed into an OpenAL Soft compatible HRTF.
#
-# This definition is used to transform the left ear HRIRs from a data set
-# used in several papers and articles by Fumitada Itakura, Kazuya Takeda,
-# Mikio Ikeda, Shoji Kajita, and Takanori Nishino.
+# This definition is used to transform the left and right ear HRIRs from a
+# data set used in several papers and articles by Fumitada Itakura, Kazuya
+# Takeda, Mikio Ikeda, Shoji Kajita, and Takanori Nishino.
#
# The data (data02.tgz) can be obtained from The Database of Head Related
# Transfer Functions hosted by the Takeda Laboratory at Nagoya University:
@@ -17,1994 +17,3942 @@
rate = 44100
-points = 512
+# The CIAIR set is stereo because it provides both ear HRIRs.
+type = stereo
-# The CIAIR set is composed of a uniform number of azimuths for all but the
-# poles (-90 and 90 degree elevation).
-azimuths = 1, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 1
+points = 512
# No head radius was provided. Just use the average radius of 9 cm.
radius = 0.09
-# The distance between the source and the listener is not known for this set,
-# so 1.5 m is used.
+# The CIAIR set is composed of a single field with an unknown distance
+# between the source and the listener, so a guess of 1.5 meters is used.
distance = 1.5
+# This set has a uniform number of azimuths for all but the poles (-90 and 90
+# degree elevation).
+azimuths = 1, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 1
+
# The CIAIR source azimuth is counter-clockwise, so it needs to be flipped.
# The extension of the source data may be misleading, they're ASCII text
-# lists of floating point values (one per line).
-
-[ 9, 0 ] = ascii (fp) : "./hrtfs/elev-45/L-45e000a.dat"
-[ 9, 1 ] = ascii (fp) : "./hrtfs/elev-45/L-45e355a.dat"
-[ 9, 2 ] = ascii (fp) : "./hrtfs/elev-45/L-45e350a.dat"
-[ 9, 3 ] = ascii (fp) : "./hrtfs/elev-45/L-45e345a.dat"
-[ 9, 4 ] = ascii (fp) : "./hrtfs/elev-45/L-45e340a.dat"
-[ 9, 5 ] = ascii (fp) : "./hrtfs/elev-45/L-45e335a.dat"
-[ 9, 6 ] = ascii (fp) : "./hrtfs/elev-45/L-45e330a.dat"
-[ 9, 7 ] = ascii (fp) : "./hrtfs/elev-45/L-45e325a.dat"
-[ 9, 8 ] = ascii (fp) : "./hrtfs/elev-45/L-45e320a.dat"
-[ 9, 9 ] = ascii (fp) : "./hrtfs/elev-45/L-45e315a.dat"
-[ 9, 10 ] = ascii (fp) : "./hrtfs/elev-45/L-45e310a.dat"
-[ 9, 11 ] = ascii (fp) : "./hrtfs/elev-45/L-45e305a.dat"
-[ 9, 12 ] = ascii (fp) : "./hrtfs/elev-45/L-45e300a.dat"
-[ 9, 13 ] = ascii (fp) : "./hrtfs/elev-45/L-45e295a.dat"
-[ 9, 14 ] = ascii (fp) : "./hrtfs/elev-45/L-45e290a.dat"
-[ 9, 15 ] = ascii (fp) : "./hrtfs/elev-45/L-45e285a.dat"
-[ 9, 16 ] = ascii (fp) : "./hrtfs/elev-45/L-45e280a.dat"
-[ 9, 17 ] = ascii (fp) : "./hrtfs/elev-45/L-45e275a.dat"
-[ 9, 18 ] = ascii (fp) : "./hrtfs/elev-45/L-45e270a.dat"
-[ 9, 19 ] = ascii (fp) : "./hrtfs/elev-45/L-45e265a.dat"
-[ 9, 20 ] = ascii (fp) : "./hrtfs/elev-45/L-45e260a.dat"
-[ 9, 21 ] = ascii (fp) : "./hrtfs/elev-45/L-45e255a.dat"
-[ 9, 22 ] = ascii (fp) : "./hrtfs/elev-45/L-45e250a.dat"
-[ 9, 23 ] = ascii (fp) : "./hrtfs/elev-45/L-45e245a.dat"
-[ 9, 24 ] = ascii (fp) : "./hrtfs/elev-45/L-45e240a.dat"
-[ 9, 25 ] = ascii (fp) : "./hrtfs/elev-45/L-45e235a.dat"
-[ 9, 26 ] = ascii (fp) : "./hrtfs/elev-45/L-45e230a.dat"
-[ 9, 27 ] = ascii (fp) : "./hrtfs/elev-45/L-45e225a.dat"
-[ 9, 28 ] = ascii (fp) : "./hrtfs/elev-45/L-45e220a.dat"
-[ 9, 29 ] = ascii (fp) : "./hrtfs/elev-45/L-45e215a.dat"
-[ 9, 30 ] = ascii (fp) : "./hrtfs/elev-45/L-45e210a.dat"
-[ 9, 31 ] = ascii (fp) : "./hrtfs/elev-45/L-45e205a.dat"
-[ 9, 32 ] = ascii (fp) : "./hrtfs/elev-45/L-45e200a.dat"
-[ 9, 33 ] = ascii (fp) : "./hrtfs/elev-45/L-45e195a.dat"
-[ 9, 34 ] = ascii (fp) : "./hrtfs/elev-45/L-45e190a.dat"
-[ 9, 35 ] = ascii (fp) : "./hrtfs/elev-45/L-45e185a.dat"
-[ 9, 36 ] = ascii (fp) : "./hrtfs/elev-45/L-45e180a.dat"
-[ 9, 37 ] = ascii (fp) : "./hrtfs/elev-45/L-45e175a.dat"
-[ 9, 38 ] = ascii (fp) : "./hrtfs/elev-45/L-45e170a.dat"
-[ 9, 39 ] = ascii (fp) : "./hrtfs/elev-45/L-45e165a.dat"
-[ 9, 40 ] = ascii (fp) : "./hrtfs/elev-45/L-45e160a.dat"
-[ 9, 41 ] = ascii (fp) : "./hrtfs/elev-45/L-45e155a.dat"
-[ 9, 42 ] = ascii (fp) : "./hrtfs/elev-45/L-45e150a.dat"
-[ 9, 43 ] = ascii (fp) : "./hrtfs/elev-45/L-45e145a.dat"
-[ 9, 44 ] = ascii (fp) : "./hrtfs/elev-45/L-45e140a.dat"
-[ 9, 45 ] = ascii (fp) : "./hrtfs/elev-45/L-45e135a.dat"
-[ 9, 46 ] = ascii (fp) : "./hrtfs/elev-45/L-45e130a.dat"
-[ 9, 47 ] = ascii (fp) : "./hrtfs/elev-45/L-45e125a.dat"
-[ 9, 48 ] = ascii (fp) : "./hrtfs/elev-45/L-45e120a.dat"
-[ 9, 49 ] = ascii (fp) : "./hrtfs/elev-45/L-45e115a.dat"
-[ 9, 50 ] = ascii (fp) : "./hrtfs/elev-45/L-45e110a.dat"
-[ 9, 51 ] = ascii (fp) : "./hrtfs/elev-45/L-45e105a.dat"
-[ 9, 52 ] = ascii (fp) : "./hrtfs/elev-45/L-45e100a.dat"
-[ 9, 53 ] = ascii (fp) : "./hrtfs/elev-45/L-45e095a.dat"
-[ 9, 54 ] = ascii (fp) : "./hrtfs/elev-45/L-45e090a.dat"
-[ 9, 55 ] = ascii (fp) : "./hrtfs/elev-45/L-45e085a.dat"
-[ 9, 56 ] = ascii (fp) : "./hrtfs/elev-45/L-45e080a.dat"
-[ 9, 57 ] = ascii (fp) : "./hrtfs/elev-45/L-45e075a.dat"
-[ 9, 58 ] = ascii (fp) : "./hrtfs/elev-45/L-45e070a.dat"
-[ 9, 59 ] = ascii (fp) : "./hrtfs/elev-45/L-45e065a.dat"
-[ 9, 60 ] = ascii (fp) : "./hrtfs/elev-45/L-45e060a.dat"
-[ 9, 61 ] = ascii (fp) : "./hrtfs/elev-45/L-45e055a.dat"
-[ 9, 62 ] = ascii (fp) : "./hrtfs/elev-45/L-45e050a.dat"
-[ 9, 63 ] = ascii (fp) : "./hrtfs/elev-45/L-45e045a.dat"
-[ 9, 64 ] = ascii (fp) : "./hrtfs/elev-45/L-45e040a.dat"
-[ 9, 65 ] = ascii (fp) : "./hrtfs/elev-45/L-45e035a.dat"
-[ 9, 66 ] = ascii (fp) : "./hrtfs/elev-45/L-45e030a.dat"
-[ 9, 67 ] = ascii (fp) : "./hrtfs/elev-45/L-45e025a.dat"
-[ 9, 68 ] = ascii (fp) : "./hrtfs/elev-45/L-45e020a.dat"
-[ 9, 69 ] = ascii (fp) : "./hrtfs/elev-45/L-45e015a.dat"
-[ 9, 70 ] = ascii (fp) : "./hrtfs/elev-45/L-45e010a.dat"
-[ 9, 71 ] = ascii (fp) : "./hrtfs/elev-45/L-45e005a.dat"
+# lists of floating point values (one per line). Left and right ear HRIRs
+# (from the respective files) are used to create a stereo HRTF.
+[ 9, 0 ] = ascii (fp) : "./hrtfs/elev-45/L-45e000a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e000a.dat right
+[ 9, 1 ] = ascii (fp) : "./hrtfs/elev-45/L-45e355a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e355a.dat right
+[ 9, 2 ] = ascii (fp) : "./hrtfs/elev-45/L-45e350a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e350a.dat right
+[ 9, 3 ] = ascii (fp) : "./hrtfs/elev-45/L-45e345a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e345a.dat right
+[ 9, 4 ] = ascii (fp) : "./hrtfs/elev-45/L-45e340a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e340a.dat right
+[ 9, 5 ] = ascii (fp) : "./hrtfs/elev-45/L-45e335a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e335a.dat right
+[ 9, 6 ] = ascii (fp) : "./hrtfs/elev-45/L-45e330a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e330a.dat right
+[ 9, 7 ] = ascii (fp) : "./hrtfs/elev-45/L-45e325a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e325a.dat right
+[ 9, 8 ] = ascii (fp) : "./hrtfs/elev-45/L-45e320a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e320a.dat right
+[ 9, 9 ] = ascii (fp) : "./hrtfs/elev-45/L-45e315a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e315a.dat right
+[ 9, 10 ] = ascii (fp) : "./hrtfs/elev-45/L-45e310a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e310a.dat right
+[ 9, 11 ] = ascii (fp) : "./hrtfs/elev-45/L-45e305a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e305a.dat right
+[ 9, 12 ] = ascii (fp) : "./hrtfs/elev-45/L-45e300a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e300a.dat right
+[ 9, 13 ] = ascii (fp) : "./hrtfs/elev-45/L-45e295a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e295a.dat right
+[ 9, 14 ] = ascii (fp) : "./hrtfs/elev-45/L-45e290a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e290a.dat right
+[ 9, 15 ] = ascii (fp) : "./hrtfs/elev-45/L-45e285a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e285a.dat right
+[ 9, 16 ] = ascii (fp) : "./hrtfs/elev-45/L-45e280a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e280a.dat right
+[ 9, 17 ] = ascii (fp) : "./hrtfs/elev-45/L-45e275a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e275a.dat right
+[ 9, 18 ] = ascii (fp) : "./hrtfs/elev-45/L-45e270a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e270a.dat right
+[ 9, 19 ] = ascii (fp) : "./hrtfs/elev-45/L-45e265a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e265a.dat right
+[ 9, 20 ] = ascii (fp) : "./hrtfs/elev-45/L-45e260a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e260a.dat right
+[ 9, 21 ] = ascii (fp) : "./hrtfs/elev-45/L-45e255a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e255a.dat right
+[ 9, 22 ] = ascii (fp) : "./hrtfs/elev-45/L-45e250a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e250a.dat right
+[ 9, 23 ] = ascii (fp) : "./hrtfs/elev-45/L-45e245a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e245a.dat right
+[ 9, 24 ] = ascii (fp) : "./hrtfs/elev-45/L-45e240a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e240a.dat right
+[ 9, 25 ] = ascii (fp) : "./hrtfs/elev-45/L-45e235a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e235a.dat right
+[ 9, 26 ] = ascii (fp) : "./hrtfs/elev-45/L-45e230a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e230a.dat right
+[ 9, 27 ] = ascii (fp) : "./hrtfs/elev-45/L-45e225a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e225a.dat right
+[ 9, 28 ] = ascii (fp) : "./hrtfs/elev-45/L-45e220a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e220a.dat right
+[ 9, 29 ] = ascii (fp) : "./hrtfs/elev-45/L-45e215a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e215a.dat right
+[ 9, 30 ] = ascii (fp) : "./hrtfs/elev-45/L-45e210a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e210a.dat right
+[ 9, 31 ] = ascii (fp) : "./hrtfs/elev-45/L-45e205a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e205a.dat right
+[ 9, 32 ] = ascii (fp) : "./hrtfs/elev-45/L-45e200a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e200a.dat right
+[ 9, 33 ] = ascii (fp) : "./hrtfs/elev-45/L-45e195a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e195a.dat right
+[ 9, 34 ] = ascii (fp) : "./hrtfs/elev-45/L-45e190a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e190a.dat right
+[ 9, 35 ] = ascii (fp) : "./hrtfs/elev-45/L-45e185a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e185a.dat right
+[ 9, 36 ] = ascii (fp) : "./hrtfs/elev-45/L-45e180a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e180a.dat right
+[ 9, 37 ] = ascii (fp) : "./hrtfs/elev-45/L-45e175a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e175a.dat right
+[ 9, 38 ] = ascii (fp) : "./hrtfs/elev-45/L-45e170a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e170a.dat right
+[ 9, 39 ] = ascii (fp) : "./hrtfs/elev-45/L-45e165a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e165a.dat right
+[ 9, 40 ] = ascii (fp) : "./hrtfs/elev-45/L-45e160a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e160a.dat right
+[ 9, 41 ] = ascii (fp) : "./hrtfs/elev-45/L-45e155a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e155a.dat right
+[ 9, 42 ] = ascii (fp) : "./hrtfs/elev-45/L-45e150a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e150a.dat right
+[ 9, 43 ] = ascii (fp) : "./hrtfs/elev-45/L-45e145a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e145a.dat right
+[ 9, 44 ] = ascii (fp) : "./hrtfs/elev-45/L-45e140a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e140a.dat right
+[ 9, 45 ] = ascii (fp) : "./hrtfs/elev-45/L-45e135a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e135a.dat right
+[ 9, 46 ] = ascii (fp) : "./hrtfs/elev-45/L-45e130a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e130a.dat right
+[ 9, 47 ] = ascii (fp) : "./hrtfs/elev-45/L-45e125a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e125a.dat right
+[ 9, 48 ] = ascii (fp) : "./hrtfs/elev-45/L-45e120a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e120a.dat right
+[ 9, 49 ] = ascii (fp) : "./hrtfs/elev-45/L-45e115a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e115a.dat right
+[ 9, 50 ] = ascii (fp) : "./hrtfs/elev-45/L-45e110a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e110a.dat right
+[ 9, 51 ] = ascii (fp) : "./hrtfs/elev-45/L-45e105a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e105a.dat right
+[ 9, 52 ] = ascii (fp) : "./hrtfs/elev-45/L-45e100a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e100a.dat right
+[ 9, 53 ] = ascii (fp) : "./hrtfs/elev-45/L-45e095a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e095a.dat right
+[ 9, 54 ] = ascii (fp) : "./hrtfs/elev-45/L-45e090a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e090a.dat right
+[ 9, 55 ] = ascii (fp) : "./hrtfs/elev-45/L-45e085a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e085a.dat right
+[ 9, 56 ] = ascii (fp) : "./hrtfs/elev-45/L-45e080a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e080a.dat right
+[ 9, 57 ] = ascii (fp) : "./hrtfs/elev-45/L-45e075a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e075a.dat right
+[ 9, 58 ] = ascii (fp) : "./hrtfs/elev-45/L-45e070a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e070a.dat right
+[ 9, 59 ] = ascii (fp) : "./hrtfs/elev-45/L-45e065a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e065a.dat right
+[ 9, 60 ] = ascii (fp) : "./hrtfs/elev-45/L-45e060a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e060a.dat right
+[ 9, 61 ] = ascii (fp) : "./hrtfs/elev-45/L-45e055a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e055a.dat right
+[ 9, 62 ] = ascii (fp) : "./hrtfs/elev-45/L-45e050a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e050a.dat right
+[ 9, 63 ] = ascii (fp) : "./hrtfs/elev-45/L-45e045a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e045a.dat right
+[ 9, 64 ] = ascii (fp) : "./hrtfs/elev-45/L-45e040a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e040a.dat right
+[ 9, 65 ] = ascii (fp) : "./hrtfs/elev-45/L-45e035a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e035a.dat right
+[ 9, 66 ] = ascii (fp) : "./hrtfs/elev-45/L-45e030a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e030a.dat right
+[ 9, 67 ] = ascii (fp) : "./hrtfs/elev-45/L-45e025a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e025a.dat right
+[ 9, 68 ] = ascii (fp) : "./hrtfs/elev-45/L-45e020a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e020a.dat right
+[ 9, 69 ] = ascii (fp) : "./hrtfs/elev-45/L-45e015a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e015a.dat right
+[ 9, 70 ] = ascii (fp) : "./hrtfs/elev-45/L-45e010a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e010a.dat right
+[ 9, 71 ] = ascii (fp) : "./hrtfs/elev-45/L-45e005a.dat left
+ + ascii (fp) : "./hrtfs/elev-45/R-45e005a.dat right
-[ 10, 0 ] = ascii (fp) : "./hrtfs/elev-40/L-40e000a.dat"
-[ 10, 1 ] = ascii (fp) : "./hrtfs/elev-40/L-40e355a.dat"
-[ 10, 2 ] = ascii (fp) : "./hrtfs/elev-40/L-40e350a.dat"
-[ 10, 3 ] = ascii (fp) : "./hrtfs/elev-40/L-40e345a.dat"
-[ 10, 4 ] = ascii (fp) : "./hrtfs/elev-40/L-40e340a.dat"
-[ 10, 5 ] = ascii (fp) : "./hrtfs/elev-40/L-40e335a.dat"
-[ 10, 6 ] = ascii (fp) : "./hrtfs/elev-40/L-40e330a.dat"
-[ 10, 7 ] = ascii (fp) : "./hrtfs/elev-40/L-40e325a.dat"
-[ 10, 8 ] = ascii (fp) : "./hrtfs/elev-40/L-40e320a.dat"
-[ 10, 9 ] = ascii (fp) : "./hrtfs/elev-40/L-40e315a.dat"
-[ 10, 10 ] = ascii (fp) : "./hrtfs/elev-40/L-40e310a.dat"
-[ 10, 11 ] = ascii (fp) : "./hrtfs/elev-40/L-40e305a.dat"
-[ 10, 12 ] = ascii (fp) : "./hrtfs/elev-40/L-40e300a.dat"
-[ 10, 13 ] = ascii (fp) : "./hrtfs/elev-40/L-40e295a.dat"
-[ 10, 14 ] = ascii (fp) : "./hrtfs/elev-40/L-40e290a.dat"
-[ 10, 15 ] = ascii (fp) : "./hrtfs/elev-40/L-40e285a.dat"
-[ 10, 16 ] = ascii (fp) : "./hrtfs/elev-40/L-40e280a.dat"
-[ 10, 17 ] = ascii (fp) : "./hrtfs/elev-40/L-40e275a.dat"
-[ 10, 18 ] = ascii (fp) : "./hrtfs/elev-40/L-40e270a.dat"
-[ 10, 19 ] = ascii (fp) : "./hrtfs/elev-40/L-40e265a.dat"
-[ 10, 20 ] = ascii (fp) : "./hrtfs/elev-40/L-40e260a.dat"
-[ 10, 21 ] = ascii (fp) : "./hrtfs/elev-40/L-40e255a.dat"
-[ 10, 22 ] = ascii (fp) : "./hrtfs/elev-40/L-40e250a.dat"
-[ 10, 23 ] = ascii (fp) : "./hrtfs/elev-40/L-40e245a.dat"
-[ 10, 24 ] = ascii (fp) : "./hrtfs/elev-40/L-40e240a.dat"
-[ 10, 25 ] = ascii (fp) : "./hrtfs/elev-40/L-40e235a.dat"
-[ 10, 26 ] = ascii (fp) : "./hrtfs/elev-40/L-40e230a.dat"
-[ 10, 27 ] = ascii (fp) : "./hrtfs/elev-40/L-40e225a.dat"
-[ 10, 28 ] = ascii (fp) : "./hrtfs/elev-40/L-40e220a.dat"
-[ 10, 29 ] = ascii (fp) : "./hrtfs/elev-40/L-40e215a.dat"
-[ 10, 30 ] = ascii (fp) : "./hrtfs/elev-40/L-40e210a.dat"
-[ 10, 31 ] = ascii (fp) : "./hrtfs/elev-40/L-40e205a.dat"
-[ 10, 32 ] = ascii (fp) : "./hrtfs/elev-40/L-40e200a.dat"
-[ 10, 33 ] = ascii (fp) : "./hrtfs/elev-40/L-40e195a.dat"
-[ 10, 34 ] = ascii (fp) : "./hrtfs/elev-40/L-40e190a.dat"
-[ 10, 35 ] = ascii (fp) : "./hrtfs/elev-40/L-40e185a.dat"
-[ 10, 36 ] = ascii (fp) : "./hrtfs/elev-40/L-40e180a.dat"
-[ 10, 37 ] = ascii (fp) : "./hrtfs/elev-40/L-40e175a.dat"
-[ 10, 38 ] = ascii (fp) : "./hrtfs/elev-40/L-40e170a.dat"
-[ 10, 39 ] = ascii (fp) : "./hrtfs/elev-40/L-40e165a.dat"
-[ 10, 40 ] = ascii (fp) : "./hrtfs/elev-40/L-40e160a.dat"
-[ 10, 41 ] = ascii (fp) : "./hrtfs/elev-40/L-40e155a.dat"
-[ 10, 42 ] = ascii (fp) : "./hrtfs/elev-40/L-40e150a.dat"
-[ 10, 43 ] = ascii (fp) : "./hrtfs/elev-40/L-40e145a.dat"
-[ 10, 44 ] = ascii (fp) : "./hrtfs/elev-40/L-40e140a.dat"
-[ 10, 45 ] = ascii (fp) : "./hrtfs/elev-40/L-40e135a.dat"
-[ 10, 46 ] = ascii (fp) : "./hrtfs/elev-40/L-40e130a.dat"
-[ 10, 47 ] = ascii (fp) : "./hrtfs/elev-40/L-40e125a.dat"
-[ 10, 48 ] = ascii (fp) : "./hrtfs/elev-40/L-40e120a.dat"
-[ 10, 49 ] = ascii (fp) : "./hrtfs/elev-40/L-40e115a.dat"
-[ 10, 50 ] = ascii (fp) : "./hrtfs/elev-40/L-40e110a.dat"
-[ 10, 51 ] = ascii (fp) : "./hrtfs/elev-40/L-40e105a.dat"
-[ 10, 52 ] = ascii (fp) : "./hrtfs/elev-40/L-40e100a.dat"
-[ 10, 53 ] = ascii (fp) : "./hrtfs/elev-40/L-40e095a.dat"
-[ 10, 54 ] = ascii (fp) : "./hrtfs/elev-40/L-40e090a.dat"
-[ 10, 55 ] = ascii (fp) : "./hrtfs/elev-40/L-40e085a.dat"
-[ 10, 56 ] = ascii (fp) : "./hrtfs/elev-40/L-40e080a.dat"
-[ 10, 57 ] = ascii (fp) : "./hrtfs/elev-40/L-40e075a.dat"
-[ 10, 58 ] = ascii (fp) : "./hrtfs/elev-40/L-40e070a.dat"
-[ 10, 59 ] = ascii (fp) : "./hrtfs/elev-40/L-40e065a.dat"
-[ 10, 60 ] = ascii (fp) : "./hrtfs/elev-40/L-40e060a.dat"
-[ 10, 61 ] = ascii (fp) : "./hrtfs/elev-40/L-40e055a.dat"
-[ 10, 62 ] = ascii (fp) : "./hrtfs/elev-40/L-40e050a.dat"
-[ 10, 63 ] = ascii (fp) : "./hrtfs/elev-40/L-40e045a.dat"
-[ 10, 64 ] = ascii (fp) : "./hrtfs/elev-40/L-40e040a.dat"
-[ 10, 65 ] = ascii (fp) : "./hrtfs/elev-40/L-40e035a.dat"
-[ 10, 66 ] = ascii (fp) : "./hrtfs/elev-40/L-40e030a.dat"
-[ 10, 67 ] = ascii (fp) : "./hrtfs/elev-40/L-40e025a.dat"
-[ 10, 68 ] = ascii (fp) : "./hrtfs/elev-40/L-40e020a.dat"
-[ 10, 69 ] = ascii (fp) : "./hrtfs/elev-40/L-40e015a.dat"
-[ 10, 70 ] = ascii (fp) : "./hrtfs/elev-40/L-40e010a.dat"
-[ 10, 71 ] = ascii (fp) : "./hrtfs/elev-40/L-40e005a.dat"
+[ 10, 0 ] = ascii (fp) : "./hrtfs/elev-40/L-40e000a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e000a.dat right
+[ 10, 1 ] = ascii (fp) : "./hrtfs/elev-40/L-40e355a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e355a.dat right
+[ 10, 2 ] = ascii (fp) : "./hrtfs/elev-40/L-40e350a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e350a.dat right
+[ 10, 3 ] = ascii (fp) : "./hrtfs/elev-40/L-40e345a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e345a.dat right
+[ 10, 4 ] = ascii (fp) : "./hrtfs/elev-40/L-40e340a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e340a.dat right
+[ 10, 5 ] = ascii (fp) : "./hrtfs/elev-40/L-40e335a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e335a.dat right
+[ 10, 6 ] = ascii (fp) : "./hrtfs/elev-40/L-40e330a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e330a.dat right
+[ 10, 7 ] = ascii (fp) : "./hrtfs/elev-40/L-40e325a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e325a.dat right
+[ 10, 8 ] = ascii (fp) : "./hrtfs/elev-40/L-40e320a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e320a.dat right
+[ 10, 9 ] = ascii (fp) : "./hrtfs/elev-40/L-40e315a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e315a.dat right
+[ 10, 10 ] = ascii (fp) : "./hrtfs/elev-40/L-40e310a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e310a.dat right
+[ 10, 11 ] = ascii (fp) : "./hrtfs/elev-40/L-40e305a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e305a.dat right
+[ 10, 12 ] = ascii (fp) : "./hrtfs/elev-40/L-40e300a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e300a.dat right
+[ 10, 13 ] = ascii (fp) : "./hrtfs/elev-40/L-40e295a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e295a.dat right
+[ 10, 14 ] = ascii (fp) : "./hrtfs/elev-40/L-40e290a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e290a.dat right
+[ 10, 15 ] = ascii (fp) : "./hrtfs/elev-40/L-40e285a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e285a.dat right
+[ 10, 16 ] = ascii (fp) : "./hrtfs/elev-40/L-40e280a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e280a.dat right
+[ 10, 17 ] = ascii (fp) : "./hrtfs/elev-40/L-40e275a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e275a.dat right
+[ 10, 18 ] = ascii (fp) : "./hrtfs/elev-40/L-40e270a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e270a.dat right
+[ 10, 19 ] = ascii (fp) : "./hrtfs/elev-40/L-40e265a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e265a.dat right
+[ 10, 20 ] = ascii (fp) : "./hrtfs/elev-40/L-40e260a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e260a.dat right
+[ 10, 21 ] = ascii (fp) : "./hrtfs/elev-40/L-40e255a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e255a.dat right
+[ 10, 22 ] = ascii (fp) : "./hrtfs/elev-40/L-40e250a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e250a.dat right
+[ 10, 23 ] = ascii (fp) : "./hrtfs/elev-40/L-40e245a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e245a.dat right
+[ 10, 24 ] = ascii (fp) : "./hrtfs/elev-40/L-40e240a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e240a.dat right
+[ 10, 25 ] = ascii (fp) : "./hrtfs/elev-40/L-40e235a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e235a.dat right
+[ 10, 26 ] = ascii (fp) : "./hrtfs/elev-40/L-40e230a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e230a.dat right
+[ 10, 27 ] = ascii (fp) : "./hrtfs/elev-40/L-40e225a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e225a.dat right
+[ 10, 28 ] = ascii (fp) : "./hrtfs/elev-40/L-40e220a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e220a.dat right
+[ 10, 29 ] = ascii (fp) : "./hrtfs/elev-40/L-40e215a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e215a.dat right
+[ 10, 30 ] = ascii (fp) : "./hrtfs/elev-40/L-40e210a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e210a.dat right
+[ 10, 31 ] = ascii (fp) : "./hrtfs/elev-40/L-40e205a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e205a.dat right
+[ 10, 32 ] = ascii (fp) : "./hrtfs/elev-40/L-40e200a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e200a.dat right
+[ 10, 33 ] = ascii (fp) : "./hrtfs/elev-40/L-40e195a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e195a.dat right
+[ 10, 34 ] = ascii (fp) : "./hrtfs/elev-40/L-40e190a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e190a.dat right
+[ 10, 35 ] = ascii (fp) : "./hrtfs/elev-40/L-40e185a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e185a.dat right
+[ 10, 36 ] = ascii (fp) : "./hrtfs/elev-40/L-40e180a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e180a.dat right
+[ 10, 37 ] = ascii (fp) : "./hrtfs/elev-40/L-40e175a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e175a.dat right
+[ 10, 38 ] = ascii (fp) : "./hrtfs/elev-40/L-40e170a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e170a.dat right
+[ 10, 39 ] = ascii (fp) : "./hrtfs/elev-40/L-40e165a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e165a.dat right
+[ 10, 40 ] = ascii (fp) : "./hrtfs/elev-40/L-40e160a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e160a.dat right
+[ 10, 41 ] = ascii (fp) : "./hrtfs/elev-40/L-40e155a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e155a.dat right
+[ 10, 42 ] = ascii (fp) : "./hrtfs/elev-40/L-40e150a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e150a.dat right
+[ 10, 43 ] = ascii (fp) : "./hrtfs/elev-40/L-40e145a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e145a.dat right
+[ 10, 44 ] = ascii (fp) : "./hrtfs/elev-40/L-40e140a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e140a.dat right
+[ 10, 45 ] = ascii (fp) : "./hrtfs/elev-40/L-40e135a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e135a.dat right
+[ 10, 46 ] = ascii (fp) : "./hrtfs/elev-40/L-40e130a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e130a.dat right
+[ 10, 47 ] = ascii (fp) : "./hrtfs/elev-40/L-40e125a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e125a.dat right
+[ 10, 48 ] = ascii (fp) : "./hrtfs/elev-40/L-40e120a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e120a.dat right
+[ 10, 49 ] = ascii (fp) : "./hrtfs/elev-40/L-40e115a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e115a.dat right
+[ 10, 50 ] = ascii (fp) : "./hrtfs/elev-40/L-40e110a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e110a.dat right
+[ 10, 51 ] = ascii (fp) : "./hrtfs/elev-40/L-40e105a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e105a.dat right
+[ 10, 52 ] = ascii (fp) : "./hrtfs/elev-40/L-40e100a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e100a.dat right
+[ 10, 53 ] = ascii (fp) : "./hrtfs/elev-40/L-40e095a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e095a.dat right
+[ 10, 54 ] = ascii (fp) : "./hrtfs/elev-40/L-40e090a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e090a.dat right
+[ 10, 55 ] = ascii (fp) : "./hrtfs/elev-40/L-40e085a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e085a.dat right
+[ 10, 56 ] = ascii (fp) : "./hrtfs/elev-40/L-40e080a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e080a.dat right
+[ 10, 57 ] = ascii (fp) : "./hrtfs/elev-40/L-40e075a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e075a.dat right
+[ 10, 58 ] = ascii (fp) : "./hrtfs/elev-40/L-40e070a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e070a.dat right
+[ 10, 59 ] = ascii (fp) : "./hrtfs/elev-40/L-40e065a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e065a.dat right
+[ 10, 60 ] = ascii (fp) : "./hrtfs/elev-40/L-40e060a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e060a.dat right
+[ 10, 61 ] = ascii (fp) : "./hrtfs/elev-40/L-40e055a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e055a.dat right
+[ 10, 62 ] = ascii (fp) : "./hrtfs/elev-40/L-40e050a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e050a.dat right
+[ 10, 63 ] = ascii (fp) : "./hrtfs/elev-40/L-40e045a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e045a.dat right
+[ 10, 64 ] = ascii (fp) : "./hrtfs/elev-40/L-40e040a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e040a.dat right
+[ 10, 65 ] = ascii (fp) : "./hrtfs/elev-40/L-40e035a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e035a.dat right
+[ 10, 66 ] = ascii (fp) : "./hrtfs/elev-40/L-40e030a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e030a.dat right
+[ 10, 67 ] = ascii (fp) : "./hrtfs/elev-40/L-40e025a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e025a.dat right
+[ 10, 68 ] = ascii (fp) : "./hrtfs/elev-40/L-40e020a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e020a.dat right
+[ 10, 69 ] = ascii (fp) : "./hrtfs/elev-40/L-40e015a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e015a.dat right
+[ 10, 70 ] = ascii (fp) : "./hrtfs/elev-40/L-40e010a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e010a.dat right
+[ 10, 71 ] = ascii (fp) : "./hrtfs/elev-40/L-40e005a.dat left
+ + ascii (fp) : "./hrtfs/elev-40/R-40e005a.dat right
-[ 11, 0 ] = ascii (fp) : "./hrtfs/elev-35/L-35e000a.dat"
-[ 11, 1 ] = ascii (fp) : "./hrtfs/elev-35/L-35e355a.dat"
-[ 11, 2 ] = ascii (fp) : "./hrtfs/elev-35/L-35e350a.dat"
-[ 11, 3 ] = ascii (fp) : "./hrtfs/elev-35/L-35e345a.dat"
-[ 11, 4 ] = ascii (fp) : "./hrtfs/elev-35/L-35e340a.dat"
-[ 11, 5 ] = ascii (fp) : "./hrtfs/elev-35/L-35e335a.dat"
-[ 11, 6 ] = ascii (fp) : "./hrtfs/elev-35/L-35e330a.dat"
-[ 11, 7 ] = ascii (fp) : "./hrtfs/elev-35/L-35e325a.dat"
-[ 11, 8 ] = ascii (fp) : "./hrtfs/elev-35/L-35e320a.dat"
-[ 11, 9 ] = ascii (fp) : "./hrtfs/elev-35/L-35e315a.dat"
-[ 11, 10 ] = ascii (fp) : "./hrtfs/elev-35/L-35e310a.dat"
-[ 11, 11 ] = ascii (fp) : "./hrtfs/elev-35/L-35e305a.dat"
-[ 11, 12 ] = ascii (fp) : "./hrtfs/elev-35/L-35e300a.dat"
-[ 11, 13 ] = ascii (fp) : "./hrtfs/elev-35/L-35e295a.dat"
-[ 11, 14 ] = ascii (fp) : "./hrtfs/elev-35/L-35e290a.dat"
-[ 11, 15 ] = ascii (fp) : "./hrtfs/elev-35/L-35e285a.dat"
-[ 11, 16 ] = ascii (fp) : "./hrtfs/elev-35/L-35e280a.dat"
-[ 11, 17 ] = ascii (fp) : "./hrtfs/elev-35/L-35e275a.dat"
-[ 11, 18 ] = ascii (fp) : "./hrtfs/elev-35/L-35e270a.dat"
-[ 11, 19 ] = ascii (fp) : "./hrtfs/elev-35/L-35e265a.dat"
-[ 11, 20 ] = ascii (fp) : "./hrtfs/elev-35/L-35e260a.dat"
-[ 11, 21 ] = ascii (fp) : "./hrtfs/elev-35/L-35e255a.dat"
-[ 11, 22 ] = ascii (fp) : "./hrtfs/elev-35/L-35e250a.dat"
-[ 11, 23 ] = ascii (fp) : "./hrtfs/elev-35/L-35e245a.dat"
-[ 11, 24 ] = ascii (fp) : "./hrtfs/elev-35/L-35e240a.dat"
-[ 11, 25 ] = ascii (fp) : "./hrtfs/elev-35/L-35e235a.dat"
-[ 11, 26 ] = ascii (fp) : "./hrtfs/elev-35/L-35e230a.dat"
-[ 11, 27 ] = ascii (fp) : "./hrtfs/elev-35/L-35e225a.dat"
-[ 11, 28 ] = ascii (fp) : "./hrtfs/elev-35/L-35e220a.dat"
-[ 11, 29 ] = ascii (fp) : "./hrtfs/elev-35/L-35e215a.dat"
-[ 11, 30 ] = ascii (fp) : "./hrtfs/elev-35/L-35e210a.dat"
-[ 11, 31 ] = ascii (fp) : "./hrtfs/elev-35/L-35e205a.dat"
-[ 11, 32 ] = ascii (fp) : "./hrtfs/elev-35/L-35e200a.dat"
-[ 11, 33 ] = ascii (fp) : "./hrtfs/elev-35/L-35e195a.dat"
-[ 11, 34 ] = ascii (fp) : "./hrtfs/elev-35/L-35e190a.dat"
-[ 11, 35 ] = ascii (fp) : "./hrtfs/elev-35/L-35e185a.dat"
-[ 11, 36 ] = ascii (fp) : "./hrtfs/elev-35/L-35e180a.dat"
-[ 11, 37 ] = ascii (fp) : "./hrtfs/elev-35/L-35e175a.dat"
-[ 11, 38 ] = ascii (fp) : "./hrtfs/elev-35/L-35e170a.dat"
-[ 11, 39 ] = ascii (fp) : "./hrtfs/elev-35/L-35e165a.dat"
-[ 11, 40 ] = ascii (fp) : "./hrtfs/elev-35/L-35e160a.dat"
-[ 11, 41 ] = ascii (fp) : "./hrtfs/elev-35/L-35e155a.dat"
-[ 11, 42 ] = ascii (fp) : "./hrtfs/elev-35/L-35e150a.dat"
-[ 11, 43 ] = ascii (fp) : "./hrtfs/elev-35/L-35e145a.dat"
-[ 11, 44 ] = ascii (fp) : "./hrtfs/elev-35/L-35e140a.dat"
-[ 11, 45 ] = ascii (fp) : "./hrtfs/elev-35/L-35e135a.dat"
-[ 11, 46 ] = ascii (fp) : "./hrtfs/elev-35/L-35e130a.dat"
-[ 11, 47 ] = ascii (fp) : "./hrtfs/elev-35/L-35e125a.dat"
-[ 11, 48 ] = ascii (fp) : "./hrtfs/elev-35/L-35e120a.dat"
-[ 11, 49 ] = ascii (fp) : "./hrtfs/elev-35/L-35e115a.dat"
-[ 11, 50 ] = ascii (fp) : "./hrtfs/elev-35/L-35e110a.dat"
-[ 11, 51 ] = ascii (fp) : "./hrtfs/elev-35/L-35e105a.dat"
-[ 11, 52 ] = ascii (fp) : "./hrtfs/elev-35/L-35e100a.dat"
-[ 11, 53 ] = ascii (fp) : "./hrtfs/elev-35/L-35e095a.dat"
-[ 11, 54 ] = ascii (fp) : "./hrtfs/elev-35/L-35e090a.dat"
-[ 11, 55 ] = ascii (fp) : "./hrtfs/elev-35/L-35e085a.dat"
-[ 11, 56 ] = ascii (fp) : "./hrtfs/elev-35/L-35e080a.dat"
-[ 11, 57 ] = ascii (fp) : "./hrtfs/elev-35/L-35e075a.dat"
-[ 11, 58 ] = ascii (fp) : "./hrtfs/elev-35/L-35e070a.dat"
-[ 11, 59 ] = ascii (fp) : "./hrtfs/elev-35/L-35e065a.dat"
-[ 11, 60 ] = ascii (fp) : "./hrtfs/elev-35/L-35e060a.dat"
-[ 11, 61 ] = ascii (fp) : "./hrtfs/elev-35/L-35e055a.dat"
-[ 11, 62 ] = ascii (fp) : "./hrtfs/elev-35/L-35e050a.dat"
-[ 11, 63 ] = ascii (fp) : "./hrtfs/elev-35/L-35e045a.dat"
-[ 11, 64 ] = ascii (fp) : "./hrtfs/elev-35/L-35e040a.dat"
-[ 11, 65 ] = ascii (fp) : "./hrtfs/elev-35/L-35e035a.dat"
-[ 11, 66 ] = ascii (fp) : "./hrtfs/elev-35/L-35e030a.dat"
-[ 11, 67 ] = ascii (fp) : "./hrtfs/elev-35/L-35e025a.dat"
-[ 11, 68 ] = ascii (fp) : "./hrtfs/elev-35/L-35e020a.dat"
-[ 11, 69 ] = ascii (fp) : "./hrtfs/elev-35/L-35e015a.dat"
-[ 11, 70 ] = ascii (fp) : "./hrtfs/elev-35/L-35e010a.dat"
-[ 11, 71 ] = ascii (fp) : "./hrtfs/elev-35/L-35e005a.dat"
+[ 11, 0 ] = ascii (fp) : "./hrtfs/elev-35/L-35e000a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e000a.dat right
+[ 11, 1 ] = ascii (fp) : "./hrtfs/elev-35/L-35e355a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e355a.dat right
+[ 11, 2 ] = ascii (fp) : "./hrtfs/elev-35/L-35e350a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e350a.dat right
+[ 11, 3 ] = ascii (fp) : "./hrtfs/elev-35/L-35e345a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e345a.dat right
+[ 11, 4 ] = ascii (fp) : "./hrtfs/elev-35/L-35e340a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e340a.dat right
+[ 11, 5 ] = ascii (fp) : "./hrtfs/elev-35/L-35e335a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e335a.dat right
+[ 11, 6 ] = ascii (fp) : "./hrtfs/elev-35/L-35e330a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e330a.dat right
+[ 11, 7 ] = ascii (fp) : "./hrtfs/elev-35/L-35e325a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e325a.dat right
+[ 11, 8 ] = ascii (fp) : "./hrtfs/elev-35/L-35e320a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e320a.dat right
+[ 11, 9 ] = ascii (fp) : "./hrtfs/elev-35/L-35e315a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e315a.dat right
+[ 11, 10 ] = ascii (fp) : "./hrtfs/elev-35/L-35e310a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e310a.dat right
+[ 11, 11 ] = ascii (fp) : "./hrtfs/elev-35/L-35e305a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e305a.dat right
+[ 11, 12 ] = ascii (fp) : "./hrtfs/elev-35/L-35e300a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e300a.dat right
+[ 11, 13 ] = ascii (fp) : "./hrtfs/elev-35/L-35e295a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e295a.dat right
+[ 11, 14 ] = ascii (fp) : "./hrtfs/elev-35/L-35e290a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e290a.dat right
+[ 11, 15 ] = ascii (fp) : "./hrtfs/elev-35/L-35e285a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e285a.dat right
+[ 11, 16 ] = ascii (fp) : "./hrtfs/elev-35/L-35e280a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e280a.dat right
+[ 11, 17 ] = ascii (fp) : "./hrtfs/elev-35/L-35e275a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e275a.dat right
+[ 11, 18 ] = ascii (fp) : "./hrtfs/elev-35/L-35e270a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e270a.dat right
+[ 11, 19 ] = ascii (fp) : "./hrtfs/elev-35/L-35e265a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e265a.dat right
+[ 11, 20 ] = ascii (fp) : "./hrtfs/elev-35/L-35e260a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e260a.dat right
+[ 11, 21 ] = ascii (fp) : "./hrtfs/elev-35/L-35e255a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e255a.dat right
+[ 11, 22 ] = ascii (fp) : "./hrtfs/elev-35/L-35e250a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e250a.dat right
+[ 11, 23 ] = ascii (fp) : "./hrtfs/elev-35/L-35e245a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e245a.dat right
+[ 11, 24 ] = ascii (fp) : "./hrtfs/elev-35/L-35e240a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e240a.dat right
+[ 11, 25 ] = ascii (fp) : "./hrtfs/elev-35/L-35e235a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e235a.dat right
+[ 11, 26 ] = ascii (fp) : "./hrtfs/elev-35/L-35e230a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e230a.dat right
+[ 11, 27 ] = ascii (fp) : "./hrtfs/elev-35/L-35e225a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e225a.dat right
+[ 11, 28 ] = ascii (fp) : "./hrtfs/elev-35/L-35e220a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e220a.dat right
+[ 11, 29 ] = ascii (fp) : "./hrtfs/elev-35/L-35e215a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e215a.dat right
+[ 11, 30 ] = ascii (fp) : "./hrtfs/elev-35/L-35e210a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e210a.dat right
+[ 11, 31 ] = ascii (fp) : "./hrtfs/elev-35/L-35e205a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e205a.dat right
+[ 11, 32 ] = ascii (fp) : "./hrtfs/elev-35/L-35e200a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e200a.dat right
+[ 11, 33 ] = ascii (fp) : "./hrtfs/elev-35/L-35e195a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e195a.dat right
+[ 11, 34 ] = ascii (fp) : "./hrtfs/elev-35/L-35e190a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e190a.dat right
+[ 11, 35 ] = ascii (fp) : "./hrtfs/elev-35/L-35e185a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e185a.dat right
+[ 11, 36 ] = ascii (fp) : "./hrtfs/elev-35/L-35e180a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e180a.dat right
+[ 11, 37 ] = ascii (fp) : "./hrtfs/elev-35/L-35e175a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e175a.dat right
+[ 11, 38 ] = ascii (fp) : "./hrtfs/elev-35/L-35e170a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e170a.dat right
+[ 11, 39 ] = ascii (fp) : "./hrtfs/elev-35/L-35e165a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e165a.dat right
+[ 11, 40 ] = ascii (fp) : "./hrtfs/elev-35/L-35e160a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e160a.dat right
+[ 11, 41 ] = ascii (fp) : "./hrtfs/elev-35/L-35e155a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e155a.dat right
+[ 11, 42 ] = ascii (fp) : "./hrtfs/elev-35/L-35e150a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e150a.dat right
+[ 11, 43 ] = ascii (fp) : "./hrtfs/elev-35/L-35e145a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e145a.dat right
+[ 11, 44 ] = ascii (fp) : "./hrtfs/elev-35/L-35e140a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e140a.dat right
+[ 11, 45 ] = ascii (fp) : "./hrtfs/elev-35/L-35e135a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e135a.dat right
+[ 11, 46 ] = ascii (fp) : "./hrtfs/elev-35/L-35e130a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e130a.dat right
+[ 11, 47 ] = ascii (fp) : "./hrtfs/elev-35/L-35e125a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e125a.dat right
+[ 11, 48 ] = ascii (fp) : "./hrtfs/elev-35/L-35e120a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e120a.dat right
+[ 11, 49 ] = ascii (fp) : "./hrtfs/elev-35/L-35e115a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e115a.dat right
+[ 11, 50 ] = ascii (fp) : "./hrtfs/elev-35/L-35e110a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e110a.dat right
+[ 11, 51 ] = ascii (fp) : "./hrtfs/elev-35/L-35e105a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e105a.dat right
+[ 11, 52 ] = ascii (fp) : "./hrtfs/elev-35/L-35e100a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e100a.dat right
+[ 11, 53 ] = ascii (fp) : "./hrtfs/elev-35/L-35e095a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e095a.dat right
+[ 11, 54 ] = ascii (fp) : "./hrtfs/elev-35/L-35e090a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e090a.dat right
+[ 11, 55 ] = ascii (fp) : "./hrtfs/elev-35/L-35e085a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e085a.dat right
+[ 11, 56 ] = ascii (fp) : "./hrtfs/elev-35/L-35e080a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e080a.dat right
+[ 11, 57 ] = ascii (fp) : "./hrtfs/elev-35/L-35e075a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e075a.dat right
+[ 11, 58 ] = ascii (fp) : "./hrtfs/elev-35/L-35e070a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e070a.dat right
+[ 11, 59 ] = ascii (fp) : "./hrtfs/elev-35/L-35e065a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e065a.dat right
+[ 11, 60 ] = ascii (fp) : "./hrtfs/elev-35/L-35e060a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e060a.dat right
+[ 11, 61 ] = ascii (fp) : "./hrtfs/elev-35/L-35e055a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e055a.dat right
+[ 11, 62 ] = ascii (fp) : "./hrtfs/elev-35/L-35e050a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e050a.dat right
+[ 11, 63 ] = ascii (fp) : "./hrtfs/elev-35/L-35e045a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e045a.dat right
+[ 11, 64 ] = ascii (fp) : "./hrtfs/elev-35/L-35e040a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e040a.dat right
+[ 11, 65 ] = ascii (fp) : "./hrtfs/elev-35/L-35e035a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e035a.dat right
+[ 11, 66 ] = ascii (fp) : "./hrtfs/elev-35/L-35e030a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e030a.dat right
+[ 11, 67 ] = ascii (fp) : "./hrtfs/elev-35/L-35e025a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e025a.dat right
+[ 11, 68 ] = ascii (fp) : "./hrtfs/elev-35/L-35e020a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e020a.dat right
+[ 11, 69 ] = ascii (fp) : "./hrtfs/elev-35/L-35e015a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e015a.dat right
+[ 11, 70 ] = ascii (fp) : "./hrtfs/elev-35/L-35e010a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e010a.dat right
+[ 11, 71 ] = ascii (fp) : "./hrtfs/elev-35/L-35e005a.dat left
+ + ascii (fp) : "./hrtfs/elev-35/R-35e005a.dat right
-[ 12, 0 ] = ascii (fp) : "./hrtfs/elev-30/L-30e000a.dat"
-[ 12, 1 ] = ascii (fp) : "./hrtfs/elev-30/L-30e355a.dat"
-[ 12, 2 ] = ascii (fp) : "./hrtfs/elev-30/L-30e350a.dat"
-[ 12, 3 ] = ascii (fp) : "./hrtfs/elev-30/L-30e345a.dat"
-[ 12, 4 ] = ascii (fp) : "./hrtfs/elev-30/L-30e340a.dat"
-[ 12, 5 ] = ascii (fp) : "./hrtfs/elev-30/L-30e335a.dat"
-[ 12, 6 ] = ascii (fp) : "./hrtfs/elev-30/L-30e330a.dat"
-[ 12, 7 ] = ascii (fp) : "./hrtfs/elev-30/L-30e325a.dat"
-[ 12, 8 ] = ascii (fp) : "./hrtfs/elev-30/L-30e320a.dat"
-[ 12, 9 ] = ascii (fp) : "./hrtfs/elev-30/L-30e315a.dat"
-[ 12, 10 ] = ascii (fp) : "./hrtfs/elev-30/L-30e310a.dat"
-[ 12, 11 ] = ascii (fp) : "./hrtfs/elev-30/L-30e305a.dat"
-[ 12, 12 ] = ascii (fp) : "./hrtfs/elev-30/L-30e300a.dat"
-[ 12, 13 ] = ascii (fp) : "./hrtfs/elev-30/L-30e295a.dat"
-[ 12, 14 ] = ascii (fp) : "./hrtfs/elev-30/L-30e290a.dat"
-[ 12, 15 ] = ascii (fp) : "./hrtfs/elev-30/L-30e285a.dat"
-[ 12, 16 ] = ascii (fp) : "./hrtfs/elev-30/L-30e280a.dat"
-[ 12, 17 ] = ascii (fp) : "./hrtfs/elev-30/L-30e275a.dat"
-[ 12, 18 ] = ascii (fp) : "./hrtfs/elev-30/L-30e270a.dat"
-[ 12, 19 ] = ascii (fp) : "./hrtfs/elev-30/L-30e265a.dat"
-[ 12, 20 ] = ascii (fp) : "./hrtfs/elev-30/L-30e260a.dat"
-[ 12, 21 ] = ascii (fp) : "./hrtfs/elev-30/L-30e255a.dat"
-[ 12, 22 ] = ascii (fp) : "./hrtfs/elev-30/L-30e250a.dat"
-[ 12, 23 ] = ascii (fp) : "./hrtfs/elev-30/L-30e245a.dat"
-[ 12, 24 ] = ascii (fp) : "./hrtfs/elev-30/L-30e240a.dat"
-[ 12, 25 ] = ascii (fp) : "./hrtfs/elev-30/L-30e235a.dat"
-[ 12, 26 ] = ascii (fp) : "./hrtfs/elev-30/L-30e230a.dat"
-[ 12, 27 ] = ascii (fp) : "./hrtfs/elev-30/L-30e225a.dat"
-[ 12, 28 ] = ascii (fp) : "./hrtfs/elev-30/L-30e220a.dat"
-[ 12, 29 ] = ascii (fp) : "./hrtfs/elev-30/L-30e215a.dat"
-[ 12, 30 ] = ascii (fp) : "./hrtfs/elev-30/L-30e210a.dat"
-[ 12, 31 ] = ascii (fp) : "./hrtfs/elev-30/L-30e205a.dat"
-[ 12, 32 ] = ascii (fp) : "./hrtfs/elev-30/L-30e200a.dat"
-[ 12, 33 ] = ascii (fp) : "./hrtfs/elev-30/L-30e195a.dat"
-[ 12, 34 ] = ascii (fp) : "./hrtfs/elev-30/L-30e190a.dat"
-[ 12, 35 ] = ascii (fp) : "./hrtfs/elev-30/L-30e185a.dat"
-[ 12, 36 ] = ascii (fp) : "./hrtfs/elev-30/L-30e180a.dat"
-[ 12, 37 ] = ascii (fp) : "./hrtfs/elev-30/L-30e175a.dat"
-[ 12, 38 ] = ascii (fp) : "./hrtfs/elev-30/L-30e170a.dat"
-[ 12, 39 ] = ascii (fp) : "./hrtfs/elev-30/L-30e165a.dat"
-[ 12, 40 ] = ascii (fp) : "./hrtfs/elev-30/L-30e160a.dat"
-[ 12, 41 ] = ascii (fp) : "./hrtfs/elev-30/L-30e155a.dat"
-[ 12, 42 ] = ascii (fp) : "./hrtfs/elev-30/L-30e150a.dat"
-[ 12, 43 ] = ascii (fp) : "./hrtfs/elev-30/L-30e145a.dat"
-[ 12, 44 ] = ascii (fp) : "./hrtfs/elev-30/L-30e140a.dat"
-[ 12, 45 ] = ascii (fp) : "./hrtfs/elev-30/L-30e135a.dat"
-[ 12, 46 ] = ascii (fp) : "./hrtfs/elev-30/L-30e130a.dat"
-[ 12, 47 ] = ascii (fp) : "./hrtfs/elev-30/L-30e125a.dat"
-[ 12, 48 ] = ascii (fp) : "./hrtfs/elev-30/L-30e120a.dat"
-[ 12, 49 ] = ascii (fp) : "./hrtfs/elev-30/L-30e115a.dat"
-[ 12, 50 ] = ascii (fp) : "./hrtfs/elev-30/L-30e110a.dat"
-[ 12, 51 ] = ascii (fp) : "./hrtfs/elev-30/L-30e105a.dat"
-[ 12, 52 ] = ascii (fp) : "./hrtfs/elev-30/L-30e100a.dat"
-[ 12, 53 ] = ascii (fp) : "./hrtfs/elev-30/L-30e095a.dat"
-[ 12, 54 ] = ascii (fp) : "./hrtfs/elev-30/L-30e090a.dat"
-[ 12, 55 ] = ascii (fp) : "./hrtfs/elev-30/L-30e085a.dat"
-[ 12, 56 ] = ascii (fp) : "./hrtfs/elev-30/L-30e080a.dat"
-[ 12, 57 ] = ascii (fp) : "./hrtfs/elev-30/L-30e075a.dat"
-[ 12, 58 ] = ascii (fp) : "./hrtfs/elev-30/L-30e070a.dat"
-[ 12, 59 ] = ascii (fp) : "./hrtfs/elev-30/L-30e065a.dat"
-[ 12, 60 ] = ascii (fp) : "./hrtfs/elev-30/L-30e060a.dat"
-[ 12, 61 ] = ascii (fp) : "./hrtfs/elev-30/L-30e055a.dat"
-[ 12, 62 ] = ascii (fp) : "./hrtfs/elev-30/L-30e050a.dat"
-[ 12, 63 ] = ascii (fp) : "./hrtfs/elev-30/L-30e045a.dat"
-[ 12, 64 ] = ascii (fp) : "./hrtfs/elev-30/L-30e040a.dat"
-[ 12, 65 ] = ascii (fp) : "./hrtfs/elev-30/L-30e035a.dat"
-[ 12, 66 ] = ascii (fp) : "./hrtfs/elev-30/L-30e030a.dat"
-[ 12, 67 ] = ascii (fp) : "./hrtfs/elev-30/L-30e025a.dat"
-[ 12, 68 ] = ascii (fp) : "./hrtfs/elev-30/L-30e020a.dat"
-[ 12, 69 ] = ascii (fp) : "./hrtfs/elev-30/L-30e015a.dat"
-[ 12, 70 ] = ascii (fp) : "./hrtfs/elev-30/L-30e010a.dat"
-[ 12, 71 ] = ascii (fp) : "./hrtfs/elev-30/L-30e005a.dat"
+[ 12, 0 ] = ascii (fp) : "./hrtfs/elev-30/L-30e000a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e000a.dat right
+[ 12, 1 ] = ascii (fp) : "./hrtfs/elev-30/L-30e355a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e355a.dat right
+[ 12, 2 ] = ascii (fp) : "./hrtfs/elev-30/L-30e350a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e350a.dat right
+[ 12, 3 ] = ascii (fp) : "./hrtfs/elev-30/L-30e345a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e345a.dat right
+[ 12, 4 ] = ascii (fp) : "./hrtfs/elev-30/L-30e340a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e340a.dat right
+[ 12, 5 ] = ascii (fp) : "./hrtfs/elev-30/L-30e335a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e335a.dat right
+[ 12, 6 ] = ascii (fp) : "./hrtfs/elev-30/L-30e330a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e330a.dat right
+[ 12, 7 ] = ascii (fp) : "./hrtfs/elev-30/L-30e325a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e325a.dat right
+[ 12, 8 ] = ascii (fp) : "./hrtfs/elev-30/L-30e320a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e320a.dat right
+[ 12, 9 ] = ascii (fp) : "./hrtfs/elev-30/L-30e315a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e315a.dat right
+[ 12, 10 ] = ascii (fp) : "./hrtfs/elev-30/L-30e310a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e310a.dat right
+[ 12, 11 ] = ascii (fp) : "./hrtfs/elev-30/L-30e305a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e305a.dat right
+[ 12, 12 ] = ascii (fp) : "./hrtfs/elev-30/L-30e300a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e300a.dat right
+[ 12, 13 ] = ascii (fp) : "./hrtfs/elev-30/L-30e295a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e295a.dat right
+[ 12, 14 ] = ascii (fp) : "./hrtfs/elev-30/L-30e290a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e290a.dat right
+[ 12, 15 ] = ascii (fp) : "./hrtfs/elev-30/L-30e285a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e285a.dat right
+[ 12, 16 ] = ascii (fp) : "./hrtfs/elev-30/L-30e280a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e280a.dat right
+[ 12, 17 ] = ascii (fp) : "./hrtfs/elev-30/L-30e275a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e275a.dat right
+[ 12, 18 ] = ascii (fp) : "./hrtfs/elev-30/L-30e270a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e270a.dat right
+[ 12, 19 ] = ascii (fp) : "./hrtfs/elev-30/L-30e265a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e265a.dat right
+[ 12, 20 ] = ascii (fp) : "./hrtfs/elev-30/L-30e260a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e260a.dat right
+[ 12, 21 ] = ascii (fp) : "./hrtfs/elev-30/L-30e255a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e255a.dat right
+[ 12, 22 ] = ascii (fp) : "./hrtfs/elev-30/L-30e250a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e250a.dat right
+[ 12, 23 ] = ascii (fp) : "./hrtfs/elev-30/L-30e245a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e245a.dat right
+[ 12, 24 ] = ascii (fp) : "./hrtfs/elev-30/L-30e240a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e240a.dat right
+[ 12, 25 ] = ascii (fp) : "./hrtfs/elev-30/L-30e235a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e235a.dat right
+[ 12, 26 ] = ascii (fp) : "./hrtfs/elev-30/L-30e230a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e230a.dat right
+[ 12, 27 ] = ascii (fp) : "./hrtfs/elev-30/L-30e225a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e225a.dat right
+[ 12, 28 ] = ascii (fp) : "./hrtfs/elev-30/L-30e220a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e220a.dat right
+[ 12, 29 ] = ascii (fp) : "./hrtfs/elev-30/L-30e215a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e215a.dat right
+[ 12, 30 ] = ascii (fp) : "./hrtfs/elev-30/L-30e210a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e210a.dat right
+[ 12, 31 ] = ascii (fp) : "./hrtfs/elev-30/L-30e205a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e205a.dat right
+[ 12, 32 ] = ascii (fp) : "./hrtfs/elev-30/L-30e200a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e200a.dat right
+[ 12, 33 ] = ascii (fp) : "./hrtfs/elev-30/L-30e195a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e195a.dat right
+[ 12, 34 ] = ascii (fp) : "./hrtfs/elev-30/L-30e190a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e190a.dat right
+[ 12, 35 ] = ascii (fp) : "./hrtfs/elev-30/L-30e185a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e185a.dat right
+[ 12, 36 ] = ascii (fp) : "./hrtfs/elev-30/L-30e180a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e180a.dat right
+[ 12, 37 ] = ascii (fp) : "./hrtfs/elev-30/L-30e175a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e175a.dat right
+[ 12, 38 ] = ascii (fp) : "./hrtfs/elev-30/L-30e170a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e170a.dat right
+[ 12, 39 ] = ascii (fp) : "./hrtfs/elev-30/L-30e165a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e165a.dat right
+[ 12, 40 ] = ascii (fp) : "./hrtfs/elev-30/L-30e160a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e160a.dat right
+[ 12, 41 ] = ascii (fp) : "./hrtfs/elev-30/L-30e155a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e155a.dat right
+[ 12, 42 ] = ascii (fp) : "./hrtfs/elev-30/L-30e150a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e150a.dat right
+[ 12, 43 ] = ascii (fp) : "./hrtfs/elev-30/L-30e145a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e145a.dat right
+[ 12, 44 ] = ascii (fp) : "./hrtfs/elev-30/L-30e140a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e140a.dat right
+[ 12, 45 ] = ascii (fp) : "./hrtfs/elev-30/L-30e135a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e135a.dat right
+[ 12, 46 ] = ascii (fp) : "./hrtfs/elev-30/L-30e130a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e130a.dat right
+[ 12, 47 ] = ascii (fp) : "./hrtfs/elev-30/L-30e125a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e125a.dat right
+[ 12, 48 ] = ascii (fp) : "./hrtfs/elev-30/L-30e120a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e120a.dat right
+[ 12, 49 ] = ascii (fp) : "./hrtfs/elev-30/L-30e115a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e115a.dat right
+[ 12, 50 ] = ascii (fp) : "./hrtfs/elev-30/L-30e110a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e110a.dat right
+[ 12, 51 ] = ascii (fp) : "./hrtfs/elev-30/L-30e105a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e105a.dat right
+[ 12, 52 ] = ascii (fp) : "./hrtfs/elev-30/L-30e100a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e100a.dat right
+[ 12, 53 ] = ascii (fp) : "./hrtfs/elev-30/L-30e095a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e095a.dat right
+[ 12, 54 ] = ascii (fp) : "./hrtfs/elev-30/L-30e090a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e090a.dat right
+[ 12, 55 ] = ascii (fp) : "./hrtfs/elev-30/L-30e085a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e085a.dat right
+[ 12, 56 ] = ascii (fp) : "./hrtfs/elev-30/L-30e080a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e080a.dat right
+[ 12, 57 ] = ascii (fp) : "./hrtfs/elev-30/L-30e075a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e075a.dat right
+[ 12, 58 ] = ascii (fp) : "./hrtfs/elev-30/L-30e070a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e070a.dat right
+[ 12, 59 ] = ascii (fp) : "./hrtfs/elev-30/L-30e065a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e065a.dat right
+[ 12, 60 ] = ascii (fp) : "./hrtfs/elev-30/L-30e060a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e060a.dat right
+[ 12, 61 ] = ascii (fp) : "./hrtfs/elev-30/L-30e055a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e055a.dat right
+[ 12, 62 ] = ascii (fp) : "./hrtfs/elev-30/L-30e050a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e050a.dat right
+[ 12, 63 ] = ascii (fp) : "./hrtfs/elev-30/L-30e045a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e045a.dat right
+[ 12, 64 ] = ascii (fp) : "./hrtfs/elev-30/L-30e040a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e040a.dat right
+[ 12, 65 ] = ascii (fp) : "./hrtfs/elev-30/L-30e035a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e035a.dat right
+[ 12, 66 ] = ascii (fp) : "./hrtfs/elev-30/L-30e030a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e030a.dat right
+[ 12, 67 ] = ascii (fp) : "./hrtfs/elev-30/L-30e025a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e025a.dat right
+[ 12, 68 ] = ascii (fp) : "./hrtfs/elev-30/L-30e020a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e020a.dat right
+[ 12, 69 ] = ascii (fp) : "./hrtfs/elev-30/L-30e015a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e015a.dat right
+[ 12, 70 ] = ascii (fp) : "./hrtfs/elev-30/L-30e010a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e010a.dat right
+[ 12, 71 ] = ascii (fp) : "./hrtfs/elev-30/L-30e005a.dat left
+ + ascii (fp) : "./hrtfs/elev-30/R-30e005a.dat right
-[ 13, 0 ] = ascii (fp) : "./hrtfs/elev-25/L-25e000a.dat"
-[ 13, 1 ] = ascii (fp) : "./hrtfs/elev-25/L-25e355a.dat"
-[ 13, 2 ] = ascii (fp) : "./hrtfs/elev-25/L-25e350a.dat"
-[ 13, 3 ] = ascii (fp) : "./hrtfs/elev-25/L-25e345a.dat"
-[ 13, 4 ] = ascii (fp) : "./hrtfs/elev-25/L-25e340a.dat"
-[ 13, 5 ] = ascii (fp) : "./hrtfs/elev-25/L-25e335a.dat"
-[ 13, 6 ] = ascii (fp) : "./hrtfs/elev-25/L-25e330a.dat"
-[ 13, 7 ] = ascii (fp) : "./hrtfs/elev-25/L-25e325a.dat"
-[ 13, 8 ] = ascii (fp) : "./hrtfs/elev-25/L-25e320a.dat"
-[ 13, 9 ] = ascii (fp) : "./hrtfs/elev-25/L-25e315a.dat"
-[ 13, 10 ] = ascii (fp) : "./hrtfs/elev-25/L-25e310a.dat"
-[ 13, 11 ] = ascii (fp) : "./hrtfs/elev-25/L-25e305a.dat"
-[ 13, 12 ] = ascii (fp) : "./hrtfs/elev-25/L-25e300a.dat"
-[ 13, 13 ] = ascii (fp) : "./hrtfs/elev-25/L-25e295a.dat"
-[ 13, 14 ] = ascii (fp) : "./hrtfs/elev-25/L-25e290a.dat"
-[ 13, 15 ] = ascii (fp) : "./hrtfs/elev-25/L-25e285a.dat"
-[ 13, 16 ] = ascii (fp) : "./hrtfs/elev-25/L-25e280a.dat"
-[ 13, 17 ] = ascii (fp) : "./hrtfs/elev-25/L-25e275a.dat"
-[ 13, 18 ] = ascii (fp) : "./hrtfs/elev-25/L-25e270a.dat"
-[ 13, 19 ] = ascii (fp) : "./hrtfs/elev-25/L-25e265a.dat"
-[ 13, 20 ] = ascii (fp) : "./hrtfs/elev-25/L-25e260a.dat"
-[ 13, 21 ] = ascii (fp) : "./hrtfs/elev-25/L-25e255a.dat"
-[ 13, 22 ] = ascii (fp) : "./hrtfs/elev-25/L-25e250a.dat"
-[ 13, 23 ] = ascii (fp) : "./hrtfs/elev-25/L-25e245a.dat"
-[ 13, 24 ] = ascii (fp) : "./hrtfs/elev-25/L-25e240a.dat"
-[ 13, 25 ] = ascii (fp) : "./hrtfs/elev-25/L-25e235a.dat"
-[ 13, 26 ] = ascii (fp) : "./hrtfs/elev-25/L-25e230a.dat"
-[ 13, 27 ] = ascii (fp) : "./hrtfs/elev-25/L-25e225a.dat"
-[ 13, 28 ] = ascii (fp) : "./hrtfs/elev-25/L-25e220a.dat"
-[ 13, 29 ] = ascii (fp) : "./hrtfs/elev-25/L-25e215a.dat"
-[ 13, 30 ] = ascii (fp) : "./hrtfs/elev-25/L-25e210a.dat"
-[ 13, 31 ] = ascii (fp) : "./hrtfs/elev-25/L-25e205a.dat"
-[ 13, 32 ] = ascii (fp) : "./hrtfs/elev-25/L-25e200a.dat"
-[ 13, 33 ] = ascii (fp) : "./hrtfs/elev-25/L-25e195a.dat"
-[ 13, 34 ] = ascii (fp) : "./hrtfs/elev-25/L-25e190a.dat"
-[ 13, 35 ] = ascii (fp) : "./hrtfs/elev-25/L-25e185a.dat"
-[ 13, 36 ] = ascii (fp) : "./hrtfs/elev-25/L-25e180a.dat"
-[ 13, 37 ] = ascii (fp) : "./hrtfs/elev-25/L-25e175a.dat"
-[ 13, 38 ] = ascii (fp) : "./hrtfs/elev-25/L-25e170a.dat"
-[ 13, 39 ] = ascii (fp) : "./hrtfs/elev-25/L-25e165a.dat"
-[ 13, 40 ] = ascii (fp) : "./hrtfs/elev-25/L-25e160a.dat"
-[ 13, 41 ] = ascii (fp) : "./hrtfs/elev-25/L-25e155a.dat"
-[ 13, 42 ] = ascii (fp) : "./hrtfs/elev-25/L-25e150a.dat"
-[ 13, 43 ] = ascii (fp) : "./hrtfs/elev-25/L-25e145a.dat"
-[ 13, 44 ] = ascii (fp) : "./hrtfs/elev-25/L-25e140a.dat"
-[ 13, 45 ] = ascii (fp) : "./hrtfs/elev-25/L-25e135a.dat"
-[ 13, 46 ] = ascii (fp) : "./hrtfs/elev-25/L-25e130a.dat"
-[ 13, 47 ] = ascii (fp) : "./hrtfs/elev-25/L-25e125a.dat"
-[ 13, 48 ] = ascii (fp) : "./hrtfs/elev-25/L-25e120a.dat"
-[ 13, 49 ] = ascii (fp) : "./hrtfs/elev-25/L-25e115a.dat"
-[ 13, 50 ] = ascii (fp) : "./hrtfs/elev-25/L-25e110a.dat"
-[ 13, 51 ] = ascii (fp) : "./hrtfs/elev-25/L-25e105a.dat"
-[ 13, 52 ] = ascii (fp) : "./hrtfs/elev-25/L-25e100a.dat"
-[ 13, 53 ] = ascii (fp) : "./hrtfs/elev-25/L-25e095a.dat"
-[ 13, 54 ] = ascii (fp) : "./hrtfs/elev-25/L-25e090a.dat"
-[ 13, 55 ] = ascii (fp) : "./hrtfs/elev-25/L-25e085a.dat"
-[ 13, 56 ] = ascii (fp) : "./hrtfs/elev-25/L-25e080a.dat"
-[ 13, 57 ] = ascii (fp) : "./hrtfs/elev-25/L-25e075a.dat"
-[ 13, 58 ] = ascii (fp) : "./hrtfs/elev-25/L-25e070a.dat"
-[ 13, 59 ] = ascii (fp) : "./hrtfs/elev-25/L-25e065a.dat"
-[ 13, 60 ] = ascii (fp) : "./hrtfs/elev-25/L-25e060a.dat"
-[ 13, 61 ] = ascii (fp) : "./hrtfs/elev-25/L-25e055a.dat"
-[ 13, 62 ] = ascii (fp) : "./hrtfs/elev-25/L-25e050a.dat"
-[ 13, 63 ] = ascii (fp) : "./hrtfs/elev-25/L-25e045a.dat"
-[ 13, 64 ] = ascii (fp) : "./hrtfs/elev-25/L-25e040a.dat"
-[ 13, 65 ] = ascii (fp) : "./hrtfs/elev-25/L-25e035a.dat"
-[ 13, 66 ] = ascii (fp) : "./hrtfs/elev-25/L-25e030a.dat"
-[ 13, 67 ] = ascii (fp) : "./hrtfs/elev-25/L-25e025a.dat"
-[ 13, 68 ] = ascii (fp) : "./hrtfs/elev-25/L-25e020a.dat"
-[ 13, 69 ] = ascii (fp) : "./hrtfs/elev-25/L-25e015a.dat"
-[ 13, 70 ] = ascii (fp) : "./hrtfs/elev-25/L-25e010a.dat"
-[ 13, 71 ] = ascii (fp) : "./hrtfs/elev-25/L-25e005a.dat"
+[ 13, 0 ] = ascii (fp) : "./hrtfs/elev-25/L-25e000a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e000a.dat right
+[ 13, 1 ] = ascii (fp) : "./hrtfs/elev-25/L-25e355a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e355a.dat right
+[ 13, 2 ] = ascii (fp) : "./hrtfs/elev-25/L-25e350a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e350a.dat right
+[ 13, 3 ] = ascii (fp) : "./hrtfs/elev-25/L-25e345a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e345a.dat right
+[ 13, 4 ] = ascii (fp) : "./hrtfs/elev-25/L-25e340a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e340a.dat right
+[ 13, 5 ] = ascii (fp) : "./hrtfs/elev-25/L-25e335a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e335a.dat right
+[ 13, 6 ] = ascii (fp) : "./hrtfs/elev-25/L-25e330a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e330a.dat right
+[ 13, 7 ] = ascii (fp) : "./hrtfs/elev-25/L-25e325a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e325a.dat right
+[ 13, 8 ] = ascii (fp) : "./hrtfs/elev-25/L-25e320a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e320a.dat right
+[ 13, 9 ] = ascii (fp) : "./hrtfs/elev-25/L-25e315a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e315a.dat right
+[ 13, 10 ] = ascii (fp) : "./hrtfs/elev-25/L-25e310a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e310a.dat right
+[ 13, 11 ] = ascii (fp) : "./hrtfs/elev-25/L-25e305a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e305a.dat right
+[ 13, 12 ] = ascii (fp) : "./hrtfs/elev-25/L-25e300a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e300a.dat right
+[ 13, 13 ] = ascii (fp) : "./hrtfs/elev-25/L-25e295a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e295a.dat right
+[ 13, 14 ] = ascii (fp) : "./hrtfs/elev-25/L-25e290a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e290a.dat right
+[ 13, 15 ] = ascii (fp) : "./hrtfs/elev-25/L-25e285a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e285a.dat right
+[ 13, 16 ] = ascii (fp) : "./hrtfs/elev-25/L-25e280a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e280a.dat right
+[ 13, 17 ] = ascii (fp) : "./hrtfs/elev-25/L-25e275a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e275a.dat right
+[ 13, 18 ] = ascii (fp) : "./hrtfs/elev-25/L-25e270a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e270a.dat right
+[ 13, 19 ] = ascii (fp) : "./hrtfs/elev-25/L-25e265a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e265a.dat right
+[ 13, 20 ] = ascii (fp) : "./hrtfs/elev-25/L-25e260a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e260a.dat right
+[ 13, 21 ] = ascii (fp) : "./hrtfs/elev-25/L-25e255a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e255a.dat right
+[ 13, 22 ] = ascii (fp) : "./hrtfs/elev-25/L-25e250a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e250a.dat right
+[ 13, 23 ] = ascii (fp) : "./hrtfs/elev-25/L-25e245a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e245a.dat right
+[ 13, 24 ] = ascii (fp) : "./hrtfs/elev-25/L-25e240a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e240a.dat right
+[ 13, 25 ] = ascii (fp) : "./hrtfs/elev-25/L-25e235a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e235a.dat right
+[ 13, 26 ] = ascii (fp) : "./hrtfs/elev-25/L-25e230a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e230a.dat right
+[ 13, 27 ] = ascii (fp) : "./hrtfs/elev-25/L-25e225a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e225a.dat right
+[ 13, 28 ] = ascii (fp) : "./hrtfs/elev-25/L-25e220a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e220a.dat right
+[ 13, 29 ] = ascii (fp) : "./hrtfs/elev-25/L-25e215a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e215a.dat right
+[ 13, 30 ] = ascii (fp) : "./hrtfs/elev-25/L-25e210a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e210a.dat right
+[ 13, 31 ] = ascii (fp) : "./hrtfs/elev-25/L-25e205a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e205a.dat right
+[ 13, 32 ] = ascii (fp) : "./hrtfs/elev-25/L-25e200a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e200a.dat right
+[ 13, 33 ] = ascii (fp) : "./hrtfs/elev-25/L-25e195a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e195a.dat right
+[ 13, 34 ] = ascii (fp) : "./hrtfs/elev-25/L-25e190a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e190a.dat right
+[ 13, 35 ] = ascii (fp) : "./hrtfs/elev-25/L-25e185a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e185a.dat right
+[ 13, 36 ] = ascii (fp) : "./hrtfs/elev-25/L-25e180a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e180a.dat right
+[ 13, 37 ] = ascii (fp) : "./hrtfs/elev-25/L-25e175a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e175a.dat right
+[ 13, 38 ] = ascii (fp) : "./hrtfs/elev-25/L-25e170a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e170a.dat right
+[ 13, 39 ] = ascii (fp) : "./hrtfs/elev-25/L-25e165a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e165a.dat right
+[ 13, 40 ] = ascii (fp) : "./hrtfs/elev-25/L-25e160a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e160a.dat right
+[ 13, 41 ] = ascii (fp) : "./hrtfs/elev-25/L-25e155a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e155a.dat right
+[ 13, 42 ] = ascii (fp) : "./hrtfs/elev-25/L-25e150a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e150a.dat right
+[ 13, 43 ] = ascii (fp) : "./hrtfs/elev-25/L-25e145a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e145a.dat right
+[ 13, 44 ] = ascii (fp) : "./hrtfs/elev-25/L-25e140a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e140a.dat right
+[ 13, 45 ] = ascii (fp) : "./hrtfs/elev-25/L-25e135a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e135a.dat right
+[ 13, 46 ] = ascii (fp) : "./hrtfs/elev-25/L-25e130a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e130a.dat right
+[ 13, 47 ] = ascii (fp) : "./hrtfs/elev-25/L-25e125a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e125a.dat right
+[ 13, 48 ] = ascii (fp) : "./hrtfs/elev-25/L-25e120a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e120a.dat right
+[ 13, 49 ] = ascii (fp) : "./hrtfs/elev-25/L-25e115a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e115a.dat right
+[ 13, 50 ] = ascii (fp) : "./hrtfs/elev-25/L-25e110a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e110a.dat right
+[ 13, 51 ] = ascii (fp) : "./hrtfs/elev-25/L-25e105a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e105a.dat right
+[ 13, 52 ] = ascii (fp) : "./hrtfs/elev-25/L-25e100a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e100a.dat right
+[ 13, 53 ] = ascii (fp) : "./hrtfs/elev-25/L-25e095a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e095a.dat right
+[ 13, 54 ] = ascii (fp) : "./hrtfs/elev-25/L-25e090a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e090a.dat right
+[ 13, 55 ] = ascii (fp) : "./hrtfs/elev-25/L-25e085a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e085a.dat right
+[ 13, 56 ] = ascii (fp) : "./hrtfs/elev-25/L-25e080a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e080a.dat right
+[ 13, 57 ] = ascii (fp) : "./hrtfs/elev-25/L-25e075a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e075a.dat right
+[ 13, 58 ] = ascii (fp) : "./hrtfs/elev-25/L-25e070a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e070a.dat right
+[ 13, 59 ] = ascii (fp) : "./hrtfs/elev-25/L-25e065a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e065a.dat right
+[ 13, 60 ] = ascii (fp) : "./hrtfs/elev-25/L-25e060a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e060a.dat right
+[ 13, 61 ] = ascii (fp) : "./hrtfs/elev-25/L-25e055a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e055a.dat right
+[ 13, 62 ] = ascii (fp) : "./hrtfs/elev-25/L-25e050a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e050a.dat right
+[ 13, 63 ] = ascii (fp) : "./hrtfs/elev-25/L-25e045a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e045a.dat right
+[ 13, 64 ] = ascii (fp) : "./hrtfs/elev-25/L-25e040a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e040a.dat right
+[ 13, 65 ] = ascii (fp) : "./hrtfs/elev-25/L-25e035a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e035a.dat right
+[ 13, 66 ] = ascii (fp) : "./hrtfs/elev-25/L-25e030a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e030a.dat right
+[ 13, 67 ] = ascii (fp) : "./hrtfs/elev-25/L-25e025a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e025a.dat right
+[ 13, 68 ] = ascii (fp) : "./hrtfs/elev-25/L-25e020a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e020a.dat right
+[ 13, 69 ] = ascii (fp) : "./hrtfs/elev-25/L-25e015a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e015a.dat right
+[ 13, 70 ] = ascii (fp) : "./hrtfs/elev-25/L-25e010a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e010a.dat right
+[ 13, 71 ] = ascii (fp) : "./hrtfs/elev-25/L-25e005a.dat left
+ + ascii (fp) : "./hrtfs/elev-25/R-25e005a.dat right
-[ 14, 0 ] = ascii (fp) : "./hrtfs/elev-20/L-20e000a.dat"
-[ 14, 1 ] = ascii (fp) : "./hrtfs/elev-20/L-20e355a.dat"
-[ 14, 2 ] = ascii (fp) : "./hrtfs/elev-20/L-20e350a.dat"
-[ 14, 3 ] = ascii (fp) : "./hrtfs/elev-20/L-20e345a.dat"
-[ 14, 4 ] = ascii (fp) : "./hrtfs/elev-20/L-20e340a.dat"
-[ 14, 5 ] = ascii (fp) : "./hrtfs/elev-20/L-20e335a.dat"
-[ 14, 6 ] = ascii (fp) : "./hrtfs/elev-20/L-20e330a.dat"
-[ 14, 7 ] = ascii (fp) : "./hrtfs/elev-20/L-20e325a.dat"
-[ 14, 8 ] = ascii (fp) : "./hrtfs/elev-20/L-20e320a.dat"
-[ 14, 9 ] = ascii (fp) : "./hrtfs/elev-20/L-20e315a.dat"
-[ 14, 10 ] = ascii (fp) : "./hrtfs/elev-20/L-20e310a.dat"
-[ 14, 11 ] = ascii (fp) : "./hrtfs/elev-20/L-20e305a.dat"
-[ 14, 12 ] = ascii (fp) : "./hrtfs/elev-20/L-20e300a.dat"
-[ 14, 13 ] = ascii (fp) : "./hrtfs/elev-20/L-20e295a.dat"
-[ 14, 14 ] = ascii (fp) : "./hrtfs/elev-20/L-20e290a.dat"
-[ 14, 15 ] = ascii (fp) : "./hrtfs/elev-20/L-20e285a.dat"
-[ 14, 16 ] = ascii (fp) : "./hrtfs/elev-20/L-20e280a.dat"
-[ 14, 17 ] = ascii (fp) : "./hrtfs/elev-20/L-20e275a.dat"
-[ 14, 18 ] = ascii (fp) : "./hrtfs/elev-20/L-20e270a.dat"
-[ 14, 19 ] = ascii (fp) : "./hrtfs/elev-20/L-20e265a.dat"
-[ 14, 20 ] = ascii (fp) : "./hrtfs/elev-20/L-20e260a.dat"
-[ 14, 21 ] = ascii (fp) : "./hrtfs/elev-20/L-20e255a.dat"
-[ 14, 22 ] = ascii (fp) : "./hrtfs/elev-20/L-20e250a.dat"
-[ 14, 23 ] = ascii (fp) : "./hrtfs/elev-20/L-20e245a.dat"
-[ 14, 24 ] = ascii (fp) : "./hrtfs/elev-20/L-20e240a.dat"
-[ 14, 25 ] = ascii (fp) : "./hrtfs/elev-20/L-20e235a.dat"
-[ 14, 26 ] = ascii (fp) : "./hrtfs/elev-20/L-20e230a.dat"
-[ 14, 27 ] = ascii (fp) : "./hrtfs/elev-20/L-20e225a.dat"
-[ 14, 28 ] = ascii (fp) : "./hrtfs/elev-20/L-20e220a.dat"
-[ 14, 29 ] = ascii (fp) : "./hrtfs/elev-20/L-20e215a.dat"
-[ 14, 30 ] = ascii (fp) : "./hrtfs/elev-20/L-20e210a.dat"
-[ 14, 31 ] = ascii (fp) : "./hrtfs/elev-20/L-20e205a.dat"
-[ 14, 32 ] = ascii (fp) : "./hrtfs/elev-20/L-20e200a.dat"
-[ 14, 33 ] = ascii (fp) : "./hrtfs/elev-20/L-20e195a.dat"
-[ 14, 34 ] = ascii (fp) : "./hrtfs/elev-20/L-20e190a.dat"
-[ 14, 35 ] = ascii (fp) : "./hrtfs/elev-20/L-20e185a.dat"
-[ 14, 36 ] = ascii (fp) : "./hrtfs/elev-20/L-20e180a.dat"
-[ 14, 37 ] = ascii (fp) : "./hrtfs/elev-20/L-20e175a.dat"
-[ 14, 38 ] = ascii (fp) : "./hrtfs/elev-20/L-20e170a.dat"
-[ 14, 39 ] = ascii (fp) : "./hrtfs/elev-20/L-20e165a.dat"
-[ 14, 40 ] = ascii (fp) : "./hrtfs/elev-20/L-20e160a.dat"
-[ 14, 41 ] = ascii (fp) : "./hrtfs/elev-20/L-20e155a.dat"
-[ 14, 42 ] = ascii (fp) : "./hrtfs/elev-20/L-20e150a.dat"
-[ 14, 43 ] = ascii (fp) : "./hrtfs/elev-20/L-20e145a.dat"
-[ 14, 44 ] = ascii (fp) : "./hrtfs/elev-20/L-20e140a.dat"
-[ 14, 45 ] = ascii (fp) : "./hrtfs/elev-20/L-20e135a.dat"
-[ 14, 46 ] = ascii (fp) : "./hrtfs/elev-20/L-20e130a.dat"
-[ 14, 47 ] = ascii (fp) : "./hrtfs/elev-20/L-20e125a.dat"
-[ 14, 48 ] = ascii (fp) : "./hrtfs/elev-20/L-20e120a.dat"
-[ 14, 49 ] = ascii (fp) : "./hrtfs/elev-20/L-20e115a.dat"
-[ 14, 50 ] = ascii (fp) : "./hrtfs/elev-20/L-20e110a.dat"
-[ 14, 51 ] = ascii (fp) : "./hrtfs/elev-20/L-20e105a.dat"
-[ 14, 52 ] = ascii (fp) : "./hrtfs/elev-20/L-20e100a.dat"
-[ 14, 53 ] = ascii (fp) : "./hrtfs/elev-20/L-20e095a.dat"
-[ 14, 54 ] = ascii (fp) : "./hrtfs/elev-20/L-20e090a.dat"
-[ 14, 55 ] = ascii (fp) : "./hrtfs/elev-20/L-20e085a.dat"
-[ 14, 56 ] = ascii (fp) : "./hrtfs/elev-20/L-20e080a.dat"
-[ 14, 57 ] = ascii (fp) : "./hrtfs/elev-20/L-20e075a.dat"
-[ 14, 58 ] = ascii (fp) : "./hrtfs/elev-20/L-20e070a.dat"
-[ 14, 59 ] = ascii (fp) : "./hrtfs/elev-20/L-20e065a.dat"
-[ 14, 60 ] = ascii (fp) : "./hrtfs/elev-20/L-20e060a.dat"
-[ 14, 61 ] = ascii (fp) : "./hrtfs/elev-20/L-20e055a.dat"
-[ 14, 62 ] = ascii (fp) : "./hrtfs/elev-20/L-20e050a.dat"
-[ 14, 63 ] = ascii (fp) : "./hrtfs/elev-20/L-20e045a.dat"
-[ 14, 64 ] = ascii (fp) : "./hrtfs/elev-20/L-20e040a.dat"
-[ 14, 65 ] = ascii (fp) : "./hrtfs/elev-20/L-20e035a.dat"
-[ 14, 66 ] = ascii (fp) : "./hrtfs/elev-20/L-20e030a.dat"
-[ 14, 67 ] = ascii (fp) : "./hrtfs/elev-20/L-20e025a.dat"
-[ 14, 68 ] = ascii (fp) : "./hrtfs/elev-20/L-20e020a.dat"
-[ 14, 69 ] = ascii (fp) : "./hrtfs/elev-20/L-20e015a.dat"
-[ 14, 70 ] = ascii (fp) : "./hrtfs/elev-20/L-20e010a.dat"
-[ 14, 71 ] = ascii (fp) : "./hrtfs/elev-20/L-20e005a.dat"
+[ 14, 0 ] = ascii (fp) : "./hrtfs/elev-20/L-20e000a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e000a.dat right
+[ 14, 1 ] = ascii (fp) : "./hrtfs/elev-20/L-20e355a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e355a.dat right
+[ 14, 2 ] = ascii (fp) : "./hrtfs/elev-20/L-20e350a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e350a.dat right
+[ 14, 3 ] = ascii (fp) : "./hrtfs/elev-20/L-20e345a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e345a.dat right
+[ 14, 4 ] = ascii (fp) : "./hrtfs/elev-20/L-20e340a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e340a.dat right
+[ 14, 5 ] = ascii (fp) : "./hrtfs/elev-20/L-20e335a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e335a.dat right
+[ 14, 6 ] = ascii (fp) : "./hrtfs/elev-20/L-20e330a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e330a.dat right
+[ 14, 7 ] = ascii (fp) : "./hrtfs/elev-20/L-20e325a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e325a.dat right
+[ 14, 8 ] = ascii (fp) : "./hrtfs/elev-20/L-20e320a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e320a.dat right
+[ 14, 9 ] = ascii (fp) : "./hrtfs/elev-20/L-20e315a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e315a.dat right
+[ 14, 10 ] = ascii (fp) : "./hrtfs/elev-20/L-20e310a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e310a.dat right
+[ 14, 11 ] = ascii (fp) : "./hrtfs/elev-20/L-20e305a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e305a.dat right
+[ 14, 12 ] = ascii (fp) : "./hrtfs/elev-20/L-20e300a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e300a.dat right
+[ 14, 13 ] = ascii (fp) : "./hrtfs/elev-20/L-20e295a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e295a.dat right
+[ 14, 14 ] = ascii (fp) : "./hrtfs/elev-20/L-20e290a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e290a.dat right
+[ 14, 15 ] = ascii (fp) : "./hrtfs/elev-20/L-20e285a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e285a.dat right
+[ 14, 16 ] = ascii (fp) : "./hrtfs/elev-20/L-20e280a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e280a.dat right
+[ 14, 17 ] = ascii (fp) : "./hrtfs/elev-20/L-20e275a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e275a.dat right
+[ 14, 18 ] = ascii (fp) : "./hrtfs/elev-20/L-20e270a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e270a.dat right
+[ 14, 19 ] = ascii (fp) : "./hrtfs/elev-20/L-20e265a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e265a.dat right
+[ 14, 20 ] = ascii (fp) : "./hrtfs/elev-20/L-20e260a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e260a.dat right
+[ 14, 21 ] = ascii (fp) : "./hrtfs/elev-20/L-20e255a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e255a.dat right
+[ 14, 22 ] = ascii (fp) : "./hrtfs/elev-20/L-20e250a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e250a.dat right
+[ 14, 23 ] = ascii (fp) : "./hrtfs/elev-20/L-20e245a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e245a.dat right
+[ 14, 24 ] = ascii (fp) : "./hrtfs/elev-20/L-20e240a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e240a.dat right
+[ 14, 25 ] = ascii (fp) : "./hrtfs/elev-20/L-20e235a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e235a.dat right
+[ 14, 26 ] = ascii (fp) : "./hrtfs/elev-20/L-20e230a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e230a.dat right
+[ 14, 27 ] = ascii (fp) : "./hrtfs/elev-20/L-20e225a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e225a.dat right
+[ 14, 28 ] = ascii (fp) : "./hrtfs/elev-20/L-20e220a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e220a.dat right
+[ 14, 29 ] = ascii (fp) : "./hrtfs/elev-20/L-20e215a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e215a.dat right
+[ 14, 30 ] = ascii (fp) : "./hrtfs/elev-20/L-20e210a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e210a.dat right
+[ 14, 31 ] = ascii (fp) : "./hrtfs/elev-20/L-20e205a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e205a.dat right
+[ 14, 32 ] = ascii (fp) : "./hrtfs/elev-20/L-20e200a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e200a.dat right
+[ 14, 33 ] = ascii (fp) : "./hrtfs/elev-20/L-20e195a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e195a.dat right
+[ 14, 34 ] = ascii (fp) : "./hrtfs/elev-20/L-20e190a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e190a.dat right
+[ 14, 35 ] = ascii (fp) : "./hrtfs/elev-20/L-20e185a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e185a.dat right
+[ 14, 36 ] = ascii (fp) : "./hrtfs/elev-20/L-20e180a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e180a.dat right
+[ 14, 37 ] = ascii (fp) : "./hrtfs/elev-20/L-20e175a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e175a.dat right
+[ 14, 38 ] = ascii (fp) : "./hrtfs/elev-20/L-20e170a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e170a.dat right
+[ 14, 39 ] = ascii (fp) : "./hrtfs/elev-20/L-20e165a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e165a.dat right
+[ 14, 40 ] = ascii (fp) : "./hrtfs/elev-20/L-20e160a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e160a.dat right
+[ 14, 41 ] = ascii (fp) : "./hrtfs/elev-20/L-20e155a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e155a.dat right
+[ 14, 42 ] = ascii (fp) : "./hrtfs/elev-20/L-20e150a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e150a.dat right
+[ 14, 43 ] = ascii (fp) : "./hrtfs/elev-20/L-20e145a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e145a.dat right
+[ 14, 44 ] = ascii (fp) : "./hrtfs/elev-20/L-20e140a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e140a.dat right
+[ 14, 45 ] = ascii (fp) : "./hrtfs/elev-20/L-20e135a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e135a.dat right
+[ 14, 46 ] = ascii (fp) : "./hrtfs/elev-20/L-20e130a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e130a.dat right
+[ 14, 47 ] = ascii (fp) : "./hrtfs/elev-20/L-20e125a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e125a.dat right
+[ 14, 48 ] = ascii (fp) : "./hrtfs/elev-20/L-20e120a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e120a.dat right
+[ 14, 49 ] = ascii (fp) : "./hrtfs/elev-20/L-20e115a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e115a.dat right
+[ 14, 50 ] = ascii (fp) : "./hrtfs/elev-20/L-20e110a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e110a.dat right
+[ 14, 51 ] = ascii (fp) : "./hrtfs/elev-20/L-20e105a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e105a.dat right
+[ 14, 52 ] = ascii (fp) : "./hrtfs/elev-20/L-20e100a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e100a.dat right
+[ 14, 53 ] = ascii (fp) : "./hrtfs/elev-20/L-20e095a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e095a.dat right
+[ 14, 54 ] = ascii (fp) : "./hrtfs/elev-20/L-20e090a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e090a.dat right
+[ 14, 55 ] = ascii (fp) : "./hrtfs/elev-20/L-20e085a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e085a.dat right
+[ 14, 56 ] = ascii (fp) : "./hrtfs/elev-20/L-20e080a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e080a.dat right
+[ 14, 57 ] = ascii (fp) : "./hrtfs/elev-20/L-20e075a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e075a.dat right
+[ 14, 58 ] = ascii (fp) : "./hrtfs/elev-20/L-20e070a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e070a.dat right
+[ 14, 59 ] = ascii (fp) : "./hrtfs/elev-20/L-20e065a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e065a.dat right
+[ 14, 60 ] = ascii (fp) : "./hrtfs/elev-20/L-20e060a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e060a.dat right
+[ 14, 61 ] = ascii (fp) : "./hrtfs/elev-20/L-20e055a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e055a.dat right
+[ 14, 62 ] = ascii (fp) : "./hrtfs/elev-20/L-20e050a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e050a.dat right
+[ 14, 63 ] = ascii (fp) : "./hrtfs/elev-20/L-20e045a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e045a.dat right
+[ 14, 64 ] = ascii (fp) : "./hrtfs/elev-20/L-20e040a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e040a.dat right
+[ 14, 65 ] = ascii (fp) : "./hrtfs/elev-20/L-20e035a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e035a.dat right
+[ 14, 66 ] = ascii (fp) : "./hrtfs/elev-20/L-20e030a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e030a.dat right
+[ 14, 67 ] = ascii (fp) : "./hrtfs/elev-20/L-20e025a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e025a.dat right
+[ 14, 68 ] = ascii (fp) : "./hrtfs/elev-20/L-20e020a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e020a.dat right
+[ 14, 69 ] = ascii (fp) : "./hrtfs/elev-20/L-20e015a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e015a.dat right
+[ 14, 70 ] = ascii (fp) : "./hrtfs/elev-20/L-20e010a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e010a.dat right
+[ 14, 71 ] = ascii (fp) : "./hrtfs/elev-20/L-20e005a.dat left
+ + ascii (fp) : "./hrtfs/elev-20/R-20e005a.dat right
-[ 15, 0 ] = ascii (fp) : "./hrtfs/elev-15/L-15e000a.dat"
-[ 15, 1 ] = ascii (fp) : "./hrtfs/elev-15/L-15e355a.dat"
-[ 15, 2 ] = ascii (fp) : "./hrtfs/elev-15/L-15e350a.dat"
-[ 15, 3 ] = ascii (fp) : "./hrtfs/elev-15/L-15e345a.dat"
-[ 15, 4 ] = ascii (fp) : "./hrtfs/elev-15/L-15e340a.dat"
-[ 15, 5 ] = ascii (fp) : "./hrtfs/elev-15/L-15e335a.dat"
-[ 15, 6 ] = ascii (fp) : "./hrtfs/elev-15/L-15e330a.dat"
-[ 15, 7 ] = ascii (fp) : "./hrtfs/elev-15/L-15e325a.dat"
-[ 15, 8 ] = ascii (fp) : "./hrtfs/elev-15/L-15e320a.dat"
-[ 15, 9 ] = ascii (fp) : "./hrtfs/elev-15/L-15e315a.dat"
-[ 15, 10 ] = ascii (fp) : "./hrtfs/elev-15/L-15e310a.dat"
-[ 15, 11 ] = ascii (fp) : "./hrtfs/elev-15/L-15e305a.dat"
-[ 15, 12 ] = ascii (fp) : "./hrtfs/elev-15/L-15e300a.dat"
-[ 15, 13 ] = ascii (fp) : "./hrtfs/elev-15/L-15e295a.dat"
-[ 15, 14 ] = ascii (fp) : "./hrtfs/elev-15/L-15e290a.dat"
-[ 15, 15 ] = ascii (fp) : "./hrtfs/elev-15/L-15e285a.dat"
-[ 15, 16 ] = ascii (fp) : "./hrtfs/elev-15/L-15e280a.dat"
-[ 15, 17 ] = ascii (fp) : "./hrtfs/elev-15/L-15e275a.dat"
-[ 15, 18 ] = ascii (fp) : "./hrtfs/elev-15/L-15e270a.dat"
-[ 15, 19 ] = ascii (fp) : "./hrtfs/elev-15/L-15e265a.dat"
-[ 15, 20 ] = ascii (fp) : "./hrtfs/elev-15/L-15e260a.dat"
-[ 15, 21 ] = ascii (fp) : "./hrtfs/elev-15/L-15e255a.dat"
-[ 15, 22 ] = ascii (fp) : "./hrtfs/elev-15/L-15e250a.dat"
-[ 15, 23 ] = ascii (fp) : "./hrtfs/elev-15/L-15e245a.dat"
-[ 15, 24 ] = ascii (fp) : "./hrtfs/elev-15/L-15e240a.dat"
-[ 15, 25 ] = ascii (fp) : "./hrtfs/elev-15/L-15e235a.dat"
-[ 15, 26 ] = ascii (fp) : "./hrtfs/elev-15/L-15e230a.dat"
-[ 15, 27 ] = ascii (fp) : "./hrtfs/elev-15/L-15e225a.dat"
-[ 15, 28 ] = ascii (fp) : "./hrtfs/elev-15/L-15e220a.dat"
-[ 15, 29 ] = ascii (fp) : "./hrtfs/elev-15/L-15e215a.dat"
-[ 15, 30 ] = ascii (fp) : "./hrtfs/elev-15/L-15e210a.dat"
-[ 15, 31 ] = ascii (fp) : "./hrtfs/elev-15/L-15e205a.dat"
-[ 15, 32 ] = ascii (fp) : "./hrtfs/elev-15/L-15e200a.dat"
-[ 15, 33 ] = ascii (fp) : "./hrtfs/elev-15/L-15e195a.dat"
-[ 15, 34 ] = ascii (fp) : "./hrtfs/elev-15/L-15e190a.dat"
-[ 15, 35 ] = ascii (fp) : "./hrtfs/elev-15/L-15e185a.dat"
-[ 15, 36 ] = ascii (fp) : "./hrtfs/elev-15/L-15e180a.dat"
-[ 15, 37 ] = ascii (fp) : "./hrtfs/elev-15/L-15e175a.dat"
-[ 15, 38 ] = ascii (fp) : "./hrtfs/elev-15/L-15e170a.dat"
-[ 15, 39 ] = ascii (fp) : "./hrtfs/elev-15/L-15e165a.dat"
-[ 15, 40 ] = ascii (fp) : "./hrtfs/elev-15/L-15e160a.dat"
-[ 15, 41 ] = ascii (fp) : "./hrtfs/elev-15/L-15e155a.dat"
-[ 15, 42 ] = ascii (fp) : "./hrtfs/elev-15/L-15e150a.dat"
-[ 15, 43 ] = ascii (fp) : "./hrtfs/elev-15/L-15e145a.dat"
-[ 15, 44 ] = ascii (fp) : "./hrtfs/elev-15/L-15e140a.dat"
-[ 15, 45 ] = ascii (fp) : "./hrtfs/elev-15/L-15e135a.dat"
-[ 15, 46 ] = ascii (fp) : "./hrtfs/elev-15/L-15e130a.dat"
-[ 15, 47 ] = ascii (fp) : "./hrtfs/elev-15/L-15e125a.dat"
-[ 15, 48 ] = ascii (fp) : "./hrtfs/elev-15/L-15e120a.dat"
-[ 15, 49 ] = ascii (fp) : "./hrtfs/elev-15/L-15e115a.dat"
-[ 15, 50 ] = ascii (fp) : "./hrtfs/elev-15/L-15e110a.dat"
-[ 15, 51 ] = ascii (fp) : "./hrtfs/elev-15/L-15e105a.dat"
-[ 15, 52 ] = ascii (fp) : "./hrtfs/elev-15/L-15e100a.dat"
-[ 15, 53 ] = ascii (fp) : "./hrtfs/elev-15/L-15e095a.dat"
-[ 15, 54 ] = ascii (fp) : "./hrtfs/elev-15/L-15e090a.dat"
-[ 15, 55 ] = ascii (fp) : "./hrtfs/elev-15/L-15e085a.dat"
-[ 15, 56 ] = ascii (fp) : "./hrtfs/elev-15/L-15e080a.dat"
-[ 15, 57 ] = ascii (fp) : "./hrtfs/elev-15/L-15e075a.dat"
-[ 15, 58 ] = ascii (fp) : "./hrtfs/elev-15/L-15e070a.dat"
-[ 15, 59 ] = ascii (fp) : "./hrtfs/elev-15/L-15e065a.dat"
-[ 15, 60 ] = ascii (fp) : "./hrtfs/elev-15/L-15e060a.dat"
-[ 15, 61 ] = ascii (fp) : "./hrtfs/elev-15/L-15e055a.dat"
-[ 15, 62 ] = ascii (fp) : "./hrtfs/elev-15/L-15e050a.dat"
-[ 15, 63 ] = ascii (fp) : "./hrtfs/elev-15/L-15e045a.dat"
-[ 15, 64 ] = ascii (fp) : "./hrtfs/elev-15/L-15e040a.dat"
-[ 15, 65 ] = ascii (fp) : "./hrtfs/elev-15/L-15e035a.dat"
-[ 15, 66 ] = ascii (fp) : "./hrtfs/elev-15/L-15e030a.dat"
-[ 15, 67 ] = ascii (fp) : "./hrtfs/elev-15/L-15e025a.dat"
-[ 15, 68 ] = ascii (fp) : "./hrtfs/elev-15/L-15e020a.dat"
-[ 15, 69 ] = ascii (fp) : "./hrtfs/elev-15/L-15e015a.dat"
-[ 15, 70 ] = ascii (fp) : "./hrtfs/elev-15/L-15e010a.dat"
-[ 15, 71 ] = ascii (fp) : "./hrtfs/elev-15/L-15e005a.dat"
+[ 15, 0 ] = ascii (fp) : "./hrtfs/elev-15/L-15e000a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e000a.dat right
+[ 15, 1 ] = ascii (fp) : "./hrtfs/elev-15/L-15e355a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e355a.dat right
+[ 15, 2 ] = ascii (fp) : "./hrtfs/elev-15/L-15e350a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e350a.dat right
+[ 15, 3 ] = ascii (fp) : "./hrtfs/elev-15/L-15e345a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e345a.dat right
+[ 15, 4 ] = ascii (fp) : "./hrtfs/elev-15/L-15e340a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e340a.dat right
+[ 15, 5 ] = ascii (fp) : "./hrtfs/elev-15/L-15e335a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e335a.dat right
+[ 15, 6 ] = ascii (fp) : "./hrtfs/elev-15/L-15e330a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e330a.dat right
+[ 15, 7 ] = ascii (fp) : "./hrtfs/elev-15/L-15e325a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e325a.dat right
+[ 15, 8 ] = ascii (fp) : "./hrtfs/elev-15/L-15e320a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e320a.dat right
+[ 15, 9 ] = ascii (fp) : "./hrtfs/elev-15/L-15e315a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e315a.dat right
+[ 15, 10 ] = ascii (fp) : "./hrtfs/elev-15/L-15e310a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e310a.dat right
+[ 15, 11 ] = ascii (fp) : "./hrtfs/elev-15/L-15e305a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e305a.dat right
+[ 15, 12 ] = ascii (fp) : "./hrtfs/elev-15/L-15e300a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e300a.dat right
+[ 15, 13 ] = ascii (fp) : "./hrtfs/elev-15/L-15e295a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e295a.dat right
+[ 15, 14 ] = ascii (fp) : "./hrtfs/elev-15/L-15e290a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e290a.dat right
+[ 15, 15 ] = ascii (fp) : "./hrtfs/elev-15/L-15e285a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e285a.dat right
+[ 15, 16 ] = ascii (fp) : "./hrtfs/elev-15/L-15e280a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e280a.dat right
+[ 15, 17 ] = ascii (fp) : "./hrtfs/elev-15/L-15e275a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e275a.dat right
+[ 15, 18 ] = ascii (fp) : "./hrtfs/elev-15/L-15e270a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e270a.dat right
+[ 15, 19 ] = ascii (fp) : "./hrtfs/elev-15/L-15e265a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e265a.dat right
+[ 15, 20 ] = ascii (fp) : "./hrtfs/elev-15/L-15e260a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e260a.dat right
+[ 15, 21 ] = ascii (fp) : "./hrtfs/elev-15/L-15e255a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e255a.dat right
+[ 15, 22 ] = ascii (fp) : "./hrtfs/elev-15/L-15e250a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e250a.dat right
+[ 15, 23 ] = ascii (fp) : "./hrtfs/elev-15/L-15e245a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e245a.dat right
+[ 15, 24 ] = ascii (fp) : "./hrtfs/elev-15/L-15e240a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e240a.dat right
+[ 15, 25 ] = ascii (fp) : "./hrtfs/elev-15/L-15e235a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e235a.dat right
+[ 15, 26 ] = ascii (fp) : "./hrtfs/elev-15/L-15e230a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e230a.dat right
+[ 15, 27 ] = ascii (fp) : "./hrtfs/elev-15/L-15e225a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e225a.dat right
+[ 15, 28 ] = ascii (fp) : "./hrtfs/elev-15/L-15e220a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e220a.dat right
+[ 15, 29 ] = ascii (fp) : "./hrtfs/elev-15/L-15e215a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e215a.dat right
+[ 15, 30 ] = ascii (fp) : "./hrtfs/elev-15/L-15e210a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e210a.dat right
+[ 15, 31 ] = ascii (fp) : "./hrtfs/elev-15/L-15e205a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e205a.dat right
+[ 15, 32 ] = ascii (fp) : "./hrtfs/elev-15/L-15e200a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e200a.dat right
+[ 15, 33 ] = ascii (fp) : "./hrtfs/elev-15/L-15e195a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e195a.dat right
+[ 15, 34 ] = ascii (fp) : "./hrtfs/elev-15/L-15e190a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e190a.dat right
+[ 15, 35 ] = ascii (fp) : "./hrtfs/elev-15/L-15e185a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e185a.dat right
+[ 15, 36 ] = ascii (fp) : "./hrtfs/elev-15/L-15e180a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e180a.dat right
+[ 15, 37 ] = ascii (fp) : "./hrtfs/elev-15/L-15e175a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e175a.dat right
+[ 15, 38 ] = ascii (fp) : "./hrtfs/elev-15/L-15e170a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e170a.dat right
+[ 15, 39 ] = ascii (fp) : "./hrtfs/elev-15/L-15e165a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e165a.dat right
+[ 15, 40 ] = ascii (fp) : "./hrtfs/elev-15/L-15e160a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e160a.dat right
+[ 15, 41 ] = ascii (fp) : "./hrtfs/elev-15/L-15e155a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e155a.dat right
+[ 15, 42 ] = ascii (fp) : "./hrtfs/elev-15/L-15e150a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e150a.dat right
+[ 15, 43 ] = ascii (fp) : "./hrtfs/elev-15/L-15e145a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e145a.dat right
+[ 15, 44 ] = ascii (fp) : "./hrtfs/elev-15/L-15e140a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e140a.dat right
+[ 15, 45 ] = ascii (fp) : "./hrtfs/elev-15/L-15e135a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e135a.dat right
+[ 15, 46 ] = ascii (fp) : "./hrtfs/elev-15/L-15e130a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e130a.dat right
+[ 15, 47 ] = ascii (fp) : "./hrtfs/elev-15/L-15e125a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e125a.dat right
+[ 15, 48 ] = ascii (fp) : "./hrtfs/elev-15/L-15e120a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e120a.dat right
+[ 15, 49 ] = ascii (fp) : "./hrtfs/elev-15/L-15e115a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e115a.dat right
+[ 15, 50 ] = ascii (fp) : "./hrtfs/elev-15/L-15e110a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e110a.dat right
+[ 15, 51 ] = ascii (fp) : "./hrtfs/elev-15/L-15e105a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e105a.dat right
+[ 15, 52 ] = ascii (fp) : "./hrtfs/elev-15/L-15e100a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e100a.dat right
+[ 15, 53 ] = ascii (fp) : "./hrtfs/elev-15/L-15e095a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e095a.dat right
+[ 15, 54 ] = ascii (fp) : "./hrtfs/elev-15/L-15e090a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e090a.dat right
+[ 15, 55 ] = ascii (fp) : "./hrtfs/elev-15/L-15e085a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e085a.dat right
+[ 15, 56 ] = ascii (fp) : "./hrtfs/elev-15/L-15e080a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e080a.dat right
+[ 15, 57 ] = ascii (fp) : "./hrtfs/elev-15/L-15e075a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e075a.dat right
+[ 15, 58 ] = ascii (fp) : "./hrtfs/elev-15/L-15e070a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e070a.dat right
+[ 15, 59 ] = ascii (fp) : "./hrtfs/elev-15/L-15e065a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e065a.dat right
+[ 15, 60 ] = ascii (fp) : "./hrtfs/elev-15/L-15e060a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e060a.dat right
+[ 15, 61 ] = ascii (fp) : "./hrtfs/elev-15/L-15e055a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e055a.dat right
+[ 15, 62 ] = ascii (fp) : "./hrtfs/elev-15/L-15e050a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e050a.dat right
+[ 15, 63 ] = ascii (fp) : "./hrtfs/elev-15/L-15e045a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e045a.dat right
+[ 15, 64 ] = ascii (fp) : "./hrtfs/elev-15/L-15e040a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e040a.dat right
+[ 15, 65 ] = ascii (fp) : "./hrtfs/elev-15/L-15e035a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e035a.dat right
+[ 15, 66 ] = ascii (fp) : "./hrtfs/elev-15/L-15e030a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e030a.dat right
+[ 15, 67 ] = ascii (fp) : "./hrtfs/elev-15/L-15e025a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e025a.dat right
+[ 15, 68 ] = ascii (fp) : "./hrtfs/elev-15/L-15e020a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e020a.dat right
+[ 15, 69 ] = ascii (fp) : "./hrtfs/elev-15/L-15e015a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e015a.dat right
+[ 15, 70 ] = ascii (fp) : "./hrtfs/elev-15/L-15e010a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e010a.dat right
+[ 15, 71 ] = ascii (fp) : "./hrtfs/elev-15/L-15e005a.dat left
+ + ascii (fp) : "./hrtfs/elev-15/R-15e005a.dat right
-[ 16, 0 ] = ascii (fp) : "./hrtfs/elev-10/L-10e000a.dat"
-[ 16, 1 ] = ascii (fp) : "./hrtfs/elev-10/L-10e355a.dat"
-[ 16, 2 ] = ascii (fp) : "./hrtfs/elev-10/L-10e350a.dat"
-[ 16, 3 ] = ascii (fp) : "./hrtfs/elev-10/L-10e345a.dat"
-[ 16, 4 ] = ascii (fp) : "./hrtfs/elev-10/L-10e340a.dat"
-[ 16, 5 ] = ascii (fp) : "./hrtfs/elev-10/L-10e335a.dat"
-[ 16, 6 ] = ascii (fp) : "./hrtfs/elev-10/L-10e330a.dat"
-[ 16, 7 ] = ascii (fp) : "./hrtfs/elev-10/L-10e325a.dat"
-[ 16, 8 ] = ascii (fp) : "./hrtfs/elev-10/L-10e320a.dat"
-[ 16, 9 ] = ascii (fp) : "./hrtfs/elev-10/L-10e315a.dat"
-[ 16, 10 ] = ascii (fp) : "./hrtfs/elev-10/L-10e310a.dat"
-[ 16, 11 ] = ascii (fp) : "./hrtfs/elev-10/L-10e305a.dat"
-[ 16, 12 ] = ascii (fp) : "./hrtfs/elev-10/L-10e300a.dat"
-[ 16, 13 ] = ascii (fp) : "./hrtfs/elev-10/L-10e295a.dat"
-[ 16, 14 ] = ascii (fp) : "./hrtfs/elev-10/L-10e290a.dat"
-[ 16, 15 ] = ascii (fp) : "./hrtfs/elev-10/L-10e285a.dat"
-[ 16, 16 ] = ascii (fp) : "./hrtfs/elev-10/L-10e280a.dat"
-[ 16, 17 ] = ascii (fp) : "./hrtfs/elev-10/L-10e275a.dat"
-[ 16, 18 ] = ascii (fp) : "./hrtfs/elev-10/L-10e270a.dat"
-[ 16, 19 ] = ascii (fp) : "./hrtfs/elev-10/L-10e265a.dat"
-[ 16, 20 ] = ascii (fp) : "./hrtfs/elev-10/L-10e260a.dat"
-[ 16, 21 ] = ascii (fp) : "./hrtfs/elev-10/L-10e255a.dat"
-[ 16, 22 ] = ascii (fp) : "./hrtfs/elev-10/L-10e250a.dat"
-[ 16, 23 ] = ascii (fp) : "./hrtfs/elev-10/L-10e245a.dat"
-[ 16, 24 ] = ascii (fp) : "./hrtfs/elev-10/L-10e240a.dat"
-[ 16, 25 ] = ascii (fp) : "./hrtfs/elev-10/L-10e235a.dat"
-[ 16, 26 ] = ascii (fp) : "./hrtfs/elev-10/L-10e230a.dat"
-[ 16, 27 ] = ascii (fp) : "./hrtfs/elev-10/L-10e225a.dat"
-[ 16, 28 ] = ascii (fp) : "./hrtfs/elev-10/L-10e220a.dat"
-[ 16, 29 ] = ascii (fp) : "./hrtfs/elev-10/L-10e215a.dat"
-[ 16, 30 ] = ascii (fp) : "./hrtfs/elev-10/L-10e210a.dat"
-[ 16, 31 ] = ascii (fp) : "./hrtfs/elev-10/L-10e205a.dat"
-[ 16, 32 ] = ascii (fp) : "./hrtfs/elev-10/L-10e200a.dat"
-[ 16, 33 ] = ascii (fp) : "./hrtfs/elev-10/L-10e195a.dat"
-[ 16, 34 ] = ascii (fp) : "./hrtfs/elev-10/L-10e190a.dat"
-[ 16, 35 ] = ascii (fp) : "./hrtfs/elev-10/L-10e185a.dat"
-[ 16, 36 ] = ascii (fp) : "./hrtfs/elev-10/L-10e180a.dat"
-[ 16, 37 ] = ascii (fp) : "./hrtfs/elev-10/L-10e175a.dat"
-[ 16, 38 ] = ascii (fp) : "./hrtfs/elev-10/L-10e170a.dat"
-[ 16, 39 ] = ascii (fp) : "./hrtfs/elev-10/L-10e165a.dat"
-[ 16, 40 ] = ascii (fp) : "./hrtfs/elev-10/L-10e160a.dat"
-[ 16, 41 ] = ascii (fp) : "./hrtfs/elev-10/L-10e155a.dat"
-[ 16, 42 ] = ascii (fp) : "./hrtfs/elev-10/L-10e150a.dat"
-[ 16, 43 ] = ascii (fp) : "./hrtfs/elev-10/L-10e145a.dat"
-[ 16, 44 ] = ascii (fp) : "./hrtfs/elev-10/L-10e140a.dat"
-[ 16, 45 ] = ascii (fp) : "./hrtfs/elev-10/L-10e135a.dat"
-[ 16, 46 ] = ascii (fp) : "./hrtfs/elev-10/L-10e130a.dat"
-[ 16, 47 ] = ascii (fp) : "./hrtfs/elev-10/L-10e125a.dat"
-[ 16, 48 ] = ascii (fp) : "./hrtfs/elev-10/L-10e120a.dat"
-[ 16, 49 ] = ascii (fp) : "./hrtfs/elev-10/L-10e115a.dat"
-[ 16, 50 ] = ascii (fp) : "./hrtfs/elev-10/L-10e110a.dat"
-[ 16, 51 ] = ascii (fp) : "./hrtfs/elev-10/L-10e105a.dat"
-[ 16, 52 ] = ascii (fp) : "./hrtfs/elev-10/L-10e100a.dat"
-[ 16, 53 ] = ascii (fp) : "./hrtfs/elev-10/L-10e095a.dat"
-[ 16, 54 ] = ascii (fp) : "./hrtfs/elev-10/L-10e090a.dat"
-[ 16, 55 ] = ascii (fp) : "./hrtfs/elev-10/L-10e085a.dat"
-[ 16, 56 ] = ascii (fp) : "./hrtfs/elev-10/L-10e080a.dat"
-[ 16, 57 ] = ascii (fp) : "./hrtfs/elev-10/L-10e075a.dat"
-[ 16, 58 ] = ascii (fp) : "./hrtfs/elev-10/L-10e070a.dat"
-[ 16, 59 ] = ascii (fp) : "./hrtfs/elev-10/L-10e065a.dat"
-[ 16, 60 ] = ascii (fp) : "./hrtfs/elev-10/L-10e060a.dat"
-[ 16, 61 ] = ascii (fp) : "./hrtfs/elev-10/L-10e055a.dat"
-[ 16, 62 ] = ascii (fp) : "./hrtfs/elev-10/L-10e050a.dat"
-[ 16, 63 ] = ascii (fp) : "./hrtfs/elev-10/L-10e045a.dat"
-[ 16, 64 ] = ascii (fp) : "./hrtfs/elev-10/L-10e040a.dat"
-[ 16, 65 ] = ascii (fp) : "./hrtfs/elev-10/L-10e035a.dat"
-[ 16, 66 ] = ascii (fp) : "./hrtfs/elev-10/L-10e030a.dat"
-[ 16, 67 ] = ascii (fp) : "./hrtfs/elev-10/L-10e025a.dat"
-[ 16, 68 ] = ascii (fp) : "./hrtfs/elev-10/L-10e020a.dat"
-[ 16, 69 ] = ascii (fp) : "./hrtfs/elev-10/L-10e015a.dat"
-[ 16, 70 ] = ascii (fp) : "./hrtfs/elev-10/L-10e010a.dat"
-[ 16, 71 ] = ascii (fp) : "./hrtfs/elev-10/L-10e005a.dat"
+[ 16, 0 ] = ascii (fp) : "./hrtfs/elev-10/L-10e000a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e000a.dat right
+[ 16, 1 ] = ascii (fp) : "./hrtfs/elev-10/L-10e355a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e355a.dat right
+[ 16, 2 ] = ascii (fp) : "./hrtfs/elev-10/L-10e350a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e350a.dat right
+[ 16, 3 ] = ascii (fp) : "./hrtfs/elev-10/L-10e345a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e345a.dat right
+[ 16, 4 ] = ascii (fp) : "./hrtfs/elev-10/L-10e340a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e340a.dat right
+[ 16, 5 ] = ascii (fp) : "./hrtfs/elev-10/L-10e335a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e335a.dat right
+[ 16, 6 ] = ascii (fp) : "./hrtfs/elev-10/L-10e330a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e330a.dat right
+[ 16, 7 ] = ascii (fp) : "./hrtfs/elev-10/L-10e325a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e325a.dat right
+[ 16, 8 ] = ascii (fp) : "./hrtfs/elev-10/L-10e320a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e320a.dat right
+[ 16, 9 ] = ascii (fp) : "./hrtfs/elev-10/L-10e315a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e315a.dat right
+[ 16, 10 ] = ascii (fp) : "./hrtfs/elev-10/L-10e310a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e310a.dat right
+[ 16, 11 ] = ascii (fp) : "./hrtfs/elev-10/L-10e305a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e305a.dat right
+[ 16, 12 ] = ascii (fp) : "./hrtfs/elev-10/L-10e300a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e300a.dat right
+[ 16, 13 ] = ascii (fp) : "./hrtfs/elev-10/L-10e295a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e295a.dat right
+[ 16, 14 ] = ascii (fp) : "./hrtfs/elev-10/L-10e290a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e290a.dat right
+[ 16, 15 ] = ascii (fp) : "./hrtfs/elev-10/L-10e285a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e285a.dat right
+[ 16, 16 ] = ascii (fp) : "./hrtfs/elev-10/L-10e280a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e280a.dat right
+[ 16, 17 ] = ascii (fp) : "./hrtfs/elev-10/L-10e275a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e275a.dat right
+[ 16, 18 ] = ascii (fp) : "./hrtfs/elev-10/L-10e270a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e270a.dat right
+[ 16, 19 ] = ascii (fp) : "./hrtfs/elev-10/L-10e265a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e265a.dat right
+[ 16, 20 ] = ascii (fp) : "./hrtfs/elev-10/L-10e260a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e260a.dat right
+[ 16, 21 ] = ascii (fp) : "./hrtfs/elev-10/L-10e255a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e255a.dat right
+[ 16, 22 ] = ascii (fp) : "./hrtfs/elev-10/L-10e250a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e250a.dat right
+[ 16, 23 ] = ascii (fp) : "./hrtfs/elev-10/L-10e245a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e245a.dat right
+[ 16, 24 ] = ascii (fp) : "./hrtfs/elev-10/L-10e240a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e240a.dat right
+[ 16, 25 ] = ascii (fp) : "./hrtfs/elev-10/L-10e235a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e235a.dat right
+[ 16, 26 ] = ascii (fp) : "./hrtfs/elev-10/L-10e230a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e230a.dat right
+[ 16, 27 ] = ascii (fp) : "./hrtfs/elev-10/L-10e225a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e225a.dat right
+[ 16, 28 ] = ascii (fp) : "./hrtfs/elev-10/L-10e220a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e220a.dat right
+[ 16, 29 ] = ascii (fp) : "./hrtfs/elev-10/L-10e215a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e215a.dat right
+[ 16, 30 ] = ascii (fp) : "./hrtfs/elev-10/L-10e210a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e210a.dat right
+[ 16, 31 ] = ascii (fp) : "./hrtfs/elev-10/L-10e205a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e205a.dat right
+[ 16, 32 ] = ascii (fp) : "./hrtfs/elev-10/L-10e200a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e200a.dat right
+[ 16, 33 ] = ascii (fp) : "./hrtfs/elev-10/L-10e195a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e195a.dat right
+[ 16, 34 ] = ascii (fp) : "./hrtfs/elev-10/L-10e190a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e190a.dat right
+[ 16, 35 ] = ascii (fp) : "./hrtfs/elev-10/L-10e185a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e185a.dat right
+[ 16, 36 ] = ascii (fp) : "./hrtfs/elev-10/L-10e180a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e180a.dat right
+[ 16, 37 ] = ascii (fp) : "./hrtfs/elev-10/L-10e175a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e175a.dat right
+[ 16, 38 ] = ascii (fp) : "./hrtfs/elev-10/L-10e170a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e170a.dat right
+[ 16, 39 ] = ascii (fp) : "./hrtfs/elev-10/L-10e165a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e165a.dat right
+[ 16, 40 ] = ascii (fp) : "./hrtfs/elev-10/L-10e160a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e160a.dat right
+[ 16, 41 ] = ascii (fp) : "./hrtfs/elev-10/L-10e155a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e155a.dat right
+[ 16, 42 ] = ascii (fp) : "./hrtfs/elev-10/L-10e150a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e150a.dat right
+[ 16, 43 ] = ascii (fp) : "./hrtfs/elev-10/L-10e145a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e145a.dat right
+[ 16, 44 ] = ascii (fp) : "./hrtfs/elev-10/L-10e140a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e140a.dat right
+[ 16, 45 ] = ascii (fp) : "./hrtfs/elev-10/L-10e135a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e135a.dat right
+[ 16, 46 ] = ascii (fp) : "./hrtfs/elev-10/L-10e130a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e130a.dat right
+[ 16, 47 ] = ascii (fp) : "./hrtfs/elev-10/L-10e125a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e125a.dat right
+[ 16, 48 ] = ascii (fp) : "./hrtfs/elev-10/L-10e120a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e120a.dat right
+[ 16, 49 ] = ascii (fp) : "./hrtfs/elev-10/L-10e115a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e115a.dat right
+[ 16, 50 ] = ascii (fp) : "./hrtfs/elev-10/L-10e110a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e110a.dat right
+[ 16, 51 ] = ascii (fp) : "./hrtfs/elev-10/L-10e105a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e105a.dat right
+[ 16, 52 ] = ascii (fp) : "./hrtfs/elev-10/L-10e100a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e100a.dat right
+[ 16, 53 ] = ascii (fp) : "./hrtfs/elev-10/L-10e095a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e095a.dat right
+[ 16, 54 ] = ascii (fp) : "./hrtfs/elev-10/L-10e090a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e090a.dat right
+[ 16, 55 ] = ascii (fp) : "./hrtfs/elev-10/L-10e085a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e085a.dat right
+[ 16, 56 ] = ascii (fp) : "./hrtfs/elev-10/L-10e080a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e080a.dat right
+[ 16, 57 ] = ascii (fp) : "./hrtfs/elev-10/L-10e075a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e075a.dat right
+[ 16, 58 ] = ascii (fp) : "./hrtfs/elev-10/L-10e070a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e070a.dat right
+[ 16, 59 ] = ascii (fp) : "./hrtfs/elev-10/L-10e065a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e065a.dat right
+[ 16, 60 ] = ascii (fp) : "./hrtfs/elev-10/L-10e060a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e060a.dat right
+[ 16, 61 ] = ascii (fp) : "./hrtfs/elev-10/L-10e055a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e055a.dat right
+[ 16, 62 ] = ascii (fp) : "./hrtfs/elev-10/L-10e050a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e050a.dat right
+[ 16, 63 ] = ascii (fp) : "./hrtfs/elev-10/L-10e045a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e045a.dat right
+[ 16, 64 ] = ascii (fp) : "./hrtfs/elev-10/L-10e040a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e040a.dat right
+[ 16, 65 ] = ascii (fp) : "./hrtfs/elev-10/L-10e035a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e035a.dat right
+[ 16, 66 ] = ascii (fp) : "./hrtfs/elev-10/L-10e030a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e030a.dat right
+[ 16, 67 ] = ascii (fp) : "./hrtfs/elev-10/L-10e025a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e025a.dat right
+[ 16, 68 ] = ascii (fp) : "./hrtfs/elev-10/L-10e020a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e020a.dat right
+[ 16, 69 ] = ascii (fp) : "./hrtfs/elev-10/L-10e015a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e015a.dat right
+[ 16, 70 ] = ascii (fp) : "./hrtfs/elev-10/L-10e010a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e010a.dat right
+[ 16, 71 ] = ascii (fp) : "./hrtfs/elev-10/L-10e005a.dat left
+ + ascii (fp) : "./hrtfs/elev-10/R-10e005a.dat right
-[ 17, 0 ] = ascii (fp) : "./hrtfs/elev-5/L-5e000a.dat"
-[ 17, 1 ] = ascii (fp) : "./hrtfs/elev-5/L-5e355a.dat"
-[ 17, 2 ] = ascii (fp) : "./hrtfs/elev-5/L-5e350a.dat"
-[ 17, 3 ] = ascii (fp) : "./hrtfs/elev-5/L-5e345a.dat"
-[ 17, 4 ] = ascii (fp) : "./hrtfs/elev-5/L-5e340a.dat"
-[ 17, 5 ] = ascii (fp) : "./hrtfs/elev-5/L-5e335a.dat"
-[ 17, 6 ] = ascii (fp) : "./hrtfs/elev-5/L-5e330a.dat"
-[ 17, 7 ] = ascii (fp) : "./hrtfs/elev-5/L-5e325a.dat"
-[ 17, 8 ] = ascii (fp) : "./hrtfs/elev-5/L-5e320a.dat"
-[ 17, 9 ] = ascii (fp) : "./hrtfs/elev-5/L-5e315a.dat"
-[ 17, 10 ] = ascii (fp) : "./hrtfs/elev-5/L-5e310a.dat"
-[ 17, 11 ] = ascii (fp) : "./hrtfs/elev-5/L-5e305a.dat"
-[ 17, 12 ] = ascii (fp) : "./hrtfs/elev-5/L-5e300a.dat"
-[ 17, 13 ] = ascii (fp) : "./hrtfs/elev-5/L-5e295a.dat"
-[ 17, 14 ] = ascii (fp) : "./hrtfs/elev-5/L-5e290a.dat"
-[ 17, 15 ] = ascii (fp) : "./hrtfs/elev-5/L-5e285a.dat"
-[ 17, 16 ] = ascii (fp) : "./hrtfs/elev-5/L-5e280a.dat"
-[ 17, 17 ] = ascii (fp) : "./hrtfs/elev-5/L-5e275a.dat"
-[ 17, 18 ] = ascii (fp) : "./hrtfs/elev-5/L-5e270a.dat"
-[ 17, 19 ] = ascii (fp) : "./hrtfs/elev-5/L-5e265a.dat"
-[ 17, 20 ] = ascii (fp) : "./hrtfs/elev-5/L-5e260a.dat"
-[ 17, 21 ] = ascii (fp) : "./hrtfs/elev-5/L-5e255a.dat"
-[ 17, 22 ] = ascii (fp) : "./hrtfs/elev-5/L-5e250a.dat"
-[ 17, 23 ] = ascii (fp) : "./hrtfs/elev-5/L-5e245a.dat"
-[ 17, 24 ] = ascii (fp) : "./hrtfs/elev-5/L-5e240a.dat"
-[ 17, 25 ] = ascii (fp) : "./hrtfs/elev-5/L-5e235a.dat"
-[ 17, 26 ] = ascii (fp) : "./hrtfs/elev-5/L-5e230a.dat"
-[ 17, 27 ] = ascii (fp) : "./hrtfs/elev-5/L-5e225a.dat"
-[ 17, 28 ] = ascii (fp) : "./hrtfs/elev-5/L-5e220a.dat"
-[ 17, 29 ] = ascii (fp) : "./hrtfs/elev-5/L-5e215a.dat"
-[ 17, 30 ] = ascii (fp) : "./hrtfs/elev-5/L-5e210a.dat"
-[ 17, 31 ] = ascii (fp) : "./hrtfs/elev-5/L-5e205a.dat"
-[ 17, 32 ] = ascii (fp) : "./hrtfs/elev-5/L-5e200a.dat"
-[ 17, 33 ] = ascii (fp) : "./hrtfs/elev-5/L-5e195a.dat"
-[ 17, 34 ] = ascii (fp) : "./hrtfs/elev-5/L-5e190a.dat"
-[ 17, 35 ] = ascii (fp) : "./hrtfs/elev-5/L-5e185a.dat"
-[ 17, 36 ] = ascii (fp) : "./hrtfs/elev-5/L-5e180a.dat"
-[ 17, 37 ] = ascii (fp) : "./hrtfs/elev-5/L-5e175a.dat"
-[ 17, 38 ] = ascii (fp) : "./hrtfs/elev-5/L-5e170a.dat"
-[ 17, 39 ] = ascii (fp) : "./hrtfs/elev-5/L-5e165a.dat"
-[ 17, 40 ] = ascii (fp) : "./hrtfs/elev-5/L-5e160a.dat"
-[ 17, 41 ] = ascii (fp) : "./hrtfs/elev-5/L-5e155a.dat"
-[ 17, 42 ] = ascii (fp) : "./hrtfs/elev-5/L-5e150a.dat"
-[ 17, 43 ] = ascii (fp) : "./hrtfs/elev-5/L-5e145a.dat"
-[ 17, 44 ] = ascii (fp) : "./hrtfs/elev-5/L-5e140a.dat"
-[ 17, 45 ] = ascii (fp) : "./hrtfs/elev-5/L-5e135a.dat"
-[ 17, 46 ] = ascii (fp) : "./hrtfs/elev-5/L-5e130a.dat"
-[ 17, 47 ] = ascii (fp) : "./hrtfs/elev-5/L-5e125a.dat"
-[ 17, 48 ] = ascii (fp) : "./hrtfs/elev-5/L-5e120a.dat"
-[ 17, 49 ] = ascii (fp) : "./hrtfs/elev-5/L-5e115a.dat"
-[ 17, 50 ] = ascii (fp) : "./hrtfs/elev-5/L-5e110a.dat"
-[ 17, 51 ] = ascii (fp) : "./hrtfs/elev-5/L-5e105a.dat"
-[ 17, 52 ] = ascii (fp) : "./hrtfs/elev-5/L-5e100a.dat"
-[ 17, 53 ] = ascii (fp) : "./hrtfs/elev-5/L-5e095a.dat"
-[ 17, 54 ] = ascii (fp) : "./hrtfs/elev-5/L-5e090a.dat"
-[ 17, 55 ] = ascii (fp) : "./hrtfs/elev-5/L-5e085a.dat"
-[ 17, 56 ] = ascii (fp) : "./hrtfs/elev-5/L-5e080a.dat"
-[ 17, 57 ] = ascii (fp) : "./hrtfs/elev-5/L-5e075a.dat"
-[ 17, 58 ] = ascii (fp) : "./hrtfs/elev-5/L-5e070a.dat"
-[ 17, 59 ] = ascii (fp) : "./hrtfs/elev-5/L-5e065a.dat"
-[ 17, 60 ] = ascii (fp) : "./hrtfs/elev-5/L-5e060a.dat"
-[ 17, 61 ] = ascii (fp) : "./hrtfs/elev-5/L-5e055a.dat"
-[ 17, 62 ] = ascii (fp) : "./hrtfs/elev-5/L-5e050a.dat"
-[ 17, 63 ] = ascii (fp) : "./hrtfs/elev-5/L-5e045a.dat"
-[ 17, 64 ] = ascii (fp) : "./hrtfs/elev-5/L-5e040a.dat"
-[ 17, 65 ] = ascii (fp) : "./hrtfs/elev-5/L-5e035a.dat"
-[ 17, 66 ] = ascii (fp) : "./hrtfs/elev-5/L-5e030a.dat"
-[ 17, 67 ] = ascii (fp) : "./hrtfs/elev-5/L-5e025a.dat"
-[ 17, 68 ] = ascii (fp) : "./hrtfs/elev-5/L-5e020a.dat"
-[ 17, 69 ] = ascii (fp) : "./hrtfs/elev-5/L-5e015a.dat"
-[ 17, 70 ] = ascii (fp) : "./hrtfs/elev-5/L-5e010a.dat"
-[ 17, 71 ] = ascii (fp) : "./hrtfs/elev-5/L-5e005a.dat"
+[ 17, 0 ] = ascii (fp) : "./hrtfs/elev-5/L-5e000a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e000a.dat right
+[ 17, 1 ] = ascii (fp) : "./hrtfs/elev-5/L-5e355a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e355a.dat right
+[ 17, 2 ] = ascii (fp) : "./hrtfs/elev-5/L-5e350a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e350a.dat right
+[ 17, 3 ] = ascii (fp) : "./hrtfs/elev-5/L-5e345a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e345a.dat right
+[ 17, 4 ] = ascii (fp) : "./hrtfs/elev-5/L-5e340a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e340a.dat right
+[ 17, 5 ] = ascii (fp) : "./hrtfs/elev-5/L-5e335a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e335a.dat right
+[ 17, 6 ] = ascii (fp) : "./hrtfs/elev-5/L-5e330a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e330a.dat right
+[ 17, 7 ] = ascii (fp) : "./hrtfs/elev-5/L-5e325a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e325a.dat right
+[ 17, 8 ] = ascii (fp) : "./hrtfs/elev-5/L-5e320a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e320a.dat right
+[ 17, 9 ] = ascii (fp) : "./hrtfs/elev-5/L-5e315a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e315a.dat right
+[ 17, 10 ] = ascii (fp) : "./hrtfs/elev-5/L-5e310a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e310a.dat right
+[ 17, 11 ] = ascii (fp) : "./hrtfs/elev-5/L-5e305a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e305a.dat right
+[ 17, 12 ] = ascii (fp) : "./hrtfs/elev-5/L-5e300a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e300a.dat right
+[ 17, 13 ] = ascii (fp) : "./hrtfs/elev-5/L-5e295a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e295a.dat right
+[ 17, 14 ] = ascii (fp) : "./hrtfs/elev-5/L-5e290a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e290a.dat right
+[ 17, 15 ] = ascii (fp) : "./hrtfs/elev-5/L-5e285a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e285a.dat right
+[ 17, 16 ] = ascii (fp) : "./hrtfs/elev-5/L-5e280a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e280a.dat right
+[ 17, 17 ] = ascii (fp) : "./hrtfs/elev-5/L-5e275a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e275a.dat right
+[ 17, 18 ] = ascii (fp) : "./hrtfs/elev-5/L-5e270a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e270a.dat right
+[ 17, 19 ] = ascii (fp) : "./hrtfs/elev-5/L-5e265a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e265a.dat right
+[ 17, 20 ] = ascii (fp) : "./hrtfs/elev-5/L-5e260a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e260a.dat right
+[ 17, 21 ] = ascii (fp) : "./hrtfs/elev-5/L-5e255a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e255a.dat right
+[ 17, 22 ] = ascii (fp) : "./hrtfs/elev-5/L-5e250a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e250a.dat right
+[ 17, 23 ] = ascii (fp) : "./hrtfs/elev-5/L-5e245a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e245a.dat right
+[ 17, 24 ] = ascii (fp) : "./hrtfs/elev-5/L-5e240a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e240a.dat right
+[ 17, 25 ] = ascii (fp) : "./hrtfs/elev-5/L-5e235a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e235a.dat right
+[ 17, 26 ] = ascii (fp) : "./hrtfs/elev-5/L-5e230a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e230a.dat right
+[ 17, 27 ] = ascii (fp) : "./hrtfs/elev-5/L-5e225a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e225a.dat right
+[ 17, 28 ] = ascii (fp) : "./hrtfs/elev-5/L-5e220a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e220a.dat right
+[ 17, 29 ] = ascii (fp) : "./hrtfs/elev-5/L-5e215a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e215a.dat right
+[ 17, 30 ] = ascii (fp) : "./hrtfs/elev-5/L-5e210a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e210a.dat right
+[ 17, 31 ] = ascii (fp) : "./hrtfs/elev-5/L-5e205a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e205a.dat right
+[ 17, 32 ] = ascii (fp) : "./hrtfs/elev-5/L-5e200a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e200a.dat right
+[ 17, 33 ] = ascii (fp) : "./hrtfs/elev-5/L-5e195a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e195a.dat right
+[ 17, 34 ] = ascii (fp) : "./hrtfs/elev-5/L-5e190a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e190a.dat right
+[ 17, 35 ] = ascii (fp) : "./hrtfs/elev-5/L-5e185a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e185a.dat right
+[ 17, 36 ] = ascii (fp) : "./hrtfs/elev-5/L-5e180a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e180a.dat right
+[ 17, 37 ] = ascii (fp) : "./hrtfs/elev-5/L-5e175a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e175a.dat right
+[ 17, 38 ] = ascii (fp) : "./hrtfs/elev-5/L-5e170a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e170a.dat right
+[ 17, 39 ] = ascii (fp) : "./hrtfs/elev-5/L-5e165a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e165a.dat right
+[ 17, 40 ] = ascii (fp) : "./hrtfs/elev-5/L-5e160a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e160a.dat right
+[ 17, 41 ] = ascii (fp) : "./hrtfs/elev-5/L-5e155a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e155a.dat right
+[ 17, 42 ] = ascii (fp) : "./hrtfs/elev-5/L-5e150a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e150a.dat right
+[ 17, 43 ] = ascii (fp) : "./hrtfs/elev-5/L-5e145a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e145a.dat right
+[ 17, 44 ] = ascii (fp) : "./hrtfs/elev-5/L-5e140a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e140a.dat right
+[ 17, 45 ] = ascii (fp) : "./hrtfs/elev-5/L-5e135a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e135a.dat right
+[ 17, 46 ] = ascii (fp) : "./hrtfs/elev-5/L-5e130a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e130a.dat right
+[ 17, 47 ] = ascii (fp) : "./hrtfs/elev-5/L-5e125a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e125a.dat right
+[ 17, 48 ] = ascii (fp) : "./hrtfs/elev-5/L-5e120a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e120a.dat right
+[ 17, 49 ] = ascii (fp) : "./hrtfs/elev-5/L-5e115a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e115a.dat right
+[ 17, 50 ] = ascii (fp) : "./hrtfs/elev-5/L-5e110a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e110a.dat right
+[ 17, 51 ] = ascii (fp) : "./hrtfs/elev-5/L-5e105a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e105a.dat right
+[ 17, 52 ] = ascii (fp) : "./hrtfs/elev-5/L-5e100a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e100a.dat right
+[ 17, 53 ] = ascii (fp) : "./hrtfs/elev-5/L-5e095a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e095a.dat right
+[ 17, 54 ] = ascii (fp) : "./hrtfs/elev-5/L-5e090a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e090a.dat right
+[ 17, 55 ] = ascii (fp) : "./hrtfs/elev-5/L-5e085a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e085a.dat right
+[ 17, 56 ] = ascii (fp) : "./hrtfs/elev-5/L-5e080a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e080a.dat right
+[ 17, 57 ] = ascii (fp) : "./hrtfs/elev-5/L-5e075a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e075a.dat right
+[ 17, 58 ] = ascii (fp) : "./hrtfs/elev-5/L-5e070a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e070a.dat right
+[ 17, 59 ] = ascii (fp) : "./hrtfs/elev-5/L-5e065a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e065a.dat right
+[ 17, 60 ] = ascii (fp) : "./hrtfs/elev-5/L-5e060a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e060a.dat right
+[ 17, 61 ] = ascii (fp) : "./hrtfs/elev-5/L-5e055a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e055a.dat right
+[ 17, 62 ] = ascii (fp) : "./hrtfs/elev-5/L-5e050a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e050a.dat right
+[ 17, 63 ] = ascii (fp) : "./hrtfs/elev-5/L-5e045a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e045a.dat right
+[ 17, 64 ] = ascii (fp) : "./hrtfs/elev-5/L-5e040a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e040a.dat right
+[ 17, 65 ] = ascii (fp) : "./hrtfs/elev-5/L-5e035a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e035a.dat right
+[ 17, 66 ] = ascii (fp) : "./hrtfs/elev-5/L-5e030a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e030a.dat right
+[ 17, 67 ] = ascii (fp) : "./hrtfs/elev-5/L-5e025a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e025a.dat right
+[ 17, 68 ] = ascii (fp) : "./hrtfs/elev-5/L-5e020a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e020a.dat right
+[ 17, 69 ] = ascii (fp) : "./hrtfs/elev-5/L-5e015a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e015a.dat right
+[ 17, 70 ] = ascii (fp) : "./hrtfs/elev-5/L-5e010a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e010a.dat right
+[ 17, 71 ] = ascii (fp) : "./hrtfs/elev-5/L-5e005a.dat left
+ + ascii (fp) : "./hrtfs/elev-5/R-5e005a.dat right
-[ 18, 0 ] = ascii (fp) : "./hrtfs/elev0/L0e000a.dat"
-[ 18, 1 ] = ascii (fp) : "./hrtfs/elev0/L0e355a.dat"
-[ 18, 2 ] = ascii (fp) : "./hrtfs/elev0/L0e350a.dat"
-[ 18, 3 ] = ascii (fp) : "./hrtfs/elev0/L0e345a.dat"
-[ 18, 4 ] = ascii (fp) : "./hrtfs/elev0/L0e340a.dat"
-[ 18, 5 ] = ascii (fp) : "./hrtfs/elev0/L0e335a.dat"
-[ 18, 6 ] = ascii (fp) : "./hrtfs/elev0/L0e330a.dat"
-[ 18, 7 ] = ascii (fp) : "./hrtfs/elev0/L0e325a.dat"
-[ 18, 8 ] = ascii (fp) : "./hrtfs/elev0/L0e320a.dat"
-[ 18, 9 ] = ascii (fp) : "./hrtfs/elev0/L0e315a.dat"
-[ 18, 10 ] = ascii (fp) : "./hrtfs/elev0/L0e310a.dat"
-[ 18, 11 ] = ascii (fp) : "./hrtfs/elev0/L0e305a.dat"
-[ 18, 12 ] = ascii (fp) : "./hrtfs/elev0/L0e300a.dat"
-[ 18, 13 ] = ascii (fp) : "./hrtfs/elev0/L0e295a.dat"
-[ 18, 14 ] = ascii (fp) : "./hrtfs/elev0/L0e290a.dat"
-[ 18, 15 ] = ascii (fp) : "./hrtfs/elev0/L0e285a.dat"
-[ 18, 16 ] = ascii (fp) : "./hrtfs/elev0/L0e280a.dat"
-[ 18, 17 ] = ascii (fp) : "./hrtfs/elev0/L0e275a.dat"
-[ 18, 18 ] = ascii (fp) : "./hrtfs/elev0/L0e270a.dat"
-[ 18, 19 ] = ascii (fp) : "./hrtfs/elev0/L0e265a.dat"
-[ 18, 20 ] = ascii (fp) : "./hrtfs/elev0/L0e260a.dat"
-[ 18, 21 ] = ascii (fp) : "./hrtfs/elev0/L0e255a.dat"
-[ 18, 22 ] = ascii (fp) : "./hrtfs/elev0/L0e250a.dat"
-[ 18, 23 ] = ascii (fp) : "./hrtfs/elev0/L0e245a.dat"
-[ 18, 24 ] = ascii (fp) : "./hrtfs/elev0/L0e240a.dat"
-[ 18, 25 ] = ascii (fp) : "./hrtfs/elev0/L0e235a.dat"
-[ 18, 26 ] = ascii (fp) : "./hrtfs/elev0/L0e230a.dat"
-[ 18, 27 ] = ascii (fp) : "./hrtfs/elev0/L0e225a.dat"
-[ 18, 28 ] = ascii (fp) : "./hrtfs/elev0/L0e220a.dat"
-[ 18, 29 ] = ascii (fp) : "./hrtfs/elev0/L0e215a.dat"
-[ 18, 30 ] = ascii (fp) : "./hrtfs/elev0/L0e210a.dat"
-[ 18, 31 ] = ascii (fp) : "./hrtfs/elev0/L0e205a.dat"
-[ 18, 32 ] = ascii (fp) : "./hrtfs/elev0/L0e200a.dat"
-[ 18, 33 ] = ascii (fp) : "./hrtfs/elev0/L0e195a.dat"
-[ 18, 34 ] = ascii (fp) : "./hrtfs/elev0/L0e190a.dat"
-[ 18, 35 ] = ascii (fp) : "./hrtfs/elev0/L0e185a.dat"
-[ 18, 36 ] = ascii (fp) : "./hrtfs/elev0/L0e180a.dat"
-[ 18, 37 ] = ascii (fp) : "./hrtfs/elev0/L0e175a.dat"
-[ 18, 38 ] = ascii (fp) : "./hrtfs/elev0/L0e170a.dat"
-[ 18, 39 ] = ascii (fp) : "./hrtfs/elev0/L0e165a.dat"
-[ 18, 40 ] = ascii (fp) : "./hrtfs/elev0/L0e160a.dat"
-[ 18, 41 ] = ascii (fp) : "./hrtfs/elev0/L0e155a.dat"
-[ 18, 42 ] = ascii (fp) : "./hrtfs/elev0/L0e150a.dat"
-[ 18, 43 ] = ascii (fp) : "./hrtfs/elev0/L0e145a.dat"
-[ 18, 44 ] = ascii (fp) : "./hrtfs/elev0/L0e140a.dat"
-[ 18, 45 ] = ascii (fp) : "./hrtfs/elev0/L0e135a.dat"
-[ 18, 46 ] = ascii (fp) : "./hrtfs/elev0/L0e130a.dat"
-[ 18, 47 ] = ascii (fp) : "./hrtfs/elev0/L0e125a.dat"
-[ 18, 48 ] = ascii (fp) : "./hrtfs/elev0/L0e120a.dat"
-[ 18, 49 ] = ascii (fp) : "./hrtfs/elev0/L0e115a.dat"
-[ 18, 50 ] = ascii (fp) : "./hrtfs/elev0/L0e110a.dat"
-[ 18, 51 ] = ascii (fp) : "./hrtfs/elev0/L0e105a.dat"
-[ 18, 52 ] = ascii (fp) : "./hrtfs/elev0/L0e100a.dat"
-[ 18, 53 ] = ascii (fp) : "./hrtfs/elev0/L0e095a.dat"
-[ 18, 54 ] = ascii (fp) : "./hrtfs/elev0/L0e090a.dat"
-[ 18, 55 ] = ascii (fp) : "./hrtfs/elev0/L0e085a.dat"
-[ 18, 56 ] = ascii (fp) : "./hrtfs/elev0/L0e080a.dat"
-[ 18, 57 ] = ascii (fp) : "./hrtfs/elev0/L0e075a.dat"
-[ 18, 58 ] = ascii (fp) : "./hrtfs/elev0/L0e070a.dat"
-[ 18, 59 ] = ascii (fp) : "./hrtfs/elev0/L0e065a.dat"
-[ 18, 60 ] = ascii (fp) : "./hrtfs/elev0/L0e060a.dat"
-[ 18, 61 ] = ascii (fp) : "./hrtfs/elev0/L0e055a.dat"
-[ 18, 62 ] = ascii (fp) : "./hrtfs/elev0/L0e050a.dat"
-[ 18, 63 ] = ascii (fp) : "./hrtfs/elev0/L0e045a.dat"
-[ 18, 64 ] = ascii (fp) : "./hrtfs/elev0/L0e040a.dat"
-[ 18, 65 ] = ascii (fp) : "./hrtfs/elev0/L0e035a.dat"
-[ 18, 66 ] = ascii (fp) : "./hrtfs/elev0/L0e030a.dat"
-[ 18, 67 ] = ascii (fp) : "./hrtfs/elev0/L0e025a.dat"
-[ 18, 68 ] = ascii (fp) : "./hrtfs/elev0/L0e020a.dat"
-[ 18, 69 ] = ascii (fp) : "./hrtfs/elev0/L0e015a.dat"
-[ 18, 70 ] = ascii (fp) : "./hrtfs/elev0/L0e010a.dat"
-[ 18, 71 ] = ascii (fp) : "./hrtfs/elev0/L0e005a.dat"
+[ 18, 0 ] = ascii (fp) : "./hrtfs/elev0/L0e000a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e000a.dat right
+[ 18, 1 ] = ascii (fp) : "./hrtfs/elev0/L0e355a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e355a.dat right
+[ 18, 2 ] = ascii (fp) : "./hrtfs/elev0/L0e350a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e350a.dat right
+[ 18, 3 ] = ascii (fp) : "./hrtfs/elev0/L0e345a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e345a.dat right
+[ 18, 4 ] = ascii (fp) : "./hrtfs/elev0/L0e340a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e340a.dat right
+[ 18, 5 ] = ascii (fp) : "./hrtfs/elev0/L0e335a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e335a.dat right
+[ 18, 6 ] = ascii (fp) : "./hrtfs/elev0/L0e330a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e330a.dat right
+[ 18, 7 ] = ascii (fp) : "./hrtfs/elev0/L0e325a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e325a.dat right
+[ 18, 8 ] = ascii (fp) : "./hrtfs/elev0/L0e320a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e320a.dat right
+[ 18, 9 ] = ascii (fp) : "./hrtfs/elev0/L0e315a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e315a.dat right
+[ 18, 10 ] = ascii (fp) : "./hrtfs/elev0/L0e310a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e310a.dat right
+[ 18, 11 ] = ascii (fp) : "./hrtfs/elev0/L0e305a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e305a.dat right
+[ 18, 12 ] = ascii (fp) : "./hrtfs/elev0/L0e300a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e300a.dat right
+[ 18, 13 ] = ascii (fp) : "./hrtfs/elev0/L0e295a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e295a.dat right
+[ 18, 14 ] = ascii (fp) : "./hrtfs/elev0/L0e290a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e290a.dat right
+[ 18, 15 ] = ascii (fp) : "./hrtfs/elev0/L0e285a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e285a.dat right
+[ 18, 16 ] = ascii (fp) : "./hrtfs/elev0/L0e280a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e280a.dat right
+[ 18, 17 ] = ascii (fp) : "./hrtfs/elev0/L0e275a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e275a.dat right
+[ 18, 18 ] = ascii (fp) : "./hrtfs/elev0/L0e270a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e270a.dat right
+[ 18, 19 ] = ascii (fp) : "./hrtfs/elev0/L0e265a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e265a.dat right
+[ 18, 20 ] = ascii (fp) : "./hrtfs/elev0/L0e260a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e260a.dat right
+[ 18, 21 ] = ascii (fp) : "./hrtfs/elev0/L0e255a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e255a.dat right
+[ 18, 22 ] = ascii (fp) : "./hrtfs/elev0/L0e250a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e250a.dat right
+[ 18, 23 ] = ascii (fp) : "./hrtfs/elev0/L0e245a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e245a.dat right
+[ 18, 24 ] = ascii (fp) : "./hrtfs/elev0/L0e240a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e240a.dat right
+[ 18, 25 ] = ascii (fp) : "./hrtfs/elev0/L0e235a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e235a.dat right
+[ 18, 26 ] = ascii (fp) : "./hrtfs/elev0/L0e230a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e230a.dat right
+[ 18, 27 ] = ascii (fp) : "./hrtfs/elev0/L0e225a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e225a.dat right
+[ 18, 28 ] = ascii (fp) : "./hrtfs/elev0/L0e220a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e220a.dat right
+[ 18, 29 ] = ascii (fp) : "./hrtfs/elev0/L0e215a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e215a.dat right
+[ 18, 30 ] = ascii (fp) : "./hrtfs/elev0/L0e210a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e210a.dat right
+[ 18, 31 ] = ascii (fp) : "./hrtfs/elev0/L0e205a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e205a.dat right
+[ 18, 32 ] = ascii (fp) : "./hrtfs/elev0/L0e200a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e200a.dat right
+[ 18, 33 ] = ascii (fp) : "./hrtfs/elev0/L0e195a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e195a.dat right
+[ 18, 34 ] = ascii (fp) : "./hrtfs/elev0/L0e190a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e190a.dat right
+[ 18, 35 ] = ascii (fp) : "./hrtfs/elev0/L0e185a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e185a.dat right
+[ 18, 36 ] = ascii (fp) : "./hrtfs/elev0/L0e180a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e180a.dat right
+[ 18, 37 ] = ascii (fp) : "./hrtfs/elev0/L0e175a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e175a.dat right
+[ 18, 38 ] = ascii (fp) : "./hrtfs/elev0/L0e170a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e170a.dat right
+[ 18, 39 ] = ascii (fp) : "./hrtfs/elev0/L0e165a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e165a.dat right
+[ 18, 40 ] = ascii (fp) : "./hrtfs/elev0/L0e160a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e160a.dat right
+[ 18, 41 ] = ascii (fp) : "./hrtfs/elev0/L0e155a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e155a.dat right
+[ 18, 42 ] = ascii (fp) : "./hrtfs/elev0/L0e150a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e150a.dat right
+[ 18, 43 ] = ascii (fp) : "./hrtfs/elev0/L0e145a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e145a.dat right
+[ 18, 44 ] = ascii (fp) : "./hrtfs/elev0/L0e140a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e140a.dat right
+[ 18, 45 ] = ascii (fp) : "./hrtfs/elev0/L0e135a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e135a.dat right
+[ 18, 46 ] = ascii (fp) : "./hrtfs/elev0/L0e130a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e130a.dat right
+[ 18, 47 ] = ascii (fp) : "./hrtfs/elev0/L0e125a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e125a.dat right
+[ 18, 48 ] = ascii (fp) : "./hrtfs/elev0/L0e120a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e120a.dat right
+[ 18, 49 ] = ascii (fp) : "./hrtfs/elev0/L0e115a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e115a.dat right
+[ 18, 50 ] = ascii (fp) : "./hrtfs/elev0/L0e110a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e110a.dat right
+[ 18, 51 ] = ascii (fp) : "./hrtfs/elev0/L0e105a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e105a.dat right
+[ 18, 52 ] = ascii (fp) : "./hrtfs/elev0/L0e100a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e100a.dat right
+[ 18, 53 ] = ascii (fp) : "./hrtfs/elev0/L0e095a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e095a.dat right
+[ 18, 54 ] = ascii (fp) : "./hrtfs/elev0/L0e090a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e090a.dat right
+[ 18, 55 ] = ascii (fp) : "./hrtfs/elev0/L0e085a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e085a.dat right
+[ 18, 56 ] = ascii (fp) : "./hrtfs/elev0/L0e080a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e080a.dat right
+[ 18, 57 ] = ascii (fp) : "./hrtfs/elev0/L0e075a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e075a.dat right
+[ 18, 58 ] = ascii (fp) : "./hrtfs/elev0/L0e070a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e070a.dat right
+[ 18, 59 ] = ascii (fp) : "./hrtfs/elev0/L0e065a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e065a.dat right
+[ 18, 60 ] = ascii (fp) : "./hrtfs/elev0/L0e060a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e060a.dat right
+[ 18, 61 ] = ascii (fp) : "./hrtfs/elev0/L0e055a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e055a.dat right
+[ 18, 62 ] = ascii (fp) : "./hrtfs/elev0/L0e050a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e050a.dat right
+[ 18, 63 ] = ascii (fp) : "./hrtfs/elev0/L0e045a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e045a.dat right
+[ 18, 64 ] = ascii (fp) : "./hrtfs/elev0/L0e040a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e040a.dat right
+[ 18, 65 ] = ascii (fp) : "./hrtfs/elev0/L0e035a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e035a.dat right
+[ 18, 66 ] = ascii (fp) : "./hrtfs/elev0/L0e030a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e030a.dat right
+[ 18, 67 ] = ascii (fp) : "./hrtfs/elev0/L0e025a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e025a.dat right
+[ 18, 68 ] = ascii (fp) : "./hrtfs/elev0/L0e020a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e020a.dat right
+[ 18, 69 ] = ascii (fp) : "./hrtfs/elev0/L0e015a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e015a.dat right
+[ 18, 70 ] = ascii (fp) : "./hrtfs/elev0/L0e010a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e010a.dat right
+[ 18, 71 ] = ascii (fp) : "./hrtfs/elev0/L0e005a.dat left
+ + ascii (fp) : "./hrtfs/elev0/R0e005a.dat right
-[ 19, 0 ] = ascii (fp) : "./hrtfs/elev5/L5e000a.dat"
-[ 19, 1 ] = ascii (fp) : "./hrtfs/elev5/L5e355a.dat"
-[ 19, 2 ] = ascii (fp) : "./hrtfs/elev5/L5e350a.dat"
-[ 19, 3 ] = ascii (fp) : "./hrtfs/elev5/L5e345a.dat"
-[ 19, 4 ] = ascii (fp) : "./hrtfs/elev5/L5e340a.dat"
-[ 19, 5 ] = ascii (fp) : "./hrtfs/elev5/L5e335a.dat"
-[ 19, 6 ] = ascii (fp) : "./hrtfs/elev5/L5e330a.dat"
-[ 19, 7 ] = ascii (fp) : "./hrtfs/elev5/L5e325a.dat"
-[ 19, 8 ] = ascii (fp) : "./hrtfs/elev5/L5e320a.dat"
-[ 19, 9 ] = ascii (fp) : "./hrtfs/elev5/L5e315a.dat"
-[ 19, 10 ] = ascii (fp) : "./hrtfs/elev5/L5e310a.dat"
-[ 19, 11 ] = ascii (fp) : "./hrtfs/elev5/L5e305a.dat"
-[ 19, 12 ] = ascii (fp) : "./hrtfs/elev5/L5e300a.dat"
-[ 19, 13 ] = ascii (fp) : "./hrtfs/elev5/L5e295a.dat"
-[ 19, 14 ] = ascii (fp) : "./hrtfs/elev5/L5e290a.dat"
-[ 19, 15 ] = ascii (fp) : "./hrtfs/elev5/L5e285a.dat"
-[ 19, 16 ] = ascii (fp) : "./hrtfs/elev5/L5e280a.dat"
-[ 19, 17 ] = ascii (fp) : "./hrtfs/elev5/L5e275a.dat"
-[ 19, 18 ] = ascii (fp) : "./hrtfs/elev5/L5e270a.dat"
-[ 19, 19 ] = ascii (fp) : "./hrtfs/elev5/L5e265a.dat"
-[ 19, 20 ] = ascii (fp) : "./hrtfs/elev5/L5e260a.dat"
-[ 19, 21 ] = ascii (fp) : "./hrtfs/elev5/L5e255a.dat"
-[ 19, 22 ] = ascii (fp) : "./hrtfs/elev5/L5e250a.dat"
-[ 19, 23 ] = ascii (fp) : "./hrtfs/elev5/L5e245a.dat"
-[ 19, 24 ] = ascii (fp) : "./hrtfs/elev5/L5e240a.dat"
-[ 19, 25 ] = ascii (fp) : "./hrtfs/elev5/L5e235a.dat"
-[ 19, 26 ] = ascii (fp) : "./hrtfs/elev5/L5e230a.dat"
-[ 19, 27 ] = ascii (fp) : "./hrtfs/elev5/L5e225a.dat"
-[ 19, 28 ] = ascii (fp) : "./hrtfs/elev5/L5e220a.dat"
-[ 19, 29 ] = ascii (fp) : "./hrtfs/elev5/L5e215a.dat"
-[ 19, 30 ] = ascii (fp) : "./hrtfs/elev5/L5e210a.dat"
-[ 19, 31 ] = ascii (fp) : "./hrtfs/elev5/L5e205a.dat"
-[ 19, 32 ] = ascii (fp) : "./hrtfs/elev5/L5e200a.dat"
-[ 19, 33 ] = ascii (fp) : "./hrtfs/elev5/L5e195a.dat"
-[ 19, 34 ] = ascii (fp) : "./hrtfs/elev5/L5e190a.dat"
-[ 19, 35 ] = ascii (fp) : "./hrtfs/elev5/L5e185a.dat"
-[ 19, 36 ] = ascii (fp) : "./hrtfs/elev5/L5e180a.dat"
-[ 19, 37 ] = ascii (fp) : "./hrtfs/elev5/L5e175a.dat"
-[ 19, 38 ] = ascii (fp) : "./hrtfs/elev5/L5e170a.dat"
-[ 19, 39 ] = ascii (fp) : "./hrtfs/elev5/L5e165a.dat"
-[ 19, 40 ] = ascii (fp) : "./hrtfs/elev5/L5e160a.dat"
-[ 19, 41 ] = ascii (fp) : "./hrtfs/elev5/L5e155a.dat"
-[ 19, 42 ] = ascii (fp) : "./hrtfs/elev5/L5e150a.dat"
-[ 19, 43 ] = ascii (fp) : "./hrtfs/elev5/L5e145a.dat"
-[ 19, 44 ] = ascii (fp) : "./hrtfs/elev5/L5e140a.dat"
-[ 19, 45 ] = ascii (fp) : "./hrtfs/elev5/L5e135a.dat"
-[ 19, 46 ] = ascii (fp) : "./hrtfs/elev5/L5e130a.dat"
-[ 19, 47 ] = ascii (fp) : "./hrtfs/elev5/L5e125a.dat"
-[ 19, 48 ] = ascii (fp) : "./hrtfs/elev5/L5e120a.dat"
-[ 19, 49 ] = ascii (fp) : "./hrtfs/elev5/L5e115a.dat"
-[ 19, 50 ] = ascii (fp) : "./hrtfs/elev5/L5e110a.dat"
-[ 19, 51 ] = ascii (fp) : "./hrtfs/elev5/L5e105a.dat"
-[ 19, 52 ] = ascii (fp) : "./hrtfs/elev5/L5e100a.dat"
-[ 19, 53 ] = ascii (fp) : "./hrtfs/elev5/L5e095a.dat"
-[ 19, 54 ] = ascii (fp) : "./hrtfs/elev5/L5e090a.dat"
-[ 19, 55 ] = ascii (fp) : "./hrtfs/elev5/L5e085a.dat"
-[ 19, 56 ] = ascii (fp) : "./hrtfs/elev5/L5e080a.dat"
-[ 19, 57 ] = ascii (fp) : "./hrtfs/elev5/L5e075a.dat"
-[ 19, 58 ] = ascii (fp) : "./hrtfs/elev5/L5e070a.dat"
-[ 19, 59 ] = ascii (fp) : "./hrtfs/elev5/L5e065a.dat"
-[ 19, 60 ] = ascii (fp) : "./hrtfs/elev5/L5e060a.dat"
-[ 19, 61 ] = ascii (fp) : "./hrtfs/elev5/L5e055a.dat"
-[ 19, 62 ] = ascii (fp) : "./hrtfs/elev5/L5e050a.dat"
-[ 19, 63 ] = ascii (fp) : "./hrtfs/elev5/L5e045a.dat"
-[ 19, 64 ] = ascii (fp) : "./hrtfs/elev5/L5e040a.dat"
-[ 19, 65 ] = ascii (fp) : "./hrtfs/elev5/L5e035a.dat"
-[ 19, 66 ] = ascii (fp) : "./hrtfs/elev5/L5e030a.dat"
-[ 19, 67 ] = ascii (fp) : "./hrtfs/elev5/L5e025a.dat"
-[ 19, 68 ] = ascii (fp) : "./hrtfs/elev5/L5e020a.dat"
-[ 19, 69 ] = ascii (fp) : "./hrtfs/elev5/L5e015a.dat"
-[ 19, 70 ] = ascii (fp) : "./hrtfs/elev5/L5e010a.dat"
-[ 19, 71 ] = ascii (fp) : "./hrtfs/elev5/L5e005a.dat"
+[ 19, 0 ] = ascii (fp) : "./hrtfs/elev5/L5e000a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e000a.dat right
+[ 19, 1 ] = ascii (fp) : "./hrtfs/elev5/L5e355a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e355a.dat right
+[ 19, 2 ] = ascii (fp) : "./hrtfs/elev5/L5e350a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e350a.dat right
+[ 19, 3 ] = ascii (fp) : "./hrtfs/elev5/L5e345a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e345a.dat right
+[ 19, 4 ] = ascii (fp) : "./hrtfs/elev5/L5e340a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e340a.dat right
+[ 19, 5 ] = ascii (fp) : "./hrtfs/elev5/L5e335a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e335a.dat right
+[ 19, 6 ] = ascii (fp) : "./hrtfs/elev5/L5e330a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e330a.dat right
+[ 19, 7 ] = ascii (fp) : "./hrtfs/elev5/L5e325a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e325a.dat right
+[ 19, 8 ] = ascii (fp) : "./hrtfs/elev5/L5e320a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e320a.dat right
+[ 19, 9 ] = ascii (fp) : "./hrtfs/elev5/L5e315a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e315a.dat right
+[ 19, 10 ] = ascii (fp) : "./hrtfs/elev5/L5e310a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e310a.dat right
+[ 19, 11 ] = ascii (fp) : "./hrtfs/elev5/L5e305a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e305a.dat right
+[ 19, 12 ] = ascii (fp) : "./hrtfs/elev5/L5e300a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e300a.dat right
+[ 19, 13 ] = ascii (fp) : "./hrtfs/elev5/L5e295a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e295a.dat right
+[ 19, 14 ] = ascii (fp) : "./hrtfs/elev5/L5e290a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e290a.dat right
+[ 19, 15 ] = ascii (fp) : "./hrtfs/elev5/L5e285a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e285a.dat right
+[ 19, 16 ] = ascii (fp) : "./hrtfs/elev5/L5e280a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e280a.dat right
+[ 19, 17 ] = ascii (fp) : "./hrtfs/elev5/L5e275a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e275a.dat right
+[ 19, 18 ] = ascii (fp) : "./hrtfs/elev5/L5e270a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e270a.dat right
+[ 19, 19 ] = ascii (fp) : "./hrtfs/elev5/L5e265a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e265a.dat right
+[ 19, 20 ] = ascii (fp) : "./hrtfs/elev5/L5e260a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e260a.dat right
+[ 19, 21 ] = ascii (fp) : "./hrtfs/elev5/L5e255a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e255a.dat right
+[ 19, 22 ] = ascii (fp) : "./hrtfs/elev5/L5e250a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e250a.dat right
+[ 19, 23 ] = ascii (fp) : "./hrtfs/elev5/L5e245a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e245a.dat right
+[ 19, 24 ] = ascii (fp) : "./hrtfs/elev5/L5e240a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e240a.dat right
+[ 19, 25 ] = ascii (fp) : "./hrtfs/elev5/L5e235a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e235a.dat right
+[ 19, 26 ] = ascii (fp) : "./hrtfs/elev5/L5e230a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e230a.dat right
+[ 19, 27 ] = ascii (fp) : "./hrtfs/elev5/L5e225a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e225a.dat right
+[ 19, 28 ] = ascii (fp) : "./hrtfs/elev5/L5e220a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e220a.dat right
+[ 19, 29 ] = ascii (fp) : "./hrtfs/elev5/L5e215a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e215a.dat right
+[ 19, 30 ] = ascii (fp) : "./hrtfs/elev5/L5e210a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e210a.dat right
+[ 19, 31 ] = ascii (fp) : "./hrtfs/elev5/L5e205a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e205a.dat right
+[ 19, 32 ] = ascii (fp) : "./hrtfs/elev5/L5e200a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e200a.dat right
+[ 19, 33 ] = ascii (fp) : "./hrtfs/elev5/L5e195a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e195a.dat right
+[ 19, 34 ] = ascii (fp) : "./hrtfs/elev5/L5e190a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e190a.dat right
+[ 19, 35 ] = ascii (fp) : "./hrtfs/elev5/L5e185a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e185a.dat right
+[ 19, 36 ] = ascii (fp) : "./hrtfs/elev5/L5e180a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e180a.dat right
+[ 19, 37 ] = ascii (fp) : "./hrtfs/elev5/L5e175a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e175a.dat right
+[ 19, 38 ] = ascii (fp) : "./hrtfs/elev5/L5e170a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e170a.dat right
+[ 19, 39 ] = ascii (fp) : "./hrtfs/elev5/L5e165a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e165a.dat right
+[ 19, 40 ] = ascii (fp) : "./hrtfs/elev5/L5e160a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e160a.dat right
+[ 19, 41 ] = ascii (fp) : "./hrtfs/elev5/L5e155a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e155a.dat right
+[ 19, 42 ] = ascii (fp) : "./hrtfs/elev5/L5e150a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e150a.dat right
+[ 19, 43 ] = ascii (fp) : "./hrtfs/elev5/L5e145a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e145a.dat right
+[ 19, 44 ] = ascii (fp) : "./hrtfs/elev5/L5e140a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e140a.dat right
+[ 19, 45 ] = ascii (fp) : "./hrtfs/elev5/L5e135a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e135a.dat right
+[ 19, 46 ] = ascii (fp) : "./hrtfs/elev5/L5e130a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e130a.dat right
+[ 19, 47 ] = ascii (fp) : "./hrtfs/elev5/L5e125a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e125a.dat right
+[ 19, 48 ] = ascii (fp) : "./hrtfs/elev5/L5e120a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e120a.dat right
+[ 19, 49 ] = ascii (fp) : "./hrtfs/elev5/L5e115a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e115a.dat right
+[ 19, 50 ] = ascii (fp) : "./hrtfs/elev5/L5e110a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e110a.dat right
+[ 19, 51 ] = ascii (fp) : "./hrtfs/elev5/L5e105a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e105a.dat right
+[ 19, 52 ] = ascii (fp) : "./hrtfs/elev5/L5e100a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e100a.dat right
+[ 19, 53 ] = ascii (fp) : "./hrtfs/elev5/L5e095a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e095a.dat right
+[ 19, 54 ] = ascii (fp) : "./hrtfs/elev5/L5e090a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e090a.dat right
+[ 19, 55 ] = ascii (fp) : "./hrtfs/elev5/L5e085a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e085a.dat right
+[ 19, 56 ] = ascii (fp) : "./hrtfs/elev5/L5e080a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e080a.dat right
+[ 19, 57 ] = ascii (fp) : "./hrtfs/elev5/L5e075a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e075a.dat right
+[ 19, 58 ] = ascii (fp) : "./hrtfs/elev5/L5e070a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e070a.dat right
+[ 19, 59 ] = ascii (fp) : "./hrtfs/elev5/L5e065a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e065a.dat right
+[ 19, 60 ] = ascii (fp) : "./hrtfs/elev5/L5e060a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e060a.dat right
+[ 19, 61 ] = ascii (fp) : "./hrtfs/elev5/L5e055a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e055a.dat right
+[ 19, 62 ] = ascii (fp) : "./hrtfs/elev5/L5e050a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e050a.dat right
+[ 19, 63 ] = ascii (fp) : "./hrtfs/elev5/L5e045a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e045a.dat right
+[ 19, 64 ] = ascii (fp) : "./hrtfs/elev5/L5e040a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e040a.dat right
+[ 19, 65 ] = ascii (fp) : "./hrtfs/elev5/L5e035a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e035a.dat right
+[ 19, 66 ] = ascii (fp) : "./hrtfs/elev5/L5e030a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e030a.dat right
+[ 19, 67 ] = ascii (fp) : "./hrtfs/elev5/L5e025a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e025a.dat right
+[ 19, 68 ] = ascii (fp) : "./hrtfs/elev5/L5e020a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e020a.dat right
+[ 19, 69 ] = ascii (fp) : "./hrtfs/elev5/L5e015a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e015a.dat right
+[ 19, 70 ] = ascii (fp) : "./hrtfs/elev5/L5e010a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e010a.dat right
+[ 19, 71 ] = ascii (fp) : "./hrtfs/elev5/L5e005a.dat left
+ + ascii (fp) : "./hrtfs/elev5/R5e005a.dat right
-[ 20, 0 ] = ascii (fp) : "./hrtfs/elev10/L10e000a.dat"
-[ 20, 1 ] = ascii (fp) : "./hrtfs/elev10/L10e355a.dat"
-[ 20, 2 ] = ascii (fp) : "./hrtfs/elev10/L10e350a.dat"
-[ 20, 3 ] = ascii (fp) : "./hrtfs/elev10/L10e345a.dat"
-[ 20, 4 ] = ascii (fp) : "./hrtfs/elev10/L10e340a.dat"
-[ 20, 5 ] = ascii (fp) : "./hrtfs/elev10/L10e335a.dat"
-[ 20, 6 ] = ascii (fp) : "./hrtfs/elev10/L10e330a.dat"
-[ 20, 7 ] = ascii (fp) : "./hrtfs/elev10/L10e325a.dat"
-[ 20, 8 ] = ascii (fp) : "./hrtfs/elev10/L10e320a.dat"
-[ 20, 9 ] = ascii (fp) : "./hrtfs/elev10/L10e315a.dat"
-[ 20, 10 ] = ascii (fp) : "./hrtfs/elev10/L10e310a.dat"
-[ 20, 11 ] = ascii (fp) : "./hrtfs/elev10/L10e305a.dat"
-[ 20, 12 ] = ascii (fp) : "./hrtfs/elev10/L10e300a.dat"
-[ 20, 13 ] = ascii (fp) : "./hrtfs/elev10/L10e295a.dat"
-[ 20, 14 ] = ascii (fp) : "./hrtfs/elev10/L10e290a.dat"
-[ 20, 15 ] = ascii (fp) : "./hrtfs/elev10/L10e285a.dat"
-[ 20, 16 ] = ascii (fp) : "./hrtfs/elev10/L10e280a.dat"
-[ 20, 17 ] = ascii (fp) : "./hrtfs/elev10/L10e275a.dat"
-[ 20, 18 ] = ascii (fp) : "./hrtfs/elev10/L10e270a.dat"
-[ 20, 19 ] = ascii (fp) : "./hrtfs/elev10/L10e265a.dat"
-[ 20, 20 ] = ascii (fp) : "./hrtfs/elev10/L10e260a.dat"
-[ 20, 21 ] = ascii (fp) : "./hrtfs/elev10/L10e255a.dat"
-[ 20, 22 ] = ascii (fp) : "./hrtfs/elev10/L10e250a.dat"
-[ 20, 23 ] = ascii (fp) : "./hrtfs/elev10/L10e245a.dat"
-[ 20, 24 ] = ascii (fp) : "./hrtfs/elev10/L10e240a.dat"
-[ 20, 25 ] = ascii (fp) : "./hrtfs/elev10/L10e235a.dat"
-[ 20, 26 ] = ascii (fp) : "./hrtfs/elev10/L10e230a.dat"
-[ 20, 27 ] = ascii (fp) : "./hrtfs/elev10/L10e225a.dat"
-[ 20, 28 ] = ascii (fp) : "./hrtfs/elev10/L10e220a.dat"
-[ 20, 29 ] = ascii (fp) : "./hrtfs/elev10/L10e215a.dat"
-[ 20, 30 ] = ascii (fp) : "./hrtfs/elev10/L10e210a.dat"
-[ 20, 31 ] = ascii (fp) : "./hrtfs/elev10/L10e205a.dat"
-[ 20, 32 ] = ascii (fp) : "./hrtfs/elev10/L10e200a.dat"
-[ 20, 33 ] = ascii (fp) : "./hrtfs/elev10/L10e195a.dat"
-[ 20, 34 ] = ascii (fp) : "./hrtfs/elev10/L10e190a.dat"
-[ 20, 35 ] = ascii (fp) : "./hrtfs/elev10/L10e185a.dat"
-[ 20, 36 ] = ascii (fp) : "./hrtfs/elev10/L10e180a.dat"
-[ 20, 37 ] = ascii (fp) : "./hrtfs/elev10/L10e175a.dat"
-[ 20, 38 ] = ascii (fp) : "./hrtfs/elev10/L10e170a.dat"
-[ 20, 39 ] = ascii (fp) : "./hrtfs/elev10/L10e165a.dat"
-[ 20, 40 ] = ascii (fp) : "./hrtfs/elev10/L10e160a.dat"
-[ 20, 41 ] = ascii (fp) : "./hrtfs/elev10/L10e155a.dat"
-[ 20, 42 ] = ascii (fp) : "./hrtfs/elev10/L10e150a.dat"
-[ 20, 43 ] = ascii (fp) : "./hrtfs/elev10/L10e145a.dat"
-[ 20, 44 ] = ascii (fp) : "./hrtfs/elev10/L10e140a.dat"
-[ 20, 45 ] = ascii (fp) : "./hrtfs/elev10/L10e135a.dat"
-[ 20, 46 ] = ascii (fp) : "./hrtfs/elev10/L10e130a.dat"
-[ 20, 47 ] = ascii (fp) : "./hrtfs/elev10/L10e125a.dat"
-[ 20, 48 ] = ascii (fp) : "./hrtfs/elev10/L10e120a.dat"
-[ 20, 49 ] = ascii (fp) : "./hrtfs/elev10/L10e115a.dat"
-[ 20, 50 ] = ascii (fp) : "./hrtfs/elev10/L10e110a.dat"
-[ 20, 51 ] = ascii (fp) : "./hrtfs/elev10/L10e105a.dat"
-[ 20, 52 ] = ascii (fp) : "./hrtfs/elev10/L10e100a.dat"
-[ 20, 53 ] = ascii (fp) : "./hrtfs/elev10/L10e095a.dat"
-[ 20, 54 ] = ascii (fp) : "./hrtfs/elev10/L10e090a.dat"
-[ 20, 55 ] = ascii (fp) : "./hrtfs/elev10/L10e085a.dat"
-[ 20, 56 ] = ascii (fp) : "./hrtfs/elev10/L10e080a.dat"
-[ 20, 57 ] = ascii (fp) : "./hrtfs/elev10/L10e075a.dat"
-[ 20, 58 ] = ascii (fp) : "./hrtfs/elev10/L10e070a.dat"
-[ 20, 59 ] = ascii (fp) : "./hrtfs/elev10/L10e065a.dat"
-[ 20, 60 ] = ascii (fp) : "./hrtfs/elev10/L10e060a.dat"
-[ 20, 61 ] = ascii (fp) : "./hrtfs/elev10/L10e055a.dat"
-[ 20, 62 ] = ascii (fp) : "./hrtfs/elev10/L10e050a.dat"
-[ 20, 63 ] = ascii (fp) : "./hrtfs/elev10/L10e045a.dat"
-[ 20, 64 ] = ascii (fp) : "./hrtfs/elev10/L10e040a.dat"
-[ 20, 65 ] = ascii (fp) : "./hrtfs/elev10/L10e035a.dat"
-[ 20, 66 ] = ascii (fp) : "./hrtfs/elev10/L10e030a.dat"
-[ 20, 67 ] = ascii (fp) : "./hrtfs/elev10/L10e025a.dat"
-[ 20, 68 ] = ascii (fp) : "./hrtfs/elev10/L10e020a.dat"
-[ 20, 69 ] = ascii (fp) : "./hrtfs/elev10/L10e015a.dat"
-[ 20, 70 ] = ascii (fp) : "./hrtfs/elev10/L10e010a.dat"
-[ 20, 71 ] = ascii (fp) : "./hrtfs/elev10/L10e005a.dat"
+[ 20, 0 ] = ascii (fp) : "./hrtfs/elev10/L10e000a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e000a.dat right
+[ 20, 1 ] = ascii (fp) : "./hrtfs/elev10/L10e355a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e355a.dat right
+[ 20, 2 ] = ascii (fp) : "./hrtfs/elev10/L10e350a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e350a.dat right
+[ 20, 3 ] = ascii (fp) : "./hrtfs/elev10/L10e345a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e345a.dat right
+[ 20, 4 ] = ascii (fp) : "./hrtfs/elev10/L10e340a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e340a.dat right
+[ 20, 5 ] = ascii (fp) : "./hrtfs/elev10/L10e335a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e335a.dat right
+[ 20, 6 ] = ascii (fp) : "./hrtfs/elev10/L10e330a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e330a.dat right
+[ 20, 7 ] = ascii (fp) : "./hrtfs/elev10/L10e325a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e325a.dat right
+[ 20, 8 ] = ascii (fp) : "./hrtfs/elev10/L10e320a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e320a.dat right
+[ 20, 9 ] = ascii (fp) : "./hrtfs/elev10/L10e315a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e315a.dat right
+[ 20, 10 ] = ascii (fp) : "./hrtfs/elev10/L10e310a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e310a.dat right
+[ 20, 11 ] = ascii (fp) : "./hrtfs/elev10/L10e305a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e305a.dat right
+[ 20, 12 ] = ascii (fp) : "./hrtfs/elev10/L10e300a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e300a.dat right
+[ 20, 13 ] = ascii (fp) : "./hrtfs/elev10/L10e295a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e295a.dat right
+[ 20, 14 ] = ascii (fp) : "./hrtfs/elev10/L10e290a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e290a.dat right
+[ 20, 15 ] = ascii (fp) : "./hrtfs/elev10/L10e285a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e285a.dat right
+[ 20, 16 ] = ascii (fp) : "./hrtfs/elev10/L10e280a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e280a.dat right
+[ 20, 17 ] = ascii (fp) : "./hrtfs/elev10/L10e275a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e275a.dat right
+[ 20, 18 ] = ascii (fp) : "./hrtfs/elev10/L10e270a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e270a.dat right
+[ 20, 19 ] = ascii (fp) : "./hrtfs/elev10/L10e265a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e265a.dat right
+[ 20, 20 ] = ascii (fp) : "./hrtfs/elev10/L10e260a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e260a.dat right
+[ 20, 21 ] = ascii (fp) : "./hrtfs/elev10/L10e255a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e255a.dat right
+[ 20, 22 ] = ascii (fp) : "./hrtfs/elev10/L10e250a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e250a.dat right
+[ 20, 23 ] = ascii (fp) : "./hrtfs/elev10/L10e245a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e245a.dat right
+[ 20, 24 ] = ascii (fp) : "./hrtfs/elev10/L10e240a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e240a.dat right
+[ 20, 25 ] = ascii (fp) : "./hrtfs/elev10/L10e235a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e235a.dat right
+[ 20, 26 ] = ascii (fp) : "./hrtfs/elev10/L10e230a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e230a.dat right
+[ 20, 27 ] = ascii (fp) : "./hrtfs/elev10/L10e225a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e225a.dat right
+[ 20, 28 ] = ascii (fp) : "./hrtfs/elev10/L10e220a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e220a.dat right
+[ 20, 29 ] = ascii (fp) : "./hrtfs/elev10/L10e215a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e215a.dat right
+[ 20, 30 ] = ascii (fp) : "./hrtfs/elev10/L10e210a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e210a.dat right
+[ 20, 31 ] = ascii (fp) : "./hrtfs/elev10/L10e205a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e205a.dat right
+[ 20, 32 ] = ascii (fp) : "./hrtfs/elev10/L10e200a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e200a.dat right
+[ 20, 33 ] = ascii (fp) : "./hrtfs/elev10/L10e195a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e195a.dat right
+[ 20, 34 ] = ascii (fp) : "./hrtfs/elev10/L10e190a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e190a.dat right
+[ 20, 35 ] = ascii (fp) : "./hrtfs/elev10/L10e185a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e185a.dat right
+[ 20, 36 ] = ascii (fp) : "./hrtfs/elev10/L10e180a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e180a.dat right
+[ 20, 37 ] = ascii (fp) : "./hrtfs/elev10/L10e175a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e175a.dat right
+[ 20, 38 ] = ascii (fp) : "./hrtfs/elev10/L10e170a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e170a.dat right
+[ 20, 39 ] = ascii (fp) : "./hrtfs/elev10/L10e165a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e165a.dat right
+[ 20, 40 ] = ascii (fp) : "./hrtfs/elev10/L10e160a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e160a.dat right
+[ 20, 41 ] = ascii (fp) : "./hrtfs/elev10/L10e155a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e155a.dat right
+[ 20, 42 ] = ascii (fp) : "./hrtfs/elev10/L10e150a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e150a.dat right
+[ 20, 43 ] = ascii (fp) : "./hrtfs/elev10/L10e145a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e145a.dat right
+[ 20, 44 ] = ascii (fp) : "./hrtfs/elev10/L10e140a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e140a.dat right
+[ 20, 45 ] = ascii (fp) : "./hrtfs/elev10/L10e135a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e135a.dat right
+[ 20, 46 ] = ascii (fp) : "./hrtfs/elev10/L10e130a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e130a.dat right
+[ 20, 47 ] = ascii (fp) : "./hrtfs/elev10/L10e125a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e125a.dat right
+[ 20, 48 ] = ascii (fp) : "./hrtfs/elev10/L10e120a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e120a.dat right
+[ 20, 49 ] = ascii (fp) : "./hrtfs/elev10/L10e115a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e115a.dat right
+[ 20, 50 ] = ascii (fp) : "./hrtfs/elev10/L10e110a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e110a.dat right
+[ 20, 51 ] = ascii (fp) : "./hrtfs/elev10/L10e105a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e105a.dat right
+[ 20, 52 ] = ascii (fp) : "./hrtfs/elev10/L10e100a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e100a.dat right
+[ 20, 53 ] = ascii (fp) : "./hrtfs/elev10/L10e095a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e095a.dat right
+[ 20, 54 ] = ascii (fp) : "./hrtfs/elev10/L10e090a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e090a.dat right
+[ 20, 55 ] = ascii (fp) : "./hrtfs/elev10/L10e085a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e085a.dat right
+[ 20, 56 ] = ascii (fp) : "./hrtfs/elev10/L10e080a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e080a.dat right
+[ 20, 57 ] = ascii (fp) : "./hrtfs/elev10/L10e075a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e075a.dat right
+[ 20, 58 ] = ascii (fp) : "./hrtfs/elev10/L10e070a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e070a.dat right
+[ 20, 59 ] = ascii (fp) : "./hrtfs/elev10/L10e065a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e065a.dat right
+[ 20, 60 ] = ascii (fp) : "./hrtfs/elev10/L10e060a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e060a.dat right
+[ 20, 61 ] = ascii (fp) : "./hrtfs/elev10/L10e055a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e055a.dat right
+[ 20, 62 ] = ascii (fp) : "./hrtfs/elev10/L10e050a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e050a.dat right
+[ 20, 63 ] = ascii (fp) : "./hrtfs/elev10/L10e045a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e045a.dat right
+[ 20, 64 ] = ascii (fp) : "./hrtfs/elev10/L10e040a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e040a.dat right
+[ 20, 65 ] = ascii (fp) : "./hrtfs/elev10/L10e035a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e035a.dat right
+[ 20, 66 ] = ascii (fp) : "./hrtfs/elev10/L10e030a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e030a.dat right
+[ 20, 67 ] = ascii (fp) : "./hrtfs/elev10/L10e025a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e025a.dat right
+[ 20, 68 ] = ascii (fp) : "./hrtfs/elev10/L10e020a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e020a.dat right
+[ 20, 69 ] = ascii (fp) : "./hrtfs/elev10/L10e015a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e015a.dat right
+[ 20, 70 ] = ascii (fp) : "./hrtfs/elev10/L10e010a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e010a.dat right
+[ 20, 71 ] = ascii (fp) : "./hrtfs/elev10/L10e005a.dat left
+ + ascii (fp) : "./hrtfs/elev10/R10e005a.dat right
-[ 21, 0 ] = ascii (fp) : "./hrtfs/elev15/L15e000a.dat"
-[ 21, 1 ] = ascii (fp) : "./hrtfs/elev15/L15e355a.dat"
-[ 21, 2 ] = ascii (fp) : "./hrtfs/elev15/L15e350a.dat"
-[ 21, 3 ] = ascii (fp) : "./hrtfs/elev15/L15e345a.dat"
-[ 21, 4 ] = ascii (fp) : "./hrtfs/elev15/L15e340a.dat"
-[ 21, 5 ] = ascii (fp) : "./hrtfs/elev15/L15e335a.dat"
-[ 21, 6 ] = ascii (fp) : "./hrtfs/elev15/L15e330a.dat"
-[ 21, 7 ] = ascii (fp) : "./hrtfs/elev15/L15e325a.dat"
-[ 21, 8 ] = ascii (fp) : "./hrtfs/elev15/L15e320a.dat"
-[ 21, 9 ] = ascii (fp) : "./hrtfs/elev15/L15e315a.dat"
-[ 21, 10 ] = ascii (fp) : "./hrtfs/elev15/L15e310a.dat"
-[ 21, 11 ] = ascii (fp) : "./hrtfs/elev15/L15e305a.dat"
-[ 21, 12 ] = ascii (fp) : "./hrtfs/elev15/L15e300a.dat"
-[ 21, 13 ] = ascii (fp) : "./hrtfs/elev15/L15e295a.dat"
-[ 21, 14 ] = ascii (fp) : "./hrtfs/elev15/L15e290a.dat"
-[ 21, 15 ] = ascii (fp) : "./hrtfs/elev15/L15e285a.dat"
-[ 21, 16 ] = ascii (fp) : "./hrtfs/elev15/L15e280a.dat"
-[ 21, 17 ] = ascii (fp) : "./hrtfs/elev15/L15e275a.dat"
-[ 21, 18 ] = ascii (fp) : "./hrtfs/elev15/L15e270a.dat"
-[ 21, 19 ] = ascii (fp) : "./hrtfs/elev15/L15e265a.dat"
-[ 21, 20 ] = ascii (fp) : "./hrtfs/elev15/L15e260a.dat"
-[ 21, 21 ] = ascii (fp) : "./hrtfs/elev15/L15e255a.dat"
-[ 21, 22 ] = ascii (fp) : "./hrtfs/elev15/L15e250a.dat"
-[ 21, 23 ] = ascii (fp) : "./hrtfs/elev15/L15e245a.dat"
-[ 21, 24 ] = ascii (fp) : "./hrtfs/elev15/L15e240a.dat"
-[ 21, 25 ] = ascii (fp) : "./hrtfs/elev15/L15e235a.dat"
-[ 21, 26 ] = ascii (fp) : "./hrtfs/elev15/L15e230a.dat"
-[ 21, 27 ] = ascii (fp) : "./hrtfs/elev15/L15e225a.dat"
-[ 21, 28 ] = ascii (fp) : "./hrtfs/elev15/L15e220a.dat"
-[ 21, 29 ] = ascii (fp) : "./hrtfs/elev15/L15e215a.dat"
-[ 21, 30 ] = ascii (fp) : "./hrtfs/elev15/L15e210a.dat"
-[ 21, 31 ] = ascii (fp) : "./hrtfs/elev15/L15e205a.dat"
-[ 21, 32 ] = ascii (fp) : "./hrtfs/elev15/L15e200a.dat"
-[ 21, 33 ] = ascii (fp) : "./hrtfs/elev15/L15e195a.dat"
-[ 21, 34 ] = ascii (fp) : "./hrtfs/elev15/L15e190a.dat"
-[ 21, 35 ] = ascii (fp) : "./hrtfs/elev15/L15e185a.dat"
-[ 21, 36 ] = ascii (fp) : "./hrtfs/elev15/L15e180a.dat"
-[ 21, 37 ] = ascii (fp) : "./hrtfs/elev15/L15e175a.dat"
-[ 21, 38 ] = ascii (fp) : "./hrtfs/elev15/L15e170a.dat"
-[ 21, 39 ] = ascii (fp) : "./hrtfs/elev15/L15e165a.dat"
-[ 21, 40 ] = ascii (fp) : "./hrtfs/elev15/L15e160a.dat"
-[ 21, 41 ] = ascii (fp) : "./hrtfs/elev15/L15e155a.dat"
-[ 21, 42 ] = ascii (fp) : "./hrtfs/elev15/L15e150a.dat"
-[ 21, 43 ] = ascii (fp) : "./hrtfs/elev15/L15e145a.dat"
-[ 21, 44 ] = ascii (fp) : "./hrtfs/elev15/L15e140a.dat"
-[ 21, 45 ] = ascii (fp) : "./hrtfs/elev15/L15e135a.dat"
-[ 21, 46 ] = ascii (fp) : "./hrtfs/elev15/L15e130a.dat"
-[ 21, 47 ] = ascii (fp) : "./hrtfs/elev15/L15e125a.dat"
-[ 21, 48 ] = ascii (fp) : "./hrtfs/elev15/L15e120a.dat"
-[ 21, 49 ] = ascii (fp) : "./hrtfs/elev15/L15e115a.dat"
-[ 21, 50 ] = ascii (fp) : "./hrtfs/elev15/L15e110a.dat"
-[ 21, 51 ] = ascii (fp) : "./hrtfs/elev15/L15e105a.dat"
-[ 21, 52 ] = ascii (fp) : "./hrtfs/elev15/L15e100a.dat"
-[ 21, 53 ] = ascii (fp) : "./hrtfs/elev15/L15e095a.dat"
-[ 21, 54 ] = ascii (fp) : "./hrtfs/elev15/L15e090a.dat"
-[ 21, 55 ] = ascii (fp) : "./hrtfs/elev15/L15e085a.dat"
-[ 21, 56 ] = ascii (fp) : "./hrtfs/elev15/L15e080a.dat"
-[ 21, 57 ] = ascii (fp) : "./hrtfs/elev15/L15e075a.dat"
-[ 21, 58 ] = ascii (fp) : "./hrtfs/elev15/L15e070a.dat"
-[ 21, 59 ] = ascii (fp) : "./hrtfs/elev15/L15e065a.dat"
-[ 21, 60 ] = ascii (fp) : "./hrtfs/elev15/L15e060a.dat"
-[ 21, 61 ] = ascii (fp) : "./hrtfs/elev15/L15e055a.dat"
-[ 21, 62 ] = ascii (fp) : "./hrtfs/elev15/L15e050a.dat"
-[ 21, 63 ] = ascii (fp) : "./hrtfs/elev15/L15e045a.dat"
-[ 21, 64 ] = ascii (fp) : "./hrtfs/elev15/L15e040a.dat"
-[ 21, 65 ] = ascii (fp) : "./hrtfs/elev15/L15e035a.dat"
-[ 21, 66 ] = ascii (fp) : "./hrtfs/elev15/L15e030a.dat"
-[ 21, 67 ] = ascii (fp) : "./hrtfs/elev15/L15e025a.dat"
-[ 21, 68 ] = ascii (fp) : "./hrtfs/elev15/L15e020a.dat"
-[ 21, 69 ] = ascii (fp) : "./hrtfs/elev15/L15e015a.dat"
-[ 21, 70 ] = ascii (fp) : "./hrtfs/elev15/L15e010a.dat"
-[ 21, 71 ] = ascii (fp) : "./hrtfs/elev15/L15e005a.dat"
+[ 21, 0 ] = ascii (fp) : "./hrtfs/elev15/L15e000a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e000a.dat right
+[ 21, 1 ] = ascii (fp) : "./hrtfs/elev15/L15e355a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e355a.dat right
+[ 21, 2 ] = ascii (fp) : "./hrtfs/elev15/L15e350a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e350a.dat right
+[ 21, 3 ] = ascii (fp) : "./hrtfs/elev15/L15e345a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e345a.dat right
+[ 21, 4 ] = ascii (fp) : "./hrtfs/elev15/L15e340a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e340a.dat right
+[ 21, 5 ] = ascii (fp) : "./hrtfs/elev15/L15e335a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e335a.dat right
+[ 21, 6 ] = ascii (fp) : "./hrtfs/elev15/L15e330a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e330a.dat right
+[ 21, 7 ] = ascii (fp) : "./hrtfs/elev15/L15e325a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e325a.dat right
+[ 21, 8 ] = ascii (fp) : "./hrtfs/elev15/L15e320a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e320a.dat right
+[ 21, 9 ] = ascii (fp) : "./hrtfs/elev15/L15e315a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e315a.dat right
+[ 21, 10 ] = ascii (fp) : "./hrtfs/elev15/L15e310a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e310a.dat right
+[ 21, 11 ] = ascii (fp) : "./hrtfs/elev15/L15e305a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e305a.dat right
+[ 21, 12 ] = ascii (fp) : "./hrtfs/elev15/L15e300a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e300a.dat right
+[ 21, 13 ] = ascii (fp) : "./hrtfs/elev15/L15e295a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e295a.dat right
+[ 21, 14 ] = ascii (fp) : "./hrtfs/elev15/L15e290a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e290a.dat right
+[ 21, 15 ] = ascii (fp) : "./hrtfs/elev15/L15e285a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e285a.dat right
+[ 21, 16 ] = ascii (fp) : "./hrtfs/elev15/L15e280a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e280a.dat right
+[ 21, 17 ] = ascii (fp) : "./hrtfs/elev15/L15e275a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e275a.dat right
+[ 21, 18 ] = ascii (fp) : "./hrtfs/elev15/L15e270a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e270a.dat right
+[ 21, 19 ] = ascii (fp) : "./hrtfs/elev15/L15e265a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e265a.dat right
+[ 21, 20 ] = ascii (fp) : "./hrtfs/elev15/L15e260a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e260a.dat right
+[ 21, 21 ] = ascii (fp) : "./hrtfs/elev15/L15e255a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e255a.dat right
+[ 21, 22 ] = ascii (fp) : "./hrtfs/elev15/L15e250a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e250a.dat right
+[ 21, 23 ] = ascii (fp) : "./hrtfs/elev15/L15e245a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e245a.dat right
+[ 21, 24 ] = ascii (fp) : "./hrtfs/elev15/L15e240a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e240a.dat right
+[ 21, 25 ] = ascii (fp) : "./hrtfs/elev15/L15e235a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e235a.dat right
+[ 21, 26 ] = ascii (fp) : "./hrtfs/elev15/L15e230a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e230a.dat right
+[ 21, 27 ] = ascii (fp) : "./hrtfs/elev15/L15e225a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e225a.dat right
+[ 21, 28 ] = ascii (fp) : "./hrtfs/elev15/L15e220a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e220a.dat right
+[ 21, 29 ] = ascii (fp) : "./hrtfs/elev15/L15e215a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e215a.dat right
+[ 21, 30 ] = ascii (fp) : "./hrtfs/elev15/L15e210a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e210a.dat right
+[ 21, 31 ] = ascii (fp) : "./hrtfs/elev15/L15e205a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e205a.dat right
+[ 21, 32 ] = ascii (fp) : "./hrtfs/elev15/L15e200a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e200a.dat right
+[ 21, 33 ] = ascii (fp) : "./hrtfs/elev15/L15e195a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e195a.dat right
+[ 21, 34 ] = ascii (fp) : "./hrtfs/elev15/L15e190a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e190a.dat right
+[ 21, 35 ] = ascii (fp) : "./hrtfs/elev15/L15e185a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e185a.dat right
+[ 21, 36 ] = ascii (fp) : "./hrtfs/elev15/L15e180a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e180a.dat right
+[ 21, 37 ] = ascii (fp) : "./hrtfs/elev15/L15e175a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e175a.dat right
+[ 21, 38 ] = ascii (fp) : "./hrtfs/elev15/L15e170a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e170a.dat right
+[ 21, 39 ] = ascii (fp) : "./hrtfs/elev15/L15e165a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e165a.dat right
+[ 21, 40 ] = ascii (fp) : "./hrtfs/elev15/L15e160a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e160a.dat right
+[ 21, 41 ] = ascii (fp) : "./hrtfs/elev15/L15e155a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e155a.dat right
+[ 21, 42 ] = ascii (fp) : "./hrtfs/elev15/L15e150a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e150a.dat right
+[ 21, 43 ] = ascii (fp) : "./hrtfs/elev15/L15e145a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e145a.dat right
+[ 21, 44 ] = ascii (fp) : "./hrtfs/elev15/L15e140a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e140a.dat right
+[ 21, 45 ] = ascii (fp) : "./hrtfs/elev15/L15e135a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e135a.dat right
+[ 21, 46 ] = ascii (fp) : "./hrtfs/elev15/L15e130a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e130a.dat right
+[ 21, 47 ] = ascii (fp) : "./hrtfs/elev15/L15e125a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e125a.dat right
+[ 21, 48 ] = ascii (fp) : "./hrtfs/elev15/L15e120a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e120a.dat right
+[ 21, 49 ] = ascii (fp) : "./hrtfs/elev15/L15e115a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e115a.dat right
+[ 21, 50 ] = ascii (fp) : "./hrtfs/elev15/L15e110a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e110a.dat right
+[ 21, 51 ] = ascii (fp) : "./hrtfs/elev15/L15e105a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e105a.dat right
+[ 21, 52 ] = ascii (fp) : "./hrtfs/elev15/L15e100a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e100a.dat right
+[ 21, 53 ] = ascii (fp) : "./hrtfs/elev15/L15e095a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e095a.dat right
+[ 21, 54 ] = ascii (fp) : "./hrtfs/elev15/L15e090a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e090a.dat right
+[ 21, 55 ] = ascii (fp) : "./hrtfs/elev15/L15e085a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e085a.dat right
+[ 21, 56 ] = ascii (fp) : "./hrtfs/elev15/L15e080a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e080a.dat right
+[ 21, 57 ] = ascii (fp) : "./hrtfs/elev15/L15e075a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e075a.dat right
+[ 21, 58 ] = ascii (fp) : "./hrtfs/elev15/L15e070a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e070a.dat right
+[ 21, 59 ] = ascii (fp) : "./hrtfs/elev15/L15e065a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e065a.dat right
+[ 21, 60 ] = ascii (fp) : "./hrtfs/elev15/L15e060a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e060a.dat right
+[ 21, 61 ] = ascii (fp) : "./hrtfs/elev15/L15e055a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e055a.dat right
+[ 21, 62 ] = ascii (fp) : "./hrtfs/elev15/L15e050a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e050a.dat right
+[ 21, 63 ] = ascii (fp) : "./hrtfs/elev15/L15e045a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e045a.dat right
+[ 21, 64 ] = ascii (fp) : "./hrtfs/elev15/L15e040a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e040a.dat right
+[ 21, 65 ] = ascii (fp) : "./hrtfs/elev15/L15e035a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e035a.dat right
+[ 21, 66 ] = ascii (fp) : "./hrtfs/elev15/L15e030a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e030a.dat right
+[ 21, 67 ] = ascii (fp) : "./hrtfs/elev15/L15e025a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e025a.dat right
+[ 21, 68 ] = ascii (fp) : "./hrtfs/elev15/L15e020a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e020a.dat right
+[ 21, 69 ] = ascii (fp) : "./hrtfs/elev15/L15e015a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e015a.dat right
+[ 21, 70 ] = ascii (fp) : "./hrtfs/elev15/L15e010a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e010a.dat right
+[ 21, 71 ] = ascii (fp) : "./hrtfs/elev15/L15e005a.dat left
+ + ascii (fp) : "./hrtfs/elev15/R15e005a.dat right
-[ 22, 0 ] = ascii (fp) : "./hrtfs/elev20/L20e000a.dat"
-[ 22, 1 ] = ascii (fp) : "./hrtfs/elev20/L20e355a.dat"
-[ 22, 2 ] = ascii (fp) : "./hrtfs/elev20/L20e350a.dat"
-[ 22, 3 ] = ascii (fp) : "./hrtfs/elev20/L20e345a.dat"
-[ 22, 4 ] = ascii (fp) : "./hrtfs/elev20/L20e340a.dat"
-[ 22, 5 ] = ascii (fp) : "./hrtfs/elev20/L20e335a.dat"
-[ 22, 6 ] = ascii (fp) : "./hrtfs/elev20/L20e330a.dat"
-[ 22, 7 ] = ascii (fp) : "./hrtfs/elev20/L20e325a.dat"
-[ 22, 8 ] = ascii (fp) : "./hrtfs/elev20/L20e320a.dat"
-[ 22, 9 ] = ascii (fp) : "./hrtfs/elev20/L20e315a.dat"
-[ 22, 10 ] = ascii (fp) : "./hrtfs/elev20/L20e310a.dat"
-[ 22, 11 ] = ascii (fp) : "./hrtfs/elev20/L20e305a.dat"
-[ 22, 12 ] = ascii (fp) : "./hrtfs/elev20/L20e300a.dat"
-[ 22, 13 ] = ascii (fp) : "./hrtfs/elev20/L20e295a.dat"
-[ 22, 14 ] = ascii (fp) : "./hrtfs/elev20/L20e290a.dat"
-[ 22, 15 ] = ascii (fp) : "./hrtfs/elev20/L20e285a.dat"
-[ 22, 16 ] = ascii (fp) : "./hrtfs/elev20/L20e280a.dat"
-[ 22, 17 ] = ascii (fp) : "./hrtfs/elev20/L20e275a.dat"
-[ 22, 18 ] = ascii (fp) : "./hrtfs/elev20/L20e270a.dat"
-[ 22, 19 ] = ascii (fp) : "./hrtfs/elev20/L20e265a.dat"
-[ 22, 20 ] = ascii (fp) : "./hrtfs/elev20/L20e260a.dat"
-[ 22, 21 ] = ascii (fp) : "./hrtfs/elev20/L20e255a.dat"
-[ 22, 22 ] = ascii (fp) : "./hrtfs/elev20/L20e250a.dat"
-[ 22, 23 ] = ascii (fp) : "./hrtfs/elev20/L20e245a.dat"
-[ 22, 24 ] = ascii (fp) : "./hrtfs/elev20/L20e240a.dat"
-[ 22, 25 ] = ascii (fp) : "./hrtfs/elev20/L20e235a.dat"
-[ 22, 26 ] = ascii (fp) : "./hrtfs/elev20/L20e230a.dat"
-[ 22, 27 ] = ascii (fp) : "./hrtfs/elev20/L20e225a.dat"
-[ 22, 28 ] = ascii (fp) : "./hrtfs/elev20/L20e220a.dat"
-[ 22, 29 ] = ascii (fp) : "./hrtfs/elev20/L20e215a.dat"
-[ 22, 30 ] = ascii (fp) : "./hrtfs/elev20/L20e210a.dat"
-[ 22, 31 ] = ascii (fp) : "./hrtfs/elev20/L20e205a.dat"
-[ 22, 32 ] = ascii (fp) : "./hrtfs/elev20/L20e200a.dat"
-[ 22, 33 ] = ascii (fp) : "./hrtfs/elev20/L20e195a.dat"
-[ 22, 34 ] = ascii (fp) : "./hrtfs/elev20/L20e190a.dat"
-[ 22, 35 ] = ascii (fp) : "./hrtfs/elev20/L20e185a.dat"
-[ 22, 36 ] = ascii (fp) : "./hrtfs/elev20/L20e180a.dat"
-[ 22, 37 ] = ascii (fp) : "./hrtfs/elev20/L20e175a.dat"
-[ 22, 38 ] = ascii (fp) : "./hrtfs/elev20/L20e170a.dat"
-[ 22, 39 ] = ascii (fp) : "./hrtfs/elev20/L20e165a.dat"
-[ 22, 40 ] = ascii (fp) : "./hrtfs/elev20/L20e160a.dat"
-[ 22, 41 ] = ascii (fp) : "./hrtfs/elev20/L20e155a.dat"
-[ 22, 42 ] = ascii (fp) : "./hrtfs/elev20/L20e150a.dat"
-[ 22, 43 ] = ascii (fp) : "./hrtfs/elev20/L20e145a.dat"
-[ 22, 44 ] = ascii (fp) : "./hrtfs/elev20/L20e140a.dat"
-[ 22, 45 ] = ascii (fp) : "./hrtfs/elev20/L20e135a.dat"
-[ 22, 46 ] = ascii (fp) : "./hrtfs/elev20/L20e130a.dat"
-[ 22, 47 ] = ascii (fp) : "./hrtfs/elev20/L20e125a.dat"
-[ 22, 48 ] = ascii (fp) : "./hrtfs/elev20/L20e120a.dat"
-[ 22, 49 ] = ascii (fp) : "./hrtfs/elev20/L20e115a.dat"
-[ 22, 50 ] = ascii (fp) : "./hrtfs/elev20/L20e110a.dat"
-[ 22, 51 ] = ascii (fp) : "./hrtfs/elev20/L20e105a.dat"
-[ 22, 52 ] = ascii (fp) : "./hrtfs/elev20/L20e100a.dat"
-[ 22, 53 ] = ascii (fp) : "./hrtfs/elev20/L20e095a.dat"
-[ 22, 54 ] = ascii (fp) : "./hrtfs/elev20/L20e090a.dat"
-[ 22, 55 ] = ascii (fp) : "./hrtfs/elev20/L20e085a.dat"
-[ 22, 56 ] = ascii (fp) : "./hrtfs/elev20/L20e080a.dat"
-[ 22, 57 ] = ascii (fp) : "./hrtfs/elev20/L20e075a.dat"
-[ 22, 58 ] = ascii (fp) : "./hrtfs/elev20/L20e070a.dat"
-[ 22, 59 ] = ascii (fp) : "./hrtfs/elev20/L20e065a.dat"
-[ 22, 60 ] = ascii (fp) : "./hrtfs/elev20/L20e060a.dat"
-[ 22, 61 ] = ascii (fp) : "./hrtfs/elev20/L20e055a.dat"
-[ 22, 62 ] = ascii (fp) : "./hrtfs/elev20/L20e050a.dat"
-[ 22, 63 ] = ascii (fp) : "./hrtfs/elev20/L20e045a.dat"
-[ 22, 64 ] = ascii (fp) : "./hrtfs/elev20/L20e040a.dat"
-[ 22, 65 ] = ascii (fp) : "./hrtfs/elev20/L20e035a.dat"
-[ 22, 66 ] = ascii (fp) : "./hrtfs/elev20/L20e030a.dat"
-[ 22, 67 ] = ascii (fp) : "./hrtfs/elev20/L20e025a.dat"
-[ 22, 68 ] = ascii (fp) : "./hrtfs/elev20/L20e020a.dat"
-[ 22, 69 ] = ascii (fp) : "./hrtfs/elev20/L20e015a.dat"
-[ 22, 70 ] = ascii (fp) : "./hrtfs/elev20/L20e010a.dat"
-[ 22, 71 ] = ascii (fp) : "./hrtfs/elev20/L20e005a.dat"
+[ 22, 0 ] = ascii (fp) : "./hrtfs/elev20/L20e000a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e000a.dat right
+[ 22, 1 ] = ascii (fp) : "./hrtfs/elev20/L20e355a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e355a.dat right
+[ 22, 2 ] = ascii (fp) : "./hrtfs/elev20/L20e350a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e350a.dat right
+[ 22, 3 ] = ascii (fp) : "./hrtfs/elev20/L20e345a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e345a.dat right
+[ 22, 4 ] = ascii (fp) : "./hrtfs/elev20/L20e340a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e340a.dat right
+[ 22, 5 ] = ascii (fp) : "./hrtfs/elev20/L20e335a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e335a.dat right
+[ 22, 6 ] = ascii (fp) : "./hrtfs/elev20/L20e330a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e330a.dat right
+[ 22, 7 ] = ascii (fp) : "./hrtfs/elev20/L20e325a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e325a.dat right
+[ 22, 8 ] = ascii (fp) : "./hrtfs/elev20/L20e320a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e320a.dat right
+[ 22, 9 ] = ascii (fp) : "./hrtfs/elev20/L20e315a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e315a.dat right
+[ 22, 10 ] = ascii (fp) : "./hrtfs/elev20/L20e310a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e310a.dat right
+[ 22, 11 ] = ascii (fp) : "./hrtfs/elev20/L20e305a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e305a.dat right
+[ 22, 12 ] = ascii (fp) : "./hrtfs/elev20/L20e300a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e300a.dat right
+[ 22, 13 ] = ascii (fp) : "./hrtfs/elev20/L20e295a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e295a.dat right
+[ 22, 14 ] = ascii (fp) : "./hrtfs/elev20/L20e290a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e290a.dat right
+[ 22, 15 ] = ascii (fp) : "./hrtfs/elev20/L20e285a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e285a.dat right
+[ 22, 16 ] = ascii (fp) : "./hrtfs/elev20/L20e280a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e280a.dat right
+[ 22, 17 ] = ascii (fp) : "./hrtfs/elev20/L20e275a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e275a.dat right
+[ 22, 18 ] = ascii (fp) : "./hrtfs/elev20/L20e270a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e270a.dat right
+[ 22, 19 ] = ascii (fp) : "./hrtfs/elev20/L20e265a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e265a.dat right
+[ 22, 20 ] = ascii (fp) : "./hrtfs/elev20/L20e260a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e260a.dat right
+[ 22, 21 ] = ascii (fp) : "./hrtfs/elev20/L20e255a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e255a.dat right
+[ 22, 22 ] = ascii (fp) : "./hrtfs/elev20/L20e250a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e250a.dat right
+[ 22, 23 ] = ascii (fp) : "./hrtfs/elev20/L20e245a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e245a.dat right
+[ 22, 24 ] = ascii (fp) : "./hrtfs/elev20/L20e240a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e240a.dat right
+[ 22, 25 ] = ascii (fp) : "./hrtfs/elev20/L20e235a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e235a.dat right
+[ 22, 26 ] = ascii (fp) : "./hrtfs/elev20/L20e230a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e230a.dat right
+[ 22, 27 ] = ascii (fp) : "./hrtfs/elev20/L20e225a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e225a.dat right
+[ 22, 28 ] = ascii (fp) : "./hrtfs/elev20/L20e220a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e220a.dat right
+[ 22, 29 ] = ascii (fp) : "./hrtfs/elev20/L20e215a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e215a.dat right
+[ 22, 30 ] = ascii (fp) : "./hrtfs/elev20/L20e210a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e210a.dat right
+[ 22, 31 ] = ascii (fp) : "./hrtfs/elev20/L20e205a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e205a.dat right
+[ 22, 32 ] = ascii (fp) : "./hrtfs/elev20/L20e200a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e200a.dat right
+[ 22, 33 ] = ascii (fp) : "./hrtfs/elev20/L20e195a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e195a.dat right
+[ 22, 34 ] = ascii (fp) : "./hrtfs/elev20/L20e190a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e190a.dat right
+[ 22, 35 ] = ascii (fp) : "./hrtfs/elev20/L20e185a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e185a.dat right
+[ 22, 36 ] = ascii (fp) : "./hrtfs/elev20/L20e180a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e180a.dat right
+[ 22, 37 ] = ascii (fp) : "./hrtfs/elev20/L20e175a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e175a.dat right
+[ 22, 38 ] = ascii (fp) : "./hrtfs/elev20/L20e170a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e170a.dat right
+[ 22, 39 ] = ascii (fp) : "./hrtfs/elev20/L20e165a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e165a.dat right
+[ 22, 40 ] = ascii (fp) : "./hrtfs/elev20/L20e160a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e160a.dat right
+[ 22, 41 ] = ascii (fp) : "./hrtfs/elev20/L20e155a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e155a.dat right
+[ 22, 42 ] = ascii (fp) : "./hrtfs/elev20/L20e150a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e150a.dat right
+[ 22, 43 ] = ascii (fp) : "./hrtfs/elev20/L20e145a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e145a.dat right
+[ 22, 44 ] = ascii (fp) : "./hrtfs/elev20/L20e140a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e140a.dat right
+[ 22, 45 ] = ascii (fp) : "./hrtfs/elev20/L20e135a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e135a.dat right
+[ 22, 46 ] = ascii (fp) : "./hrtfs/elev20/L20e130a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e130a.dat right
+[ 22, 47 ] = ascii (fp) : "./hrtfs/elev20/L20e125a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e125a.dat right
+[ 22, 48 ] = ascii (fp) : "./hrtfs/elev20/L20e120a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e120a.dat right
+[ 22, 49 ] = ascii (fp) : "./hrtfs/elev20/L20e115a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e115a.dat right
+[ 22, 50 ] = ascii (fp) : "./hrtfs/elev20/L20e110a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e110a.dat right
+[ 22, 51 ] = ascii (fp) : "./hrtfs/elev20/L20e105a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e105a.dat right
+[ 22, 52 ] = ascii (fp) : "./hrtfs/elev20/L20e100a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e100a.dat right
+[ 22, 53 ] = ascii (fp) : "./hrtfs/elev20/L20e095a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e095a.dat right
+[ 22, 54 ] = ascii (fp) : "./hrtfs/elev20/L20e090a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e090a.dat right
+[ 22, 55 ] = ascii (fp) : "./hrtfs/elev20/L20e085a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e085a.dat right
+[ 22, 56 ] = ascii (fp) : "./hrtfs/elev20/L20e080a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e080a.dat right
+[ 22, 57 ] = ascii (fp) : "./hrtfs/elev20/L20e075a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e075a.dat right
+[ 22, 58 ] = ascii (fp) : "./hrtfs/elev20/L20e070a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e070a.dat right
+[ 22, 59 ] = ascii (fp) : "./hrtfs/elev20/L20e065a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e065a.dat right
+[ 22, 60 ] = ascii (fp) : "./hrtfs/elev20/L20e060a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e060a.dat right
+[ 22, 61 ] = ascii (fp) : "./hrtfs/elev20/L20e055a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e055a.dat right
+[ 22, 62 ] = ascii (fp) : "./hrtfs/elev20/L20e050a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e050a.dat right
+[ 22, 63 ] = ascii (fp) : "./hrtfs/elev20/L20e045a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e045a.dat right
+[ 22, 64 ] = ascii (fp) : "./hrtfs/elev20/L20e040a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e040a.dat right
+[ 22, 65 ] = ascii (fp) : "./hrtfs/elev20/L20e035a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e035a.dat right
+[ 22, 66 ] = ascii (fp) : "./hrtfs/elev20/L20e030a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e030a.dat right
+[ 22, 67 ] = ascii (fp) : "./hrtfs/elev20/L20e025a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e025a.dat right
+[ 22, 68 ] = ascii (fp) : "./hrtfs/elev20/L20e020a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e020a.dat right
+[ 22, 69 ] = ascii (fp) : "./hrtfs/elev20/L20e015a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e015a.dat right
+[ 22, 70 ] = ascii (fp) : "./hrtfs/elev20/L20e010a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e010a.dat right
+[ 22, 71 ] = ascii (fp) : "./hrtfs/elev20/L20e005a.dat left
+ + ascii (fp) : "./hrtfs/elev20/R20e005a.dat right
-[ 23, 0 ] = ascii (fp) : "./hrtfs/elev25/L25e000a.dat"
-[ 23, 1 ] = ascii (fp) : "./hrtfs/elev25/L25e355a.dat"
-[ 23, 2 ] = ascii (fp) : "./hrtfs/elev25/L25e350a.dat"
-[ 23, 3 ] = ascii (fp) : "./hrtfs/elev25/L25e345a.dat"
-[ 23, 4 ] = ascii (fp) : "./hrtfs/elev25/L25e340a.dat"
-[ 23, 5 ] = ascii (fp) : "./hrtfs/elev25/L25e335a.dat"
-[ 23, 6 ] = ascii (fp) : "./hrtfs/elev25/L25e330a.dat"
-[ 23, 7 ] = ascii (fp) : "./hrtfs/elev25/L25e325a.dat"
-[ 23, 8 ] = ascii (fp) : "./hrtfs/elev25/L25e320a.dat"
-[ 23, 9 ] = ascii (fp) : "./hrtfs/elev25/L25e315a.dat"
-[ 23, 10 ] = ascii (fp) : "./hrtfs/elev25/L25e310a.dat"
-[ 23, 11 ] = ascii (fp) : "./hrtfs/elev25/L25e305a.dat"
-[ 23, 12 ] = ascii (fp) : "./hrtfs/elev25/L25e300a.dat"
-[ 23, 13 ] = ascii (fp) : "./hrtfs/elev25/L25e295a.dat"
-[ 23, 14 ] = ascii (fp) : "./hrtfs/elev25/L25e290a.dat"
-[ 23, 15 ] = ascii (fp) : "./hrtfs/elev25/L25e285a.dat"
-[ 23, 16 ] = ascii (fp) : "./hrtfs/elev25/L25e280a.dat"
-[ 23, 17 ] = ascii (fp) : "./hrtfs/elev25/L25e275a.dat"
-[ 23, 18 ] = ascii (fp) : "./hrtfs/elev25/L25e270a.dat"
-[ 23, 19 ] = ascii (fp) : "./hrtfs/elev25/L25e265a.dat"
-[ 23, 20 ] = ascii (fp) : "./hrtfs/elev25/L25e260a.dat"
-[ 23, 21 ] = ascii (fp) : "./hrtfs/elev25/L25e255a.dat"
-[ 23, 22 ] = ascii (fp) : "./hrtfs/elev25/L25e250a.dat"
-[ 23, 23 ] = ascii (fp) : "./hrtfs/elev25/L25e245a.dat"
-[ 23, 24 ] = ascii (fp) : "./hrtfs/elev25/L25e240a.dat"
-[ 23, 25 ] = ascii (fp) : "./hrtfs/elev25/L25e235a.dat"
-[ 23, 26 ] = ascii (fp) : "./hrtfs/elev25/L25e230a.dat"
-[ 23, 27 ] = ascii (fp) : "./hrtfs/elev25/L25e225a.dat"
-[ 23, 28 ] = ascii (fp) : "./hrtfs/elev25/L25e220a.dat"
-[ 23, 29 ] = ascii (fp) : "./hrtfs/elev25/L25e215a.dat"
-[ 23, 30 ] = ascii (fp) : "./hrtfs/elev25/L25e210a.dat"
-[ 23, 31 ] = ascii (fp) : "./hrtfs/elev25/L25e205a.dat"
-[ 23, 32 ] = ascii (fp) : "./hrtfs/elev25/L25e200a.dat"
-[ 23, 33 ] = ascii (fp) : "./hrtfs/elev25/L25e195a.dat"
-[ 23, 34 ] = ascii (fp) : "./hrtfs/elev25/L25e190a.dat"
-[ 23, 35 ] = ascii (fp) : "./hrtfs/elev25/L25e185a.dat"
-[ 23, 36 ] = ascii (fp) : "./hrtfs/elev25/L25e180a.dat"
-[ 23, 37 ] = ascii (fp) : "./hrtfs/elev25/L25e175a.dat"
-[ 23, 38 ] = ascii (fp) : "./hrtfs/elev25/L25e170a.dat"
-[ 23, 39 ] = ascii (fp) : "./hrtfs/elev25/L25e165a.dat"
-[ 23, 40 ] = ascii (fp) : "./hrtfs/elev25/L25e160a.dat"
-[ 23, 41 ] = ascii (fp) : "./hrtfs/elev25/L25e155a.dat"
-[ 23, 42 ] = ascii (fp) : "./hrtfs/elev25/L25e150a.dat"
-[ 23, 43 ] = ascii (fp) : "./hrtfs/elev25/L25e145a.dat"
-[ 23, 44 ] = ascii (fp) : "./hrtfs/elev25/L25e140a.dat"
-[ 23, 45 ] = ascii (fp) : "./hrtfs/elev25/L25e135a.dat"
-[ 23, 46 ] = ascii (fp) : "./hrtfs/elev25/L25e130a.dat"
-[ 23, 47 ] = ascii (fp) : "./hrtfs/elev25/L25e125a.dat"
-[ 23, 48 ] = ascii (fp) : "./hrtfs/elev25/L25e120a.dat"
-[ 23, 49 ] = ascii (fp) : "./hrtfs/elev25/L25e115a.dat"
-[ 23, 50 ] = ascii (fp) : "./hrtfs/elev25/L25e110a.dat"
-[ 23, 51 ] = ascii (fp) : "./hrtfs/elev25/L25e105a.dat"
-[ 23, 52 ] = ascii (fp) : "./hrtfs/elev25/L25e100a.dat"
-[ 23, 53 ] = ascii (fp) : "./hrtfs/elev25/L25e095a.dat"
-[ 23, 54 ] = ascii (fp) : "./hrtfs/elev25/L25e090a.dat"
-[ 23, 55 ] = ascii (fp) : "./hrtfs/elev25/L25e085a.dat"
-[ 23, 56 ] = ascii (fp) : "./hrtfs/elev25/L25e080a.dat"
-[ 23, 57 ] = ascii (fp) : "./hrtfs/elev25/L25e075a.dat"
-[ 23, 58 ] = ascii (fp) : "./hrtfs/elev25/L25e070a.dat"
-[ 23, 59 ] = ascii (fp) : "./hrtfs/elev25/L25e065a.dat"
-[ 23, 60 ] = ascii (fp) : "./hrtfs/elev25/L25e060a.dat"
-[ 23, 61 ] = ascii (fp) : "./hrtfs/elev25/L25e055a.dat"
-[ 23, 62 ] = ascii (fp) : "./hrtfs/elev25/L25e050a.dat"
-[ 23, 63 ] = ascii (fp) : "./hrtfs/elev25/L25e045a.dat"
-[ 23, 64 ] = ascii (fp) : "./hrtfs/elev25/L25e040a.dat"
-[ 23, 65 ] = ascii (fp) : "./hrtfs/elev25/L25e035a.dat"
-[ 23, 66 ] = ascii (fp) : "./hrtfs/elev25/L25e030a.dat"
-[ 23, 67 ] = ascii (fp) : "./hrtfs/elev25/L25e025a.dat"
-[ 23, 68 ] = ascii (fp) : "./hrtfs/elev25/L25e020a.dat"
-[ 23, 69 ] = ascii (fp) : "./hrtfs/elev25/L25e015a.dat"
-[ 23, 70 ] = ascii (fp) : "./hrtfs/elev25/L25e010a.dat"
-[ 23, 71 ] = ascii (fp) : "./hrtfs/elev25/L25e005a.dat"
+[ 23, 0 ] = ascii (fp) : "./hrtfs/elev25/L25e000a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e000a.dat right
+[ 23, 1 ] = ascii (fp) : "./hrtfs/elev25/L25e355a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e355a.dat right
+[ 23, 2 ] = ascii (fp) : "./hrtfs/elev25/L25e350a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e350a.dat right
+[ 23, 3 ] = ascii (fp) : "./hrtfs/elev25/L25e345a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e345a.dat right
+[ 23, 4 ] = ascii (fp) : "./hrtfs/elev25/L25e340a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e340a.dat right
+[ 23, 5 ] = ascii (fp) : "./hrtfs/elev25/L25e335a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e335a.dat right
+[ 23, 6 ] = ascii (fp) : "./hrtfs/elev25/L25e330a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e330a.dat right
+[ 23, 7 ] = ascii (fp) : "./hrtfs/elev25/L25e325a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e325a.dat right
+[ 23, 8 ] = ascii (fp) : "./hrtfs/elev25/L25e320a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e320a.dat right
+[ 23, 9 ] = ascii (fp) : "./hrtfs/elev25/L25e315a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e315a.dat right
+[ 23, 10 ] = ascii (fp) : "./hrtfs/elev25/L25e310a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e310a.dat right
+[ 23, 11 ] = ascii (fp) : "./hrtfs/elev25/L25e305a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e305a.dat right
+[ 23, 12 ] = ascii (fp) : "./hrtfs/elev25/L25e300a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e300a.dat right
+[ 23, 13 ] = ascii (fp) : "./hrtfs/elev25/L25e295a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e295a.dat right
+[ 23, 14 ] = ascii (fp) : "./hrtfs/elev25/L25e290a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e290a.dat right
+[ 23, 15 ] = ascii (fp) : "./hrtfs/elev25/L25e285a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e285a.dat right
+[ 23, 16 ] = ascii (fp) : "./hrtfs/elev25/L25e280a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e280a.dat right
+[ 23, 17 ] = ascii (fp) : "./hrtfs/elev25/L25e275a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e275a.dat right
+[ 23, 18 ] = ascii (fp) : "./hrtfs/elev25/L25e270a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e270a.dat right
+[ 23, 19 ] = ascii (fp) : "./hrtfs/elev25/L25e265a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e265a.dat right
+[ 23, 20 ] = ascii (fp) : "./hrtfs/elev25/L25e260a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e260a.dat right
+[ 23, 21 ] = ascii (fp) : "./hrtfs/elev25/L25e255a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e255a.dat right
+[ 23, 22 ] = ascii (fp) : "./hrtfs/elev25/L25e250a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e250a.dat right
+[ 23, 23 ] = ascii (fp) : "./hrtfs/elev25/L25e245a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e245a.dat right
+[ 23, 24 ] = ascii (fp) : "./hrtfs/elev25/L25e240a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e240a.dat right
+[ 23, 25 ] = ascii (fp) : "./hrtfs/elev25/L25e235a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e235a.dat right
+[ 23, 26 ] = ascii (fp) : "./hrtfs/elev25/L25e230a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e230a.dat right
+[ 23, 27 ] = ascii (fp) : "./hrtfs/elev25/L25e225a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e225a.dat right
+[ 23, 28 ] = ascii (fp) : "./hrtfs/elev25/L25e220a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e220a.dat right
+[ 23, 29 ] = ascii (fp) : "./hrtfs/elev25/L25e215a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e215a.dat right
+[ 23, 30 ] = ascii (fp) : "./hrtfs/elev25/L25e210a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e210a.dat right
+[ 23, 31 ] = ascii (fp) : "./hrtfs/elev25/L25e205a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e205a.dat right
+[ 23, 32 ] = ascii (fp) : "./hrtfs/elev25/L25e200a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e200a.dat right
+[ 23, 33 ] = ascii (fp) : "./hrtfs/elev25/L25e195a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e195a.dat right
+[ 23, 34 ] = ascii (fp) : "./hrtfs/elev25/L25e190a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e190a.dat right
+[ 23, 35 ] = ascii (fp) : "./hrtfs/elev25/L25e185a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e185a.dat right
+[ 23, 36 ] = ascii (fp) : "./hrtfs/elev25/L25e180a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e180a.dat right
+[ 23, 37 ] = ascii (fp) : "./hrtfs/elev25/L25e175a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e175a.dat right
+[ 23, 38 ] = ascii (fp) : "./hrtfs/elev25/L25e170a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e170a.dat right
+[ 23, 39 ] = ascii (fp) : "./hrtfs/elev25/L25e165a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e165a.dat right
+[ 23, 40 ] = ascii (fp) : "./hrtfs/elev25/L25e160a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e160a.dat right
+[ 23, 41 ] = ascii (fp) : "./hrtfs/elev25/L25e155a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e155a.dat right
+[ 23, 42 ] = ascii (fp) : "./hrtfs/elev25/L25e150a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e150a.dat right
+[ 23, 43 ] = ascii (fp) : "./hrtfs/elev25/L25e145a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e145a.dat right
+[ 23, 44 ] = ascii (fp) : "./hrtfs/elev25/L25e140a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e140a.dat right
+[ 23, 45 ] = ascii (fp) : "./hrtfs/elev25/L25e135a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e135a.dat right
+[ 23, 46 ] = ascii (fp) : "./hrtfs/elev25/L25e130a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e130a.dat right
+[ 23, 47 ] = ascii (fp) : "./hrtfs/elev25/L25e125a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e125a.dat right
+[ 23, 48 ] = ascii (fp) : "./hrtfs/elev25/L25e120a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e120a.dat right
+[ 23, 49 ] = ascii (fp) : "./hrtfs/elev25/L25e115a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e115a.dat right
+[ 23, 50 ] = ascii (fp) : "./hrtfs/elev25/L25e110a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e110a.dat right
+[ 23, 51 ] = ascii (fp) : "./hrtfs/elev25/L25e105a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e105a.dat right
+[ 23, 52 ] = ascii (fp) : "./hrtfs/elev25/L25e100a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e100a.dat right
+[ 23, 53 ] = ascii (fp) : "./hrtfs/elev25/L25e095a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e095a.dat right
+[ 23, 54 ] = ascii (fp) : "./hrtfs/elev25/L25e090a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e090a.dat right
+[ 23, 55 ] = ascii (fp) : "./hrtfs/elev25/L25e085a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e085a.dat right
+[ 23, 56 ] = ascii (fp) : "./hrtfs/elev25/L25e080a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e080a.dat right
+[ 23, 57 ] = ascii (fp) : "./hrtfs/elev25/L25e075a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e075a.dat right
+[ 23, 58 ] = ascii (fp) : "./hrtfs/elev25/L25e070a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e070a.dat right
+[ 23, 59 ] = ascii (fp) : "./hrtfs/elev25/L25e065a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e065a.dat right
+[ 23, 60 ] = ascii (fp) : "./hrtfs/elev25/L25e060a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e060a.dat right
+[ 23, 61 ] = ascii (fp) : "./hrtfs/elev25/L25e055a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e055a.dat right
+[ 23, 62 ] = ascii (fp) : "./hrtfs/elev25/L25e050a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e050a.dat right
+[ 23, 63 ] = ascii (fp) : "./hrtfs/elev25/L25e045a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e045a.dat right
+[ 23, 64 ] = ascii (fp) : "./hrtfs/elev25/L25e040a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e040a.dat right
+[ 23, 65 ] = ascii (fp) : "./hrtfs/elev25/L25e035a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e035a.dat right
+[ 23, 66 ] = ascii (fp) : "./hrtfs/elev25/L25e030a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e030a.dat right
+[ 23, 67 ] = ascii (fp) : "./hrtfs/elev25/L25e025a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e025a.dat right
+[ 23, 68 ] = ascii (fp) : "./hrtfs/elev25/L25e020a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e020a.dat right
+[ 23, 69 ] = ascii (fp) : "./hrtfs/elev25/L25e015a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e015a.dat right
+[ 23, 70 ] = ascii (fp) : "./hrtfs/elev25/L25e010a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e010a.dat right
+[ 23, 71 ] = ascii (fp) : "./hrtfs/elev25/L25e005a.dat left
+ + ascii (fp) : "./hrtfs/elev25/R25e005a.dat right
-[ 24, 0 ] = ascii (fp) : "./hrtfs/elev30/L30e000a.dat"
-[ 24, 1 ] = ascii (fp) : "./hrtfs/elev30/L30e355a.dat"
-[ 24, 2 ] = ascii (fp) : "./hrtfs/elev30/L30e350a.dat"
-[ 24, 3 ] = ascii (fp) : "./hrtfs/elev30/L30e345a.dat"
-[ 24, 4 ] = ascii (fp) : "./hrtfs/elev30/L30e340a.dat"
-[ 24, 5 ] = ascii (fp) : "./hrtfs/elev30/L30e335a.dat"
-[ 24, 6 ] = ascii (fp) : "./hrtfs/elev30/L30e330a.dat"
-[ 24, 7 ] = ascii (fp) : "./hrtfs/elev30/L30e325a.dat"
-[ 24, 8 ] = ascii (fp) : "./hrtfs/elev30/L30e320a.dat"
-[ 24, 9 ] = ascii (fp) : "./hrtfs/elev30/L30e315a.dat"
-[ 24, 10 ] = ascii (fp) : "./hrtfs/elev30/L30e310a.dat"
-[ 24, 11 ] = ascii (fp) : "./hrtfs/elev30/L30e305a.dat"
-[ 24, 12 ] = ascii (fp) : "./hrtfs/elev30/L30e300a.dat"
-[ 24, 13 ] = ascii (fp) : "./hrtfs/elev30/L30e295a.dat"
-[ 24, 14 ] = ascii (fp) : "./hrtfs/elev30/L30e290a.dat"
-[ 24, 15 ] = ascii (fp) : "./hrtfs/elev30/L30e285a.dat"
-[ 24, 16 ] = ascii (fp) : "./hrtfs/elev30/L30e280a.dat"
-[ 24, 17 ] = ascii (fp) : "./hrtfs/elev30/L30e275a.dat"
-[ 24, 18 ] = ascii (fp) : "./hrtfs/elev30/L30e270a.dat"
-[ 24, 19 ] = ascii (fp) : "./hrtfs/elev30/L30e265a.dat"
-[ 24, 20 ] = ascii (fp) : "./hrtfs/elev30/L30e260a.dat"
-[ 24, 21 ] = ascii (fp) : "./hrtfs/elev30/L30e255a.dat"
-[ 24, 22 ] = ascii (fp) : "./hrtfs/elev30/L30e250a.dat"
-[ 24, 23 ] = ascii (fp) : "./hrtfs/elev30/L30e245a.dat"
-[ 24, 24 ] = ascii (fp) : "./hrtfs/elev30/L30e240a.dat"
-[ 24, 25 ] = ascii (fp) : "./hrtfs/elev30/L30e235a.dat"
-[ 24, 26 ] = ascii (fp) : "./hrtfs/elev30/L30e230a.dat"
-[ 24, 27 ] = ascii (fp) : "./hrtfs/elev30/L30e225a.dat"
-[ 24, 28 ] = ascii (fp) : "./hrtfs/elev30/L30e220a.dat"
-[ 24, 29 ] = ascii (fp) : "./hrtfs/elev30/L30e215a.dat"
-[ 24, 30 ] = ascii (fp) : "./hrtfs/elev30/L30e210a.dat"
-[ 24, 31 ] = ascii (fp) : "./hrtfs/elev30/L30e205a.dat"
-[ 24, 32 ] = ascii (fp) : "./hrtfs/elev30/L30e200a.dat"
-[ 24, 33 ] = ascii (fp) : "./hrtfs/elev30/L30e195a.dat"
-[ 24, 34 ] = ascii (fp) : "./hrtfs/elev30/L30e190a.dat"
-[ 24, 35 ] = ascii (fp) : "./hrtfs/elev30/L30e185a.dat"
-[ 24, 36 ] = ascii (fp) : "./hrtfs/elev30/L30e180a.dat"
-[ 24, 37 ] = ascii (fp) : "./hrtfs/elev30/L30e175a.dat"
-[ 24, 38 ] = ascii (fp) : "./hrtfs/elev30/L30e170a.dat"
-[ 24, 39 ] = ascii (fp) : "./hrtfs/elev30/L30e165a.dat"
-[ 24, 40 ] = ascii (fp) : "./hrtfs/elev30/L30e160a.dat"
-[ 24, 41 ] = ascii (fp) : "./hrtfs/elev30/L30e155a.dat"
-[ 24, 42 ] = ascii (fp) : "./hrtfs/elev30/L30e150a.dat"
-[ 24, 43 ] = ascii (fp) : "./hrtfs/elev30/L30e145a.dat"
-[ 24, 44 ] = ascii (fp) : "./hrtfs/elev30/L30e140a.dat"
-[ 24, 45 ] = ascii (fp) : "./hrtfs/elev30/L30e135a.dat"
-[ 24, 46 ] = ascii (fp) : "./hrtfs/elev30/L30e130a.dat"
-[ 24, 47 ] = ascii (fp) : "./hrtfs/elev30/L30e125a.dat"
-[ 24, 48 ] = ascii (fp) : "./hrtfs/elev30/L30e120a.dat"
-[ 24, 49 ] = ascii (fp) : "./hrtfs/elev30/L30e115a.dat"
-[ 24, 50 ] = ascii (fp) : "./hrtfs/elev30/L30e110a.dat"
-[ 24, 51 ] = ascii (fp) : "./hrtfs/elev30/L30e105a.dat"
-[ 24, 52 ] = ascii (fp) : "./hrtfs/elev30/L30e100a.dat"
-[ 24, 53 ] = ascii (fp) : "./hrtfs/elev30/L30e095a.dat"
-[ 24, 54 ] = ascii (fp) : "./hrtfs/elev30/L30e090a.dat"
-[ 24, 55 ] = ascii (fp) : "./hrtfs/elev30/L30e085a.dat"
-[ 24, 56 ] = ascii (fp) : "./hrtfs/elev30/L30e080a.dat"
-[ 24, 57 ] = ascii (fp) : "./hrtfs/elev30/L30e075a.dat"
-[ 24, 58 ] = ascii (fp) : "./hrtfs/elev30/L30e070a.dat"
-[ 24, 59 ] = ascii (fp) : "./hrtfs/elev30/L30e065a.dat"
-[ 24, 60 ] = ascii (fp) : "./hrtfs/elev30/L30e060a.dat"
-[ 24, 61 ] = ascii (fp) : "./hrtfs/elev30/L30e055a.dat"
-[ 24, 62 ] = ascii (fp) : "./hrtfs/elev30/L30e050a.dat"
-[ 24, 63 ] = ascii (fp) : "./hrtfs/elev30/L30e045a.dat"
-[ 24, 64 ] = ascii (fp) : "./hrtfs/elev30/L30e040a.dat"
-[ 24, 65 ] = ascii (fp) : "./hrtfs/elev30/L30e035a.dat"
-[ 24, 66 ] = ascii (fp) : "./hrtfs/elev30/L30e030a.dat"
-[ 24, 67 ] = ascii (fp) : "./hrtfs/elev30/L30e025a.dat"
-[ 24, 68 ] = ascii (fp) : "./hrtfs/elev30/L30e020a.dat"
-[ 24, 69 ] = ascii (fp) : "./hrtfs/elev30/L30e015a.dat"
-[ 24, 70 ] = ascii (fp) : "./hrtfs/elev30/L30e010a.dat"
-[ 24, 71 ] = ascii (fp) : "./hrtfs/elev30/L30e005a.dat"
+[ 24, 0 ] = ascii (fp) : "./hrtfs/elev30/L30e000a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e000a.dat right
+[ 24, 1 ] = ascii (fp) : "./hrtfs/elev30/L30e355a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e355a.dat right
+[ 24, 2 ] = ascii (fp) : "./hrtfs/elev30/L30e350a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e350a.dat right
+[ 24, 3 ] = ascii (fp) : "./hrtfs/elev30/L30e345a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e345a.dat right
+[ 24, 4 ] = ascii (fp) : "./hrtfs/elev30/L30e340a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e340a.dat right
+[ 24, 5 ] = ascii (fp) : "./hrtfs/elev30/L30e335a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e335a.dat right
+[ 24, 6 ] = ascii (fp) : "./hrtfs/elev30/L30e330a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e330a.dat right
+[ 24, 7 ] = ascii (fp) : "./hrtfs/elev30/L30e325a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e325a.dat right
+[ 24, 8 ] = ascii (fp) : "./hrtfs/elev30/L30e320a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e320a.dat right
+[ 24, 9 ] = ascii (fp) : "./hrtfs/elev30/L30e315a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e315a.dat right
+[ 24, 10 ] = ascii (fp) : "./hrtfs/elev30/L30e310a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e310a.dat right
+[ 24, 11 ] = ascii (fp) : "./hrtfs/elev30/L30e305a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e305a.dat right
+[ 24, 12 ] = ascii (fp) : "./hrtfs/elev30/L30e300a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e300a.dat right
+[ 24, 13 ] = ascii (fp) : "./hrtfs/elev30/L30e295a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e295a.dat right
+[ 24, 14 ] = ascii (fp) : "./hrtfs/elev30/L30e290a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e290a.dat right
+[ 24, 15 ] = ascii (fp) : "./hrtfs/elev30/L30e285a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e285a.dat right
+[ 24, 16 ] = ascii (fp) : "./hrtfs/elev30/L30e280a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e280a.dat right
+[ 24, 17 ] = ascii (fp) : "./hrtfs/elev30/L30e275a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e275a.dat right
+[ 24, 18 ] = ascii (fp) : "./hrtfs/elev30/L30e270a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e270a.dat right
+[ 24, 19 ] = ascii (fp) : "./hrtfs/elev30/L30e265a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e265a.dat right
+[ 24, 20 ] = ascii (fp) : "./hrtfs/elev30/L30e260a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e260a.dat right
+[ 24, 21 ] = ascii (fp) : "./hrtfs/elev30/L30e255a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e255a.dat right
+[ 24, 22 ] = ascii (fp) : "./hrtfs/elev30/L30e250a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e250a.dat right
+[ 24, 23 ] = ascii (fp) : "./hrtfs/elev30/L30e245a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e245a.dat right
+[ 24, 24 ] = ascii (fp) : "./hrtfs/elev30/L30e240a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e240a.dat right
+[ 24, 25 ] = ascii (fp) : "./hrtfs/elev30/L30e235a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e235a.dat right
+[ 24, 26 ] = ascii (fp) : "./hrtfs/elev30/L30e230a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e230a.dat right
+[ 24, 27 ] = ascii (fp) : "./hrtfs/elev30/L30e225a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e225a.dat right
+[ 24, 28 ] = ascii (fp) : "./hrtfs/elev30/L30e220a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e220a.dat right
+[ 24, 29 ] = ascii (fp) : "./hrtfs/elev30/L30e215a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e215a.dat right
+[ 24, 30 ] = ascii (fp) : "./hrtfs/elev30/L30e210a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e210a.dat right
+[ 24, 31 ] = ascii (fp) : "./hrtfs/elev30/L30e205a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e205a.dat right
+[ 24, 32 ] = ascii (fp) : "./hrtfs/elev30/L30e200a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e200a.dat right
+[ 24, 33 ] = ascii (fp) : "./hrtfs/elev30/L30e195a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e195a.dat right
+[ 24, 34 ] = ascii (fp) : "./hrtfs/elev30/L30e190a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e190a.dat right
+[ 24, 35 ] = ascii (fp) : "./hrtfs/elev30/L30e185a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e185a.dat right
+[ 24, 36 ] = ascii (fp) : "./hrtfs/elev30/L30e180a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e180a.dat right
+[ 24, 37 ] = ascii (fp) : "./hrtfs/elev30/L30e175a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e175a.dat right
+[ 24, 38 ] = ascii (fp) : "./hrtfs/elev30/L30e170a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e170a.dat right
+[ 24, 39 ] = ascii (fp) : "./hrtfs/elev30/L30e165a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e165a.dat right
+[ 24, 40 ] = ascii (fp) : "./hrtfs/elev30/L30e160a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e160a.dat right
+[ 24, 41 ] = ascii (fp) : "./hrtfs/elev30/L30e155a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e155a.dat right
+[ 24, 42 ] = ascii (fp) : "./hrtfs/elev30/L30e150a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e150a.dat right
+[ 24, 43 ] = ascii (fp) : "./hrtfs/elev30/L30e145a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e145a.dat right
+[ 24, 44 ] = ascii (fp) : "./hrtfs/elev30/L30e140a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e140a.dat right
+[ 24, 45 ] = ascii (fp) : "./hrtfs/elev30/L30e135a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e135a.dat right
+[ 24, 46 ] = ascii (fp) : "./hrtfs/elev30/L30e130a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e130a.dat right
+[ 24, 47 ] = ascii (fp) : "./hrtfs/elev30/L30e125a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e125a.dat right
+[ 24, 48 ] = ascii (fp) : "./hrtfs/elev30/L30e120a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e120a.dat right
+[ 24, 49 ] = ascii (fp) : "./hrtfs/elev30/L30e115a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e115a.dat right
+[ 24, 50 ] = ascii (fp) : "./hrtfs/elev30/L30e110a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e110a.dat right
+[ 24, 51 ] = ascii (fp) : "./hrtfs/elev30/L30e105a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e105a.dat right
+[ 24, 52 ] = ascii (fp) : "./hrtfs/elev30/L30e100a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e100a.dat right
+[ 24, 53 ] = ascii (fp) : "./hrtfs/elev30/L30e095a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e095a.dat right
+[ 24, 54 ] = ascii (fp) : "./hrtfs/elev30/L30e090a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e090a.dat right
+[ 24, 55 ] = ascii (fp) : "./hrtfs/elev30/L30e085a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e085a.dat right
+[ 24, 56 ] = ascii (fp) : "./hrtfs/elev30/L30e080a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e080a.dat right
+[ 24, 57 ] = ascii (fp) : "./hrtfs/elev30/L30e075a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e075a.dat right
+[ 24, 58 ] = ascii (fp) : "./hrtfs/elev30/L30e070a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e070a.dat right
+[ 24, 59 ] = ascii (fp) : "./hrtfs/elev30/L30e065a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e065a.dat right
+[ 24, 60 ] = ascii (fp) : "./hrtfs/elev30/L30e060a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e060a.dat right
+[ 24, 61 ] = ascii (fp) : "./hrtfs/elev30/L30e055a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e055a.dat right
+[ 24, 62 ] = ascii (fp) : "./hrtfs/elev30/L30e050a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e050a.dat right
+[ 24, 63 ] = ascii (fp) : "./hrtfs/elev30/L30e045a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e045a.dat right
+[ 24, 64 ] = ascii (fp) : "./hrtfs/elev30/L30e040a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e040a.dat right
+[ 24, 65 ] = ascii (fp) : "./hrtfs/elev30/L30e035a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e035a.dat right
+[ 24, 66 ] = ascii (fp) : "./hrtfs/elev30/L30e030a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e030a.dat right
+[ 24, 67 ] = ascii (fp) : "./hrtfs/elev30/L30e025a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e025a.dat right
+[ 24, 68 ] = ascii (fp) : "./hrtfs/elev30/L30e020a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e020a.dat right
+[ 24, 69 ] = ascii (fp) : "./hrtfs/elev30/L30e015a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e015a.dat right
+[ 24, 70 ] = ascii (fp) : "./hrtfs/elev30/L30e010a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e010a.dat right
+[ 24, 71 ] = ascii (fp) : "./hrtfs/elev30/L30e005a.dat left
+ + ascii (fp) : "./hrtfs/elev30/R30e005a.dat right
-[ 25, 0 ] = ascii (fp) : "./hrtfs/elev35/L35e000a.dat"
-[ 25, 1 ] = ascii (fp) : "./hrtfs/elev35/L35e355a.dat"
-[ 25, 2 ] = ascii (fp) : "./hrtfs/elev35/L35e350a.dat"
-[ 25, 3 ] = ascii (fp) : "./hrtfs/elev35/L35e345a.dat"
-[ 25, 4 ] = ascii (fp) : "./hrtfs/elev35/L35e340a.dat"
-[ 25, 5 ] = ascii (fp) : "./hrtfs/elev35/L35e335a.dat"
-[ 25, 6 ] = ascii (fp) : "./hrtfs/elev35/L35e330a.dat"
-[ 25, 7 ] = ascii (fp) : "./hrtfs/elev35/L35e325a.dat"
-[ 25, 8 ] = ascii (fp) : "./hrtfs/elev35/L35e320a.dat"
-[ 25, 9 ] = ascii (fp) : "./hrtfs/elev35/L35e315a.dat"
-[ 25, 10 ] = ascii (fp) : "./hrtfs/elev35/L35e310a.dat"
-[ 25, 11 ] = ascii (fp) : "./hrtfs/elev35/L35e305a.dat"
-[ 25, 12 ] = ascii (fp) : "./hrtfs/elev35/L35e300a.dat"
-[ 25, 13 ] = ascii (fp) : "./hrtfs/elev35/L35e295a.dat"
-[ 25, 14 ] = ascii (fp) : "./hrtfs/elev35/L35e290a.dat"
-[ 25, 15 ] = ascii (fp) : "./hrtfs/elev35/L35e285a.dat"
-[ 25, 16 ] = ascii (fp) : "./hrtfs/elev35/L35e280a.dat"
-[ 25, 17 ] = ascii (fp) : "./hrtfs/elev35/L35e275a.dat"
-[ 25, 18 ] = ascii (fp) : "./hrtfs/elev35/L35e270a.dat"
-[ 25, 19 ] = ascii (fp) : "./hrtfs/elev35/L35e265a.dat"
-[ 25, 20 ] = ascii (fp) : "./hrtfs/elev35/L35e260a.dat"
-[ 25, 21 ] = ascii (fp) : "./hrtfs/elev35/L35e255a.dat"
-[ 25, 22 ] = ascii (fp) : "./hrtfs/elev35/L35e250a.dat"
-[ 25, 23 ] = ascii (fp) : "./hrtfs/elev35/L35e245a.dat"
-[ 25, 24 ] = ascii (fp) : "./hrtfs/elev35/L35e240a.dat"
-[ 25, 25 ] = ascii (fp) : "./hrtfs/elev35/L35e235a.dat"
-[ 25, 26 ] = ascii (fp) : "./hrtfs/elev35/L35e230a.dat"
-[ 25, 27 ] = ascii (fp) : "./hrtfs/elev35/L35e225a.dat"
-[ 25, 28 ] = ascii (fp) : "./hrtfs/elev35/L35e220a.dat"
-[ 25, 29 ] = ascii (fp) : "./hrtfs/elev35/L35e215a.dat"
-[ 25, 30 ] = ascii (fp) : "./hrtfs/elev35/L35e210a.dat"
-[ 25, 31 ] = ascii (fp) : "./hrtfs/elev35/L35e205a.dat"
-[ 25, 32 ] = ascii (fp) : "./hrtfs/elev35/L35e200a.dat"
-[ 25, 33 ] = ascii (fp) : "./hrtfs/elev35/L35e195a.dat"
-[ 25, 34 ] = ascii (fp) : "./hrtfs/elev35/L35e190a.dat"
-[ 25, 35 ] = ascii (fp) : "./hrtfs/elev35/L35e185a.dat"
-[ 25, 36 ] = ascii (fp) : "./hrtfs/elev35/L35e180a.dat"
-[ 25, 37 ] = ascii (fp) : "./hrtfs/elev35/L35e175a.dat"
-[ 25, 38 ] = ascii (fp) : "./hrtfs/elev35/L35e170a.dat"
-[ 25, 39 ] = ascii (fp) : "./hrtfs/elev35/L35e165a.dat"
-[ 25, 40 ] = ascii (fp) : "./hrtfs/elev35/L35e160a.dat"
-[ 25, 41 ] = ascii (fp) : "./hrtfs/elev35/L35e155a.dat"
-[ 25, 42 ] = ascii (fp) : "./hrtfs/elev35/L35e150a.dat"
-[ 25, 43 ] = ascii (fp) : "./hrtfs/elev35/L35e145a.dat"
-[ 25, 44 ] = ascii (fp) : "./hrtfs/elev35/L35e140a.dat"
-[ 25, 45 ] = ascii (fp) : "./hrtfs/elev35/L35e135a.dat"
-[ 25, 46 ] = ascii (fp) : "./hrtfs/elev35/L35e130a.dat"
-[ 25, 47 ] = ascii (fp) : "./hrtfs/elev35/L35e125a.dat"
-[ 25, 48 ] = ascii (fp) : "./hrtfs/elev35/L35e120a.dat"
-[ 25, 49 ] = ascii (fp) : "./hrtfs/elev35/L35e115a.dat"
-[ 25, 50 ] = ascii (fp) : "./hrtfs/elev35/L35e110a.dat"
-[ 25, 51 ] = ascii (fp) : "./hrtfs/elev35/L35e105a.dat"
-[ 25, 52 ] = ascii (fp) : "./hrtfs/elev35/L35e100a.dat"
-[ 25, 53 ] = ascii (fp) : "./hrtfs/elev35/L35e095a.dat"
-[ 25, 54 ] = ascii (fp) : "./hrtfs/elev35/L35e090a.dat"
-[ 25, 55 ] = ascii (fp) : "./hrtfs/elev35/L35e085a.dat"
-[ 25, 56 ] = ascii (fp) : "./hrtfs/elev35/L35e080a.dat"
-[ 25, 57 ] = ascii (fp) : "./hrtfs/elev35/L35e075a.dat"
-[ 25, 58 ] = ascii (fp) : "./hrtfs/elev35/L35e070a.dat"
-[ 25, 59 ] = ascii (fp) : "./hrtfs/elev35/L35e065a.dat"
-[ 25, 60 ] = ascii (fp) : "./hrtfs/elev35/L35e060a.dat"
-[ 25, 61 ] = ascii (fp) : "./hrtfs/elev35/L35e055a.dat"
-[ 25, 62 ] = ascii (fp) : "./hrtfs/elev35/L35e050a.dat"
-[ 25, 63 ] = ascii (fp) : "./hrtfs/elev35/L35e045a.dat"
-[ 25, 64 ] = ascii (fp) : "./hrtfs/elev35/L35e040a.dat"
-[ 25, 65 ] = ascii (fp) : "./hrtfs/elev35/L35e035a.dat"
-[ 25, 66 ] = ascii (fp) : "./hrtfs/elev35/L35e030a.dat"
-[ 25, 67 ] = ascii (fp) : "./hrtfs/elev35/L35e025a.dat"
-[ 25, 68 ] = ascii (fp) : "./hrtfs/elev35/L35e020a.dat"
-[ 25, 69 ] = ascii (fp) : "./hrtfs/elev35/L35e015a.dat"
-[ 25, 70 ] = ascii (fp) : "./hrtfs/elev35/L35e010a.dat"
-[ 25, 71 ] = ascii (fp) : "./hrtfs/elev35/L35e005a.dat"
+[ 25, 0 ] = ascii (fp) : "./hrtfs/elev35/L35e000a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e000a.dat right
+[ 25, 1 ] = ascii (fp) : "./hrtfs/elev35/L35e355a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e355a.dat right
+[ 25, 2 ] = ascii (fp) : "./hrtfs/elev35/L35e350a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e350a.dat right
+[ 25, 3 ] = ascii (fp) : "./hrtfs/elev35/L35e345a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e345a.dat right
+[ 25, 4 ] = ascii (fp) : "./hrtfs/elev35/L35e340a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e340a.dat right
+[ 25, 5 ] = ascii (fp) : "./hrtfs/elev35/L35e335a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e335a.dat right
+[ 25, 6 ] = ascii (fp) : "./hrtfs/elev35/L35e330a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e330a.dat right
+[ 25, 7 ] = ascii (fp) : "./hrtfs/elev35/L35e325a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e325a.dat right
+[ 25, 8 ] = ascii (fp) : "./hrtfs/elev35/L35e320a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e320a.dat right
+[ 25, 9 ] = ascii (fp) : "./hrtfs/elev35/L35e315a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e315a.dat right
+[ 25, 10 ] = ascii (fp) : "./hrtfs/elev35/L35e310a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e310a.dat right
+[ 25, 11 ] = ascii (fp) : "./hrtfs/elev35/L35e305a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e305a.dat right
+[ 25, 12 ] = ascii (fp) : "./hrtfs/elev35/L35e300a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e300a.dat right
+[ 25, 13 ] = ascii (fp) : "./hrtfs/elev35/L35e295a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e295a.dat right
+[ 25, 14 ] = ascii (fp) : "./hrtfs/elev35/L35e290a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e290a.dat right
+[ 25, 15 ] = ascii (fp) : "./hrtfs/elev35/L35e285a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e285a.dat right
+[ 25, 16 ] = ascii (fp) : "./hrtfs/elev35/L35e280a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e280a.dat right
+[ 25, 17 ] = ascii (fp) : "./hrtfs/elev35/L35e275a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e275a.dat right
+[ 25, 18 ] = ascii (fp) : "./hrtfs/elev35/L35e270a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e270a.dat right
+[ 25, 19 ] = ascii (fp) : "./hrtfs/elev35/L35e265a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e265a.dat right
+[ 25, 20 ] = ascii (fp) : "./hrtfs/elev35/L35e260a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e260a.dat right
+[ 25, 21 ] = ascii (fp) : "./hrtfs/elev35/L35e255a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e255a.dat right
+[ 25, 22 ] = ascii (fp) : "./hrtfs/elev35/L35e250a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e250a.dat right
+[ 25, 23 ] = ascii (fp) : "./hrtfs/elev35/L35e245a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e245a.dat right
+[ 25, 24 ] = ascii (fp) : "./hrtfs/elev35/L35e240a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e240a.dat right
+[ 25, 25 ] = ascii (fp) : "./hrtfs/elev35/L35e235a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e235a.dat right
+[ 25, 26 ] = ascii (fp) : "./hrtfs/elev35/L35e230a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e230a.dat right
+[ 25, 27 ] = ascii (fp) : "./hrtfs/elev35/L35e225a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e225a.dat right
+[ 25, 28 ] = ascii (fp) : "./hrtfs/elev35/L35e220a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e220a.dat right
+[ 25, 29 ] = ascii (fp) : "./hrtfs/elev35/L35e215a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e215a.dat right
+[ 25, 30 ] = ascii (fp) : "./hrtfs/elev35/L35e210a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e210a.dat right
+[ 25, 31 ] = ascii (fp) : "./hrtfs/elev35/L35e205a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e205a.dat right
+[ 25, 32 ] = ascii (fp) : "./hrtfs/elev35/L35e200a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e200a.dat right
+[ 25, 33 ] = ascii (fp) : "./hrtfs/elev35/L35e195a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e195a.dat right
+[ 25, 34 ] = ascii (fp) : "./hrtfs/elev35/L35e190a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e190a.dat right
+[ 25, 35 ] = ascii (fp) : "./hrtfs/elev35/L35e185a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e185a.dat right
+[ 25, 36 ] = ascii (fp) : "./hrtfs/elev35/L35e180a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e180a.dat right
+[ 25, 37 ] = ascii (fp) : "./hrtfs/elev35/L35e175a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e175a.dat right
+[ 25, 38 ] = ascii (fp) : "./hrtfs/elev35/L35e170a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e170a.dat right
+[ 25, 39 ] = ascii (fp) : "./hrtfs/elev35/L35e165a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e165a.dat right
+[ 25, 40 ] = ascii (fp) : "./hrtfs/elev35/L35e160a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e160a.dat right
+[ 25, 41 ] = ascii (fp) : "./hrtfs/elev35/L35e155a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e155a.dat right
+[ 25, 42 ] = ascii (fp) : "./hrtfs/elev35/L35e150a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e150a.dat right
+[ 25, 43 ] = ascii (fp) : "./hrtfs/elev35/L35e145a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e145a.dat right
+[ 25, 44 ] = ascii (fp) : "./hrtfs/elev35/L35e140a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e140a.dat right
+[ 25, 45 ] = ascii (fp) : "./hrtfs/elev35/L35e135a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e135a.dat right
+[ 25, 46 ] = ascii (fp) : "./hrtfs/elev35/L35e130a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e130a.dat right
+[ 25, 47 ] = ascii (fp) : "./hrtfs/elev35/L35e125a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e125a.dat right
+[ 25, 48 ] = ascii (fp) : "./hrtfs/elev35/L35e120a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e120a.dat right
+[ 25, 49 ] = ascii (fp) : "./hrtfs/elev35/L35e115a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e115a.dat right
+[ 25, 50 ] = ascii (fp) : "./hrtfs/elev35/L35e110a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e110a.dat right
+[ 25, 51 ] = ascii (fp) : "./hrtfs/elev35/L35e105a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e105a.dat right
+[ 25, 52 ] = ascii (fp) : "./hrtfs/elev35/L35e100a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e100a.dat right
+[ 25, 53 ] = ascii (fp) : "./hrtfs/elev35/L35e095a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e095a.dat right
+[ 25, 54 ] = ascii (fp) : "./hrtfs/elev35/L35e090a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e090a.dat right
+[ 25, 55 ] = ascii (fp) : "./hrtfs/elev35/L35e085a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e085a.dat right
+[ 25, 56 ] = ascii (fp) : "./hrtfs/elev35/L35e080a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e080a.dat right
+[ 25, 57 ] = ascii (fp) : "./hrtfs/elev35/L35e075a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e075a.dat right
+[ 25, 58 ] = ascii (fp) : "./hrtfs/elev35/L35e070a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e070a.dat right
+[ 25, 59 ] = ascii (fp) : "./hrtfs/elev35/L35e065a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e065a.dat right
+[ 25, 60 ] = ascii (fp) : "./hrtfs/elev35/L35e060a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e060a.dat right
+[ 25, 61 ] = ascii (fp) : "./hrtfs/elev35/L35e055a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e055a.dat right
+[ 25, 62 ] = ascii (fp) : "./hrtfs/elev35/L35e050a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e050a.dat right
+[ 25, 63 ] = ascii (fp) : "./hrtfs/elev35/L35e045a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e045a.dat right
+[ 25, 64 ] = ascii (fp) : "./hrtfs/elev35/L35e040a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e040a.dat right
+[ 25, 65 ] = ascii (fp) : "./hrtfs/elev35/L35e035a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e035a.dat right
+[ 25, 66 ] = ascii (fp) : "./hrtfs/elev35/L35e030a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e030a.dat right
+[ 25, 67 ] = ascii (fp) : "./hrtfs/elev35/L35e025a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e025a.dat right
+[ 25, 68 ] = ascii (fp) : "./hrtfs/elev35/L35e020a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e020a.dat right
+[ 25, 69 ] = ascii (fp) : "./hrtfs/elev35/L35e015a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e015a.dat right
+[ 25, 70 ] = ascii (fp) : "./hrtfs/elev35/L35e010a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e010a.dat right
+[ 25, 71 ] = ascii (fp) : "./hrtfs/elev35/L35e005a.dat left
+ + ascii (fp) : "./hrtfs/elev35/R35e005a.dat right
-[ 26, 0 ] = ascii (fp) : "./hrtfs/elev40/L40e000a.dat"
-[ 26, 1 ] = ascii (fp) : "./hrtfs/elev40/L40e355a.dat"
-[ 26, 2 ] = ascii (fp) : "./hrtfs/elev40/L40e350a.dat"
-[ 26, 3 ] = ascii (fp) : "./hrtfs/elev40/L40e345a.dat"
-[ 26, 4 ] = ascii (fp) : "./hrtfs/elev40/L40e340a.dat"
-[ 26, 5 ] = ascii (fp) : "./hrtfs/elev40/L40e335a.dat"
-[ 26, 6 ] = ascii (fp) : "./hrtfs/elev40/L40e330a.dat"
-[ 26, 7 ] = ascii (fp) : "./hrtfs/elev40/L40e325a.dat"
-[ 26, 8 ] = ascii (fp) : "./hrtfs/elev40/L40e320a.dat"
-[ 26, 9 ] = ascii (fp) : "./hrtfs/elev40/L40e315a.dat"
-[ 26, 10 ] = ascii (fp) : "./hrtfs/elev40/L40e310a.dat"
-[ 26, 11 ] = ascii (fp) : "./hrtfs/elev40/L40e305a.dat"
-[ 26, 12 ] = ascii (fp) : "./hrtfs/elev40/L40e300a.dat"
-[ 26, 13 ] = ascii (fp) : "./hrtfs/elev40/L40e295a.dat"
-[ 26, 14 ] = ascii (fp) : "./hrtfs/elev40/L40e290a.dat"
-[ 26, 15 ] = ascii (fp) : "./hrtfs/elev40/L40e285a.dat"
-[ 26, 16 ] = ascii (fp) : "./hrtfs/elev40/L40e280a.dat"
-[ 26, 17 ] = ascii (fp) : "./hrtfs/elev40/L40e275a.dat"
-[ 26, 18 ] = ascii (fp) : "./hrtfs/elev40/L40e270a.dat"
-[ 26, 19 ] = ascii (fp) : "./hrtfs/elev40/L40e265a.dat"
-[ 26, 20 ] = ascii (fp) : "./hrtfs/elev40/L40e260a.dat"
-[ 26, 21 ] = ascii (fp) : "./hrtfs/elev40/L40e255a.dat"
-[ 26, 22 ] = ascii (fp) : "./hrtfs/elev40/L40e250a.dat"
-[ 26, 23 ] = ascii (fp) : "./hrtfs/elev40/L40e245a.dat"
-[ 26, 24 ] = ascii (fp) : "./hrtfs/elev40/L40e240a.dat"
-[ 26, 25 ] = ascii (fp) : "./hrtfs/elev40/L40e235a.dat"
-[ 26, 26 ] = ascii (fp) : "./hrtfs/elev40/L40e230a.dat"
-[ 26, 27 ] = ascii (fp) : "./hrtfs/elev40/L40e225a.dat"
-[ 26, 28 ] = ascii (fp) : "./hrtfs/elev40/L40e220a.dat"
-[ 26, 29 ] = ascii (fp) : "./hrtfs/elev40/L40e215a.dat"
-[ 26, 30 ] = ascii (fp) : "./hrtfs/elev40/L40e210a.dat"
-[ 26, 31 ] = ascii (fp) : "./hrtfs/elev40/L40e205a.dat"
-[ 26, 32 ] = ascii (fp) : "./hrtfs/elev40/L40e200a.dat"
-[ 26, 33 ] = ascii (fp) : "./hrtfs/elev40/L40e195a.dat"
-[ 26, 34 ] = ascii (fp) : "./hrtfs/elev40/L40e190a.dat"
-[ 26, 35 ] = ascii (fp) : "./hrtfs/elev40/L40e185a.dat"
-[ 26, 36 ] = ascii (fp) : "./hrtfs/elev40/L40e180a.dat"
-[ 26, 37 ] = ascii (fp) : "./hrtfs/elev40/L40e175a.dat"
-[ 26, 38 ] = ascii (fp) : "./hrtfs/elev40/L40e170a.dat"
-[ 26, 39 ] = ascii (fp) : "./hrtfs/elev40/L40e165a.dat"
-[ 26, 40 ] = ascii (fp) : "./hrtfs/elev40/L40e160a.dat"
-[ 26, 41 ] = ascii (fp) : "./hrtfs/elev40/L40e155a.dat"
-[ 26, 42 ] = ascii (fp) : "./hrtfs/elev40/L40e150a.dat"
-[ 26, 43 ] = ascii (fp) : "./hrtfs/elev40/L40e145a.dat"
-[ 26, 44 ] = ascii (fp) : "./hrtfs/elev40/L40e140a.dat"
-[ 26, 45 ] = ascii (fp) : "./hrtfs/elev40/L40e135a.dat"
-[ 26, 46 ] = ascii (fp) : "./hrtfs/elev40/L40e130a.dat"
-[ 26, 47 ] = ascii (fp) : "./hrtfs/elev40/L40e125a.dat"
-[ 26, 48 ] = ascii (fp) : "./hrtfs/elev40/L40e120a.dat"
-[ 26, 49 ] = ascii (fp) : "./hrtfs/elev40/L40e115a.dat"
-[ 26, 50 ] = ascii (fp) : "./hrtfs/elev40/L40e110a.dat"
-[ 26, 51 ] = ascii (fp) : "./hrtfs/elev40/L40e105a.dat"
-[ 26, 52 ] = ascii (fp) : "./hrtfs/elev40/L40e100a.dat"
-[ 26, 53 ] = ascii (fp) : "./hrtfs/elev40/L40e095a.dat"
-[ 26, 54 ] = ascii (fp) : "./hrtfs/elev40/L40e090a.dat"
-[ 26, 55 ] = ascii (fp) : "./hrtfs/elev40/L40e085a.dat"
-[ 26, 56 ] = ascii (fp) : "./hrtfs/elev40/L40e080a.dat"
-[ 26, 57 ] = ascii (fp) : "./hrtfs/elev40/L40e075a.dat"
-[ 26, 58 ] = ascii (fp) : "./hrtfs/elev40/L40e070a.dat"
-[ 26, 59 ] = ascii (fp) : "./hrtfs/elev40/L40e065a.dat"
-[ 26, 60 ] = ascii (fp) : "./hrtfs/elev40/L40e060a.dat"
-[ 26, 61 ] = ascii (fp) : "./hrtfs/elev40/L40e055a.dat"
-[ 26, 62 ] = ascii (fp) : "./hrtfs/elev40/L40e050a.dat"
-[ 26, 63 ] = ascii (fp) : "./hrtfs/elev40/L40e045a.dat"
-[ 26, 64 ] = ascii (fp) : "./hrtfs/elev40/L40e040a.dat"
-[ 26, 65 ] = ascii (fp) : "./hrtfs/elev40/L40e035a.dat"
-[ 26, 66 ] = ascii (fp) : "./hrtfs/elev40/L40e030a.dat"
-[ 26, 67 ] = ascii (fp) : "./hrtfs/elev40/L40e025a.dat"
-[ 26, 68 ] = ascii (fp) : "./hrtfs/elev40/L40e020a.dat"
-[ 26, 69 ] = ascii (fp) : "./hrtfs/elev40/L40e015a.dat"
-[ 26, 70 ] = ascii (fp) : "./hrtfs/elev40/L40e010a.dat"
-[ 26, 71 ] = ascii (fp) : "./hrtfs/elev40/L40e005a.dat"
+[ 26, 0 ] = ascii (fp) : "./hrtfs/elev40/L40e000a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e000a.dat right
+[ 26, 1 ] = ascii (fp) : "./hrtfs/elev40/L40e355a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e355a.dat right
+[ 26, 2 ] = ascii (fp) : "./hrtfs/elev40/L40e350a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e350a.dat right
+[ 26, 3 ] = ascii (fp) : "./hrtfs/elev40/L40e345a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e345a.dat right
+[ 26, 4 ] = ascii (fp) : "./hrtfs/elev40/L40e340a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e340a.dat right
+[ 26, 5 ] = ascii (fp) : "./hrtfs/elev40/L40e335a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e335a.dat right
+[ 26, 6 ] = ascii (fp) : "./hrtfs/elev40/L40e330a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e330a.dat right
+[ 26, 7 ] = ascii (fp) : "./hrtfs/elev40/L40e325a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e325a.dat right
+[ 26, 8 ] = ascii (fp) : "./hrtfs/elev40/L40e320a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e320a.dat right
+[ 26, 9 ] = ascii (fp) : "./hrtfs/elev40/L40e315a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e315a.dat right
+[ 26, 10 ] = ascii (fp) : "./hrtfs/elev40/L40e310a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e310a.dat right
+[ 26, 11 ] = ascii (fp) : "./hrtfs/elev40/L40e305a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e305a.dat right
+[ 26, 12 ] = ascii (fp) : "./hrtfs/elev40/L40e300a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e300a.dat right
+[ 26, 13 ] = ascii (fp) : "./hrtfs/elev40/L40e295a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e295a.dat right
+[ 26, 14 ] = ascii (fp) : "./hrtfs/elev40/L40e290a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e290a.dat right
+[ 26, 15 ] = ascii (fp) : "./hrtfs/elev40/L40e285a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e285a.dat right
+[ 26, 16 ] = ascii (fp) : "./hrtfs/elev40/L40e280a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e280a.dat right
+[ 26, 17 ] = ascii (fp) : "./hrtfs/elev40/L40e275a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e275a.dat right
+[ 26, 18 ] = ascii (fp) : "./hrtfs/elev40/L40e270a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e270a.dat right
+[ 26, 19 ] = ascii (fp) : "./hrtfs/elev40/L40e265a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e265a.dat right
+[ 26, 20 ] = ascii (fp) : "./hrtfs/elev40/L40e260a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e260a.dat right
+[ 26, 21 ] = ascii (fp) : "./hrtfs/elev40/L40e255a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e255a.dat right
+[ 26, 22 ] = ascii (fp) : "./hrtfs/elev40/L40e250a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e250a.dat right
+[ 26, 23 ] = ascii (fp) : "./hrtfs/elev40/L40e245a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e245a.dat right
+[ 26, 24 ] = ascii (fp) : "./hrtfs/elev40/L40e240a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e240a.dat right
+[ 26, 25 ] = ascii (fp) : "./hrtfs/elev40/L40e235a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e235a.dat right
+[ 26, 26 ] = ascii (fp) : "./hrtfs/elev40/L40e230a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e230a.dat right
+[ 26, 27 ] = ascii (fp) : "./hrtfs/elev40/L40e225a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e225a.dat right
+[ 26, 28 ] = ascii (fp) : "./hrtfs/elev40/L40e220a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e220a.dat right
+[ 26, 29 ] = ascii (fp) : "./hrtfs/elev40/L40e215a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e215a.dat right
+[ 26, 30 ] = ascii (fp) : "./hrtfs/elev40/L40e210a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e210a.dat right
+[ 26, 31 ] = ascii (fp) : "./hrtfs/elev40/L40e205a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e205a.dat right
+[ 26, 32 ] = ascii (fp) : "./hrtfs/elev40/L40e200a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e200a.dat right
+[ 26, 33 ] = ascii (fp) : "./hrtfs/elev40/L40e195a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e195a.dat right
+[ 26, 34 ] = ascii (fp) : "./hrtfs/elev40/L40e190a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e190a.dat right
+[ 26, 35 ] = ascii (fp) : "./hrtfs/elev40/L40e185a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e185a.dat right
+[ 26, 36 ] = ascii (fp) : "./hrtfs/elev40/L40e180a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e180a.dat right
+[ 26, 37 ] = ascii (fp) : "./hrtfs/elev40/L40e175a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e175a.dat right
+[ 26, 38 ] = ascii (fp) : "./hrtfs/elev40/L40e170a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e170a.dat right
+[ 26, 39 ] = ascii (fp) : "./hrtfs/elev40/L40e165a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e165a.dat right
+[ 26, 40 ] = ascii (fp) : "./hrtfs/elev40/L40e160a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e160a.dat right
+[ 26, 41 ] = ascii (fp) : "./hrtfs/elev40/L40e155a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e155a.dat right
+[ 26, 42 ] = ascii (fp) : "./hrtfs/elev40/L40e150a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e150a.dat right
+[ 26, 43 ] = ascii (fp) : "./hrtfs/elev40/L40e145a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e145a.dat right
+[ 26, 44 ] = ascii (fp) : "./hrtfs/elev40/L40e140a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e140a.dat right
+[ 26, 45 ] = ascii (fp) : "./hrtfs/elev40/L40e135a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e135a.dat right
+[ 26, 46 ] = ascii (fp) : "./hrtfs/elev40/L40e130a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e130a.dat right
+[ 26, 47 ] = ascii (fp) : "./hrtfs/elev40/L40e125a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e125a.dat right
+[ 26, 48 ] = ascii (fp) : "./hrtfs/elev40/L40e120a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e120a.dat right
+[ 26, 49 ] = ascii (fp) : "./hrtfs/elev40/L40e115a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e115a.dat right
+[ 26, 50 ] = ascii (fp) : "./hrtfs/elev40/L40e110a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e110a.dat right
+[ 26, 51 ] = ascii (fp) : "./hrtfs/elev40/L40e105a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e105a.dat right
+[ 26, 52 ] = ascii (fp) : "./hrtfs/elev40/L40e100a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e100a.dat right
+[ 26, 53 ] = ascii (fp) : "./hrtfs/elev40/L40e095a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e095a.dat right
+[ 26, 54 ] = ascii (fp) : "./hrtfs/elev40/L40e090a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e090a.dat right
+[ 26, 55 ] = ascii (fp) : "./hrtfs/elev40/L40e085a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e085a.dat right
+[ 26, 56 ] = ascii (fp) : "./hrtfs/elev40/L40e080a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e080a.dat right
+[ 26, 57 ] = ascii (fp) : "./hrtfs/elev40/L40e075a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e075a.dat right
+[ 26, 58 ] = ascii (fp) : "./hrtfs/elev40/L40e070a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e070a.dat right
+[ 26, 59 ] = ascii (fp) : "./hrtfs/elev40/L40e065a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e065a.dat right
+[ 26, 60 ] = ascii (fp) : "./hrtfs/elev40/L40e060a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e060a.dat right
+[ 26, 61 ] = ascii (fp) : "./hrtfs/elev40/L40e055a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e055a.dat right
+[ 26, 62 ] = ascii (fp) : "./hrtfs/elev40/L40e050a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e050a.dat right
+[ 26, 63 ] = ascii (fp) : "./hrtfs/elev40/L40e045a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e045a.dat right
+[ 26, 64 ] = ascii (fp) : "./hrtfs/elev40/L40e040a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e040a.dat right
+[ 26, 65 ] = ascii (fp) : "./hrtfs/elev40/L40e035a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e035a.dat right
+[ 26, 66 ] = ascii (fp) : "./hrtfs/elev40/L40e030a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e030a.dat right
+[ 26, 67 ] = ascii (fp) : "./hrtfs/elev40/L40e025a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e025a.dat right
+[ 26, 68 ] = ascii (fp) : "./hrtfs/elev40/L40e020a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e020a.dat right
+[ 26, 69 ] = ascii (fp) : "./hrtfs/elev40/L40e015a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e015a.dat right
+[ 26, 70 ] = ascii (fp) : "./hrtfs/elev40/L40e010a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e010a.dat right
+[ 26, 71 ] = ascii (fp) : "./hrtfs/elev40/L40e005a.dat left
+ + ascii (fp) : "./hrtfs/elev40/R40e005a.dat right
-[ 27, 0 ] = ascii (fp) : "./hrtfs/elev45/L45e000a.dat"
-[ 27, 1 ] = ascii (fp) : "./hrtfs/elev45/L45e355a.dat"
-[ 27, 2 ] = ascii (fp) : "./hrtfs/elev45/L45e350a.dat"
-[ 27, 3 ] = ascii (fp) : "./hrtfs/elev45/L45e345a.dat"
-[ 27, 4 ] = ascii (fp) : "./hrtfs/elev45/L45e340a.dat"
-[ 27, 5 ] = ascii (fp) : "./hrtfs/elev45/L45e335a.dat"
-[ 27, 6 ] = ascii (fp) : "./hrtfs/elev45/L45e330a.dat"
-[ 27, 7 ] = ascii (fp) : "./hrtfs/elev45/L45e325a.dat"
-[ 27, 8 ] = ascii (fp) : "./hrtfs/elev45/L45e320a.dat"
-[ 27, 9 ] = ascii (fp) : "./hrtfs/elev45/L45e315a.dat"
-[ 27, 10 ] = ascii (fp) : "./hrtfs/elev45/L45e310a.dat"
-[ 27, 11 ] = ascii (fp) : "./hrtfs/elev45/L45e305a.dat"
-[ 27, 12 ] = ascii (fp) : "./hrtfs/elev45/L45e300a.dat"
-[ 27, 13 ] = ascii (fp) : "./hrtfs/elev45/L45e295a.dat"
-[ 27, 14 ] = ascii (fp) : "./hrtfs/elev45/L45e290a.dat"
-[ 27, 15 ] = ascii (fp) : "./hrtfs/elev45/L45e285a.dat"
-[ 27, 16 ] = ascii (fp) : "./hrtfs/elev45/L45e280a.dat"
-[ 27, 17 ] = ascii (fp) : "./hrtfs/elev45/L45e275a.dat"
-[ 27, 18 ] = ascii (fp) : "./hrtfs/elev45/L45e270a.dat"
-[ 27, 19 ] = ascii (fp) : "./hrtfs/elev45/L45e265a.dat"
-[ 27, 20 ] = ascii (fp) : "./hrtfs/elev45/L45e260a.dat"
-[ 27, 21 ] = ascii (fp) : "./hrtfs/elev45/L45e255a.dat"
-[ 27, 22 ] = ascii (fp) : "./hrtfs/elev45/L45e250a.dat"
-[ 27, 23 ] = ascii (fp) : "./hrtfs/elev45/L45e245a.dat"
-[ 27, 24 ] = ascii (fp) : "./hrtfs/elev45/L45e240a.dat"
-[ 27, 25 ] = ascii (fp) : "./hrtfs/elev45/L45e235a.dat"
-[ 27, 26 ] = ascii (fp) : "./hrtfs/elev45/L45e230a.dat"
-[ 27, 27 ] = ascii (fp) : "./hrtfs/elev45/L45e225a.dat"
-[ 27, 28 ] = ascii (fp) : "./hrtfs/elev45/L45e220a.dat"
-[ 27, 29 ] = ascii (fp) : "./hrtfs/elev45/L45e215a.dat"
-[ 27, 30 ] = ascii (fp) : "./hrtfs/elev45/L45e210a.dat"
-[ 27, 31 ] = ascii (fp) : "./hrtfs/elev45/L45e205a.dat"
-[ 27, 32 ] = ascii (fp) : "./hrtfs/elev45/L45e200a.dat"
-[ 27, 33 ] = ascii (fp) : "./hrtfs/elev45/L45e195a.dat"
-[ 27, 34 ] = ascii (fp) : "./hrtfs/elev45/L45e190a.dat"
-[ 27, 35 ] = ascii (fp) : "./hrtfs/elev45/L45e185a.dat"
-[ 27, 36 ] = ascii (fp) : "./hrtfs/elev45/L45e180a.dat"
-[ 27, 37 ] = ascii (fp) : "./hrtfs/elev45/L45e175a.dat"
-[ 27, 38 ] = ascii (fp) : "./hrtfs/elev45/L45e170a.dat"
-[ 27, 39 ] = ascii (fp) : "./hrtfs/elev45/L45e165a.dat"
-[ 27, 40 ] = ascii (fp) : "./hrtfs/elev45/L45e160a.dat"
-[ 27, 41 ] = ascii (fp) : "./hrtfs/elev45/L45e155a.dat"
-[ 27, 42 ] = ascii (fp) : "./hrtfs/elev45/L45e150a.dat"
-[ 27, 43 ] = ascii (fp) : "./hrtfs/elev45/L45e145a.dat"
-[ 27, 44 ] = ascii (fp) : "./hrtfs/elev45/L45e140a.dat"
-[ 27, 45 ] = ascii (fp) : "./hrtfs/elev45/L45e135a.dat"
-[ 27, 46 ] = ascii (fp) : "./hrtfs/elev45/L45e130a.dat"
-[ 27, 47 ] = ascii (fp) : "./hrtfs/elev45/L45e125a.dat"
-[ 27, 48 ] = ascii (fp) : "./hrtfs/elev45/L45e120a.dat"
-[ 27, 49 ] = ascii (fp) : "./hrtfs/elev45/L45e115a.dat"
-[ 27, 50 ] = ascii (fp) : "./hrtfs/elev45/L45e110a.dat"
-[ 27, 51 ] = ascii (fp) : "./hrtfs/elev45/L45e105a.dat"
-[ 27, 52 ] = ascii (fp) : "./hrtfs/elev45/L45e100a.dat"
-[ 27, 53 ] = ascii (fp) : "./hrtfs/elev45/L45e095a.dat"
-[ 27, 54 ] = ascii (fp) : "./hrtfs/elev45/L45e090a.dat"
-[ 27, 55 ] = ascii (fp) : "./hrtfs/elev45/L45e085a.dat"
-[ 27, 56 ] = ascii (fp) : "./hrtfs/elev45/L45e080a.dat"
-[ 27, 57 ] = ascii (fp) : "./hrtfs/elev45/L45e075a.dat"
-[ 27, 58 ] = ascii (fp) : "./hrtfs/elev45/L45e070a.dat"
-[ 27, 59 ] = ascii (fp) : "./hrtfs/elev45/L45e065a.dat"
-[ 27, 60 ] = ascii (fp) : "./hrtfs/elev45/L45e060a.dat"
-[ 27, 61 ] = ascii (fp) : "./hrtfs/elev45/L45e055a.dat"
-[ 27, 62 ] = ascii (fp) : "./hrtfs/elev45/L45e050a.dat"
-[ 27, 63 ] = ascii (fp) : "./hrtfs/elev45/L45e045a.dat"
-[ 27, 64 ] = ascii (fp) : "./hrtfs/elev45/L45e040a.dat"
-[ 27, 65 ] = ascii (fp) : "./hrtfs/elev45/L45e035a.dat"
-[ 27, 66 ] = ascii (fp) : "./hrtfs/elev45/L45e030a.dat"
-[ 27, 67 ] = ascii (fp) : "./hrtfs/elev45/L45e025a.dat"
-[ 27, 68 ] = ascii (fp) : "./hrtfs/elev45/L45e020a.dat"
-[ 27, 69 ] = ascii (fp) : "./hrtfs/elev45/L45e015a.dat"
-[ 27, 70 ] = ascii (fp) : "./hrtfs/elev45/L45e010a.dat"
-[ 27, 71 ] = ascii (fp) : "./hrtfs/elev45/L45e005a.dat"
+[ 27, 0 ] = ascii (fp) : "./hrtfs/elev45/L45e000a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e000a.dat right
+[ 27, 1 ] = ascii (fp) : "./hrtfs/elev45/L45e355a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e355a.dat right
+[ 27, 2 ] = ascii (fp) : "./hrtfs/elev45/L45e350a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e350a.dat right
+[ 27, 3 ] = ascii (fp) : "./hrtfs/elev45/L45e345a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e345a.dat right
+[ 27, 4 ] = ascii (fp) : "./hrtfs/elev45/L45e340a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e340a.dat right
+[ 27, 5 ] = ascii (fp) : "./hrtfs/elev45/L45e335a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e335a.dat right
+[ 27, 6 ] = ascii (fp) : "./hrtfs/elev45/L45e330a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e330a.dat right
+[ 27, 7 ] = ascii (fp) : "./hrtfs/elev45/L45e325a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e325a.dat right
+[ 27, 8 ] = ascii (fp) : "./hrtfs/elev45/L45e320a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e320a.dat right
+[ 27, 9 ] = ascii (fp) : "./hrtfs/elev45/L45e315a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e315a.dat right
+[ 27, 10 ] = ascii (fp) : "./hrtfs/elev45/L45e310a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e310a.dat right
+[ 27, 11 ] = ascii (fp) : "./hrtfs/elev45/L45e305a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e305a.dat right
+[ 27, 12 ] = ascii (fp) : "./hrtfs/elev45/L45e300a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e300a.dat right
+[ 27, 13 ] = ascii (fp) : "./hrtfs/elev45/L45e295a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e295a.dat right
+[ 27, 14 ] = ascii (fp) : "./hrtfs/elev45/L45e290a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e290a.dat right
+[ 27, 15 ] = ascii (fp) : "./hrtfs/elev45/L45e285a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e285a.dat right
+[ 27, 16 ] = ascii (fp) : "./hrtfs/elev45/L45e280a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e280a.dat right
+[ 27, 17 ] = ascii (fp) : "./hrtfs/elev45/L45e275a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e275a.dat right
+[ 27, 18 ] = ascii (fp) : "./hrtfs/elev45/L45e270a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e270a.dat right
+[ 27, 19 ] = ascii (fp) : "./hrtfs/elev45/L45e265a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e265a.dat right
+[ 27, 20 ] = ascii (fp) : "./hrtfs/elev45/L45e260a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e260a.dat right
+[ 27, 21 ] = ascii (fp) : "./hrtfs/elev45/L45e255a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e255a.dat right
+[ 27, 22 ] = ascii (fp) : "./hrtfs/elev45/L45e250a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e250a.dat right
+[ 27, 23 ] = ascii (fp) : "./hrtfs/elev45/L45e245a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e245a.dat right
+[ 27, 24 ] = ascii (fp) : "./hrtfs/elev45/L45e240a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e240a.dat right
+[ 27, 25 ] = ascii (fp) : "./hrtfs/elev45/L45e235a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e235a.dat right
+[ 27, 26 ] = ascii (fp) : "./hrtfs/elev45/L45e230a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e230a.dat right
+[ 27, 27 ] = ascii (fp) : "./hrtfs/elev45/L45e225a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e225a.dat right
+[ 27, 28 ] = ascii (fp) : "./hrtfs/elev45/L45e220a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e220a.dat right
+[ 27, 29 ] = ascii (fp) : "./hrtfs/elev45/L45e215a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e215a.dat right
+[ 27, 30 ] = ascii (fp) : "./hrtfs/elev45/L45e210a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e210a.dat right
+[ 27, 31 ] = ascii (fp) : "./hrtfs/elev45/L45e205a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e205a.dat right
+[ 27, 32 ] = ascii (fp) : "./hrtfs/elev45/L45e200a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e200a.dat right
+[ 27, 33 ] = ascii (fp) : "./hrtfs/elev45/L45e195a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e195a.dat right
+[ 27, 34 ] = ascii (fp) : "./hrtfs/elev45/L45e190a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e190a.dat right
+[ 27, 35 ] = ascii (fp) : "./hrtfs/elev45/L45e185a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e185a.dat right
+[ 27, 36 ] = ascii (fp) : "./hrtfs/elev45/L45e180a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e180a.dat right
+[ 27, 37 ] = ascii (fp) : "./hrtfs/elev45/L45e175a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e175a.dat right
+[ 27, 38 ] = ascii (fp) : "./hrtfs/elev45/L45e170a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e170a.dat right
+[ 27, 39 ] = ascii (fp) : "./hrtfs/elev45/L45e165a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e165a.dat right
+[ 27, 40 ] = ascii (fp) : "./hrtfs/elev45/L45e160a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e160a.dat right
+[ 27, 41 ] = ascii (fp) : "./hrtfs/elev45/L45e155a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e155a.dat right
+[ 27, 42 ] = ascii (fp) : "./hrtfs/elev45/L45e150a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e150a.dat right
+[ 27, 43 ] = ascii (fp) : "./hrtfs/elev45/L45e145a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e145a.dat right
+[ 27, 44 ] = ascii (fp) : "./hrtfs/elev45/L45e140a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e140a.dat right
+[ 27, 45 ] = ascii (fp) : "./hrtfs/elev45/L45e135a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e135a.dat right
+[ 27, 46 ] = ascii (fp) : "./hrtfs/elev45/L45e130a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e130a.dat right
+[ 27, 47 ] = ascii (fp) : "./hrtfs/elev45/L45e125a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e125a.dat right
+[ 27, 48 ] = ascii (fp) : "./hrtfs/elev45/L45e120a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e120a.dat right
+[ 27, 49 ] = ascii (fp) : "./hrtfs/elev45/L45e115a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e115a.dat right
+[ 27, 50 ] = ascii (fp) : "./hrtfs/elev45/L45e110a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e110a.dat right
+[ 27, 51 ] = ascii (fp) : "./hrtfs/elev45/L45e105a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e105a.dat right
+[ 27, 52 ] = ascii (fp) : "./hrtfs/elev45/L45e100a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e100a.dat right
+[ 27, 53 ] = ascii (fp) : "./hrtfs/elev45/L45e095a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e095a.dat right
+[ 27, 54 ] = ascii (fp) : "./hrtfs/elev45/L45e090a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e090a.dat right
+[ 27, 55 ] = ascii (fp) : "./hrtfs/elev45/L45e085a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e085a.dat right
+[ 27, 56 ] = ascii (fp) : "./hrtfs/elev45/L45e080a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e080a.dat right
+[ 27, 57 ] = ascii (fp) : "./hrtfs/elev45/L45e075a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e075a.dat right
+[ 27, 58 ] = ascii (fp) : "./hrtfs/elev45/L45e070a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e070a.dat right
+[ 27, 59 ] = ascii (fp) : "./hrtfs/elev45/L45e065a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e065a.dat right
+[ 27, 60 ] = ascii (fp) : "./hrtfs/elev45/L45e060a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e060a.dat right
+[ 27, 61 ] = ascii (fp) : "./hrtfs/elev45/L45e055a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e055a.dat right
+[ 27, 62 ] = ascii (fp) : "./hrtfs/elev45/L45e050a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e050a.dat right
+[ 27, 63 ] = ascii (fp) : "./hrtfs/elev45/L45e045a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e045a.dat right
+[ 27, 64 ] = ascii (fp) : "./hrtfs/elev45/L45e040a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e040a.dat right
+[ 27, 65 ] = ascii (fp) : "./hrtfs/elev45/L45e035a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e035a.dat right
+[ 27, 66 ] = ascii (fp) : "./hrtfs/elev45/L45e030a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e030a.dat right
+[ 27, 67 ] = ascii (fp) : "./hrtfs/elev45/L45e025a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e025a.dat right
+[ 27, 68 ] = ascii (fp) : "./hrtfs/elev45/L45e020a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e020a.dat right
+[ 27, 69 ] = ascii (fp) : "./hrtfs/elev45/L45e015a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e015a.dat right
+[ 27, 70 ] = ascii (fp) : "./hrtfs/elev45/L45e010a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e010a.dat right
+[ 27, 71 ] = ascii (fp) : "./hrtfs/elev45/L45e005a.dat left
+ + ascii (fp) : "./hrtfs/elev45/R45e005a.dat right
-[ 28, 0 ] = ascii (fp) : "./hrtfs/elev50/L50e000a.dat"
-[ 28, 1 ] = ascii (fp) : "./hrtfs/elev50/L50e355a.dat"
-[ 28, 2 ] = ascii (fp) : "./hrtfs/elev50/L50e350a.dat"
-[ 28, 3 ] = ascii (fp) : "./hrtfs/elev50/L50e345a.dat"
-[ 28, 4 ] = ascii (fp) : "./hrtfs/elev50/L50e340a.dat"
-[ 28, 5 ] = ascii (fp) : "./hrtfs/elev50/L50e335a.dat"
-[ 28, 6 ] = ascii (fp) : "./hrtfs/elev50/L50e330a.dat"
-[ 28, 7 ] = ascii (fp) : "./hrtfs/elev50/L50e325a.dat"
-[ 28, 8 ] = ascii (fp) : "./hrtfs/elev50/L50e320a.dat"
-[ 28, 9 ] = ascii (fp) : "./hrtfs/elev50/L50e315a.dat"
-[ 28, 10 ] = ascii (fp) : "./hrtfs/elev50/L50e310a.dat"
-[ 28, 11 ] = ascii (fp) : "./hrtfs/elev50/L50e305a.dat"
-[ 28, 12 ] = ascii (fp) : "./hrtfs/elev50/L50e300a.dat"
-[ 28, 13 ] = ascii (fp) : "./hrtfs/elev50/L50e295a.dat"
-[ 28, 14 ] = ascii (fp) : "./hrtfs/elev50/L50e290a.dat"
-[ 28, 15 ] = ascii (fp) : "./hrtfs/elev50/L50e285a.dat"
-[ 28, 16 ] = ascii (fp) : "./hrtfs/elev50/L50e280a.dat"
-[ 28, 17 ] = ascii (fp) : "./hrtfs/elev50/L50e275a.dat"
-[ 28, 18 ] = ascii (fp) : "./hrtfs/elev50/L50e270a.dat"
-[ 28, 19 ] = ascii (fp) : "./hrtfs/elev50/L50e265a.dat"
-[ 28, 20 ] = ascii (fp) : "./hrtfs/elev50/L50e260a.dat"
-[ 28, 21 ] = ascii (fp) : "./hrtfs/elev50/L50e255a.dat"
-[ 28, 22 ] = ascii (fp) : "./hrtfs/elev50/L50e250a.dat"
-[ 28, 23 ] = ascii (fp) : "./hrtfs/elev50/L50e245a.dat"
-[ 28, 24 ] = ascii (fp) : "./hrtfs/elev50/L50e240a.dat"
-[ 28, 25 ] = ascii (fp) : "./hrtfs/elev50/L50e235a.dat"
-[ 28, 26 ] = ascii (fp) : "./hrtfs/elev50/L50e230a.dat"
-[ 28, 27 ] = ascii (fp) : "./hrtfs/elev50/L50e225a.dat"
-[ 28, 28 ] = ascii (fp) : "./hrtfs/elev50/L50e220a.dat"
-[ 28, 29 ] = ascii (fp) : "./hrtfs/elev50/L50e215a.dat"
-[ 28, 30 ] = ascii (fp) : "./hrtfs/elev50/L50e210a.dat"
-[ 28, 31 ] = ascii (fp) : "./hrtfs/elev50/L50e205a.dat"
-[ 28, 32 ] = ascii (fp) : "./hrtfs/elev50/L50e200a.dat"
-[ 28, 33 ] = ascii (fp) : "./hrtfs/elev50/L50e195a.dat"
-[ 28, 34 ] = ascii (fp) : "./hrtfs/elev50/L50e190a.dat"
-[ 28, 35 ] = ascii (fp) : "./hrtfs/elev50/L50e185a.dat"
-[ 28, 36 ] = ascii (fp) : "./hrtfs/elev50/L50e180a.dat"
-[ 28, 37 ] = ascii (fp) : "./hrtfs/elev50/L50e175a.dat"
-[ 28, 38 ] = ascii (fp) : "./hrtfs/elev50/L50e170a.dat"
-[ 28, 39 ] = ascii (fp) : "./hrtfs/elev50/L50e165a.dat"
-[ 28, 40 ] = ascii (fp) : "./hrtfs/elev50/L50e160a.dat"
-[ 28, 41 ] = ascii (fp) : "./hrtfs/elev50/L50e155a.dat"
-[ 28, 42 ] = ascii (fp) : "./hrtfs/elev50/L50e150a.dat"
-[ 28, 43 ] = ascii (fp) : "./hrtfs/elev50/L50e145a.dat"
-[ 28, 44 ] = ascii (fp) : "./hrtfs/elev50/L50e140a.dat"
-[ 28, 45 ] = ascii (fp) : "./hrtfs/elev50/L50e135a.dat"
-[ 28, 46 ] = ascii (fp) : "./hrtfs/elev50/L50e130a.dat"
-[ 28, 47 ] = ascii (fp) : "./hrtfs/elev50/L50e125a.dat"
-[ 28, 48 ] = ascii (fp) : "./hrtfs/elev50/L50e120a.dat"
-[ 28, 49 ] = ascii (fp) : "./hrtfs/elev50/L50e115a.dat"
-[ 28, 50 ] = ascii (fp) : "./hrtfs/elev50/L50e110a.dat"
-[ 28, 51 ] = ascii (fp) : "./hrtfs/elev50/L50e105a.dat"
-[ 28, 52 ] = ascii (fp) : "./hrtfs/elev50/L50e100a.dat"
-[ 28, 53 ] = ascii (fp) : "./hrtfs/elev50/L50e095a.dat"
-[ 28, 54 ] = ascii (fp) : "./hrtfs/elev50/L50e090a.dat"
-[ 28, 55 ] = ascii (fp) : "./hrtfs/elev50/L50e085a.dat"
-[ 28, 56 ] = ascii (fp) : "./hrtfs/elev50/L50e080a.dat"
-[ 28, 57 ] = ascii (fp) : "./hrtfs/elev50/L50e075a.dat"
-[ 28, 58 ] = ascii (fp) : "./hrtfs/elev50/L50e070a.dat"
-[ 28, 59 ] = ascii (fp) : "./hrtfs/elev50/L50e065a.dat"
-[ 28, 60 ] = ascii (fp) : "./hrtfs/elev50/L50e060a.dat"
-[ 28, 61 ] = ascii (fp) : "./hrtfs/elev50/L50e055a.dat"
-[ 28, 62 ] = ascii (fp) : "./hrtfs/elev50/L50e050a.dat"
-[ 28, 63 ] = ascii (fp) : "./hrtfs/elev50/L50e045a.dat"
-[ 28, 64 ] = ascii (fp) : "./hrtfs/elev50/L50e040a.dat"
-[ 28, 65 ] = ascii (fp) : "./hrtfs/elev50/L50e035a.dat"
-[ 28, 66 ] = ascii (fp) : "./hrtfs/elev50/L50e030a.dat"
-[ 28, 67 ] = ascii (fp) : "./hrtfs/elev50/L50e025a.dat"
-[ 28, 68 ] = ascii (fp) : "./hrtfs/elev50/L50e020a.dat"
-[ 28, 69 ] = ascii (fp) : "./hrtfs/elev50/L50e015a.dat"
-[ 28, 70 ] = ascii (fp) : "./hrtfs/elev50/L50e010a.dat"
-[ 28, 71 ] = ascii (fp) : "./hrtfs/elev50/L50e005a.dat"
+[ 28, 0 ] = ascii (fp) : "./hrtfs/elev50/L50e000a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e000a.dat right
+[ 28, 1 ] = ascii (fp) : "./hrtfs/elev50/L50e355a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e355a.dat right
+[ 28, 2 ] = ascii (fp) : "./hrtfs/elev50/L50e350a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e350a.dat right
+[ 28, 3 ] = ascii (fp) : "./hrtfs/elev50/L50e345a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e345a.dat right
+[ 28, 4 ] = ascii (fp) : "./hrtfs/elev50/L50e340a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e340a.dat right
+[ 28, 5 ] = ascii (fp) : "./hrtfs/elev50/L50e335a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e335a.dat right
+[ 28, 6 ] = ascii (fp) : "./hrtfs/elev50/L50e330a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e330a.dat right
+[ 28, 7 ] = ascii (fp) : "./hrtfs/elev50/L50e325a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e325a.dat right
+[ 28, 8 ] = ascii (fp) : "./hrtfs/elev50/L50e320a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e320a.dat right
+[ 28, 9 ] = ascii (fp) : "./hrtfs/elev50/L50e315a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e315a.dat right
+[ 28, 10 ] = ascii (fp) : "./hrtfs/elev50/L50e310a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e310a.dat right
+[ 28, 11 ] = ascii (fp) : "./hrtfs/elev50/L50e305a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e305a.dat right
+[ 28, 12 ] = ascii (fp) : "./hrtfs/elev50/L50e300a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e300a.dat right
+[ 28, 13 ] = ascii (fp) : "./hrtfs/elev50/L50e295a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e295a.dat right
+[ 28, 14 ] = ascii (fp) : "./hrtfs/elev50/L50e290a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e290a.dat right
+[ 28, 15 ] = ascii (fp) : "./hrtfs/elev50/L50e285a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e285a.dat right
+[ 28, 16 ] = ascii (fp) : "./hrtfs/elev50/L50e280a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e280a.dat right
+[ 28, 17 ] = ascii (fp) : "./hrtfs/elev50/L50e275a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e275a.dat right
+[ 28, 18 ] = ascii (fp) : "./hrtfs/elev50/L50e270a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e270a.dat right
+[ 28, 19 ] = ascii (fp) : "./hrtfs/elev50/L50e265a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e265a.dat right
+[ 28, 20 ] = ascii (fp) : "./hrtfs/elev50/L50e260a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e260a.dat right
+[ 28, 21 ] = ascii (fp) : "./hrtfs/elev50/L50e255a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e255a.dat right
+[ 28, 22 ] = ascii (fp) : "./hrtfs/elev50/L50e250a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e250a.dat right
+[ 28, 23 ] = ascii (fp) : "./hrtfs/elev50/L50e245a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e245a.dat right
+[ 28, 24 ] = ascii (fp) : "./hrtfs/elev50/L50e240a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e240a.dat right
+[ 28, 25 ] = ascii (fp) : "./hrtfs/elev50/L50e235a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e235a.dat right
+[ 28, 26 ] = ascii (fp) : "./hrtfs/elev50/L50e230a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e230a.dat right
+[ 28, 27 ] = ascii (fp) : "./hrtfs/elev50/L50e225a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e225a.dat right
+[ 28, 28 ] = ascii (fp) : "./hrtfs/elev50/L50e220a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e220a.dat right
+[ 28, 29 ] = ascii (fp) : "./hrtfs/elev50/L50e215a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e215a.dat right
+[ 28, 30 ] = ascii (fp) : "./hrtfs/elev50/L50e210a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e210a.dat right
+[ 28, 31 ] = ascii (fp) : "./hrtfs/elev50/L50e205a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e205a.dat right
+[ 28, 32 ] = ascii (fp) : "./hrtfs/elev50/L50e200a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e200a.dat right
+[ 28, 33 ] = ascii (fp) : "./hrtfs/elev50/L50e195a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e195a.dat right
+[ 28, 34 ] = ascii (fp) : "./hrtfs/elev50/L50e190a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e190a.dat right
+[ 28, 35 ] = ascii (fp) : "./hrtfs/elev50/L50e185a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e185a.dat right
+[ 28, 36 ] = ascii (fp) : "./hrtfs/elev50/L50e180a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e180a.dat right
+[ 28, 37 ] = ascii (fp) : "./hrtfs/elev50/L50e175a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e175a.dat right
+[ 28, 38 ] = ascii (fp) : "./hrtfs/elev50/L50e170a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e170a.dat right
+[ 28, 39 ] = ascii (fp) : "./hrtfs/elev50/L50e165a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e165a.dat right
+[ 28, 40 ] = ascii (fp) : "./hrtfs/elev50/L50e160a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e160a.dat right
+[ 28, 41 ] = ascii (fp) : "./hrtfs/elev50/L50e155a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e155a.dat right
+[ 28, 42 ] = ascii (fp) : "./hrtfs/elev50/L50e150a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e150a.dat right
+[ 28, 43 ] = ascii (fp) : "./hrtfs/elev50/L50e145a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e145a.dat right
+[ 28, 44 ] = ascii (fp) : "./hrtfs/elev50/L50e140a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e140a.dat right
+[ 28, 45 ] = ascii (fp) : "./hrtfs/elev50/L50e135a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e135a.dat right
+[ 28, 46 ] = ascii (fp) : "./hrtfs/elev50/L50e130a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e130a.dat right
+[ 28, 47 ] = ascii (fp) : "./hrtfs/elev50/L50e125a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e125a.dat right
+[ 28, 48 ] = ascii (fp) : "./hrtfs/elev50/L50e120a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e120a.dat right
+[ 28, 49 ] = ascii (fp) : "./hrtfs/elev50/L50e115a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e115a.dat right
+[ 28, 50 ] = ascii (fp) : "./hrtfs/elev50/L50e110a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e110a.dat right
+[ 28, 51 ] = ascii (fp) : "./hrtfs/elev50/L50e105a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e105a.dat right
+[ 28, 52 ] = ascii (fp) : "./hrtfs/elev50/L50e100a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e100a.dat right
+[ 28, 53 ] = ascii (fp) : "./hrtfs/elev50/L50e095a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e095a.dat right
+[ 28, 54 ] = ascii (fp) : "./hrtfs/elev50/L50e090a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e090a.dat right
+[ 28, 55 ] = ascii (fp) : "./hrtfs/elev50/L50e085a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e085a.dat right
+[ 28, 56 ] = ascii (fp) : "./hrtfs/elev50/L50e080a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e080a.dat right
+[ 28, 57 ] = ascii (fp) : "./hrtfs/elev50/L50e075a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e075a.dat right
+[ 28, 58 ] = ascii (fp) : "./hrtfs/elev50/L50e070a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e070a.dat right
+[ 28, 59 ] = ascii (fp) : "./hrtfs/elev50/L50e065a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e065a.dat right
+[ 28, 60 ] = ascii (fp) : "./hrtfs/elev50/L50e060a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e060a.dat right
+[ 28, 61 ] = ascii (fp) : "./hrtfs/elev50/L50e055a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e055a.dat right
+[ 28, 62 ] = ascii (fp) : "./hrtfs/elev50/L50e050a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e050a.dat right
+[ 28, 63 ] = ascii (fp) : "./hrtfs/elev50/L50e045a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e045a.dat right
+[ 28, 64 ] = ascii (fp) : "./hrtfs/elev50/L50e040a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e040a.dat right
+[ 28, 65 ] = ascii (fp) : "./hrtfs/elev50/L50e035a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e035a.dat right
+[ 28, 66 ] = ascii (fp) : "./hrtfs/elev50/L50e030a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e030a.dat right
+[ 28, 67 ] = ascii (fp) : "./hrtfs/elev50/L50e025a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e025a.dat right
+[ 28, 68 ] = ascii (fp) : "./hrtfs/elev50/L50e020a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e020a.dat right
+[ 28, 69 ] = ascii (fp) : "./hrtfs/elev50/L50e015a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e015a.dat right
+[ 28, 70 ] = ascii (fp) : "./hrtfs/elev50/L50e010a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e010a.dat right
+[ 28, 71 ] = ascii (fp) : "./hrtfs/elev50/L50e005a.dat left
+ + ascii (fp) : "./hrtfs/elev50/R50e005a.dat right
-[ 29, 0 ] = ascii (fp) : "./hrtfs/elev55/L55e000a.dat"
-[ 29, 1 ] = ascii (fp) : "./hrtfs/elev55/L55e355a.dat"
-[ 29, 2 ] = ascii (fp) : "./hrtfs/elev55/L55e350a.dat"
-[ 29, 3 ] = ascii (fp) : "./hrtfs/elev55/L55e345a.dat"
-[ 29, 4 ] = ascii (fp) : "./hrtfs/elev55/L55e340a.dat"
-[ 29, 5 ] = ascii (fp) : "./hrtfs/elev55/L55e335a.dat"
-[ 29, 6 ] = ascii (fp) : "./hrtfs/elev55/L55e330a.dat"
-[ 29, 7 ] = ascii (fp) : "./hrtfs/elev55/L55e325a.dat"
-[ 29, 8 ] = ascii (fp) : "./hrtfs/elev55/L55e320a.dat"
-[ 29, 9 ] = ascii (fp) : "./hrtfs/elev55/L55e315a.dat"
-[ 29, 10 ] = ascii (fp) : "./hrtfs/elev55/L55e310a.dat"
-[ 29, 11 ] = ascii (fp) : "./hrtfs/elev55/L55e305a.dat"
-[ 29, 12 ] = ascii (fp) : "./hrtfs/elev55/L55e300a.dat"
-[ 29, 13 ] = ascii (fp) : "./hrtfs/elev55/L55e295a.dat"
-[ 29, 14 ] = ascii (fp) : "./hrtfs/elev55/L55e290a.dat"
-[ 29, 15 ] = ascii (fp) : "./hrtfs/elev55/L55e285a.dat"
-[ 29, 16 ] = ascii (fp) : "./hrtfs/elev55/L55e280a.dat"
-[ 29, 17 ] = ascii (fp) : "./hrtfs/elev55/L55e275a.dat"
-[ 29, 18 ] = ascii (fp) : "./hrtfs/elev55/L55e270a.dat"
-[ 29, 19 ] = ascii (fp) : "./hrtfs/elev55/L55e265a.dat"
-[ 29, 20 ] = ascii (fp) : "./hrtfs/elev55/L55e260a.dat"
-[ 29, 21 ] = ascii (fp) : "./hrtfs/elev55/L55e255a.dat"
-[ 29, 22 ] = ascii (fp) : "./hrtfs/elev55/L55e250a.dat"
-[ 29, 23 ] = ascii (fp) : "./hrtfs/elev55/L55e245a.dat"
-[ 29, 24 ] = ascii (fp) : "./hrtfs/elev55/L55e240a.dat"
-[ 29, 25 ] = ascii (fp) : "./hrtfs/elev55/L55e235a.dat"
-[ 29, 26 ] = ascii (fp) : "./hrtfs/elev55/L55e230a.dat"
-[ 29, 27 ] = ascii (fp) : "./hrtfs/elev55/L55e225a.dat"
-[ 29, 28 ] = ascii (fp) : "./hrtfs/elev55/L55e220a.dat"
-[ 29, 29 ] = ascii (fp) : "./hrtfs/elev55/L55e215a.dat"
-[ 29, 30 ] = ascii (fp) : "./hrtfs/elev55/L55e210a.dat"
-[ 29, 31 ] = ascii (fp) : "./hrtfs/elev55/L55e205a.dat"
-[ 29, 32 ] = ascii (fp) : "./hrtfs/elev55/L55e200a.dat"
-[ 29, 33 ] = ascii (fp) : "./hrtfs/elev55/L55e195a.dat"
-[ 29, 34 ] = ascii (fp) : "./hrtfs/elev55/L55e190a.dat"
-[ 29, 35 ] = ascii (fp) : "./hrtfs/elev55/L55e185a.dat"
-[ 29, 36 ] = ascii (fp) : "./hrtfs/elev55/L55e180a.dat"
-[ 29, 37 ] = ascii (fp) : "./hrtfs/elev55/L55e175a.dat"
-[ 29, 38 ] = ascii (fp) : "./hrtfs/elev55/L55e170a.dat"
-[ 29, 39 ] = ascii (fp) : "./hrtfs/elev55/L55e165a.dat"
-[ 29, 40 ] = ascii (fp) : "./hrtfs/elev55/L55e160a.dat"
-[ 29, 41 ] = ascii (fp) : "./hrtfs/elev55/L55e155a.dat"
-[ 29, 42 ] = ascii (fp) : "./hrtfs/elev55/L55e150a.dat"
-[ 29, 43 ] = ascii (fp) : "./hrtfs/elev55/L55e145a.dat"
-[ 29, 44 ] = ascii (fp) : "./hrtfs/elev55/L55e140a.dat"
-[ 29, 45 ] = ascii (fp) : "./hrtfs/elev55/L55e135a.dat"
-[ 29, 46 ] = ascii (fp) : "./hrtfs/elev55/L55e130a.dat"
-[ 29, 47 ] = ascii (fp) : "./hrtfs/elev55/L55e125a.dat"
-[ 29, 48 ] = ascii (fp) : "./hrtfs/elev55/L55e120a.dat"
-[ 29, 49 ] = ascii (fp) : "./hrtfs/elev55/L55e115a.dat"
-[ 29, 50 ] = ascii (fp) : "./hrtfs/elev55/L55e110a.dat"
-[ 29, 51 ] = ascii (fp) : "./hrtfs/elev55/L55e105a.dat"
-[ 29, 52 ] = ascii (fp) : "./hrtfs/elev55/L55e100a.dat"
-[ 29, 53 ] = ascii (fp) : "./hrtfs/elev55/L55e095a.dat"
-[ 29, 54 ] = ascii (fp) : "./hrtfs/elev55/L55e090a.dat"
-[ 29, 55 ] = ascii (fp) : "./hrtfs/elev55/L55e085a.dat"
-[ 29, 56 ] = ascii (fp) : "./hrtfs/elev55/L55e080a.dat"
-[ 29, 57 ] = ascii (fp) : "./hrtfs/elev55/L55e075a.dat"
-[ 29, 58 ] = ascii (fp) : "./hrtfs/elev55/L55e070a.dat"
-[ 29, 59 ] = ascii (fp) : "./hrtfs/elev55/L55e065a.dat"
-[ 29, 60 ] = ascii (fp) : "./hrtfs/elev55/L55e060a.dat"
-[ 29, 61 ] = ascii (fp) : "./hrtfs/elev55/L55e055a.dat"
-[ 29, 62 ] = ascii (fp) : "./hrtfs/elev55/L55e050a.dat"
-[ 29, 63 ] = ascii (fp) : "./hrtfs/elev55/L55e045a.dat"
-[ 29, 64 ] = ascii (fp) : "./hrtfs/elev55/L55e040a.dat"
-[ 29, 65 ] = ascii (fp) : "./hrtfs/elev55/L55e035a.dat"
-[ 29, 66 ] = ascii (fp) : "./hrtfs/elev55/L55e030a.dat"
-[ 29, 67 ] = ascii (fp) : "./hrtfs/elev55/L55e025a.dat"
-[ 29, 68 ] = ascii (fp) : "./hrtfs/elev55/L55e020a.dat"
-[ 29, 69 ] = ascii (fp) : "./hrtfs/elev55/L55e015a.dat"
-[ 29, 70 ] = ascii (fp) : "./hrtfs/elev55/L55e010a.dat"
-[ 29, 71 ] = ascii (fp) : "./hrtfs/elev55/L55e005a.dat"
+[ 29, 0 ] = ascii (fp) : "./hrtfs/elev55/L55e000a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e000a.dat right
+[ 29, 1 ] = ascii (fp) : "./hrtfs/elev55/L55e355a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e355a.dat right
+[ 29, 2 ] = ascii (fp) : "./hrtfs/elev55/L55e350a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e350a.dat right
+[ 29, 3 ] = ascii (fp) : "./hrtfs/elev55/L55e345a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e345a.dat right
+[ 29, 4 ] = ascii (fp) : "./hrtfs/elev55/L55e340a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e340a.dat right
+[ 29, 5 ] = ascii (fp) : "./hrtfs/elev55/L55e335a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e335a.dat right
+[ 29, 6 ] = ascii (fp) : "./hrtfs/elev55/L55e330a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e330a.dat right
+[ 29, 7 ] = ascii (fp) : "./hrtfs/elev55/L55e325a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e325a.dat right
+[ 29, 8 ] = ascii (fp) : "./hrtfs/elev55/L55e320a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e320a.dat right
+[ 29, 9 ] = ascii (fp) : "./hrtfs/elev55/L55e315a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e315a.dat right
+[ 29, 10 ] = ascii (fp) : "./hrtfs/elev55/L55e310a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e310a.dat right
+[ 29, 11 ] = ascii (fp) : "./hrtfs/elev55/L55e305a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e305a.dat right
+[ 29, 12 ] = ascii (fp) : "./hrtfs/elev55/L55e300a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e300a.dat right
+[ 29, 13 ] = ascii (fp) : "./hrtfs/elev55/L55e295a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e295a.dat right
+[ 29, 14 ] = ascii (fp) : "./hrtfs/elev55/L55e290a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e290a.dat right
+[ 29, 15 ] = ascii (fp) : "./hrtfs/elev55/L55e285a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e285a.dat right
+[ 29, 16 ] = ascii (fp) : "./hrtfs/elev55/L55e280a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e280a.dat right
+[ 29, 17 ] = ascii (fp) : "./hrtfs/elev55/L55e275a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e275a.dat right
+[ 29, 18 ] = ascii (fp) : "./hrtfs/elev55/L55e270a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e270a.dat right
+[ 29, 19 ] = ascii (fp) : "./hrtfs/elev55/L55e265a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e265a.dat right
+[ 29, 20 ] = ascii (fp) : "./hrtfs/elev55/L55e260a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e260a.dat right
+[ 29, 21 ] = ascii (fp) : "./hrtfs/elev55/L55e255a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e255a.dat right
+[ 29, 22 ] = ascii (fp) : "./hrtfs/elev55/L55e250a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e250a.dat right
+[ 29, 23 ] = ascii (fp) : "./hrtfs/elev55/L55e245a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e245a.dat right
+[ 29, 24 ] = ascii (fp) : "./hrtfs/elev55/L55e240a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e240a.dat right
+[ 29, 25 ] = ascii (fp) : "./hrtfs/elev55/L55e235a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e235a.dat right
+[ 29, 26 ] = ascii (fp) : "./hrtfs/elev55/L55e230a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e230a.dat right
+[ 29, 27 ] = ascii (fp) : "./hrtfs/elev55/L55e225a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e225a.dat right
+[ 29, 28 ] = ascii (fp) : "./hrtfs/elev55/L55e220a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e220a.dat right
+[ 29, 29 ] = ascii (fp) : "./hrtfs/elev55/L55e215a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e215a.dat right
+[ 29, 30 ] = ascii (fp) : "./hrtfs/elev55/L55e210a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e210a.dat right
+[ 29, 31 ] = ascii (fp) : "./hrtfs/elev55/L55e205a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e205a.dat right
+[ 29, 32 ] = ascii (fp) : "./hrtfs/elev55/L55e200a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e200a.dat right
+[ 29, 33 ] = ascii (fp) : "./hrtfs/elev55/L55e195a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e195a.dat right
+[ 29, 34 ] = ascii (fp) : "./hrtfs/elev55/L55e190a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e190a.dat right
+[ 29, 35 ] = ascii (fp) : "./hrtfs/elev55/L55e185a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e185a.dat right
+[ 29, 36 ] = ascii (fp) : "./hrtfs/elev55/L55e180a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e180a.dat right
+[ 29, 37 ] = ascii (fp) : "./hrtfs/elev55/L55e175a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e175a.dat right
+[ 29, 38 ] = ascii (fp) : "./hrtfs/elev55/L55e170a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e170a.dat right
+[ 29, 39 ] = ascii (fp) : "./hrtfs/elev55/L55e165a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e165a.dat right
+[ 29, 40 ] = ascii (fp) : "./hrtfs/elev55/L55e160a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e160a.dat right
+[ 29, 41 ] = ascii (fp) : "./hrtfs/elev55/L55e155a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e155a.dat right
+[ 29, 42 ] = ascii (fp) : "./hrtfs/elev55/L55e150a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e150a.dat right
+[ 29, 43 ] = ascii (fp) : "./hrtfs/elev55/L55e145a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e145a.dat right
+[ 29, 44 ] = ascii (fp) : "./hrtfs/elev55/L55e140a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e140a.dat right
+[ 29, 45 ] = ascii (fp) : "./hrtfs/elev55/L55e135a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e135a.dat right
+[ 29, 46 ] = ascii (fp) : "./hrtfs/elev55/L55e130a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e130a.dat right
+[ 29, 47 ] = ascii (fp) : "./hrtfs/elev55/L55e125a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e125a.dat right
+[ 29, 48 ] = ascii (fp) : "./hrtfs/elev55/L55e120a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e120a.dat right
+[ 29, 49 ] = ascii (fp) : "./hrtfs/elev55/L55e115a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e115a.dat right
+[ 29, 50 ] = ascii (fp) : "./hrtfs/elev55/L55e110a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e110a.dat right
+[ 29, 51 ] = ascii (fp) : "./hrtfs/elev55/L55e105a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e105a.dat right
+[ 29, 52 ] = ascii (fp) : "./hrtfs/elev55/L55e100a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e100a.dat right
+[ 29, 53 ] = ascii (fp) : "./hrtfs/elev55/L55e095a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e095a.dat right
+[ 29, 54 ] = ascii (fp) : "./hrtfs/elev55/L55e090a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e090a.dat right
+[ 29, 55 ] = ascii (fp) : "./hrtfs/elev55/L55e085a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e085a.dat right
+[ 29, 56 ] = ascii (fp) : "./hrtfs/elev55/L55e080a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e080a.dat right
+[ 29, 57 ] = ascii (fp) : "./hrtfs/elev55/L55e075a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e075a.dat right
+[ 29, 58 ] = ascii (fp) : "./hrtfs/elev55/L55e070a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e070a.dat right
+[ 29, 59 ] = ascii (fp) : "./hrtfs/elev55/L55e065a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e065a.dat right
+[ 29, 60 ] = ascii (fp) : "./hrtfs/elev55/L55e060a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e060a.dat right
+[ 29, 61 ] = ascii (fp) : "./hrtfs/elev55/L55e055a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e055a.dat right
+[ 29, 62 ] = ascii (fp) : "./hrtfs/elev55/L55e050a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e050a.dat right
+[ 29, 63 ] = ascii (fp) : "./hrtfs/elev55/L55e045a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e045a.dat right
+[ 29, 64 ] = ascii (fp) : "./hrtfs/elev55/L55e040a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e040a.dat right
+[ 29, 65 ] = ascii (fp) : "./hrtfs/elev55/L55e035a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e035a.dat right
+[ 29, 66 ] = ascii (fp) : "./hrtfs/elev55/L55e030a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e030a.dat right
+[ 29, 67 ] = ascii (fp) : "./hrtfs/elev55/L55e025a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e025a.dat right
+[ 29, 68 ] = ascii (fp) : "./hrtfs/elev55/L55e020a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e020a.dat right
+[ 29, 69 ] = ascii (fp) : "./hrtfs/elev55/L55e015a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e015a.dat right
+[ 29, 70 ] = ascii (fp) : "./hrtfs/elev55/L55e010a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e010a.dat right
+[ 29, 71 ] = ascii (fp) : "./hrtfs/elev55/L55e005a.dat left
+ + ascii (fp) : "./hrtfs/elev55/R55e005a.dat right
-[ 30, 0 ] = ascii (fp) : "./hrtfs/elev60/L60e000a.dat"
-[ 30, 1 ] = ascii (fp) : "./hrtfs/elev60/L60e355a.dat"
-[ 30, 2 ] = ascii (fp) : "./hrtfs/elev60/L60e350a.dat"
-[ 30, 3 ] = ascii (fp) : "./hrtfs/elev60/L60e345a.dat"
-[ 30, 4 ] = ascii (fp) : "./hrtfs/elev60/L60e340a.dat"
-[ 30, 5 ] = ascii (fp) : "./hrtfs/elev60/L60e335a.dat"
-[ 30, 6 ] = ascii (fp) : "./hrtfs/elev60/L60e330a.dat"
-[ 30, 7 ] = ascii (fp) : "./hrtfs/elev60/L60e325a.dat"
-[ 30, 8 ] = ascii (fp) : "./hrtfs/elev60/L60e320a.dat"
-[ 30, 9 ] = ascii (fp) : "./hrtfs/elev60/L60e315a.dat"
-[ 30, 10 ] = ascii (fp) : "./hrtfs/elev60/L60e310a.dat"
-[ 30, 11 ] = ascii (fp) : "./hrtfs/elev60/L60e305a.dat"
-[ 30, 12 ] = ascii (fp) : "./hrtfs/elev60/L60e300a.dat"
-[ 30, 13 ] = ascii (fp) : "./hrtfs/elev60/L60e295a.dat"
-[ 30, 14 ] = ascii (fp) : "./hrtfs/elev60/L60e290a.dat"
-[ 30, 15 ] = ascii (fp) : "./hrtfs/elev60/L60e285a.dat"
-[ 30, 16 ] = ascii (fp) : "./hrtfs/elev60/L60e280a.dat"
-[ 30, 17 ] = ascii (fp) : "./hrtfs/elev60/L60e275a.dat"
-[ 30, 18 ] = ascii (fp) : "./hrtfs/elev60/L60e270a.dat"
-[ 30, 19 ] = ascii (fp) : "./hrtfs/elev60/L60e265a.dat"
-[ 30, 20 ] = ascii (fp) : "./hrtfs/elev60/L60e260a.dat"
-[ 30, 21 ] = ascii (fp) : "./hrtfs/elev60/L60e255a.dat"
-[ 30, 22 ] = ascii (fp) : "./hrtfs/elev60/L60e250a.dat"
-[ 30, 23 ] = ascii (fp) : "./hrtfs/elev60/L60e245a.dat"
-[ 30, 24 ] = ascii (fp) : "./hrtfs/elev60/L60e240a.dat"
-[ 30, 25 ] = ascii (fp) : "./hrtfs/elev60/L60e235a.dat"
-[ 30, 26 ] = ascii (fp) : "./hrtfs/elev60/L60e230a.dat"
-[ 30, 27 ] = ascii (fp) : "./hrtfs/elev60/L60e225a.dat"
-[ 30, 28 ] = ascii (fp) : "./hrtfs/elev60/L60e220a.dat"
-[ 30, 29 ] = ascii (fp) : "./hrtfs/elev60/L60e215a.dat"
-[ 30, 30 ] = ascii (fp) : "./hrtfs/elev60/L60e210a.dat"
-[ 30, 31 ] = ascii (fp) : "./hrtfs/elev60/L60e205a.dat"
-[ 30, 32 ] = ascii (fp) : "./hrtfs/elev60/L60e200a.dat"
-[ 30, 33 ] = ascii (fp) : "./hrtfs/elev60/L60e195a.dat"
-[ 30, 34 ] = ascii (fp) : "./hrtfs/elev60/L60e190a.dat"
-[ 30, 35 ] = ascii (fp) : "./hrtfs/elev60/L60e185a.dat"
-[ 30, 36 ] = ascii (fp) : "./hrtfs/elev60/L60e180a.dat"
-[ 30, 37 ] = ascii (fp) : "./hrtfs/elev60/L60e175a.dat"
-[ 30, 38 ] = ascii (fp) : "./hrtfs/elev60/L60e170a.dat"
-[ 30, 39 ] = ascii (fp) : "./hrtfs/elev60/L60e165a.dat"
-[ 30, 40 ] = ascii (fp) : "./hrtfs/elev60/L60e160a.dat"
-[ 30, 41 ] = ascii (fp) : "./hrtfs/elev60/L60e155a.dat"
-[ 30, 42 ] = ascii (fp) : "./hrtfs/elev60/L60e150a.dat"
-[ 30, 43 ] = ascii (fp) : "./hrtfs/elev60/L60e145a.dat"
-[ 30, 44 ] = ascii (fp) : "./hrtfs/elev60/L60e140a.dat"
-[ 30, 45 ] = ascii (fp) : "./hrtfs/elev60/L60e135a.dat"
-[ 30, 46 ] = ascii (fp) : "./hrtfs/elev60/L60e130a.dat"
-[ 30, 47 ] = ascii (fp) : "./hrtfs/elev60/L60e125a.dat"
-[ 30, 48 ] = ascii (fp) : "./hrtfs/elev60/L60e120a.dat"
-[ 30, 49 ] = ascii (fp) : "./hrtfs/elev60/L60e115a.dat"
-[ 30, 50 ] = ascii (fp) : "./hrtfs/elev60/L60e110a.dat"
-[ 30, 51 ] = ascii (fp) : "./hrtfs/elev60/L60e105a.dat"
-[ 30, 52 ] = ascii (fp) : "./hrtfs/elev60/L60e100a.dat"
-[ 30, 53 ] = ascii (fp) : "./hrtfs/elev60/L60e095a.dat"
-[ 30, 54 ] = ascii (fp) : "./hrtfs/elev60/L60e090a.dat"
-[ 30, 55 ] = ascii (fp) : "./hrtfs/elev60/L60e085a.dat"
-[ 30, 56 ] = ascii (fp) : "./hrtfs/elev60/L60e080a.dat"
-[ 30, 57 ] = ascii (fp) : "./hrtfs/elev60/L60e075a.dat"
-[ 30, 58 ] = ascii (fp) : "./hrtfs/elev60/L60e070a.dat"
-[ 30, 59 ] = ascii (fp) : "./hrtfs/elev60/L60e065a.dat"
-[ 30, 60 ] = ascii (fp) : "./hrtfs/elev60/L60e060a.dat"
-[ 30, 61 ] = ascii (fp) : "./hrtfs/elev60/L60e055a.dat"
-[ 30, 62 ] = ascii (fp) : "./hrtfs/elev60/L60e050a.dat"
-[ 30, 63 ] = ascii (fp) : "./hrtfs/elev60/L60e045a.dat"
-[ 30, 64 ] = ascii (fp) : "./hrtfs/elev60/L60e040a.dat"
-[ 30, 65 ] = ascii (fp) : "./hrtfs/elev60/L60e035a.dat"
-[ 30, 66 ] = ascii (fp) : "./hrtfs/elev60/L60e030a.dat"
-[ 30, 67 ] = ascii (fp) : "./hrtfs/elev60/L60e025a.dat"
-[ 30, 68 ] = ascii (fp) : "./hrtfs/elev60/L60e020a.dat"
-[ 30, 69 ] = ascii (fp) : "./hrtfs/elev60/L60e015a.dat"
-[ 30, 70 ] = ascii (fp) : "./hrtfs/elev60/L60e010a.dat"
-[ 30, 71 ] = ascii (fp) : "./hrtfs/elev60/L60e005a.dat"
+[ 30, 0 ] = ascii (fp) : "./hrtfs/elev60/L60e000a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e000a.dat right
+[ 30, 1 ] = ascii (fp) : "./hrtfs/elev60/L60e355a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e355a.dat right
+[ 30, 2 ] = ascii (fp) : "./hrtfs/elev60/L60e350a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e350a.dat right
+[ 30, 3 ] = ascii (fp) : "./hrtfs/elev60/L60e345a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e345a.dat right
+[ 30, 4 ] = ascii (fp) : "./hrtfs/elev60/L60e340a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e340a.dat right
+[ 30, 5 ] = ascii (fp) : "./hrtfs/elev60/L60e335a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e335a.dat right
+[ 30, 6 ] = ascii (fp) : "./hrtfs/elev60/L60e330a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e330a.dat right
+[ 30, 7 ] = ascii (fp) : "./hrtfs/elev60/L60e325a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e325a.dat right
+[ 30, 8 ] = ascii (fp) : "./hrtfs/elev60/L60e320a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e320a.dat right
+[ 30, 9 ] = ascii (fp) : "./hrtfs/elev60/L60e315a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e315a.dat right
+[ 30, 10 ] = ascii (fp) : "./hrtfs/elev60/L60e310a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e310a.dat right
+[ 30, 11 ] = ascii (fp) : "./hrtfs/elev60/L60e305a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e305a.dat right
+[ 30, 12 ] = ascii (fp) : "./hrtfs/elev60/L60e300a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e300a.dat right
+[ 30, 13 ] = ascii (fp) : "./hrtfs/elev60/L60e295a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e295a.dat right
+[ 30, 14 ] = ascii (fp) : "./hrtfs/elev60/L60e290a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e290a.dat right
+[ 30, 15 ] = ascii (fp) : "./hrtfs/elev60/L60e285a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e285a.dat right
+[ 30, 16 ] = ascii (fp) : "./hrtfs/elev60/L60e280a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e280a.dat right
+[ 30, 17 ] = ascii (fp) : "./hrtfs/elev60/L60e275a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e275a.dat right
+[ 30, 18 ] = ascii (fp) : "./hrtfs/elev60/L60e270a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e270a.dat right
+[ 30, 19 ] = ascii (fp) : "./hrtfs/elev60/L60e265a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e265a.dat right
+[ 30, 20 ] = ascii (fp) : "./hrtfs/elev60/L60e260a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e260a.dat right
+[ 30, 21 ] = ascii (fp) : "./hrtfs/elev60/L60e255a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e255a.dat right
+[ 30, 22 ] = ascii (fp) : "./hrtfs/elev60/L60e250a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e250a.dat right
+[ 30, 23 ] = ascii (fp) : "./hrtfs/elev60/L60e245a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e245a.dat right
+[ 30, 24 ] = ascii (fp) : "./hrtfs/elev60/L60e240a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e240a.dat right
+[ 30, 25 ] = ascii (fp) : "./hrtfs/elev60/L60e235a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e235a.dat right
+[ 30, 26 ] = ascii (fp) : "./hrtfs/elev60/L60e230a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e230a.dat right
+[ 30, 27 ] = ascii (fp) : "./hrtfs/elev60/L60e225a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e225a.dat right
+[ 30, 28 ] = ascii (fp) : "./hrtfs/elev60/L60e220a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e220a.dat right
+[ 30, 29 ] = ascii (fp) : "./hrtfs/elev60/L60e215a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e215a.dat right
+[ 30, 30 ] = ascii (fp) : "./hrtfs/elev60/L60e210a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e210a.dat right
+[ 30, 31 ] = ascii (fp) : "./hrtfs/elev60/L60e205a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e205a.dat right
+[ 30, 32 ] = ascii (fp) : "./hrtfs/elev60/L60e200a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e200a.dat right
+[ 30, 33 ] = ascii (fp) : "./hrtfs/elev60/L60e195a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e195a.dat right
+[ 30, 34 ] = ascii (fp) : "./hrtfs/elev60/L60e190a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e190a.dat right
+[ 30, 35 ] = ascii (fp) : "./hrtfs/elev60/L60e185a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e185a.dat right
+[ 30, 36 ] = ascii (fp) : "./hrtfs/elev60/L60e180a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e180a.dat right
+[ 30, 37 ] = ascii (fp) : "./hrtfs/elev60/L60e175a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e175a.dat right
+[ 30, 38 ] = ascii (fp) : "./hrtfs/elev60/L60e170a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e170a.dat right
+[ 30, 39 ] = ascii (fp) : "./hrtfs/elev60/L60e165a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e165a.dat right
+[ 30, 40 ] = ascii (fp) : "./hrtfs/elev60/L60e160a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e160a.dat right
+[ 30, 41 ] = ascii (fp) : "./hrtfs/elev60/L60e155a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e155a.dat right
+[ 30, 42 ] = ascii (fp) : "./hrtfs/elev60/L60e150a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e150a.dat right
+[ 30, 43 ] = ascii (fp) : "./hrtfs/elev60/L60e145a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e145a.dat right
+[ 30, 44 ] = ascii (fp) : "./hrtfs/elev60/L60e140a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e140a.dat right
+[ 30, 45 ] = ascii (fp) : "./hrtfs/elev60/L60e135a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e135a.dat right
+[ 30, 46 ] = ascii (fp) : "./hrtfs/elev60/L60e130a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e130a.dat right
+[ 30, 47 ] = ascii (fp) : "./hrtfs/elev60/L60e125a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e125a.dat right
+[ 30, 48 ] = ascii (fp) : "./hrtfs/elev60/L60e120a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e120a.dat right
+[ 30, 49 ] = ascii (fp) : "./hrtfs/elev60/L60e115a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e115a.dat right
+[ 30, 50 ] = ascii (fp) : "./hrtfs/elev60/L60e110a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e110a.dat right
+[ 30, 51 ] = ascii (fp) : "./hrtfs/elev60/L60e105a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e105a.dat right
+[ 30, 52 ] = ascii (fp) : "./hrtfs/elev60/L60e100a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e100a.dat right
+[ 30, 53 ] = ascii (fp) : "./hrtfs/elev60/L60e095a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e095a.dat right
+[ 30, 54 ] = ascii (fp) : "./hrtfs/elev60/L60e090a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e090a.dat right
+[ 30, 55 ] = ascii (fp) : "./hrtfs/elev60/L60e085a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e085a.dat right
+[ 30, 56 ] = ascii (fp) : "./hrtfs/elev60/L60e080a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e080a.dat right
+[ 30, 57 ] = ascii (fp) : "./hrtfs/elev60/L60e075a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e075a.dat right
+[ 30, 58 ] = ascii (fp) : "./hrtfs/elev60/L60e070a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e070a.dat right
+[ 30, 59 ] = ascii (fp) : "./hrtfs/elev60/L60e065a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e065a.dat right
+[ 30, 60 ] = ascii (fp) : "./hrtfs/elev60/L60e060a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e060a.dat right
+[ 30, 61 ] = ascii (fp) : "./hrtfs/elev60/L60e055a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e055a.dat right
+[ 30, 62 ] = ascii (fp) : "./hrtfs/elev60/L60e050a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e050a.dat right
+[ 30, 63 ] = ascii (fp) : "./hrtfs/elev60/L60e045a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e045a.dat right
+[ 30, 64 ] = ascii (fp) : "./hrtfs/elev60/L60e040a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e040a.dat right
+[ 30, 65 ] = ascii (fp) : "./hrtfs/elev60/L60e035a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e035a.dat right
+[ 30, 66 ] = ascii (fp) : "./hrtfs/elev60/L60e030a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e030a.dat right
+[ 30, 67 ] = ascii (fp) : "./hrtfs/elev60/L60e025a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e025a.dat right
+[ 30, 68 ] = ascii (fp) : "./hrtfs/elev60/L60e020a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e020a.dat right
+[ 30, 69 ] = ascii (fp) : "./hrtfs/elev60/L60e015a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e015a.dat right
+[ 30, 70 ] = ascii (fp) : "./hrtfs/elev60/L60e010a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e010a.dat right
+[ 30, 71 ] = ascii (fp) : "./hrtfs/elev60/L60e005a.dat left
+ + ascii (fp) : "./hrtfs/elev60/R60e005a.dat right
-[ 31, 0 ] = ascii (fp) : "./hrtfs/elev65/L65e000a.dat"
-[ 31, 1 ] = ascii (fp) : "./hrtfs/elev65/L65e355a.dat"
-[ 31, 2 ] = ascii (fp) : "./hrtfs/elev65/L65e350a.dat"
-[ 31, 3 ] = ascii (fp) : "./hrtfs/elev65/L65e345a.dat"
-[ 31, 4 ] = ascii (fp) : "./hrtfs/elev65/L65e340a.dat"
-[ 31, 5 ] = ascii (fp) : "./hrtfs/elev65/L65e335a.dat"
-[ 31, 6 ] = ascii (fp) : "./hrtfs/elev65/L65e330a.dat"
-[ 31, 7 ] = ascii (fp) : "./hrtfs/elev65/L65e325a.dat"
-[ 31, 8 ] = ascii (fp) : "./hrtfs/elev65/L65e320a.dat"
-[ 31, 9 ] = ascii (fp) : "./hrtfs/elev65/L65e315a.dat"
-[ 31, 10 ] = ascii (fp) : "./hrtfs/elev65/L65e310a.dat"
-[ 31, 11 ] = ascii (fp) : "./hrtfs/elev65/L65e305a.dat"
-[ 31, 12 ] = ascii (fp) : "./hrtfs/elev65/L65e300a.dat"
-[ 31, 13 ] = ascii (fp) : "./hrtfs/elev65/L65e295a.dat"
-[ 31, 14 ] = ascii (fp) : "./hrtfs/elev65/L65e290a.dat"
-[ 31, 15 ] = ascii (fp) : "./hrtfs/elev65/L65e285a.dat"
-[ 31, 16 ] = ascii (fp) : "./hrtfs/elev65/L65e280a.dat"
-[ 31, 17 ] = ascii (fp) : "./hrtfs/elev65/L65e275a.dat"
-[ 31, 18 ] = ascii (fp) : "./hrtfs/elev65/L65e270a.dat"
-[ 31, 19 ] = ascii (fp) : "./hrtfs/elev65/L65e265a.dat"
-[ 31, 20 ] = ascii (fp) : "./hrtfs/elev65/L65e260a.dat"
-[ 31, 21 ] = ascii (fp) : "./hrtfs/elev65/L65e255a.dat"
-[ 31, 22 ] = ascii (fp) : "./hrtfs/elev65/L65e250a.dat"
-[ 31, 23 ] = ascii (fp) : "./hrtfs/elev65/L65e245a.dat"
-[ 31, 24 ] = ascii (fp) : "./hrtfs/elev65/L65e240a.dat"
-[ 31, 25 ] = ascii (fp) : "./hrtfs/elev65/L65e235a.dat"
-[ 31, 26 ] = ascii (fp) : "./hrtfs/elev65/L65e230a.dat"
-[ 31, 27 ] = ascii (fp) : "./hrtfs/elev65/L65e225a.dat"
-[ 31, 28 ] = ascii (fp) : "./hrtfs/elev65/L65e220a.dat"
-[ 31, 29 ] = ascii (fp) : "./hrtfs/elev65/L65e215a.dat"
-[ 31, 30 ] = ascii (fp) : "./hrtfs/elev65/L65e210a.dat"
-[ 31, 31 ] = ascii (fp) : "./hrtfs/elev65/L65e205a.dat"
-[ 31, 32 ] = ascii (fp) : "./hrtfs/elev65/L65e200a.dat"
-[ 31, 33 ] = ascii (fp) : "./hrtfs/elev65/L65e195a.dat"
-[ 31, 34 ] = ascii (fp) : "./hrtfs/elev65/L65e190a.dat"
-[ 31, 35 ] = ascii (fp) : "./hrtfs/elev65/L65e185a.dat"
-[ 31, 36 ] = ascii (fp) : "./hrtfs/elev65/L65e180a.dat"
-[ 31, 37 ] = ascii (fp) : "./hrtfs/elev65/L65e175a.dat"
-[ 31, 38 ] = ascii (fp) : "./hrtfs/elev65/L65e170a.dat"
-[ 31, 39 ] = ascii (fp) : "./hrtfs/elev65/L65e165a.dat"
-[ 31, 40 ] = ascii (fp) : "./hrtfs/elev65/L65e160a.dat"
-[ 31, 41 ] = ascii (fp) : "./hrtfs/elev65/L65e155a.dat"
-[ 31, 42 ] = ascii (fp) : "./hrtfs/elev65/L65e150a.dat"
-[ 31, 43 ] = ascii (fp) : "./hrtfs/elev65/L65e145a.dat"
-[ 31, 44 ] = ascii (fp) : "./hrtfs/elev65/L65e140a.dat"
-[ 31, 45 ] = ascii (fp) : "./hrtfs/elev65/L65e135a.dat"
-[ 31, 46 ] = ascii (fp) : "./hrtfs/elev65/L65e130a.dat"
-[ 31, 47 ] = ascii (fp) : "./hrtfs/elev65/L65e125a.dat"
-[ 31, 48 ] = ascii (fp) : "./hrtfs/elev65/L65e120a.dat"
-[ 31, 49 ] = ascii (fp) : "./hrtfs/elev65/L65e115a.dat"
-[ 31, 50 ] = ascii (fp) : "./hrtfs/elev65/L65e110a.dat"
-[ 31, 51 ] = ascii (fp) : "./hrtfs/elev65/L65e105a.dat"
-[ 31, 52 ] = ascii (fp) : "./hrtfs/elev65/L65e100a.dat"
-[ 31, 53 ] = ascii (fp) : "./hrtfs/elev65/L65e095a.dat"
-[ 31, 54 ] = ascii (fp) : "./hrtfs/elev65/L65e090a.dat"
-[ 31, 55 ] = ascii (fp) : "./hrtfs/elev65/L65e085a.dat"
-[ 31, 56 ] = ascii (fp) : "./hrtfs/elev65/L65e080a.dat"
-[ 31, 57 ] = ascii (fp) : "./hrtfs/elev65/L65e075a.dat"
-[ 31, 58 ] = ascii (fp) : "./hrtfs/elev65/L65e070a.dat"
-[ 31, 59 ] = ascii (fp) : "./hrtfs/elev65/L65e065a.dat"
-[ 31, 60 ] = ascii (fp) : "./hrtfs/elev65/L65e060a.dat"
-[ 31, 61 ] = ascii (fp) : "./hrtfs/elev65/L65e055a.dat"
-[ 31, 62 ] = ascii (fp) : "./hrtfs/elev65/L65e050a.dat"
-[ 31, 63 ] = ascii (fp) : "./hrtfs/elev65/L65e045a.dat"
-[ 31, 64 ] = ascii (fp) : "./hrtfs/elev65/L65e040a.dat"
-[ 31, 65 ] = ascii (fp) : "./hrtfs/elev65/L65e035a.dat"
-[ 31, 66 ] = ascii (fp) : "./hrtfs/elev65/L65e030a.dat"
-[ 31, 67 ] = ascii (fp) : "./hrtfs/elev65/L65e025a.dat"
-[ 31, 68 ] = ascii (fp) : "./hrtfs/elev65/L65e020a.dat"
-[ 31, 69 ] = ascii (fp) : "./hrtfs/elev65/L65e015a.dat"
-[ 31, 70 ] = ascii (fp) : "./hrtfs/elev65/L65e010a.dat"
-[ 31, 71 ] = ascii (fp) : "./hrtfs/elev65/L65e005a.dat"
+[ 31, 0 ] = ascii (fp) : "./hrtfs/elev65/L65e000a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e000a.dat right
+[ 31, 1 ] = ascii (fp) : "./hrtfs/elev65/L65e355a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e355a.dat right
+[ 31, 2 ] = ascii (fp) : "./hrtfs/elev65/L65e350a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e350a.dat right
+[ 31, 3 ] = ascii (fp) : "./hrtfs/elev65/L65e345a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e345a.dat right
+[ 31, 4 ] = ascii (fp) : "./hrtfs/elev65/L65e340a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e340a.dat right
+[ 31, 5 ] = ascii (fp) : "./hrtfs/elev65/L65e335a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e335a.dat right
+[ 31, 6 ] = ascii (fp) : "./hrtfs/elev65/L65e330a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e330a.dat right
+[ 31, 7 ] = ascii (fp) : "./hrtfs/elev65/L65e325a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e325a.dat right
+[ 31, 8 ] = ascii (fp) : "./hrtfs/elev65/L65e320a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e320a.dat right
+[ 31, 9 ] = ascii (fp) : "./hrtfs/elev65/L65e315a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e315a.dat right
+[ 31, 10 ] = ascii (fp) : "./hrtfs/elev65/L65e310a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e310a.dat right
+[ 31, 11 ] = ascii (fp) : "./hrtfs/elev65/L65e305a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e305a.dat right
+[ 31, 12 ] = ascii (fp) : "./hrtfs/elev65/L65e300a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e300a.dat right
+[ 31, 13 ] = ascii (fp) : "./hrtfs/elev65/L65e295a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e295a.dat right
+[ 31, 14 ] = ascii (fp) : "./hrtfs/elev65/L65e290a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e290a.dat right
+[ 31, 15 ] = ascii (fp) : "./hrtfs/elev65/L65e285a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e285a.dat right
+[ 31, 16 ] = ascii (fp) : "./hrtfs/elev65/L65e280a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e280a.dat right
+[ 31, 17 ] = ascii (fp) : "./hrtfs/elev65/L65e275a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e275a.dat right
+[ 31, 18 ] = ascii (fp) : "./hrtfs/elev65/L65e270a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e270a.dat right
+[ 31, 19 ] = ascii (fp) : "./hrtfs/elev65/L65e265a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e265a.dat right
+[ 31, 20 ] = ascii (fp) : "./hrtfs/elev65/L65e260a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e260a.dat right
+[ 31, 21 ] = ascii (fp) : "./hrtfs/elev65/L65e255a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e255a.dat right
+[ 31, 22 ] = ascii (fp) : "./hrtfs/elev65/L65e250a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e250a.dat right
+[ 31, 23 ] = ascii (fp) : "./hrtfs/elev65/L65e245a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e245a.dat right
+[ 31, 24 ] = ascii (fp) : "./hrtfs/elev65/L65e240a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e240a.dat right
+[ 31, 25 ] = ascii (fp) : "./hrtfs/elev65/L65e235a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e235a.dat right
+[ 31, 26 ] = ascii (fp) : "./hrtfs/elev65/L65e230a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e230a.dat right
+[ 31, 27 ] = ascii (fp) : "./hrtfs/elev65/L65e225a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e225a.dat right
+[ 31, 28 ] = ascii (fp) : "./hrtfs/elev65/L65e220a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e220a.dat right
+[ 31, 29 ] = ascii (fp) : "./hrtfs/elev65/L65e215a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e215a.dat right
+[ 31, 30 ] = ascii (fp) : "./hrtfs/elev65/L65e210a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e210a.dat right
+[ 31, 31 ] = ascii (fp) : "./hrtfs/elev65/L65e205a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e205a.dat right
+[ 31, 32 ] = ascii (fp) : "./hrtfs/elev65/L65e200a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e200a.dat right
+[ 31, 33 ] = ascii (fp) : "./hrtfs/elev65/L65e195a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e195a.dat right
+[ 31, 34 ] = ascii (fp) : "./hrtfs/elev65/L65e190a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e190a.dat right
+[ 31, 35 ] = ascii (fp) : "./hrtfs/elev65/L65e185a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e185a.dat right
+[ 31, 36 ] = ascii (fp) : "./hrtfs/elev65/L65e180a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e180a.dat right
+[ 31, 37 ] = ascii (fp) : "./hrtfs/elev65/L65e175a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e175a.dat right
+[ 31, 38 ] = ascii (fp) : "./hrtfs/elev65/L65e170a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e170a.dat right
+[ 31, 39 ] = ascii (fp) : "./hrtfs/elev65/L65e165a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e165a.dat right
+[ 31, 40 ] = ascii (fp) : "./hrtfs/elev65/L65e160a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e160a.dat right
+[ 31, 41 ] = ascii (fp) : "./hrtfs/elev65/L65e155a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e155a.dat right
+[ 31, 42 ] = ascii (fp) : "./hrtfs/elev65/L65e150a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e150a.dat right
+[ 31, 43 ] = ascii (fp) : "./hrtfs/elev65/L65e145a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e145a.dat right
+[ 31, 44 ] = ascii (fp) : "./hrtfs/elev65/L65e140a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e140a.dat right
+[ 31, 45 ] = ascii (fp) : "./hrtfs/elev65/L65e135a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e135a.dat right
+[ 31, 46 ] = ascii (fp) : "./hrtfs/elev65/L65e130a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e130a.dat right
+[ 31, 47 ] = ascii (fp) : "./hrtfs/elev65/L65e125a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e125a.dat right
+[ 31, 48 ] = ascii (fp) : "./hrtfs/elev65/L65e120a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e120a.dat right
+[ 31, 49 ] = ascii (fp) : "./hrtfs/elev65/L65e115a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e115a.dat right
+[ 31, 50 ] = ascii (fp) : "./hrtfs/elev65/L65e110a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e110a.dat right
+[ 31, 51 ] = ascii (fp) : "./hrtfs/elev65/L65e105a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e105a.dat right
+[ 31, 52 ] = ascii (fp) : "./hrtfs/elev65/L65e100a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e100a.dat right
+[ 31, 53 ] = ascii (fp) : "./hrtfs/elev65/L65e095a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e095a.dat right
+[ 31, 54 ] = ascii (fp) : "./hrtfs/elev65/L65e090a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e090a.dat right
+[ 31, 55 ] = ascii (fp) : "./hrtfs/elev65/L65e085a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e085a.dat right
+[ 31, 56 ] = ascii (fp) : "./hrtfs/elev65/L65e080a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e080a.dat right
+[ 31, 57 ] = ascii (fp) : "./hrtfs/elev65/L65e075a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e075a.dat right
+[ 31, 58 ] = ascii (fp) : "./hrtfs/elev65/L65e070a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e070a.dat right
+[ 31, 59 ] = ascii (fp) : "./hrtfs/elev65/L65e065a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e065a.dat right
+[ 31, 60 ] = ascii (fp) : "./hrtfs/elev65/L65e060a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e060a.dat right
+[ 31, 61 ] = ascii (fp) : "./hrtfs/elev65/L65e055a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e055a.dat right
+[ 31, 62 ] = ascii (fp) : "./hrtfs/elev65/L65e050a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e050a.dat right
+[ 31, 63 ] = ascii (fp) : "./hrtfs/elev65/L65e045a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e045a.dat right
+[ 31, 64 ] = ascii (fp) : "./hrtfs/elev65/L65e040a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e040a.dat right
+[ 31, 65 ] = ascii (fp) : "./hrtfs/elev65/L65e035a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e035a.dat right
+[ 31, 66 ] = ascii (fp) : "./hrtfs/elev65/L65e030a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e030a.dat right
+[ 31, 67 ] = ascii (fp) : "./hrtfs/elev65/L65e025a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e025a.dat right
+[ 31, 68 ] = ascii (fp) : "./hrtfs/elev65/L65e020a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e020a.dat right
+[ 31, 69 ] = ascii (fp) : "./hrtfs/elev65/L65e015a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e015a.dat right
+[ 31, 70 ] = ascii (fp) : "./hrtfs/elev65/L65e010a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e010a.dat right
+[ 31, 71 ] = ascii (fp) : "./hrtfs/elev65/L65e005a.dat left
+ + ascii (fp) : "./hrtfs/elev65/R65e005a.dat right
-[ 32, 0 ] = ascii (fp) : "./hrtfs/elev70/L70e000a.dat"
-[ 32, 1 ] = ascii (fp) : "./hrtfs/elev70/L70e355a.dat"
-[ 32, 2 ] = ascii (fp) : "./hrtfs/elev70/L70e350a.dat"
-[ 32, 3 ] = ascii (fp) : "./hrtfs/elev70/L70e345a.dat"
-[ 32, 4 ] = ascii (fp) : "./hrtfs/elev70/L70e340a.dat"
-[ 32, 5 ] = ascii (fp) : "./hrtfs/elev70/L70e335a.dat"
-[ 32, 6 ] = ascii (fp) : "./hrtfs/elev70/L70e330a.dat"
-[ 32, 7 ] = ascii (fp) : "./hrtfs/elev70/L70e325a.dat"
-[ 32, 8 ] = ascii (fp) : "./hrtfs/elev70/L70e320a.dat"
-[ 32, 9 ] = ascii (fp) : "./hrtfs/elev70/L70e315a.dat"
-[ 32, 10 ] = ascii (fp) : "./hrtfs/elev70/L70e310a.dat"
-[ 32, 11 ] = ascii (fp) : "./hrtfs/elev70/L70e305a.dat"
-[ 32, 12 ] = ascii (fp) : "./hrtfs/elev70/L70e300a.dat"
-[ 32, 13 ] = ascii (fp) : "./hrtfs/elev70/L70e295a.dat"
-[ 32, 14 ] = ascii (fp) : "./hrtfs/elev70/L70e290a.dat"
-[ 32, 15 ] = ascii (fp) : "./hrtfs/elev70/L70e285a.dat"
-[ 32, 16 ] = ascii (fp) : "./hrtfs/elev70/L70e280a.dat"
-[ 32, 17 ] = ascii (fp) : "./hrtfs/elev70/L70e275a.dat"
-[ 32, 18 ] = ascii (fp) : "./hrtfs/elev70/L70e270a.dat"
-[ 32, 19 ] = ascii (fp) : "./hrtfs/elev70/L70e265a.dat"
-[ 32, 20 ] = ascii (fp) : "./hrtfs/elev70/L70e260a.dat"
-[ 32, 21 ] = ascii (fp) : "./hrtfs/elev70/L70e255a.dat"
-[ 32, 22 ] = ascii (fp) : "./hrtfs/elev70/L70e250a.dat"
-[ 32, 23 ] = ascii (fp) : "./hrtfs/elev70/L70e245a.dat"
-[ 32, 24 ] = ascii (fp) : "./hrtfs/elev70/L70e240a.dat"
-[ 32, 25 ] = ascii (fp) : "./hrtfs/elev70/L70e235a.dat"
-[ 32, 26 ] = ascii (fp) : "./hrtfs/elev70/L70e230a.dat"
-[ 32, 27 ] = ascii (fp) : "./hrtfs/elev70/L70e225a.dat"
-[ 32, 28 ] = ascii (fp) : "./hrtfs/elev70/L70e220a.dat"
-[ 32, 29 ] = ascii (fp) : "./hrtfs/elev70/L70e215a.dat"
-[ 32, 30 ] = ascii (fp) : "./hrtfs/elev70/L70e210a.dat"
-[ 32, 31 ] = ascii (fp) : "./hrtfs/elev70/L70e205a.dat"
-[ 32, 32 ] = ascii (fp) : "./hrtfs/elev70/L70e200a.dat"
-[ 32, 33 ] = ascii (fp) : "./hrtfs/elev70/L70e195a.dat"
-[ 32, 34 ] = ascii (fp) : "./hrtfs/elev70/L70e190a.dat"
-[ 32, 35 ] = ascii (fp) : "./hrtfs/elev70/L70e185a.dat"
-[ 32, 36 ] = ascii (fp) : "./hrtfs/elev70/L70e180a.dat"
-[ 32, 37 ] = ascii (fp) : "./hrtfs/elev70/L70e175a.dat"
-[ 32, 38 ] = ascii (fp) : "./hrtfs/elev70/L70e170a.dat"
-[ 32, 39 ] = ascii (fp) : "./hrtfs/elev70/L70e165a.dat"
-[ 32, 40 ] = ascii (fp) : "./hrtfs/elev70/L70e160a.dat"
-[ 32, 41 ] = ascii (fp) : "./hrtfs/elev70/L70e155a.dat"
-[ 32, 42 ] = ascii (fp) : "./hrtfs/elev70/L70e150a.dat"
-[ 32, 43 ] = ascii (fp) : "./hrtfs/elev70/L70e145a.dat"
-[ 32, 44 ] = ascii (fp) : "./hrtfs/elev70/L70e140a.dat"
-[ 32, 45 ] = ascii (fp) : "./hrtfs/elev70/L70e135a.dat"
-[ 32, 46 ] = ascii (fp) : "./hrtfs/elev70/L70e130a.dat"
-[ 32, 47 ] = ascii (fp) : "./hrtfs/elev70/L70e125a.dat"
-[ 32, 48 ] = ascii (fp) : "./hrtfs/elev70/L70e120a.dat"
-[ 32, 49 ] = ascii (fp) : "./hrtfs/elev70/L70e115a.dat"
-[ 32, 50 ] = ascii (fp) : "./hrtfs/elev70/L70e110a.dat"
-[ 32, 51 ] = ascii (fp) : "./hrtfs/elev70/L70e105a.dat"
-[ 32, 52 ] = ascii (fp) : "./hrtfs/elev70/L70e100a.dat"
-[ 32, 53 ] = ascii (fp) : "./hrtfs/elev70/L70e095a.dat"
-[ 32, 54 ] = ascii (fp) : "./hrtfs/elev70/L70e090a.dat"
-[ 32, 55 ] = ascii (fp) : "./hrtfs/elev70/L70e085a.dat"
-[ 32, 56 ] = ascii (fp) : "./hrtfs/elev70/L70e080a.dat"
-[ 32, 57 ] = ascii (fp) : "./hrtfs/elev70/L70e075a.dat"
-[ 32, 58 ] = ascii (fp) : "./hrtfs/elev70/L70e070a.dat"
-[ 32, 59 ] = ascii (fp) : "./hrtfs/elev70/L70e065a.dat"
-[ 32, 60 ] = ascii (fp) : "./hrtfs/elev70/L70e060a.dat"
-[ 32, 61 ] = ascii (fp) : "./hrtfs/elev70/L70e055a.dat"
-[ 32, 62 ] = ascii (fp) : "./hrtfs/elev70/L70e050a.dat"
-[ 32, 63 ] = ascii (fp) : "./hrtfs/elev70/L70e045a.dat"
-[ 32, 64 ] = ascii (fp) : "./hrtfs/elev70/L70e040a.dat"
-[ 32, 65 ] = ascii (fp) : "./hrtfs/elev70/L70e035a.dat"
-[ 32, 66 ] = ascii (fp) : "./hrtfs/elev70/L70e030a.dat"
-[ 32, 67 ] = ascii (fp) : "./hrtfs/elev70/L70e025a.dat"
-[ 32, 68 ] = ascii (fp) : "./hrtfs/elev70/L70e020a.dat"
-[ 32, 69 ] = ascii (fp) : "./hrtfs/elev70/L70e015a.dat"
-[ 32, 70 ] = ascii (fp) : "./hrtfs/elev70/L70e010a.dat"
-[ 32, 71 ] = ascii (fp) : "./hrtfs/elev70/L70e005a.dat"
+[ 32, 0 ] = ascii (fp) : "./hrtfs/elev70/L70e000a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e000a.dat right
+[ 32, 1 ] = ascii (fp) : "./hrtfs/elev70/L70e355a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e355a.dat right
+[ 32, 2 ] = ascii (fp) : "./hrtfs/elev70/L70e350a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e350a.dat right
+[ 32, 3 ] = ascii (fp) : "./hrtfs/elev70/L70e345a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e345a.dat right
+[ 32, 4 ] = ascii (fp) : "./hrtfs/elev70/L70e340a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e340a.dat right
+[ 32, 5 ] = ascii (fp) : "./hrtfs/elev70/L70e335a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e335a.dat right
+[ 32, 6 ] = ascii (fp) : "./hrtfs/elev70/L70e330a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e330a.dat right
+[ 32, 7 ] = ascii (fp) : "./hrtfs/elev70/L70e325a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e325a.dat right
+[ 32, 8 ] = ascii (fp) : "./hrtfs/elev70/L70e320a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e320a.dat right
+[ 32, 9 ] = ascii (fp) : "./hrtfs/elev70/L70e315a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e315a.dat right
+[ 32, 10 ] = ascii (fp) : "./hrtfs/elev70/L70e310a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e310a.dat right
+[ 32, 11 ] = ascii (fp) : "./hrtfs/elev70/L70e305a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e305a.dat right
+[ 32, 12 ] = ascii (fp) : "./hrtfs/elev70/L70e300a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e300a.dat right
+[ 32, 13 ] = ascii (fp) : "./hrtfs/elev70/L70e295a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e295a.dat right
+[ 32, 14 ] = ascii (fp) : "./hrtfs/elev70/L70e290a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e290a.dat right
+[ 32, 15 ] = ascii (fp) : "./hrtfs/elev70/L70e285a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e285a.dat right
+[ 32, 16 ] = ascii (fp) : "./hrtfs/elev70/L70e280a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e280a.dat right
+[ 32, 17 ] = ascii (fp) : "./hrtfs/elev70/L70e275a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e275a.dat right
+[ 32, 18 ] = ascii (fp) : "./hrtfs/elev70/L70e270a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e270a.dat right
+[ 32, 19 ] = ascii (fp) : "./hrtfs/elev70/L70e265a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e265a.dat right
+[ 32, 20 ] = ascii (fp) : "./hrtfs/elev70/L70e260a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e260a.dat right
+[ 32, 21 ] = ascii (fp) : "./hrtfs/elev70/L70e255a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e255a.dat right
+[ 32, 22 ] = ascii (fp) : "./hrtfs/elev70/L70e250a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e250a.dat right
+[ 32, 23 ] = ascii (fp) : "./hrtfs/elev70/L70e245a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e245a.dat right
+[ 32, 24 ] = ascii (fp) : "./hrtfs/elev70/L70e240a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e240a.dat right
+[ 32, 25 ] = ascii (fp) : "./hrtfs/elev70/L70e235a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e235a.dat right
+[ 32, 26 ] = ascii (fp) : "./hrtfs/elev70/L70e230a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e230a.dat right
+[ 32, 27 ] = ascii (fp) : "./hrtfs/elev70/L70e225a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e225a.dat right
+[ 32, 28 ] = ascii (fp) : "./hrtfs/elev70/L70e220a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e220a.dat right
+[ 32, 29 ] = ascii (fp) : "./hrtfs/elev70/L70e215a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e215a.dat right
+[ 32, 30 ] = ascii (fp) : "./hrtfs/elev70/L70e210a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e210a.dat right
+[ 32, 31 ] = ascii (fp) : "./hrtfs/elev70/L70e205a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e205a.dat right
+[ 32, 32 ] = ascii (fp) : "./hrtfs/elev70/L70e200a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e200a.dat right
+[ 32, 33 ] = ascii (fp) : "./hrtfs/elev70/L70e195a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e195a.dat right
+[ 32, 34 ] = ascii (fp) : "./hrtfs/elev70/L70e190a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e190a.dat right
+[ 32, 35 ] = ascii (fp) : "./hrtfs/elev70/L70e185a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e185a.dat right
+[ 32, 36 ] = ascii (fp) : "./hrtfs/elev70/L70e180a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e180a.dat right
+[ 32, 37 ] = ascii (fp) : "./hrtfs/elev70/L70e175a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e175a.dat right
+[ 32, 38 ] = ascii (fp) : "./hrtfs/elev70/L70e170a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e170a.dat right
+[ 32, 39 ] = ascii (fp) : "./hrtfs/elev70/L70e165a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e165a.dat right
+[ 32, 40 ] = ascii (fp) : "./hrtfs/elev70/L70e160a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e160a.dat right
+[ 32, 41 ] = ascii (fp) : "./hrtfs/elev70/L70e155a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e155a.dat right
+[ 32, 42 ] = ascii (fp) : "./hrtfs/elev70/L70e150a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e150a.dat right
+[ 32, 43 ] = ascii (fp) : "./hrtfs/elev70/L70e145a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e145a.dat right
+[ 32, 44 ] = ascii (fp) : "./hrtfs/elev70/L70e140a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e140a.dat right
+[ 32, 45 ] = ascii (fp) : "./hrtfs/elev70/L70e135a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e135a.dat right
+[ 32, 46 ] = ascii (fp) : "./hrtfs/elev70/L70e130a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e130a.dat right
+[ 32, 47 ] = ascii (fp) : "./hrtfs/elev70/L70e125a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e125a.dat right
+[ 32, 48 ] = ascii (fp) : "./hrtfs/elev70/L70e120a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e120a.dat right
+[ 32, 49 ] = ascii (fp) : "./hrtfs/elev70/L70e115a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e115a.dat right
+[ 32, 50 ] = ascii (fp) : "./hrtfs/elev70/L70e110a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e110a.dat right
+[ 32, 51 ] = ascii (fp) : "./hrtfs/elev70/L70e105a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e105a.dat right
+[ 32, 52 ] = ascii (fp) : "./hrtfs/elev70/L70e100a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e100a.dat right
+[ 32, 53 ] = ascii (fp) : "./hrtfs/elev70/L70e095a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e095a.dat right
+[ 32, 54 ] = ascii (fp) : "./hrtfs/elev70/L70e090a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e090a.dat right
+[ 32, 55 ] = ascii (fp) : "./hrtfs/elev70/L70e085a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e085a.dat right
+[ 32, 56 ] = ascii (fp) : "./hrtfs/elev70/L70e080a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e080a.dat right
+[ 32, 57 ] = ascii (fp) : "./hrtfs/elev70/L70e075a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e075a.dat right
+[ 32, 58 ] = ascii (fp) : "./hrtfs/elev70/L70e070a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e070a.dat right
+[ 32, 59 ] = ascii (fp) : "./hrtfs/elev70/L70e065a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e065a.dat right
+[ 32, 60 ] = ascii (fp) : "./hrtfs/elev70/L70e060a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e060a.dat right
+[ 32, 61 ] = ascii (fp) : "./hrtfs/elev70/L70e055a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e055a.dat right
+[ 32, 62 ] = ascii (fp) : "./hrtfs/elev70/L70e050a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e050a.dat right
+[ 32, 63 ] = ascii (fp) : "./hrtfs/elev70/L70e045a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e045a.dat right
+[ 32, 64 ] = ascii (fp) : "./hrtfs/elev70/L70e040a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e040a.dat right
+[ 32, 65 ] = ascii (fp) : "./hrtfs/elev70/L70e035a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e035a.dat right
+[ 32, 66 ] = ascii (fp) : "./hrtfs/elev70/L70e030a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e030a.dat right
+[ 32, 67 ] = ascii (fp) : "./hrtfs/elev70/L70e025a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e025a.dat right
+[ 32, 68 ] = ascii (fp) : "./hrtfs/elev70/L70e020a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e020a.dat right
+[ 32, 69 ] = ascii (fp) : "./hrtfs/elev70/L70e015a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e015a.dat right
+[ 32, 70 ] = ascii (fp) : "./hrtfs/elev70/L70e010a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e010a.dat right
+[ 32, 71 ] = ascii (fp) : "./hrtfs/elev70/L70e005a.dat left
+ + ascii (fp) : "./hrtfs/elev70/R70e005a.dat right
-[ 33, 0 ] = ascii (fp) : "./hrtfs/elev75/L75e000a.dat"
-[ 33, 1 ] = ascii (fp) : "./hrtfs/elev75/L75e355a.dat"
-[ 33, 2 ] = ascii (fp) : "./hrtfs/elev75/L75e350a.dat"
-[ 33, 3 ] = ascii (fp) : "./hrtfs/elev75/L75e345a.dat"
-[ 33, 4 ] = ascii (fp) : "./hrtfs/elev75/L75e340a.dat"
-[ 33, 5 ] = ascii (fp) : "./hrtfs/elev75/L75e335a.dat"
-[ 33, 6 ] = ascii (fp) : "./hrtfs/elev75/L75e330a.dat"
-[ 33, 7 ] = ascii (fp) : "./hrtfs/elev75/L75e325a.dat"
-[ 33, 8 ] = ascii (fp) : "./hrtfs/elev75/L75e320a.dat"
-[ 33, 9 ] = ascii (fp) : "./hrtfs/elev75/L75e315a.dat"
-[ 33, 10 ] = ascii (fp) : "./hrtfs/elev75/L75e310a.dat"
-[ 33, 11 ] = ascii (fp) : "./hrtfs/elev75/L75e305a.dat"
-[ 33, 12 ] = ascii (fp) : "./hrtfs/elev75/L75e300a.dat"
-[ 33, 13 ] = ascii (fp) : "./hrtfs/elev75/L75e295a.dat"
-[ 33, 14 ] = ascii (fp) : "./hrtfs/elev75/L75e290a.dat"
-[ 33, 15 ] = ascii (fp) : "./hrtfs/elev75/L75e285a.dat"
-[ 33, 16 ] = ascii (fp) : "./hrtfs/elev75/L75e280a.dat"
-[ 33, 17 ] = ascii (fp) : "./hrtfs/elev75/L75e275a.dat"
-[ 33, 18 ] = ascii (fp) : "./hrtfs/elev75/L75e270a.dat"
-[ 33, 19 ] = ascii (fp) : "./hrtfs/elev75/L75e265a.dat"
-[ 33, 20 ] = ascii (fp) : "./hrtfs/elev75/L75e260a.dat"
-[ 33, 21 ] = ascii (fp) : "./hrtfs/elev75/L75e255a.dat"
-[ 33, 22 ] = ascii (fp) : "./hrtfs/elev75/L75e250a.dat"
-[ 33, 23 ] = ascii (fp) : "./hrtfs/elev75/L75e245a.dat"
-[ 33, 24 ] = ascii (fp) : "./hrtfs/elev75/L75e240a.dat"
-[ 33, 25 ] = ascii (fp) : "./hrtfs/elev75/L75e235a.dat"
-[ 33, 26 ] = ascii (fp) : "./hrtfs/elev75/L75e230a.dat"
-[ 33, 27 ] = ascii (fp) : "./hrtfs/elev75/L75e225a.dat"
-[ 33, 28 ] = ascii (fp) : "./hrtfs/elev75/L75e220a.dat"
-[ 33, 29 ] = ascii (fp) : "./hrtfs/elev75/L75e215a.dat"
-[ 33, 30 ] = ascii (fp) : "./hrtfs/elev75/L75e210a.dat"
-[ 33, 31 ] = ascii (fp) : "./hrtfs/elev75/L75e205a.dat"
-[ 33, 32 ] = ascii (fp) : "./hrtfs/elev75/L75e200a.dat"
-[ 33, 33 ] = ascii (fp) : "./hrtfs/elev75/L75e195a.dat"
-[ 33, 34 ] = ascii (fp) : "./hrtfs/elev75/L75e190a.dat"
-[ 33, 35 ] = ascii (fp) : "./hrtfs/elev75/L75e185a.dat"
-[ 33, 36 ] = ascii (fp) : "./hrtfs/elev75/L75e180a.dat"
-[ 33, 37 ] = ascii (fp) : "./hrtfs/elev75/L75e175a.dat"
-[ 33, 38 ] = ascii (fp) : "./hrtfs/elev75/L75e170a.dat"
-[ 33, 39 ] = ascii (fp) : "./hrtfs/elev75/L75e165a.dat"
-[ 33, 40 ] = ascii (fp) : "./hrtfs/elev75/L75e160a.dat"
-[ 33, 41 ] = ascii (fp) : "./hrtfs/elev75/L75e155a.dat"
-[ 33, 42 ] = ascii (fp) : "./hrtfs/elev75/L75e150a.dat"
-[ 33, 43 ] = ascii (fp) : "./hrtfs/elev75/L75e145a.dat"
-[ 33, 44 ] = ascii (fp) : "./hrtfs/elev75/L75e140a.dat"
-[ 33, 45 ] = ascii (fp) : "./hrtfs/elev75/L75e135a.dat"
-[ 33, 46 ] = ascii (fp) : "./hrtfs/elev75/L75e130a.dat"
-[ 33, 47 ] = ascii (fp) : "./hrtfs/elev75/L75e125a.dat"
-[ 33, 48 ] = ascii (fp) : "./hrtfs/elev75/L75e120a.dat"
-[ 33, 49 ] = ascii (fp) : "./hrtfs/elev75/L75e115a.dat"
-[ 33, 50 ] = ascii (fp) : "./hrtfs/elev75/L75e110a.dat"
-[ 33, 51 ] = ascii (fp) : "./hrtfs/elev75/L75e105a.dat"
-[ 33, 52 ] = ascii (fp) : "./hrtfs/elev75/L75e100a.dat"
-[ 33, 53 ] = ascii (fp) : "./hrtfs/elev75/L75e095a.dat"
-[ 33, 54 ] = ascii (fp) : "./hrtfs/elev75/L75e090a.dat"
-[ 33, 55 ] = ascii (fp) : "./hrtfs/elev75/L75e085a.dat"
-[ 33, 56 ] = ascii (fp) : "./hrtfs/elev75/L75e080a.dat"
-[ 33, 57 ] = ascii (fp) : "./hrtfs/elev75/L75e075a.dat"
-[ 33, 58 ] = ascii (fp) : "./hrtfs/elev75/L75e070a.dat"
-[ 33, 59 ] = ascii (fp) : "./hrtfs/elev75/L75e065a.dat"
-[ 33, 60 ] = ascii (fp) : "./hrtfs/elev75/L75e060a.dat"
-[ 33, 61 ] = ascii (fp) : "./hrtfs/elev75/L75e055a.dat"
-[ 33, 62 ] = ascii (fp) : "./hrtfs/elev75/L75e050a.dat"
-[ 33, 63 ] = ascii (fp) : "./hrtfs/elev75/L75e045a.dat"
-[ 33, 64 ] = ascii (fp) : "./hrtfs/elev75/L75e040a.dat"
-[ 33, 65 ] = ascii (fp) : "./hrtfs/elev75/L75e035a.dat"
-[ 33, 66 ] = ascii (fp) : "./hrtfs/elev75/L75e030a.dat"
-[ 33, 67 ] = ascii (fp) : "./hrtfs/elev75/L75e025a.dat"
-[ 33, 68 ] = ascii (fp) : "./hrtfs/elev75/L75e020a.dat"
-[ 33, 69 ] = ascii (fp) : "./hrtfs/elev75/L75e015a.dat"
-[ 33, 70 ] = ascii (fp) : "./hrtfs/elev75/L75e010a.dat"
-[ 33, 71 ] = ascii (fp) : "./hrtfs/elev75/L75e005a.dat"
+[ 33, 0 ] = ascii (fp) : "./hrtfs/elev75/L75e000a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e000a.dat right
+[ 33, 1 ] = ascii (fp) : "./hrtfs/elev75/L75e355a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e355a.dat right
+[ 33, 2 ] = ascii (fp) : "./hrtfs/elev75/L75e350a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e350a.dat right
+[ 33, 3 ] = ascii (fp) : "./hrtfs/elev75/L75e345a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e345a.dat right
+[ 33, 4 ] = ascii (fp) : "./hrtfs/elev75/L75e340a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e340a.dat right
+[ 33, 5 ] = ascii (fp) : "./hrtfs/elev75/L75e335a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e335a.dat right
+[ 33, 6 ] = ascii (fp) : "./hrtfs/elev75/L75e330a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e330a.dat right
+[ 33, 7 ] = ascii (fp) : "./hrtfs/elev75/L75e325a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e325a.dat right
+[ 33, 8 ] = ascii (fp) : "./hrtfs/elev75/L75e320a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e320a.dat right
+[ 33, 9 ] = ascii (fp) : "./hrtfs/elev75/L75e315a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e315a.dat right
+[ 33, 10 ] = ascii (fp) : "./hrtfs/elev75/L75e310a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e310a.dat right
+[ 33, 11 ] = ascii (fp) : "./hrtfs/elev75/L75e305a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e305a.dat right
+[ 33, 12 ] = ascii (fp) : "./hrtfs/elev75/L75e300a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e300a.dat right
+[ 33, 13 ] = ascii (fp) : "./hrtfs/elev75/L75e295a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e295a.dat right
+[ 33, 14 ] = ascii (fp) : "./hrtfs/elev75/L75e290a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e290a.dat right
+[ 33, 15 ] = ascii (fp) : "./hrtfs/elev75/L75e285a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e285a.dat right
+[ 33, 16 ] = ascii (fp) : "./hrtfs/elev75/L75e280a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e280a.dat right
+[ 33, 17 ] = ascii (fp) : "./hrtfs/elev75/L75e275a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e275a.dat right
+[ 33, 18 ] = ascii (fp) : "./hrtfs/elev75/L75e270a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e270a.dat right
+[ 33, 19 ] = ascii (fp) : "./hrtfs/elev75/L75e265a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e265a.dat right
+[ 33, 20 ] = ascii (fp) : "./hrtfs/elev75/L75e260a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e260a.dat right
+[ 33, 21 ] = ascii (fp) : "./hrtfs/elev75/L75e255a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e255a.dat right
+[ 33, 22 ] = ascii (fp) : "./hrtfs/elev75/L75e250a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e250a.dat right
+[ 33, 23 ] = ascii (fp) : "./hrtfs/elev75/L75e245a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e245a.dat right
+[ 33, 24 ] = ascii (fp) : "./hrtfs/elev75/L75e240a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e240a.dat right
+[ 33, 25 ] = ascii (fp) : "./hrtfs/elev75/L75e235a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e235a.dat right
+[ 33, 26 ] = ascii (fp) : "./hrtfs/elev75/L75e230a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e230a.dat right
+[ 33, 27 ] = ascii (fp) : "./hrtfs/elev75/L75e225a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e225a.dat right
+[ 33, 28 ] = ascii (fp) : "./hrtfs/elev75/L75e220a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e220a.dat right
+[ 33, 29 ] = ascii (fp) : "./hrtfs/elev75/L75e215a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e215a.dat right
+[ 33, 30 ] = ascii (fp) : "./hrtfs/elev75/L75e210a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e210a.dat right
+[ 33, 31 ] = ascii (fp) : "./hrtfs/elev75/L75e205a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e205a.dat right
+[ 33, 32 ] = ascii (fp) : "./hrtfs/elev75/L75e200a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e200a.dat right
+[ 33, 33 ] = ascii (fp) : "./hrtfs/elev75/L75e195a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e195a.dat right
+[ 33, 34 ] = ascii (fp) : "./hrtfs/elev75/L75e190a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e190a.dat right
+[ 33, 35 ] = ascii (fp) : "./hrtfs/elev75/L75e185a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e185a.dat right
+[ 33, 36 ] = ascii (fp) : "./hrtfs/elev75/L75e180a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e180a.dat right
+[ 33, 37 ] = ascii (fp) : "./hrtfs/elev75/L75e175a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e175a.dat right
+[ 33, 38 ] = ascii (fp) : "./hrtfs/elev75/L75e170a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e170a.dat right
+[ 33, 39 ] = ascii (fp) : "./hrtfs/elev75/L75e165a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e165a.dat right
+[ 33, 40 ] = ascii (fp) : "./hrtfs/elev75/L75e160a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e160a.dat right
+[ 33, 41 ] = ascii (fp) : "./hrtfs/elev75/L75e155a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e155a.dat right
+[ 33, 42 ] = ascii (fp) : "./hrtfs/elev75/L75e150a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e150a.dat right
+[ 33, 43 ] = ascii (fp) : "./hrtfs/elev75/L75e145a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e145a.dat right
+[ 33, 44 ] = ascii (fp) : "./hrtfs/elev75/L75e140a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e140a.dat right
+[ 33, 45 ] = ascii (fp) : "./hrtfs/elev75/L75e135a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e135a.dat right
+[ 33, 46 ] = ascii (fp) : "./hrtfs/elev75/L75e130a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e130a.dat right
+[ 33, 47 ] = ascii (fp) : "./hrtfs/elev75/L75e125a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e125a.dat right
+[ 33, 48 ] = ascii (fp) : "./hrtfs/elev75/L75e120a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e120a.dat right
+[ 33, 49 ] = ascii (fp) : "./hrtfs/elev75/L75e115a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e115a.dat right
+[ 33, 50 ] = ascii (fp) : "./hrtfs/elev75/L75e110a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e110a.dat right
+[ 33, 51 ] = ascii (fp) : "./hrtfs/elev75/L75e105a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e105a.dat right
+[ 33, 52 ] = ascii (fp) : "./hrtfs/elev75/L75e100a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e100a.dat right
+[ 33, 53 ] = ascii (fp) : "./hrtfs/elev75/L75e095a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e095a.dat right
+[ 33, 54 ] = ascii (fp) : "./hrtfs/elev75/L75e090a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e090a.dat right
+[ 33, 55 ] = ascii (fp) : "./hrtfs/elev75/L75e085a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e085a.dat right
+[ 33, 56 ] = ascii (fp) : "./hrtfs/elev75/L75e080a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e080a.dat right
+[ 33, 57 ] = ascii (fp) : "./hrtfs/elev75/L75e075a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e075a.dat right
+[ 33, 58 ] = ascii (fp) : "./hrtfs/elev75/L75e070a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e070a.dat right
+[ 33, 59 ] = ascii (fp) : "./hrtfs/elev75/L75e065a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e065a.dat right
+[ 33, 60 ] = ascii (fp) : "./hrtfs/elev75/L75e060a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e060a.dat right
+[ 33, 61 ] = ascii (fp) : "./hrtfs/elev75/L75e055a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e055a.dat right
+[ 33, 62 ] = ascii (fp) : "./hrtfs/elev75/L75e050a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e050a.dat right
+[ 33, 63 ] = ascii (fp) : "./hrtfs/elev75/L75e045a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e045a.dat right
+[ 33, 64 ] = ascii (fp) : "./hrtfs/elev75/L75e040a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e040a.dat right
+[ 33, 65 ] = ascii (fp) : "./hrtfs/elev75/L75e035a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e035a.dat right
+[ 33, 66 ] = ascii (fp) : "./hrtfs/elev75/L75e030a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e030a.dat right
+[ 33, 67 ] = ascii (fp) : "./hrtfs/elev75/L75e025a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e025a.dat right
+[ 33, 68 ] = ascii (fp) : "./hrtfs/elev75/L75e020a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e020a.dat right
+[ 33, 69 ] = ascii (fp) : "./hrtfs/elev75/L75e015a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e015a.dat right
+[ 33, 70 ] = ascii (fp) : "./hrtfs/elev75/L75e010a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e010a.dat right
+[ 33, 71 ] = ascii (fp) : "./hrtfs/elev75/L75e005a.dat left
+ + ascii (fp) : "./hrtfs/elev75/R75e005a.dat right
-[ 34, 0 ] = ascii (fp) : "./hrtfs/elev80/L80e000a.dat"
-[ 34, 1 ] = ascii (fp) : "./hrtfs/elev80/L80e355a.dat"
-[ 34, 2 ] = ascii (fp) : "./hrtfs/elev80/L80e350a.dat"
-[ 34, 3 ] = ascii (fp) : "./hrtfs/elev80/L80e345a.dat"
-[ 34, 4 ] = ascii (fp) : "./hrtfs/elev80/L80e340a.dat"
-[ 34, 5 ] = ascii (fp) : "./hrtfs/elev80/L80e335a.dat"
-[ 34, 6 ] = ascii (fp) : "./hrtfs/elev80/L80e330a.dat"
-[ 34, 7 ] = ascii (fp) : "./hrtfs/elev80/L80e325a.dat"
-[ 34, 8 ] = ascii (fp) : "./hrtfs/elev80/L80e320a.dat"
-[ 34, 9 ] = ascii (fp) : "./hrtfs/elev80/L80e315a.dat"
-[ 34, 10 ] = ascii (fp) : "./hrtfs/elev80/L80e310a.dat"
-[ 34, 11 ] = ascii (fp) : "./hrtfs/elev80/L80e305a.dat"
-[ 34, 12 ] = ascii (fp) : "./hrtfs/elev80/L80e300a.dat"
-[ 34, 13 ] = ascii (fp) : "./hrtfs/elev80/L80e295a.dat"
-[ 34, 14 ] = ascii (fp) : "./hrtfs/elev80/L80e290a.dat"
-[ 34, 15 ] = ascii (fp) : "./hrtfs/elev80/L80e285a.dat"
-[ 34, 16 ] = ascii (fp) : "./hrtfs/elev80/L80e280a.dat"
-[ 34, 17 ] = ascii (fp) : "./hrtfs/elev80/L80e275a.dat"
-[ 34, 18 ] = ascii (fp) : "./hrtfs/elev80/L80e270a.dat"
-[ 34, 19 ] = ascii (fp) : "./hrtfs/elev80/L80e265a.dat"
-[ 34, 20 ] = ascii (fp) : "./hrtfs/elev80/L80e260a.dat"
-[ 34, 21 ] = ascii (fp) : "./hrtfs/elev80/L80e255a.dat"
-[ 34, 22 ] = ascii (fp) : "./hrtfs/elev80/L80e250a.dat"
-[ 34, 23 ] = ascii (fp) : "./hrtfs/elev80/L80e245a.dat"
-[ 34, 24 ] = ascii (fp) : "./hrtfs/elev80/L80e240a.dat"
-[ 34, 25 ] = ascii (fp) : "./hrtfs/elev80/L80e235a.dat"
-[ 34, 26 ] = ascii (fp) : "./hrtfs/elev80/L80e230a.dat"
-[ 34, 27 ] = ascii (fp) : "./hrtfs/elev80/L80e225a.dat"
-[ 34, 28 ] = ascii (fp) : "./hrtfs/elev80/L80e220a.dat"
-[ 34, 29 ] = ascii (fp) : "./hrtfs/elev80/L80e215a.dat"
-[ 34, 30 ] = ascii (fp) : "./hrtfs/elev80/L80e210a.dat"
-[ 34, 31 ] = ascii (fp) : "./hrtfs/elev80/L80e205a.dat"
-[ 34, 32 ] = ascii (fp) : "./hrtfs/elev80/L80e200a.dat"
-[ 34, 33 ] = ascii (fp) : "./hrtfs/elev80/L80e195a.dat"
-[ 34, 34 ] = ascii (fp) : "./hrtfs/elev80/L80e190a.dat"
-[ 34, 35 ] = ascii (fp) : "./hrtfs/elev80/L80e185a.dat"
-[ 34, 36 ] = ascii (fp) : "./hrtfs/elev80/L80e180a.dat"
-[ 34, 37 ] = ascii (fp) : "./hrtfs/elev80/L80e175a.dat"
-[ 34, 38 ] = ascii (fp) : "./hrtfs/elev80/L80e170a.dat"
-[ 34, 39 ] = ascii (fp) : "./hrtfs/elev80/L80e165a.dat"
-[ 34, 40 ] = ascii (fp) : "./hrtfs/elev80/L80e160a.dat"
-[ 34, 41 ] = ascii (fp) : "./hrtfs/elev80/L80e155a.dat"
-[ 34, 42 ] = ascii (fp) : "./hrtfs/elev80/L80e150a.dat"
-[ 34, 43 ] = ascii (fp) : "./hrtfs/elev80/L80e145a.dat"
-[ 34, 44 ] = ascii (fp) : "./hrtfs/elev80/L80e140a.dat"
-[ 34, 45 ] = ascii (fp) : "./hrtfs/elev80/L80e135a.dat"
-[ 34, 46 ] = ascii (fp) : "./hrtfs/elev80/L80e130a.dat"
-[ 34, 47 ] = ascii (fp) : "./hrtfs/elev80/L80e125a.dat"
-[ 34, 48 ] = ascii (fp) : "./hrtfs/elev80/L80e120a.dat"
-[ 34, 49 ] = ascii (fp) : "./hrtfs/elev80/L80e115a.dat"
-[ 34, 50 ] = ascii (fp) : "./hrtfs/elev80/L80e110a.dat"
-[ 34, 51 ] = ascii (fp) : "./hrtfs/elev80/L80e105a.dat"
-[ 34, 52 ] = ascii (fp) : "./hrtfs/elev80/L80e100a.dat"
-[ 34, 53 ] = ascii (fp) : "./hrtfs/elev80/L80e095a.dat"
-[ 34, 54 ] = ascii (fp) : "./hrtfs/elev80/L80e090a.dat"
-[ 34, 55 ] = ascii (fp) : "./hrtfs/elev80/L80e085a.dat"
-[ 34, 56 ] = ascii (fp) : "./hrtfs/elev80/L80e080a.dat"
-[ 34, 57 ] = ascii (fp) : "./hrtfs/elev80/L80e075a.dat"
-[ 34, 58 ] = ascii (fp) : "./hrtfs/elev80/L80e070a.dat"
-[ 34, 59 ] = ascii (fp) : "./hrtfs/elev80/L80e065a.dat"
-[ 34, 60 ] = ascii (fp) : "./hrtfs/elev80/L80e060a.dat"
-[ 34, 61 ] = ascii (fp) : "./hrtfs/elev80/L80e055a.dat"
-[ 34, 62 ] = ascii (fp) : "./hrtfs/elev80/L80e050a.dat"
-[ 34, 63 ] = ascii (fp) : "./hrtfs/elev80/L80e045a.dat"
-[ 34, 64 ] = ascii (fp) : "./hrtfs/elev80/L80e040a.dat"
-[ 34, 65 ] = ascii (fp) : "./hrtfs/elev80/L80e035a.dat"
-[ 34, 66 ] = ascii (fp) : "./hrtfs/elev80/L80e030a.dat"
-[ 34, 67 ] = ascii (fp) : "./hrtfs/elev80/L80e025a.dat"
-[ 34, 68 ] = ascii (fp) : "./hrtfs/elev80/L80e020a.dat"
-[ 34, 69 ] = ascii (fp) : "./hrtfs/elev80/L80e015a.dat"
-[ 34, 70 ] = ascii (fp) : "./hrtfs/elev80/L80e010a.dat"
-[ 34, 71 ] = ascii (fp) : "./hrtfs/elev80/L80e005a.dat"
+[ 34, 0 ] = ascii (fp) : "./hrtfs/elev80/L80e000a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e000a.dat right
+[ 34, 1 ] = ascii (fp) : "./hrtfs/elev80/L80e355a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e355a.dat right
+[ 34, 2 ] = ascii (fp) : "./hrtfs/elev80/L80e350a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e350a.dat right
+[ 34, 3 ] = ascii (fp) : "./hrtfs/elev80/L80e345a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e345a.dat right
+[ 34, 4 ] = ascii (fp) : "./hrtfs/elev80/L80e340a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e340a.dat right
+[ 34, 5 ] = ascii (fp) : "./hrtfs/elev80/L80e335a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e335a.dat right
+[ 34, 6 ] = ascii (fp) : "./hrtfs/elev80/L80e330a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e330a.dat right
+[ 34, 7 ] = ascii (fp) : "./hrtfs/elev80/L80e325a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e325a.dat right
+[ 34, 8 ] = ascii (fp) : "./hrtfs/elev80/L80e320a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e320a.dat right
+[ 34, 9 ] = ascii (fp) : "./hrtfs/elev80/L80e315a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e315a.dat right
+[ 34, 10 ] = ascii (fp) : "./hrtfs/elev80/L80e310a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e310a.dat right
+[ 34, 11 ] = ascii (fp) : "./hrtfs/elev80/L80e305a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e305a.dat right
+[ 34, 12 ] = ascii (fp) : "./hrtfs/elev80/L80e300a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e300a.dat right
+[ 34, 13 ] = ascii (fp) : "./hrtfs/elev80/L80e295a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e295a.dat right
+[ 34, 14 ] = ascii (fp) : "./hrtfs/elev80/L80e290a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e290a.dat right
+[ 34, 15 ] = ascii (fp) : "./hrtfs/elev80/L80e285a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e285a.dat right
+[ 34, 16 ] = ascii (fp) : "./hrtfs/elev80/L80e280a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e280a.dat right
+[ 34, 17 ] = ascii (fp) : "./hrtfs/elev80/L80e275a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e275a.dat right
+[ 34, 18 ] = ascii (fp) : "./hrtfs/elev80/L80e270a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e270a.dat right
+[ 34, 19 ] = ascii (fp) : "./hrtfs/elev80/L80e265a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e265a.dat right
+[ 34, 20 ] = ascii (fp) : "./hrtfs/elev80/L80e260a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e260a.dat right
+[ 34, 21 ] = ascii (fp) : "./hrtfs/elev80/L80e255a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e255a.dat right
+[ 34, 22 ] = ascii (fp) : "./hrtfs/elev80/L80e250a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e250a.dat right
+[ 34, 23 ] = ascii (fp) : "./hrtfs/elev80/L80e245a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e245a.dat right
+[ 34, 24 ] = ascii (fp) : "./hrtfs/elev80/L80e240a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e240a.dat right
+[ 34, 25 ] = ascii (fp) : "./hrtfs/elev80/L80e235a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e235a.dat right
+[ 34, 26 ] = ascii (fp) : "./hrtfs/elev80/L80e230a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e230a.dat right
+[ 34, 27 ] = ascii (fp) : "./hrtfs/elev80/L80e225a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e225a.dat right
+[ 34, 28 ] = ascii (fp) : "./hrtfs/elev80/L80e220a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e220a.dat right
+[ 34, 29 ] = ascii (fp) : "./hrtfs/elev80/L80e215a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e215a.dat right
+[ 34, 30 ] = ascii (fp) : "./hrtfs/elev80/L80e210a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e210a.dat right
+[ 34, 31 ] = ascii (fp) : "./hrtfs/elev80/L80e205a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e205a.dat right
+[ 34, 32 ] = ascii (fp) : "./hrtfs/elev80/L80e200a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e200a.dat right
+[ 34, 33 ] = ascii (fp) : "./hrtfs/elev80/L80e195a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e195a.dat right
+[ 34, 34 ] = ascii (fp) : "./hrtfs/elev80/L80e190a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e190a.dat right
+[ 34, 35 ] = ascii (fp) : "./hrtfs/elev80/L80e185a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e185a.dat right
+[ 34, 36 ] = ascii (fp) : "./hrtfs/elev80/L80e180a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e180a.dat right
+[ 34, 37 ] = ascii (fp) : "./hrtfs/elev80/L80e175a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e175a.dat right
+[ 34, 38 ] = ascii (fp) : "./hrtfs/elev80/L80e170a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e170a.dat right
+[ 34, 39 ] = ascii (fp) : "./hrtfs/elev80/L80e165a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e165a.dat right
+[ 34, 40 ] = ascii (fp) : "./hrtfs/elev80/L80e160a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e160a.dat right
+[ 34, 41 ] = ascii (fp) : "./hrtfs/elev80/L80e155a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e155a.dat right
+[ 34, 42 ] = ascii (fp) : "./hrtfs/elev80/L80e150a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e150a.dat right
+[ 34, 43 ] = ascii (fp) : "./hrtfs/elev80/L80e145a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e145a.dat right
+[ 34, 44 ] = ascii (fp) : "./hrtfs/elev80/L80e140a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e140a.dat right
+[ 34, 45 ] = ascii (fp) : "./hrtfs/elev80/L80e135a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e135a.dat right
+[ 34, 46 ] = ascii (fp) : "./hrtfs/elev80/L80e130a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e130a.dat right
+[ 34, 47 ] = ascii (fp) : "./hrtfs/elev80/L80e125a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e125a.dat right
+[ 34, 48 ] = ascii (fp) : "./hrtfs/elev80/L80e120a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e120a.dat right
+[ 34, 49 ] = ascii (fp) : "./hrtfs/elev80/L80e115a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e115a.dat right
+[ 34, 50 ] = ascii (fp) : "./hrtfs/elev80/L80e110a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e110a.dat right
+[ 34, 51 ] = ascii (fp) : "./hrtfs/elev80/L80e105a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e105a.dat right
+[ 34, 52 ] = ascii (fp) : "./hrtfs/elev80/L80e100a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e100a.dat right
+[ 34, 53 ] = ascii (fp) : "./hrtfs/elev80/L80e095a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e095a.dat right
+[ 34, 54 ] = ascii (fp) : "./hrtfs/elev80/L80e090a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e090a.dat right
+[ 34, 55 ] = ascii (fp) : "./hrtfs/elev80/L80e085a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e085a.dat right
+[ 34, 56 ] = ascii (fp) : "./hrtfs/elev80/L80e080a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e080a.dat right
+[ 34, 57 ] = ascii (fp) : "./hrtfs/elev80/L80e075a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e075a.dat right
+[ 34, 58 ] = ascii (fp) : "./hrtfs/elev80/L80e070a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e070a.dat right
+[ 34, 59 ] = ascii (fp) : "./hrtfs/elev80/L80e065a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e065a.dat right
+[ 34, 60 ] = ascii (fp) : "./hrtfs/elev80/L80e060a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e060a.dat right
+[ 34, 61 ] = ascii (fp) : "./hrtfs/elev80/L80e055a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e055a.dat right
+[ 34, 62 ] = ascii (fp) : "./hrtfs/elev80/L80e050a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e050a.dat right
+[ 34, 63 ] = ascii (fp) : "./hrtfs/elev80/L80e045a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e045a.dat right
+[ 34, 64 ] = ascii (fp) : "./hrtfs/elev80/L80e040a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e040a.dat right
+[ 34, 65 ] = ascii (fp) : "./hrtfs/elev80/L80e035a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e035a.dat right
+[ 34, 66 ] = ascii (fp) : "./hrtfs/elev80/L80e030a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e030a.dat right
+[ 34, 67 ] = ascii (fp) : "./hrtfs/elev80/L80e025a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e025a.dat right
+[ 34, 68 ] = ascii (fp) : "./hrtfs/elev80/L80e020a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e020a.dat right
+[ 34, 69 ] = ascii (fp) : "./hrtfs/elev80/L80e015a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e015a.dat right
+[ 34, 70 ] = ascii (fp) : "./hrtfs/elev80/L80e010a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e010a.dat right
+[ 34, 71 ] = ascii (fp) : "./hrtfs/elev80/L80e005a.dat left
+ + ascii (fp) : "./hrtfs/elev80/R80e005a.dat right
-[ 35, 0 ] = ascii (fp) : "./hrtfs/elev85/L85e000a.dat"
-[ 35, 1 ] = ascii (fp) : "./hrtfs/elev85/L85e355a.dat"
-[ 35, 2 ] = ascii (fp) : "./hrtfs/elev85/L85e350a.dat"
-[ 35, 3 ] = ascii (fp) : "./hrtfs/elev85/L85e345a.dat"
-[ 35, 4 ] = ascii (fp) : "./hrtfs/elev85/L85e340a.dat"
-[ 35, 5 ] = ascii (fp) : "./hrtfs/elev85/L85e335a.dat"
-[ 35, 6 ] = ascii (fp) : "./hrtfs/elev85/L85e330a.dat"
-[ 35, 7 ] = ascii (fp) : "./hrtfs/elev85/L85e325a.dat"
-[ 35, 8 ] = ascii (fp) : "./hrtfs/elev85/L85e320a.dat"
-[ 35, 9 ] = ascii (fp) : "./hrtfs/elev85/L85e315a.dat"
-[ 35, 10 ] = ascii (fp) : "./hrtfs/elev85/L85e310a.dat"
-[ 35, 11 ] = ascii (fp) : "./hrtfs/elev85/L85e305a.dat"
-[ 35, 12 ] = ascii (fp) : "./hrtfs/elev85/L85e300a.dat"
-[ 35, 13 ] = ascii (fp) : "./hrtfs/elev85/L85e295a.dat"
-[ 35, 14 ] = ascii (fp) : "./hrtfs/elev85/L85e290a.dat"
-[ 35, 15 ] = ascii (fp) : "./hrtfs/elev85/L85e285a.dat"
-[ 35, 16 ] = ascii (fp) : "./hrtfs/elev85/L85e280a.dat"
-[ 35, 17 ] = ascii (fp) : "./hrtfs/elev85/L85e275a.dat"
-[ 35, 18 ] = ascii (fp) : "./hrtfs/elev85/L85e270a.dat"
-[ 35, 19 ] = ascii (fp) : "./hrtfs/elev85/L85e265a.dat"
-[ 35, 20 ] = ascii (fp) : "./hrtfs/elev85/L85e260a.dat"
-[ 35, 21 ] = ascii (fp) : "./hrtfs/elev85/L85e255a.dat"
-[ 35, 22 ] = ascii (fp) : "./hrtfs/elev85/L85e250a.dat"
-[ 35, 23 ] = ascii (fp) : "./hrtfs/elev85/L85e245a.dat"
-[ 35, 24 ] = ascii (fp) : "./hrtfs/elev85/L85e240a.dat"
-[ 35, 25 ] = ascii (fp) : "./hrtfs/elev85/L85e235a.dat"
-[ 35, 26 ] = ascii (fp) : "./hrtfs/elev85/L85e230a.dat"
-[ 35, 27 ] = ascii (fp) : "./hrtfs/elev85/L85e225a.dat"
-[ 35, 28 ] = ascii (fp) : "./hrtfs/elev85/L85e220a.dat"
-[ 35, 29 ] = ascii (fp) : "./hrtfs/elev85/L85e215a.dat"
-[ 35, 30 ] = ascii (fp) : "./hrtfs/elev85/L85e210a.dat"
-[ 35, 31 ] = ascii (fp) : "./hrtfs/elev85/L85e205a.dat"
-[ 35, 32 ] = ascii (fp) : "./hrtfs/elev85/L85e200a.dat"
-[ 35, 33 ] = ascii (fp) : "./hrtfs/elev85/L85e195a.dat"
-[ 35, 34 ] = ascii (fp) : "./hrtfs/elev85/L85e190a.dat"
-[ 35, 35 ] = ascii (fp) : "./hrtfs/elev85/L85e185a.dat"
-[ 35, 36 ] = ascii (fp) : "./hrtfs/elev85/L85e180a.dat"
-[ 35, 37 ] = ascii (fp) : "./hrtfs/elev85/L85e175a.dat"
-[ 35, 38 ] = ascii (fp) : "./hrtfs/elev85/L85e170a.dat"
-[ 35, 39 ] = ascii (fp) : "./hrtfs/elev85/L85e165a.dat"
-[ 35, 40 ] = ascii (fp) : "./hrtfs/elev85/L85e160a.dat"
-[ 35, 41 ] = ascii (fp) : "./hrtfs/elev85/L85e155a.dat"
-[ 35, 42 ] = ascii (fp) : "./hrtfs/elev85/L85e150a.dat"
-[ 35, 43 ] = ascii (fp) : "./hrtfs/elev85/L85e145a.dat"
-[ 35, 44 ] = ascii (fp) : "./hrtfs/elev85/L85e140a.dat"
-[ 35, 45 ] = ascii (fp) : "./hrtfs/elev85/L85e135a.dat"
-[ 35, 46 ] = ascii (fp) : "./hrtfs/elev85/L85e130a.dat"
-[ 35, 47 ] = ascii (fp) : "./hrtfs/elev85/L85e125a.dat"
-[ 35, 48 ] = ascii (fp) : "./hrtfs/elev85/L85e120a.dat"
-[ 35, 49 ] = ascii (fp) : "./hrtfs/elev85/L85e115a.dat"
-[ 35, 50 ] = ascii (fp) : "./hrtfs/elev85/L85e110a.dat"
-[ 35, 51 ] = ascii (fp) : "./hrtfs/elev85/L85e105a.dat"
-[ 35, 52 ] = ascii (fp) : "./hrtfs/elev85/L85e100a.dat"
-[ 35, 53 ] = ascii (fp) : "./hrtfs/elev85/L85e095a.dat"
-[ 35, 54 ] = ascii (fp) : "./hrtfs/elev85/L85e090a.dat"
-[ 35, 55 ] = ascii (fp) : "./hrtfs/elev85/L85e085a.dat"
-[ 35, 56 ] = ascii (fp) : "./hrtfs/elev85/L85e080a.dat"
-[ 35, 57 ] = ascii (fp) : "./hrtfs/elev85/L85e075a.dat"
-[ 35, 58 ] = ascii (fp) : "./hrtfs/elev85/L85e070a.dat"
-[ 35, 59 ] = ascii (fp) : "./hrtfs/elev85/L85e065a.dat"
-[ 35, 60 ] = ascii (fp) : "./hrtfs/elev85/L85e060a.dat"
-[ 35, 61 ] = ascii (fp) : "./hrtfs/elev85/L85e055a.dat"
-[ 35, 62 ] = ascii (fp) : "./hrtfs/elev85/L85e050a.dat"
-[ 35, 63 ] = ascii (fp) : "./hrtfs/elev85/L85e045a.dat"
-[ 35, 64 ] = ascii (fp) : "./hrtfs/elev85/L85e040a.dat"
-[ 35, 65 ] = ascii (fp) : "./hrtfs/elev85/L85e035a.dat"
-[ 35, 66 ] = ascii (fp) : "./hrtfs/elev85/L85e030a.dat"
-[ 35, 67 ] = ascii (fp) : "./hrtfs/elev85/L85e025a.dat"
-[ 35, 68 ] = ascii (fp) : "./hrtfs/elev85/L85e020a.dat"
-[ 35, 69 ] = ascii (fp) : "./hrtfs/elev85/L85e015a.dat"
-[ 35, 70 ] = ascii (fp) : "./hrtfs/elev85/L85e010a.dat"
-[ 35, 71 ] = ascii (fp) : "./hrtfs/elev85/L85e005a.dat"
+[ 35, 0 ] = ascii (fp) : "./hrtfs/elev85/L85e000a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e000a.dat right
+[ 35, 1 ] = ascii (fp) : "./hrtfs/elev85/L85e355a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e355a.dat right
+[ 35, 2 ] = ascii (fp) : "./hrtfs/elev85/L85e350a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e350a.dat right
+[ 35, 3 ] = ascii (fp) : "./hrtfs/elev85/L85e345a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e345a.dat right
+[ 35, 4 ] = ascii (fp) : "./hrtfs/elev85/L85e340a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e340a.dat right
+[ 35, 5 ] = ascii (fp) : "./hrtfs/elev85/L85e335a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e335a.dat right
+[ 35, 6 ] = ascii (fp) : "./hrtfs/elev85/L85e330a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e330a.dat right
+[ 35, 7 ] = ascii (fp) : "./hrtfs/elev85/L85e325a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e325a.dat right
+[ 35, 8 ] = ascii (fp) : "./hrtfs/elev85/L85e320a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e320a.dat right
+[ 35, 9 ] = ascii (fp) : "./hrtfs/elev85/L85e315a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e315a.dat right
+[ 35, 10 ] = ascii (fp) : "./hrtfs/elev85/L85e310a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e310a.dat right
+[ 35, 11 ] = ascii (fp) : "./hrtfs/elev85/L85e305a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e305a.dat right
+[ 35, 12 ] = ascii (fp) : "./hrtfs/elev85/L85e300a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e300a.dat right
+[ 35, 13 ] = ascii (fp) : "./hrtfs/elev85/L85e295a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e295a.dat right
+[ 35, 14 ] = ascii (fp) : "./hrtfs/elev85/L85e290a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e290a.dat right
+[ 35, 15 ] = ascii (fp) : "./hrtfs/elev85/L85e285a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e285a.dat right
+[ 35, 16 ] = ascii (fp) : "./hrtfs/elev85/L85e280a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e280a.dat right
+[ 35, 17 ] = ascii (fp) : "./hrtfs/elev85/L85e275a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e275a.dat right
+[ 35, 18 ] = ascii (fp) : "./hrtfs/elev85/L85e270a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e270a.dat right
+[ 35, 19 ] = ascii (fp) : "./hrtfs/elev85/L85e265a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e265a.dat right
+[ 35, 20 ] = ascii (fp) : "./hrtfs/elev85/L85e260a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e260a.dat right
+[ 35, 21 ] = ascii (fp) : "./hrtfs/elev85/L85e255a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e255a.dat right
+[ 35, 22 ] = ascii (fp) : "./hrtfs/elev85/L85e250a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e250a.dat right
+[ 35, 23 ] = ascii (fp) : "./hrtfs/elev85/L85e245a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e245a.dat right
+[ 35, 24 ] = ascii (fp) : "./hrtfs/elev85/L85e240a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e240a.dat right
+[ 35, 25 ] = ascii (fp) : "./hrtfs/elev85/L85e235a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e235a.dat right
+[ 35, 26 ] = ascii (fp) : "./hrtfs/elev85/L85e230a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e230a.dat right
+[ 35, 27 ] = ascii (fp) : "./hrtfs/elev85/L85e225a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e225a.dat right
+[ 35, 28 ] = ascii (fp) : "./hrtfs/elev85/L85e220a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e220a.dat right
+[ 35, 29 ] = ascii (fp) : "./hrtfs/elev85/L85e215a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e215a.dat right
+[ 35, 30 ] = ascii (fp) : "./hrtfs/elev85/L85e210a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e210a.dat right
+[ 35, 31 ] = ascii (fp) : "./hrtfs/elev85/L85e205a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e205a.dat right
+[ 35, 32 ] = ascii (fp) : "./hrtfs/elev85/L85e200a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e200a.dat right
+[ 35, 33 ] = ascii (fp) : "./hrtfs/elev85/L85e195a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e195a.dat right
+[ 35, 34 ] = ascii (fp) : "./hrtfs/elev85/L85e190a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e190a.dat right
+[ 35, 35 ] = ascii (fp) : "./hrtfs/elev85/L85e185a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e185a.dat right
+[ 35, 36 ] = ascii (fp) : "./hrtfs/elev85/L85e180a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e180a.dat right
+[ 35, 37 ] = ascii (fp) : "./hrtfs/elev85/L85e175a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e175a.dat right
+[ 35, 38 ] = ascii (fp) : "./hrtfs/elev85/L85e170a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e170a.dat right
+[ 35, 39 ] = ascii (fp) : "./hrtfs/elev85/L85e165a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e165a.dat right
+[ 35, 40 ] = ascii (fp) : "./hrtfs/elev85/L85e160a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e160a.dat right
+[ 35, 41 ] = ascii (fp) : "./hrtfs/elev85/L85e155a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e155a.dat right
+[ 35, 42 ] = ascii (fp) : "./hrtfs/elev85/L85e150a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e150a.dat right
+[ 35, 43 ] = ascii (fp) : "./hrtfs/elev85/L85e145a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e145a.dat right
+[ 35, 44 ] = ascii (fp) : "./hrtfs/elev85/L85e140a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e140a.dat right
+[ 35, 45 ] = ascii (fp) : "./hrtfs/elev85/L85e135a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e135a.dat right
+[ 35, 46 ] = ascii (fp) : "./hrtfs/elev85/L85e130a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e130a.dat right
+[ 35, 47 ] = ascii (fp) : "./hrtfs/elev85/L85e125a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e125a.dat right
+[ 35, 48 ] = ascii (fp) : "./hrtfs/elev85/L85e120a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e120a.dat right
+[ 35, 49 ] = ascii (fp) : "./hrtfs/elev85/L85e115a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e115a.dat right
+[ 35, 50 ] = ascii (fp) : "./hrtfs/elev85/L85e110a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e110a.dat right
+[ 35, 51 ] = ascii (fp) : "./hrtfs/elev85/L85e105a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e105a.dat right
+[ 35, 52 ] = ascii (fp) : "./hrtfs/elev85/L85e100a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e100a.dat right
+[ 35, 53 ] = ascii (fp) : "./hrtfs/elev85/L85e095a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e095a.dat right
+[ 35, 54 ] = ascii (fp) : "./hrtfs/elev85/L85e090a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e090a.dat right
+[ 35, 55 ] = ascii (fp) : "./hrtfs/elev85/L85e085a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e085a.dat right
+[ 35, 56 ] = ascii (fp) : "./hrtfs/elev85/L85e080a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e080a.dat right
+[ 35, 57 ] = ascii (fp) : "./hrtfs/elev85/L85e075a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e075a.dat right
+[ 35, 58 ] = ascii (fp) : "./hrtfs/elev85/L85e070a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e070a.dat right
+[ 35, 59 ] = ascii (fp) : "./hrtfs/elev85/L85e065a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e065a.dat right
+[ 35, 60 ] = ascii (fp) : "./hrtfs/elev85/L85e060a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e060a.dat right
+[ 35, 61 ] = ascii (fp) : "./hrtfs/elev85/L85e055a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e055a.dat right
+[ 35, 62 ] = ascii (fp) : "./hrtfs/elev85/L85e050a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e050a.dat right
+[ 35, 63 ] = ascii (fp) : "./hrtfs/elev85/L85e045a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e045a.dat right
+[ 35, 64 ] = ascii (fp) : "./hrtfs/elev85/L85e040a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e040a.dat right
+[ 35, 65 ] = ascii (fp) : "./hrtfs/elev85/L85e035a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e035a.dat right
+[ 35, 66 ] = ascii (fp) : "./hrtfs/elev85/L85e030a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e030a.dat right
+[ 35, 67 ] = ascii (fp) : "./hrtfs/elev85/L85e025a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e025a.dat right
+[ 35, 68 ] = ascii (fp) : "./hrtfs/elev85/L85e020a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e020a.dat right
+[ 35, 69 ] = ascii (fp) : "./hrtfs/elev85/L85e015a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e015a.dat right
+[ 35, 70 ] = ascii (fp) : "./hrtfs/elev85/L85e010a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e010a.dat right
+[ 35, 71 ] = ascii (fp) : "./hrtfs/elev85/L85e005a.dat left
+ + ascii (fp) : "./hrtfs/elev85/R85e005a.dat right
-[ 36, 0 ] = ascii (fp) : "./hrtfs/elev90/L90e000a.dat"
+[ 36, 0 ] = ascii (fp) : "./hrtfs/elev90/L90e000a.dat left
+ + ascii (fp) : "./hrtfs/elev90/R90e000a.dat right
diff --git a/utils/IRC_1005.def b/utils/IRC_1005.def
index f5a16934..c2fd90b5 100644
--- a/utils/IRC_1005.def
+++ b/utils/IRC_1005.def
@@ -1,8 +1,8 @@
# This is a makehrtf HRIR definition file. It is used to define the layout
# and source data to be processed into an OpenAL Soft compatible HRTF.
#
-# This definition is used to transform an average of the left and right ear
-# HRIRs from any raw data set from the IRCAM/AKG Listen HRTF database.
+# This definition is used to transform the left and right ear HRIRs of any
+# raw data set from the IRCAM/AKG Listen HRTF database.
#
# The data sets are available free of charge from:
#
@@ -17,405 +17,409 @@
rate = 44100
+# The IRCAM sets are stereo because they provide both ear HRIRs.
+type = stereo
+
# The raw sets have up to 8192 samples, but 2048 seems large enough.
points = 2048
-# The IRCAM sets are not as dense as the MIT set.
-azimuths = 1, 6, 12, 24, 24, 24, 24, 24, 24, 24, 12, 6, 1
-
# No head radius was provided. Just use the average radius of 9 cm.
radius = 0.09
-# The distance between the source and the listener (in meters).
+# The IRCAM sets are single-field (like most others) with a distance between
+# the source and the listener of 1.95 meters.
distance = 1.95
+# This set isn't as dense as the MIT set.
+azimuths = 1, 6, 12, 24, 24, 24, 24, 24, 24, 24, 12, 6, 1
+
# The IRCAM source azimuth is counter-clockwise, so it needs to be flipped.
-# Left and right ear HRIRs (from the respective WAVE channels) are averaged.
+# Left and right ear HRIRs (from the respective WAVE channels) are used to
+# create a stereo HRTF.
# Replace all occurrences of IRC_#### for the desired subject (1005 was used
# in this demonstration).
+[ 3, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P315.wav" right
+[ 3, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P315.wav" right
+[ 3, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P315.wav" right
+[ 3, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P315.wav" right
+[ 3, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P315.wav" right
+[ 3, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P315.wav" right
+[ 3, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P315.wav" right
+[ 3, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P315.wav" right
+[ 3, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P315.wav" right
+[ 3, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P315.wav" right
+[ 3, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P315.wav" right
+[ 3, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P315.wav" right
+[ 3, 12 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P315.wav" right
+[ 3, 13 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P315.wav" right
+[ 3, 14 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P315.wav" right
+[ 3, 15 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P315.wav" right
+[ 3, 16 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P315.wav" right
+[ 3, 17 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P315.wav" right
+[ 3, 18 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P315.wav" right
+[ 3, 19 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P315.wav" right
+[ 3, 20 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P315.wav" right
+[ 3, 21 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P315.wav" right
+[ 3, 22 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P315.wav" right
+[ 3, 23 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P315.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P315.wav" right
-[ 3, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P315.wav"
-[ 3, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P315.wav"
-[ 3, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P315.wav"
-[ 3, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P315.wav"
-[ 3, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P315.wav"
-[ 3, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P315.wav"
-[ 3, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P315.wav"
-[ 3, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P315.wav"
-[ 3, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P315.wav"
-[ 3, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P315.wav"
-[ 3, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P315.wav"
-[ 3, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P315.wav"
-[ 3, 12 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P315.wav"
-[ 3, 13 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P315.wav"
-[ 3, 14 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P315.wav"
-[ 3, 15 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P315.wav"
-[ 3, 16 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P315.wav"
-[ 3, 17 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P315.wav"
-[ 3, 18 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P315.wav"
-[ 3, 19 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P315.wav"
-[ 3, 20 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P315.wav"
-[ 3, 21 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P315.wav"
-[ 3, 22 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P315.wav"
-[ 3, 23 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P315.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P315.wav"
-
-[ 4, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P330.wav"
-[ 4, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P330.wav"
-[ 4, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P330.wav"
-[ 4, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P330.wav"
-[ 4, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P330.wav"
-[ 4, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P330.wav"
-[ 4, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P330.wav"
-[ 4, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P330.wav"
-[ 4, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P330.wav"
-[ 4, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P330.wav"
-[ 4, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P330.wav"
-[ 4, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P330.wav"
-[ 4, 12 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P330.wav"
-[ 4, 13 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P330.wav"
-[ 4, 14 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P330.wav"
-[ 4, 15 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P330.wav"
-[ 4, 16 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P330.wav"
-[ 4, 17 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P330.wav"
-[ 4, 18 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P330.wav"
-[ 4, 19 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P330.wav"
-[ 4, 20 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P330.wav"
-[ 4, 21 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P330.wav"
-[ 4, 22 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P330.wav"
-[ 4, 23 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P330.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P330.wav"
+[ 4, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P330.wav" right
+[ 4, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P330.wav" right
+[ 4, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P330.wav" right
+[ 4, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P330.wav" right
+[ 4, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P330.wav" right
+[ 4, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P330.wav" right
+[ 4, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P330.wav" right
+[ 4, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P330.wav" right
+[ 4, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P330.wav" right
+[ 4, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P330.wav" right
+[ 4, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P330.wav" right
+[ 4, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P330.wav" right
+[ 4, 12 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P330.wav" right
+[ 4, 13 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P330.wav" right
+[ 4, 14 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P330.wav" right
+[ 4, 15 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P330.wav" right
+[ 4, 16 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P330.wav" right
+[ 4, 17 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P330.wav" right
+[ 4, 18 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P330.wav" right
+[ 4, 19 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P330.wav" right
+[ 4, 20 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P330.wav" right
+[ 4, 21 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P330.wav" right
+[ 4, 22 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P330.wav" right
+[ 4, 23 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P330.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P330.wav" right
-[ 5, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P345.wav"
-[ 5, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P345.wav"
-[ 5, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P345.wav"
-[ 5, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P345.wav"
-[ 5, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P345.wav"
-[ 5, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P345.wav"
-[ 5, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P345.wav"
-[ 5, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P345.wav"
-[ 5, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P345.wav"
-[ 5, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P345.wav"
-[ 5, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P345.wav"
-[ 5, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P345.wav"
-[ 5, 12 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P345.wav"
-[ 5, 13 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P345.wav"
-[ 5, 14 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P345.wav"
-[ 5, 15 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P345.wav"
-[ 5, 16 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P345.wav"
-[ 5, 17 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P345.wav"
-[ 5, 18 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P345.wav"
-[ 5, 19 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P345.wav"
-[ 5, 20 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P345.wav"
-[ 5, 21 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P345.wav"
-[ 5, 22 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P345.wav"
-[ 5, 23 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P345.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P345.wav"
+[ 5, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P345.wav" right
+[ 5, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P345.wav" right
+[ 5, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P345.wav" right
+[ 5, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P345.wav" right
+[ 5, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P345.wav" right
+[ 5, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P345.wav" right
+[ 5, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P345.wav" right
+[ 5, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P345.wav" right
+[ 5, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P345.wav" right
+[ 5, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P345.wav" right
+[ 5, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P345.wav" right
+[ 5, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P345.wav" right
+[ 5, 12 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P345.wav" right
+[ 5, 13 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P345.wav" right
+[ 5, 14 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P345.wav" right
+[ 5, 15 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P345.wav" right
+[ 5, 16 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P345.wav" right
+[ 5, 17 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P345.wav" right
+[ 5, 18 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P345.wav" right
+[ 5, 19 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P345.wav" right
+[ 5, 20 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P345.wav" right
+[ 5, 21 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P345.wav" right
+[ 5, 22 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P345.wav" right
+[ 5, 23 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P345.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P345.wav" right
-[ 6, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P000.wav"
-[ 6, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P000.wav"
-[ 6, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P000.wav"
-[ 6, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P000.wav"
-[ 6, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P000.wav"
-[ 6, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P000.wav"
-[ 6, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P000.wav"
-[ 6, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P000.wav"
-[ 6, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P000.wav"
-[ 6, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P000.wav"
-[ 6, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P000.wav"
-[ 6, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P000.wav"
-[ 6, 12 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P000.wav"
-[ 6, 13 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P000.wav"
-[ 6, 14 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P000.wav"
-[ 6, 15 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P000.wav"
-[ 6, 16 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P000.wav"
-[ 6, 17 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P000.wav"
-[ 6, 18 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P000.wav"
-[ 6, 19 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P000.wav"
-[ 6, 20 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P000.wav"
-[ 6, 21 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P000.wav"
-[ 6, 22 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P000.wav"
-[ 6, 23 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P000.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P000.wav"
+[ 6, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P000.wav" right
+[ 6, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P000.wav" right
+[ 6, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P000.wav" right
+[ 6, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P000.wav" right
+[ 6, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P000.wav" right
+[ 6, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P000.wav" right
+[ 6, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P000.wav" right
+[ 6, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P000.wav" right
+[ 6, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P000.wav" right
+[ 6, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P000.wav" right
+[ 6, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P000.wav" right
+[ 6, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P000.wav" right
+[ 6, 12 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P000.wav" right
+[ 6, 13 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P000.wav" right
+[ 6, 14 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P000.wav" right
+[ 6, 15 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P000.wav" right
+[ 6, 16 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P000.wav" right
+[ 6, 17 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P000.wav" right
+[ 6, 18 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P000.wav" right
+[ 6, 19 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P000.wav" right
+[ 6, 20 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P000.wav" right
+[ 6, 21 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P000.wav" right
+[ 6, 22 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P000.wav" right
+[ 6, 23 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P000.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P000.wav" right
-[ 7, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P015.wav"
-[ 7, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P015.wav"
-[ 7, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P015.wav"
-[ 7, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P015.wav"
-[ 7, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P015.wav"
-[ 7, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P015.wav"
-[ 7, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P015.wav"
-[ 7, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P015.wav"
-[ 7, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P015.wav"
-[ 7, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P015.wav"
-[ 7, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P015.wav"
-[ 7, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P015.wav"
-[ 7, 12 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P015.wav"
-[ 7, 13 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P015.wav"
-[ 7, 14 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P015.wav"
-[ 7, 15 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P015.wav"
-[ 7, 16 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P015.wav"
-[ 7, 17 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P015.wav"
-[ 7, 18 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P015.wav"
-[ 7, 19 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P015.wav"
-[ 7, 20 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P015.wav"
-[ 7, 21 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P015.wav"
-[ 7, 22 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P015.wav"
-[ 7, 23 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P015.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P015.wav"
+[ 7, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P015.wav" right
+[ 7, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P015.wav" right
+[ 7, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P015.wav" right
+[ 7, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P015.wav" right
+[ 7, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P015.wav" right
+[ 7, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P015.wav" right
+[ 7, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P015.wav" right
+[ 7, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P015.wav" right
+[ 7, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P015.wav" right
+[ 7, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P015.wav" right
+[ 7, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P015.wav" right
+[ 7, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P015.wav" right
+[ 7, 12 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P015.wav" right
+[ 7, 13 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P015.wav" right
+[ 7, 14 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P015.wav" right
+[ 7, 15 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P015.wav" right
+[ 7, 16 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P015.wav" right
+[ 7, 17 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P015.wav" right
+[ 7, 18 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P015.wav" right
+[ 7, 19 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P015.wav" right
+[ 7, 20 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P015.wav" right
+[ 7, 21 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P015.wav" right
+[ 7, 22 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P015.wav" right
+[ 7, 23 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P015.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P015.wav" right
-[ 8, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P030.wav"
-[ 8, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P030.wav"
-[ 8, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P030.wav"
-[ 8, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P030.wav"
-[ 8, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P030.wav"
-[ 8, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P030.wav"
-[ 8, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P030.wav"
-[ 8, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P030.wav"
-[ 8, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P030.wav"
-[ 8, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P030.wav"
-[ 8, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P030.wav"
-[ 8, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P030.wav"
-[ 8, 12 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P030.wav"
-[ 8, 13 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P030.wav"
-[ 8, 14 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P030.wav"
-[ 8, 15 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P030.wav"
-[ 8, 16 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P030.wav"
-[ 8, 17 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P030.wav"
-[ 8, 18 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P030.wav"
-[ 8, 19 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P030.wav"
-[ 8, 20 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P030.wav"
-[ 8, 21 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P030.wav"
-[ 8, 22 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P030.wav"
-[ 8, 23 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P030.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P030.wav"
+[ 8, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P030.wav" right
+[ 8, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P030.wav" right
+[ 8, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P030.wav" right
+[ 8, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P030.wav" right
+[ 8, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P030.wav" right
+[ 8, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P030.wav" right
+[ 8, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P030.wav" right
+[ 8, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P030.wav" right
+[ 8, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P030.wav" right
+[ 8, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P030.wav" right
+[ 8, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P030.wav" right
+[ 8, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P030.wav" right
+[ 8, 12 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P030.wav" right
+[ 8, 13 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P030.wav" right
+[ 8, 14 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P030.wav" right
+[ 8, 15 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P030.wav" right
+[ 8, 16 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P030.wav" right
+[ 8, 17 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P030.wav" right
+[ 8, 18 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P030.wav" right
+[ 8, 19 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P030.wav" right
+[ 8, 20 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P030.wav" right
+[ 8, 21 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P030.wav" right
+[ 8, 22 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P030.wav" right
+[ 8, 23 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P030.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P030.wav" right
-[ 9, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P045.wav"
-[ 9, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P045.wav"
-[ 9, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P045.wav"
-[ 9, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P045.wav"
-[ 9, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P045.wav"
-[ 9, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P045.wav"
-[ 9, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P045.wav"
-[ 9, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P045.wav"
-[ 9, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P045.wav"
-[ 9, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P045.wav"
-[ 9, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P045.wav"
-[ 9, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P045.wav"
-[ 9, 12 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P045.wav"
-[ 9, 13 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P045.wav"
-[ 9, 14 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P045.wav"
-[ 9, 15 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P045.wav"
-[ 9, 16 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P045.wav"
-[ 9, 17 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P045.wav"
-[ 9, 18 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P045.wav"
-[ 9, 19 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P045.wav"
-[ 9, 20 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P045.wav"
-[ 9, 21 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P045.wav"
-[ 9, 22 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P045.wav"
-[ 9, 23 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P045.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P045.wav"
+[ 9, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P045.wav" right
+[ 9, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T345_P045.wav" right
+[ 9, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P045.wav" right
+[ 9, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T315_P045.wav" right
+[ 9, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P045.wav" right
+[ 9, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T285_P045.wav" right
+[ 9, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P045.wav" right
+[ 9, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T255_P045.wav" right
+[ 9, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P045.wav" right
+[ 9, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T225_P045.wav" right
+[ 9, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P045.wav" right
+[ 9, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T195_P045.wav" right
+[ 9, 12 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P045.wav" right
+[ 9, 13 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T165_P045.wav" right
+[ 9, 14 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P045.wav" right
+[ 9, 15 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T135_P045.wav" right
+[ 9, 16 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P045.wav" right
+[ 9, 17 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T105_P045.wav" right
+[ 9, 18 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P045.wav" right
+[ 9, 19 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T075_P045.wav" right
+[ 9, 20 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P045.wav" right
+[ 9, 21 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T045_P045.wav" right
+[ 9, 22 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P045.wav" right
+[ 9, 23 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P045.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T015_P045.wav" right
-[ 10, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P060.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P060.wav"
-[ 10, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P060.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P060.wav"
-[ 10, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P060.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P060.wav"
-[ 10, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P060.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P060.wav"
-[ 10, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P060.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P060.wav"
-[ 10, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P060.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P060.wav"
-[ 10, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P060.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P060.wav"
-[ 10, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P060.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P060.wav"
-[ 10, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P060.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P060.wav"
-[ 10, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P060.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P060.wav"
-[ 10, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P060.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P060.wav"
-[ 10, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P060.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P060.wav"
+[ 10, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P060.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P060.wav" right
+[ 10, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P060.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T330_P060.wav" right
+[ 10, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P060.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P060.wav" right
+[ 10, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P060.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T270_P060.wav" right
+[ 10, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P060.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P060.wav" right
+[ 10, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P060.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T210_P060.wav" right
+[ 10, 6 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P060.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P060.wav" right
+[ 10, 7 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P060.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T150_P060.wav" right
+[ 10, 8 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P060.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P060.wav" right
+[ 10, 9 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P060.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T090_P060.wav" right
+[ 10, 10 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P060.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P060.wav" right
+[ 10, 11 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P060.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T030_P060.wav" right
-[ 11, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P075.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P075.wav"
-[ 11, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P075.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P075.wav"
-[ 11, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P075.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P075.wav"
-[ 11, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P075.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P075.wav"
-[ 11, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P075.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P075.wav"
-[ 11, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P075.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P075.wav"
+[ 11, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P075.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P075.wav" right
+[ 11, 1 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P075.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T300_P075.wav" right
+[ 11, 2 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P075.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T240_P075.wav" right
+[ 11, 3 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P075.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T180_P075.wav" right
+[ 11, 4 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P075.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T120_P075.wav" right
+[ 11, 5 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P075.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T060_P075.wav" right
-[ 12, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P090.wav"
- + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P090.wav"
+[ 12, 0 ] = wave (0) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P090.wav" left
+ + wave (1) : "./IRC/RAW/WAV/IRC_1005_R/IRC_1005_R_R0195_T000_P090.wav" right
diff --git a/utils/MIT_KEMAR.def b/utils/MIT_KEMAR.def
index 1067e0b4..e6b0ddff 100644
--- a/utils/MIT_KEMAR.def
+++ b/utils/MIT_KEMAR.def
@@ -12,26 +12,26 @@
# It is copyrighted 1994 by MIT Media Laboratory, and provided free of charge
# with no restrictions on use so long as the authors (above) are cited.
#
-# This definition is used to generate the internal HRTF table used by OpenAL
+# This definition is used to generate the default HRTF table used by OpenAL
# Soft.
# The following are the data set metrics. They must always be specified at
-# start of a definition file, but their order is not important.
+# the start of a definition file, but their order is not important.
# Sampling rate of the HRIR data (in hertz).
rate = 44100
+# The channel type of incoming HRIR data (mono or stereo). Mono channel
+# inputs will result in mirroring to provide the right ear HRIRs. If not
+# specified, this defaults to mono.
+type = mono
+
# The number of points to use from the HRIR data. This should be a
# sufficiently large value (to encompass the entire impulse response). It
# cannot be smaller than the truncation size (default is 32) specified on the
# command line.
points = 512
-# A list of the number of azimuths measured for each elevation. There must
-# be at least 5 elevations covering the 180 degrees for the data set to be
-# viable.
-azimuths = 1, 12, 24, 36, 45, 56, 60, 72, 72, 72, 72, 72, 60, 56, 45, 36, 24, 12, 1
-
# The radius of the listener's head (measured ear-to-ear in meters). The
# makehrtf utility uses this value to rescale measured propagation delays
# when a custom head radius is specified on the command line. It is also
@@ -41,62 +41,83 @@ azimuths = 1, 12, 24, 36, 45, 56, 60, 72, 72, 72, 72, 72, 60, 56, 45, 36, 24, 12
# default). At the moment, radius rescaling does not adjust HRIR coupling.
radius = 0.09
-# The distance between the source and the listener (in meters). This does
-# have to match the data set, but it's effect is minimal at the moment due to
-# the coupled nature of OpenAL Soft's HRTF model.
+# A list of the distances between the source and the listener (in meters) for
+# each field. These must start at or above the head radius and proceed in
+# ascending order. Since the MIT set is single-field, there is only one
+# distance.
distance = 1.4
-# Following the metrics is the list of source HRIRs for each elevation and
-# azimuth pair. They don't have to be specified in order, but the final
-# composition must not be sparse. They can however begin above a number of
-# elevations (as typical for HRIR measurements).
+# A list of the number of azimuths measured for each elevation per field.
+# Elevations are separated by commas (,) while fields are separated by
+# semicolons (;). There must be at least 5 elevations covering 180 degrees
+# degrees of elevation for the data set to be viable. The poles (first and
+# last elevation) must be singular (an azimuth count of 1).
+azimuths = 1, 12, 24, 36, 45, 56, 60, 72, 72, 72, 72, 72, 60, 56, 45, 36, 24, 12, 1
+
+# Following the metrics is the list of source HRIRs for each field,
+# elevation, and azimuth triplet. They don't have to be specified in order,
+# but the final composition must not be sparse. They can however begin above
+# a number of elevations (as typical for HRIR measurements).
#
-# The elevation and azimuth indices are used to determine the resulting polar
-# coordinates following OpenAL Soft's convention (-90 degree elevation
-# increasing counter-clockwise from the bottom; 0 degree azimuth increasing
-# clockwise from the front).
+# The field index is used to determine the distance coordinate (for mult-
+# field HRTFs) while the elevation and azimuth indices are used to determine
+# the resulting polar coordinates following OpenAL Soft's convention (-90
+# degree elevation increasing counter-clockwise from the bottom; 0 degree
+# azimuth increasing clockwise from the front).
#
-# More than one HRIR can be used per source, in which case the average
-# magnitude response of all references for that source is used.
+# More than one HRIR can be used per source. This allows the composition of
+# averaged magnitude responses or the specification of stereo HRTFs. Target
+# ears must (and can only be) specified for each source when the type metric
+# is set to 'stereo'.
#
# Source specification is of the form (~BNF):
#
-# source = '[' ev_index ',' az_index ']' '=' source_ref [ '+' source_ref ]*
+# source = ( sf_index | mf_index ) source_ref [ '+' source_ref ]*
+#
+# sf_index = '[' ev_index ',' az_index ']' '='
+# mf_index = '[' fd_index ',' ev_index ',' az_index ']' '='
+# source_ref = mono_ref | stereo_ref
#
+# fd_index = unsigned_integer
# ev_index = unsigned_integer
# az_index = unsigned_integer
-# source_ref = ref_spec ':' filename
+# mono_ref = ref_spec ':' filename
+# stereo_ref = ref_spec ':' filename ear
#
-# ref_spec = ( wave_fmt '(' wave_parms ')' [ '@' start_sample ] ) |
-# ( bin_fmt '(' bini_parms ')' [ '@' start_bytes ] ) |
-# ( bin_fmt '(' binf_parms ')' [ '@' start_bytes ] ) |
-# ( ascii_fmt '(' asci_parms ')' [ '@' start_elements ] ) |
-# ( ascii_fmt '(' ascf_parms ')' [ '@' start_elements ] )
+# ref_spec = ( wave_fmt '(' wave_parms ')' [ '@' start_sample ] ) |
+# ( bin_fmt '(' bini_parms ')' [ '@' start_byte ] ) |
+# ( bin_fmt '(' binf_parms ')' [ '@' start_byte ] ) |
+# ( ascii_fmt '(' asci_parms ')' [ '@' start_element ] ) |
+# ( ascii_fmt '(' ascf_parms ')' [ '@' start_element ] )
# filename = double_quoted_string
+# ear = 'left' | 'right'
#
-# wave_fmt = 'wave'
-# wave_parms = channel
-# bin_fmt = 'bin_le' | 'bin_be'
-# bini_parms = 'int' ',' byte_size [ ',' bin_sig_bits ] [ ';' skip_bytes ]
-# binf_parms = 'fp' ',' byte_size [ ';' skip_bytes ]
-# ascii_fmt = 'ascii'
-# asci_parms = 'int' ',' sig_bits [ ';' skip_elements ]
-# ascf_parms = 'fp' [ ';' skip_elements ]
-# start_sample = unsigned_integer
-# start_bytes = unsigned_integer
-# start_elements = unsigned_integer
+# wave_fmt = 'wave'
+# wave_parms = channel
+# bin_fmt = 'bin_le' | 'bin_be'
+# bini_parms = 'int' ',' byte_size [ ',' bin_sig_bits ] [ ';' skip_bytes ]
+# binf_parms = 'fp' ',' byte_size [ ';' skip_bytes ]
+# ascii_fmt = 'ascii'
+# asci_parms = 'int' ',' sig_bits [ ';' skip_elements ]
+# ascf_parms = 'fp' [ ';' skip_elements ]
+# start_sample = unsigned_integer
+# start_byte = unsigned_integer
+# start_element = unsigned_integer
#
-# channel = unsigned_integer
-# byte_size = unsigned_integer
-# bin_sig_bits = signed_integer
-# skip_bytes = unsigned_integer
-# sig_bits = unsigned_integer
-# skip_elements = unsigned_integer
+# channel = unsigned_integer
+# byte_size = unsigned_integer
+# bin_sig_bits = signed_integer
+# skip_bytes = unsigned_integer
+# sig_bits = unsigned_integer
+# skip_elements = unsigned_integer
#
# For bin_sig_bits, positive values mean the significant bits start at the
# MSB (padding toward the LSB) while negative values mean they start at the
# LSB.
+# Even though the MIT set is provided as stereo .wav files, each channel is
+# for a different sized KEMAR ear. Since it is not a stereo data set, no ear
+# is specified. The smaller KEMAR ear (in the left channel: 0) is used.
[ 5, 0 ] = wave (0) : "./MITfull/elev-40/L-40e000a.wav"
[ 5, 1 ] = wave (0) : "./MITfull/elev-40/L-40e006a.wav"
[ 5, 2 ] = wave (0) : "./MITfull/elev-40/L-40e013a.wav"
diff --git a/utils/alsoft-config/CMakeLists.txt b/utils/alsoft-config/CMakeLists.txt
index a6707a3d..67cc44c7 100644
--- a/utils/alsoft-config/CMakeLists.txt
+++ b/utils/alsoft-config/CMakeLists.txt
@@ -1,29 +1,58 @@
project(alsoft-config)
-include_directories("${alsoft-config_BINARY_DIR}")
+option(ALSOFT_NO_QT5 "Use Qt4 instead of Qt5 for alsoft-config" FALSE)
-# Need Qt 4.8.0 or newer for the iconset theme attribute to work
-find_package(Qt4 4.8.0 COMPONENTS QtCore QtGui)
-if(QT4_FOUND)
- include(${QT_USE_FILE})
+include_directories("${alsoft-config_BINARY_DIR}")
- set(alsoft-config_SRCS main.cpp
- mainwindow.cpp
- )
+set(alsoft-config_SRCS
+ main.cpp
+ mainwindow.cpp
+ mainwindow.h
+)
+set(alsoft-config_UIS mainwindow.ui)
+set(alsoft-config_MOCS mainwindow.h)
- set(alsoft-config_UIS mainwindow.ui)
- QT4_WRAP_UI(UIS ${alsoft-config_UIS})
+find_package(Qt5Widgets)
+if(Qt5Widgets_FOUND AND NOT ALSOFT_NO_QT5)
+ qt5_wrap_ui(UIS ${alsoft-config_UIS})
- set(alsoft-config_MOCS mainwindow.h)
- QT4_WRAP_CPP(MOCS ${alsoft-config_MOCS})
+ qt5_wrap_cpp(MOCS ${alsoft-config_MOCS})
add_executable(alsoft-config ${alsoft-config_SRCS} ${UIS} ${RSCS} ${TRS} ${MOCS})
- target_link_libraries(alsoft-config ${QT_LIBRARIES})
+ target_link_libraries(alsoft-config Qt5::Widgets)
+ set_property(TARGET alsoft-config APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
set_target_properties(alsoft-config PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OpenAL_BINARY_DIR})
+ if(TARGET build_version)
+ add_dependencies(alsoft-config build_version)
+ endif()
install(TARGETS alsoft-config
- RUNTIME DESTINATION bin
- LIBRARY DESTINATION "lib${LIB_SUFFIX}"
- ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
+else()
+ # Need Qt 4.8.0 or newer for the iconset theme attribute to work
+ find_package(Qt4 4.8.0 COMPONENTS QtCore QtGui)
+ if(QT4_FOUND)
+ include(${QT_USE_FILE})
+
+ qt4_wrap_ui(UIS ${alsoft-config_UIS})
+
+ qt4_wrap_cpp(MOCS ${alsoft-config_MOCS})
+
+ add_executable(alsoft-config ${alsoft-config_SRCS} ${UIS} ${RSCS} ${TRS} ${MOCS})
+ target_link_libraries(alsoft-config ${QT_LIBRARIES})
+ set_property(TARGET alsoft-config APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
+ set_target_properties(alsoft-config PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OpenAL_BINARY_DIR})
+ if(TARGET build_version)
+ add_dependencies(alsoft-config build_version)
+ endif()
+
+ install(TARGETS alsoft-config
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ )
+ endif()
endif()
diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp
index 01f59e4b..110fe4ed 100644
--- a/utils/alsoft-config/mainwindow.cpp
+++ b/utils/alsoft-config/mainwindow.cpp
@@ -1,78 +1,89 @@
#include "config.h"
+#include "version.h"
+
+#include <iostream>
+#include <cmath>
+
#include <QFileDialog>
#include <QMessageBox>
+#include <QCloseEvent>
#include <QSettings>
#include <QtGlobal>
#include "mainwindow.h"
#include "ui_mainwindow.h"
namespace {
+
static const struct {
char backend_name[16];
- char menu_string[32];
-} backendMenuList[] = {
+ char full_string[32];
+} backendList[] = {
#ifdef HAVE_JACK
- { "jack", "Add JACK" },
+ { "jack", "JACK" },
#endif
#ifdef HAVE_PULSEAUDIO
- { "pulse", "Add PulseAudio" },
+ { "pulse", "PulseAudio" },
#endif
#ifdef HAVE_ALSA
- { "alsa", "Add ALSA" },
+ { "alsa", "ALSA" },
#endif
#ifdef HAVE_COREAUDIO
- { "core", "Add CoreAudio" },
+ { "core", "CoreAudio" },
#endif
#ifdef HAVE_OSS
- { "oss", "Add OSS" },
+ { "oss", "OSS" },
#endif
#ifdef HAVE_SOLARIS
- { "solaris", "Add Solaris" },
+ { "solaris", "Solaris" },
#endif
#ifdef HAVE_SNDIO
- { "sndio", "Add SndIO" },
+ { "sndio", "SoundIO" },
#endif
#ifdef HAVE_QSA
- { "qsa", "Add QSA" },
+ { "qsa", "QSA" },
#endif
-#ifdef HAVE_MMDEVAPI
- { "mmdevapi", "Add MMDevAPI" },
+#ifdef HAVE_WASAPI
+ { "wasapi", "WASAPI" },
#endif
#ifdef HAVE_DSOUND
- { "dsound", "Add DirectSound" },
+ { "dsound", "DirectSound" },
#endif
#ifdef HAVE_WINMM
- { "winmm", "Add Windows Multimedia" },
+ { "winmm", "Windows Multimedia" },
#endif
#ifdef HAVE_PORTAUDIO
- { "port", "Add PortAudio" },
+ { "port", "PortAudio" },
#endif
#ifdef HAVE_OPENSL
- { "opensl", "Add OpenSL" },
+ { "opensl", "OpenSL" },
#endif
- { "null", "Add Null Output" },
+ { "null", "Null Output" },
#ifdef HAVE_WAVE
- { "wave", "Add Wave Writer" },
+ { "wave", "Wave Writer" },
#endif
{ "", "" }
};
-static const struct {
+static const struct NameValuePair {
const char name[64];
const char value[16];
} speakerModeList[] = {
{ "Autodetect", "" },
{ "Mono", "mono" },
{ "Stereo", "stereo" },
- { "Quadrophonic", "quad" },
+ { "Quadraphonic", "quad" },
{ "5.1 Surround (Side)", "surround51" },
{ "5.1 Surround (Rear)", "surround51rear" },
{ "6.1 Surround", "surround61" },
{ "7.1 Surround", "surround71" },
+ { "Ambisonic, 1st Order", "ambi1" },
+ { "Ambisonic, 2nd Order", "ambi2" },
+ { "Ambisonic, 3rd Order", "ambi3" },
+
{ "", "" }
}, sampleTypeList[] = {
{ "Autodetect", "" },
@@ -86,12 +97,12 @@ static const struct {
{ "", "" }
}, resamplerList[] = {
- { "Default", "" },
- { "Point (low quality, very fast)", "point" },
- { "Linear (basic quality, fast)", "linear" },
- { "4-Point Sinc (good quality)", "sinc4" },
- { "8-Point Sinc (high quality, slow)", "sinc8" },
- { "Band-limited Sinc (very high quality, very slow)", "bsinc" },
+ { "Point", "point" },
+ { "Linear", "linear" },
+ { "Default (Linear)", "" },
+ { "Cubic Spline", "cubic" },
+ { "11th order Sinc", "bsinc12" },
+ { "23rd order Sinc", "bsinc24" },
{ "", "" }
}, stereoModeList[] = {
@@ -100,6 +111,19 @@ static const struct {
{ "Headphones", "headphones" },
{ "", "" }
+}, stereoEncList[] = {
+ { "Default", "" },
+ { "Pan Pot", "panpot" },
+ { "UHJ", "uhj" },
+
+ { "", "" }
+}, ambiFormatList[] = {
+ { "Default", "" },
+ { "ACN + SN3D", "acn+sn3d" },
+ { "ACN + N3D", "acn+n3d" },
+ { "Furse-Malham", "fuma" },
+
+ { "", "" }
};
static QString getDefaultConfigName()
@@ -163,6 +187,29 @@ static QStringList getAllDataPaths(QString append=QString())
}
return list;
}
+
+template<size_t N>
+static QString getValueFromName(const NameValuePair (&list)[N], const QString &str)
+{
+ for(size_t i = 0;i < N-1;i++)
+ {
+ if(str == list[i].name)
+ return list[i].value;
+ }
+ return QString();
+}
+
+template<size_t N>
+static QString getNameFromValue(const NameValuePair (&list)[N], const QString &str)
+{
+ for(size_t i = 0;i < N-1;i++)
+ {
+ if(str == list[i].value)
+ return list[i].name;
+ }
+ return QString();
+}
+
}
MainWindow::MainWindow(QWidget *parent) :
@@ -173,7 +220,9 @@ MainWindow::MainWindow(QWidget *parent) :
mSourceCountValidator(NULL),
mEffectSlotValidator(NULL),
mSourceSendValidator(NULL),
- mSampleRateValidator(NULL)
+ mSampleRateValidator(NULL),
+ mJackBufferValidator(NULL),
+ mNeedsSave(false)
{
ui->setupUi(this);
@@ -183,12 +232,20 @@ MainWindow::MainWindow(QWidget *parent) :
for(int i = 0;sampleTypeList[i].name[0];i++)
ui->sampleFormatCombo->addItem(sampleTypeList[i].name);
ui->sampleFormatCombo->adjustSize();
- for(int i = 0;resamplerList[i].name[0];i++)
- ui->resamplerComboBox->addItem(resamplerList[i].name);
- ui->resamplerComboBox->adjustSize();
for(int i = 0;stereoModeList[i].name[0];i++)
ui->stereoModeCombo->addItem(stereoModeList[i].name);
ui->stereoModeCombo->adjustSize();
+ for(int i = 0;stereoEncList[i].name[0];i++)
+ ui->stereoEncodingComboBox->addItem(stereoEncList[i].name);
+ ui->stereoEncodingComboBox->adjustSize();
+ for(int i = 0;ambiFormatList[i].name[0];i++)
+ ui->ambiFormatComboBox->addItem(ambiFormatList[i].name);
+ ui->ambiFormatComboBox->adjustSize();
+
+ int count;
+ for(count = 0;resamplerList[count].name[0];count++) {
+ }
+ ui->resamplerSlider->setRange(0, count-1);
ui->hrtfStateComboBox->adjustSize();
@@ -237,34 +294,134 @@ MainWindow::MainWindow(QWidget *parent) :
mPeriodCountValidator = new QIntValidator(2, 16, this);
ui->periodCountEdit->setValidator(mPeriodCountValidator);
- mSourceCountValidator = new QIntValidator(0, 256, this);
+ mSourceCountValidator = new QIntValidator(0, 4096, this);
ui->srcCountLineEdit->setValidator(mSourceCountValidator);
- mEffectSlotValidator = new QIntValidator(0, 16, this);
+ mEffectSlotValidator = new QIntValidator(0, 64, this);
ui->effectSlotLineEdit->setValidator(mEffectSlotValidator);
- mSourceSendValidator = new QIntValidator(0, 4, this);
+ mSourceSendValidator = new QIntValidator(0, 16, this);
ui->srcSendLineEdit->setValidator(mSourceSendValidator);
mSampleRateValidator = new QIntValidator(8000, 192000, this);
ui->sampleRateCombo->lineEdit()->setValidator(mSampleRateValidator);
+ mJackBufferValidator = new QIntValidator(0, 8192, this);
+ ui->jackBufferSizeLine->setValidator(mJackBufferValidator);
+
connect(ui->actionLoad, SIGNAL(triggered()), this, SLOT(loadConfigFromFile()));
connect(ui->actionSave_As, SIGNAL(triggered()), this, SLOT(saveConfigAsFile()));
+ connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAboutPage()));
+
+ connect(ui->closeCancelButton, SIGNAL(clicked()), this, SLOT(cancelCloseAction()));
connect(ui->applyButton, SIGNAL(clicked()), this, SLOT(saveCurrentConfig()));
+ connect(ui->channelConfigCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
+ connect(ui->sampleFormatCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
+ connect(ui->stereoModeCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
+ connect(ui->sampleRateCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
+ connect(ui->sampleRateCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(enableApplyButton()));
+
+ connect(ui->resamplerSlider, SIGNAL(valueChanged(int)), this, SLOT(updateResamplerLabel(int)));
+
connect(ui->periodSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePeriodSizeEdit(int)));
connect(ui->periodSizeEdit, SIGNAL(editingFinished()), this, SLOT(updatePeriodSizeSlider()));
connect(ui->periodCountSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePeriodCountEdit(int)));
connect(ui->periodCountEdit, SIGNAL(editingFinished()), this, SLOT(updatePeriodCountSlider()));
+ connect(ui->stereoEncodingComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(enableApplyButton()));
+ connect(ui->ambiFormatComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(enableApplyButton()));
+ connect(ui->outputLimiterCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->outputDitherCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+
+ connect(ui->decoderHQModeCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->decoderDistCompCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->decoderNFEffectsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->decoderNFRefDelaySpinBox, SIGNAL(valueChanged(double)), this, SLOT(enableApplyButton()));
+ connect(ui->decoderQuadLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
+ connect(ui->decoderQuadButton, SIGNAL(clicked()), this, SLOT(selectQuadDecoderFile()));
+ connect(ui->decoder51LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
+ connect(ui->decoder51Button, SIGNAL(clicked()), this, SLOT(select51DecoderFile()));
+ connect(ui->decoder61LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
+ connect(ui->decoder61Button, SIGNAL(clicked()), this, SLOT(select61DecoderFile()));
+ connect(ui->decoder71LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
+ connect(ui->decoder71Button, SIGNAL(clicked()), this, SLOT(select71DecoderFile()));
+
+ connect(ui->preferredHrtfComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
+ connect(ui->hrtfStateComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
connect(ui->hrtfAddButton, SIGNAL(clicked()), this, SLOT(addHrtfFile()));
connect(ui->hrtfRemoveButton, SIGNAL(clicked()), this, SLOT(removeHrtfFile()));
connect(ui->hrtfFileList, SIGNAL(itemSelectionChanged()), this, SLOT(updateHrtfRemoveButton()));
+ connect(ui->defaultHrtfPathsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+
+ connect(ui->srcCountLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
+ connect(ui->srcSendLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
+ connect(ui->effectSlotLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton()));
+
+ connect(ui->enableSSECheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableSSE2CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableSSE3CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableSSE41CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableNeonCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
ui->enabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->enabledBackendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showEnabledBackendMenu(QPoint)));
ui->disabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->disabledBackendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showDisabledBackendMenu(QPoint)));
+ connect(ui->backendCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+
+ connect(ui->defaultReverbComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton()));
+ connect(ui->enableEaxReverbCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableStdReverbCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableAutowahCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableChorusCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableCompressorCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableDistortionCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableEchoCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableEqualizerCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableFlangerCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableFrequencyShifterCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableModulatorCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enableDedicatedCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->enablePitchShifterCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+
+ connect(ui->pulseAutospawnCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->pulseAllowMovesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->pulseFixRateCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+
+ connect(ui->jackAutospawnCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->jackBufferSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(updateJackBufferSizeEdit(int)));
+ connect(ui->jackBufferSizeLine, SIGNAL(editingFinished()), this, SLOT(updateJackBufferSizeSlider()));
+
+ connect(ui->alsaDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
+ connect(ui->alsaDefaultCaptureLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
+ connect(ui->alsaResamplerCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+ connect(ui->alsaMmapCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+
+ connect(ui->ossDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
+ connect(ui->ossPlaybackPushButton, SIGNAL(clicked(bool)), this, SLOT(selectOSSPlayback()));
+ connect(ui->ossDefaultCaptureLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
+ connect(ui->ossCapturePushButton, SIGNAL(clicked(bool)), this, SLOT(selectOSSCapture()));
+
+ connect(ui->solarisDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
+ connect(ui->solarisPlaybackPushButton, SIGNAL(clicked(bool)), this, SLOT(selectSolarisPlayback()));
+
+ connect(ui->waveOutputLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
+ connect(ui->waveOutputButton, SIGNAL(clicked(bool)), this, SLOT(selectWaveOutput()));
+ connect(ui->waveBFormatCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton()));
+
+ ui->backendListWidget->setCurrentRow(0);
+ ui->tabWidget->setCurrentIndex(0);
+
+ for(int i = 1;i < ui->backendListWidget->count();i++)
+ ui->backendListWidget->setRowHidden(i, true);
+ for(int i = 0;backendList[i].backend_name[0];i++)
+ {
+ QList<QListWidgetItem*> items = ui->backendListWidget->findItems(
+ backendList[i].full_string, Qt::MatchFixedString
+ );
+ foreach(const QListWidgetItem *item, items)
+ ui->backendListWidget->setItemHidden(item, false);
+ }
loadConfig(getDefaultConfigName());
}
@@ -278,8 +435,125 @@ MainWindow::~MainWindow()
delete mEffectSlotValidator;
delete mSourceSendValidator;
delete mSampleRateValidator;
+ delete mJackBufferValidator;
+}
+
+void MainWindow::closeEvent(QCloseEvent *event)
+{
+ if(!mNeedsSave)
+ event->accept();
+ else
+ {
+ QMessageBox::StandardButton btn = QMessageBox::warning(this,
+ tr("Apply changes?"), tr("Save changes before quitting?"),
+ QMessageBox::Save | QMessageBox::No | QMessageBox::Cancel
+ );
+ if(btn == QMessageBox::Save)
+ saveCurrentConfig();
+ if(btn == QMessageBox::Cancel)
+ event->ignore();
+ else
+ event->accept();
+ }
+}
+
+void MainWindow::cancelCloseAction()
+{
+ mNeedsSave = false;
+ close();
+}
+
+
+void MainWindow::showAboutPage()
+{
+ QMessageBox::information(this, tr("About"),
+ tr("OpenAL Soft Configuration Utility.\nBuilt for OpenAL Soft library version ")+
+ (ALSOFT_VERSION "-" ALSOFT_GIT_COMMIT_HASH " (" ALSOFT_GIT_BRANCH " branch).")
+ );
+}
+
+
+QStringList MainWindow::collectHrtfs()
+{
+ QStringList ret;
+ QStringList processed;
+
+ for(int i = 0;i < ui->hrtfFileList->count();i++)
+ {
+ QDir dir(ui->hrtfFileList->item(i)->text());
+ QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
+ foreach(const QString &fname, fnames)
+ {
+ if(!fname.endsWith(".mhr", Qt::CaseInsensitive))
+ continue;
+ QString fullname = dir.absoluteFilePath(fname);
+ if(processed.contains(fullname))
+ continue;
+ processed.push_back(fullname);
+
+ QString name = fname.left(fname.length()-4);
+ if(!ret.contains(name))
+ ret.push_back(name);
+ else
+ {
+ size_t i = 2;
+ do {
+ QString s = name+" #"+QString::number(i);
+ if(!ret.contains(s))
+ {
+ ret.push_back(s);
+ break;
+ }
+ ++i;
+ } while(1);
+ }
+ }
+ }
+
+ if(ui->defaultHrtfPathsCheckBox->isChecked())
+ {
+ QStringList paths = getAllDataPaths("/openal/hrtf");
+ foreach(const QString &name, paths)
+ {
+ QDir dir(name);
+ QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name);
+ foreach(const QString &fname, fnames)
+ {
+ if(!fname.endsWith(".mhr", Qt::CaseInsensitive))
+ continue;
+ QString fullname = dir.absoluteFilePath(fname);
+ if(processed.contains(fullname))
+ continue;
+ processed.push_back(fullname);
+
+ QString name = fname.left(fname.length()-4);
+ if(!ret.contains(name))
+ ret.push_back(name);
+ else
+ {
+ size_t i = 2;
+ do {
+ QString s = name+" #"+QString::number(i);
+ if(!ret.contains(s))
+ {
+ ret.push_back(s);
+ break;
+ }
+ ++i;
+ } while(1);
+ }
+ }
+ }
+
+#ifdef ALSOFT_EMBED_HRTF_DATA
+ ret.push_back("Built-In 44100hz");
+ ret.push_back("Built-In 48000hz");
+#endif
+ }
+ return ret;
}
+
void MainWindow::loadConfigFromFile()
{
QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
@@ -295,21 +569,11 @@ void MainWindow::loadConfig(const QString &fname)
ui->sampleFormatCombo->setCurrentIndex(0);
if(sampletype.isEmpty() == false)
{
- for(int i = 0;sampleTypeList[i].name[i];i++)
+ QString str = getNameFromValue(sampleTypeList, sampletype);
+ if(!str.isEmpty())
{
- if(sampletype == sampleTypeList[i].value)
- {
- for(int j = 1;j < ui->sampleFormatCombo->count();j++)
- {
- QString item = ui->sampleFormatCombo->itemText(j);
- if(item == sampleTypeList[i].name)
- {
- ui->sampleFormatCombo->setCurrentIndex(j);
- break;
- }
- }
- break;
- }
+ int j = ui->sampleFormatCombo->findText(str);
+ if(j > 0) ui->sampleFormatCombo->setCurrentIndex(j);
}
}
@@ -317,21 +581,11 @@ void MainWindow::loadConfig(const QString &fname)
ui->channelConfigCombo->setCurrentIndex(0);
if(channelconfig.isEmpty() == false)
{
- for(int i = 0;speakerModeList[i].name[i];i++)
+ QString str = getNameFromValue(speakerModeList, channelconfig);
+ if(!str.isEmpty())
{
- if(channelconfig == speakerModeList[i].value)
- {
- for(int j = 1;j < ui->channelConfigCombo->count();j++)
- {
- QString item = ui->channelConfigCombo->itemText(j);
- if(item == speakerModeList[i].name)
- {
- ui->channelConfigCombo->setCurrentIndex(j);
- break;
- }
- }
- break;
- }
+ int j = ui->channelConfigCombo->findText(str);
+ if(j > 0) ui->channelConfigCombo->setCurrentIndex(j);
}
}
@@ -352,29 +606,23 @@ void MainWindow::loadConfig(const QString &fname)
ui->srcSendLineEdit->insert(settings.value("sends").toString());
QString resampler = settings.value("resampler").toString().trimmed();
- ui->resamplerComboBox->setCurrentIndex(0);
- if(resampler.isEmpty() == false)
+ ui->resamplerSlider->setValue(2);
+ ui->resamplerLabel->setText(resamplerList[2].name);
+ /* The "cubic" and "sinc8" resamplers are no longer supported. Use "sinc4"
+ * as a fallback.
+ */
+ if(resampler == "cubic" || resampler == "sinc8")
+ resampler = "sinc4";
+ /* The "bsinc" resampler name is an alias for "bsinc12". */
+ else if(resampler == "bsinc")
+ resampler = "bsinc12";
+ for(int i = 0;resamplerList[i].name[0];i++)
{
- /* The "cubic" resampler is no longer supported. It's been replaced by
- * "sinc4". */
- if(resampler == "cubic")
- resampler = "sinc4";
-
- for(int i = 0;resamplerList[i].name[i];i++)
+ if(resampler == resamplerList[i].value)
{
- if(resampler == resamplerList[i].value)
- {
- for(int j = 1;j < ui->resamplerComboBox->count();j++)
- {
- QString item = ui->resamplerComboBox->itemText(j);
- if(item == resamplerList[i].name)
- {
- ui->resamplerComboBox->setCurrentIndex(j);
- break;
- }
- }
- break;
- }
+ ui->resamplerSlider->setValue(i);
+ ui->resamplerLabel->setText(resamplerList[i].name);
+ break;
}
}
@@ -382,21 +630,11 @@ void MainWindow::loadConfig(const QString &fname)
ui->stereoModeCombo->setCurrentIndex(0);
if(stereomode.isEmpty() == false)
{
- for(int i = 0;stereoModeList[i].name[i];i++)
+ QString str = getNameFromValue(stereoModeList, stereomode);
+ if(!str.isEmpty())
{
- if(stereomode == stereoModeList[i].value)
- {
- for(int j = 1;j < ui->stereoModeCombo->count();j++)
- {
- QString item = ui->stereoModeCombo->itemText(j);
- if(item == stereoModeList[i].name)
- {
- ui->stereoModeCombo->setCurrentIndex(j);
- break;
- }
- }
- break;
- }
+ int j = ui->stereoModeCombo->findText(str);
+ if(j > 0) ui->stereoModeCombo->setCurrentIndex(j);
}
}
@@ -416,36 +654,119 @@ void MainWindow::loadConfig(const QString &fname)
updatePeriodCountSlider();
}
+ if(settings.value("output-limiter").isNull())
+ ui->outputLimiterCheckBox->setCheckState(Qt::PartiallyChecked);
+ else
+ ui->outputLimiterCheckBox->setCheckState(
+ settings.value("output-limiter").toBool() ? Qt::Checked : Qt::Unchecked
+ );
+
+ if(settings.value("dither").isNull())
+ ui->outputDitherCheckBox->setCheckState(Qt::PartiallyChecked);
+ else
+ ui->outputDitherCheckBox->setCheckState(
+ settings.value("dither").toBool() ? Qt::Checked : Qt::Unchecked
+ );
+
+ QString stereopan = settings.value("stereo-encoding").toString();
+ ui->stereoEncodingComboBox->setCurrentIndex(0);
+ if(stereopan.isEmpty() == false)
+ {
+ QString str = getNameFromValue(stereoEncList, stereopan);
+ if(!str.isEmpty())
+ {
+ int j = ui->stereoEncodingComboBox->findText(str);
+ if(j > 0) ui->stereoEncodingComboBox->setCurrentIndex(j);
+ }
+ }
+
+ QString ambiformat = settings.value("ambi-format").toString();
+ ui->ambiFormatComboBox->setCurrentIndex(0);
+ if(ambiformat.isEmpty() == false)
+ {
+ QString str = getNameFromValue(ambiFormatList, ambiformat);
+ if(!str.isEmpty())
+ {
+ int j = ui->ambiFormatComboBox->findText(str);
+ if(j > 0) ui->ambiFormatComboBox->setCurrentIndex(j);
+ }
+ }
+
+ bool hqmode = settings.value("decoder/hq-mode", false).toBool();
+ ui->decoderHQModeCheckBox->setChecked(hqmode);
+ bool distcomp = settings.value("decoder/distance-comp", true).toBool();
+ ui->decoderDistCompCheckBox->setChecked(distcomp);
+ bool nfeffects = settings.value("decoder/nfc", true).toBool();
+ ui->decoderNFEffectsCheckBox->setChecked(nfeffects);
+ double refdelay = settings.value("decoder/nfc-ref-delay", 0.0).toDouble();
+ ui->decoderNFRefDelaySpinBox->setValue(refdelay);
+
+ ui->decoderQuadLineEdit->setText(settings.value("decoder/quad").toString());
+ ui->decoder51LineEdit->setText(settings.value("decoder/surround51").toString());
+ ui->decoder61LineEdit->setText(settings.value("decoder/surround61").toString());
+ ui->decoder71LineEdit->setText(settings.value("decoder/surround71").toString());
+
QStringList disabledCpuExts = settings.value("disable-cpu-exts").toStringList();
if(disabledCpuExts.size() == 1)
disabledCpuExts = disabledCpuExts[0].split(QChar(','));
- std::transform(disabledCpuExts.begin(), disabledCpuExts.end(),
- disabledCpuExts.begin(), std::mem_fun_ref(&QString::trimmed));
+ for(QStringList::iterator iter = disabledCpuExts.begin();iter != disabledCpuExts.end();iter++)
+ *iter = iter->trimmed();
ui->enableSSECheckBox->setChecked(!disabledCpuExts.contains("sse", Qt::CaseInsensitive));
ui->enableSSE2CheckBox->setChecked(!disabledCpuExts.contains("sse2", Qt::CaseInsensitive));
ui->enableSSE3CheckBox->setChecked(!disabledCpuExts.contains("sse3", Qt::CaseInsensitive));
ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains("sse4.1", Qt::CaseInsensitive));
ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains("neon", Qt::CaseInsensitive));
- if(settings.value("hrtf").toString() == QString())
- ui->hrtfStateComboBox->setCurrentIndex(0);
+ QStringList hrtf_paths = settings.value("hrtf-paths").toStringList();
+ if(hrtf_paths.size() == 1)
+ hrtf_paths = hrtf_paths[0].split(QChar(','));
+ for(QStringList::iterator iter = hrtf_paths.begin();iter != hrtf_paths.end();iter++)
+ *iter = iter->trimmed();
+ if(!hrtf_paths.empty() && !hrtf_paths.back().isEmpty())
+ ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Unchecked);
else
{
- if(settings.value("hrtf", true).toBool())
- ui->hrtfStateComboBox->setCurrentIndex(1);
- else
- ui->hrtfStateComboBox->setCurrentIndex(2);
+ hrtf_paths.removeAll(QString());
+ ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Checked);
}
-
- QStringList hrtf_tables = settings.value("hrtf_tables").toStringList();
- if(hrtf_tables.size() == 1)
- hrtf_tables = hrtf_tables[0].split(QChar(','));
- std::transform(hrtf_tables.begin(), hrtf_tables.end(),
- hrtf_tables.begin(), std::mem_fun_ref(&QString::trimmed));
+ hrtf_paths.removeDuplicates();
ui->hrtfFileList->clear();
- ui->hrtfFileList->addItems(hrtf_tables);
+ ui->hrtfFileList->addItems(hrtf_paths);
updateHrtfRemoveButton();
+ QString hrtfstate = settings.value("hrtf").toString().toLower();
+ if(hrtfstate == "true")
+ ui->hrtfStateComboBox->setCurrentIndex(1);
+ else if(hrtfstate == "false")
+ ui->hrtfStateComboBox->setCurrentIndex(2);
+ else
+ ui->hrtfStateComboBox->setCurrentIndex(0);
+
+ ui->preferredHrtfComboBox->clear();
+ ui->preferredHrtfComboBox->addItem("- Any -");
+ if(ui->defaultHrtfPathsCheckBox->isChecked())
+ {
+ QStringList hrtfs = collectHrtfs();
+ foreach(const QString &name, hrtfs)
+ ui->preferredHrtfComboBox->addItem(name);
+ }
+
+ QString defaulthrtf = settings.value("default-hrtf").toString();
+ ui->preferredHrtfComboBox->setCurrentIndex(0);
+ if(defaulthrtf.isEmpty() == false)
+ {
+ int i = ui->preferredHrtfComboBox->findText(defaulthrtf);
+ if(i > 0)
+ ui->preferredHrtfComboBox->setCurrentIndex(i);
+ else
+ {
+ i = ui->preferredHrtfComboBox->count();
+ ui->preferredHrtfComboBox->addItem(defaulthrtf);
+ ui->preferredHrtfComboBox->setCurrentIndex(i);
+ }
+ }
+ ui->preferredHrtfComboBox->adjustSize();
+
ui->enabledBackendList->clear();
ui->disabledBackendList->clear();
QStringList drivers = settings.value("drivers").toStringList();
@@ -455,17 +776,45 @@ void MainWindow::loadConfig(const QString &fname)
{
if(drivers.size() == 1)
drivers = drivers[0].split(QChar(','));
- std::transform(drivers.begin(), drivers.end(),
- drivers.begin(), std::mem_fun_ref(&QString::trimmed));
+ for(QStringList::iterator iter = drivers.begin();iter != drivers.end();iter++)
+ {
+ *iter = iter->trimmed();
+ /* Convert "mmdevapi" references to "wasapi" for backwards
+ * compatibility.
+ */
+ if(*iter == "-mmdevapi")
+ *iter = "-wasapi";
+ else if(*iter == "mmdevapi")
+ *iter = "wasapi";
+ }
bool lastWasEmpty = false;
foreach(const QString &backend, drivers)
{
lastWasEmpty = backend.isEmpty();
- if(!backend.startsWith(QChar('-')) && !lastWasEmpty)
- ui->enabledBackendList->addItem(backend);
+ if(lastWasEmpty) continue;
+
+ if(!backend.startsWith(QChar('-')))
+ for(int j = 0;backendList[j].backend_name[0];j++)
+ {
+ if(backend == backendList[j].backend_name)
+ {
+ ui->enabledBackendList->addItem(backendList[j].full_string);
+ break;
+ }
+ }
else if(backend.size() > 1)
- ui->disabledBackendList->addItem(backend.right(backend.size()-1));
+ {
+ QStringRef backendref = backend.rightRef(backend.size()-1);
+ for(int j = 0;backendList[j].backend_name[0];j++)
+ {
+ if(backendref == backendList[j].backend_name)
+ {
+ ui->disabledBackendList->addItem(backendList[j].full_string);
+ break;
+ }
+ }
+ }
}
ui->backendCheckBox->setChecked(lastWasEmpty);
}
@@ -484,28 +833,57 @@ void MainWindow::loadConfig(const QString &fname)
}
}
- ui->emulateEaxCheckBox->setChecked(settings.value("reverb/emulate-eax", false).toBool());
-
QStringList excludefx = settings.value("excludefx").toStringList();
if(excludefx.size() == 1)
excludefx = excludefx[0].split(QChar(','));
- std::transform(excludefx.begin(), excludefx.end(),
- excludefx.begin(), std::mem_fun_ref(&QString::trimmed));
+ for(QStringList::iterator iter = excludefx.begin();iter != excludefx.end();iter++)
+ *iter = iter->trimmed();
ui->enableEaxReverbCheck->setChecked(!excludefx.contains("eaxreverb", Qt::CaseInsensitive));
ui->enableStdReverbCheck->setChecked(!excludefx.contains("reverb", Qt::CaseInsensitive));
+ ui->enableAutowahCheck->setChecked(!excludefx.contains("autowah", Qt::CaseInsensitive));
ui->enableChorusCheck->setChecked(!excludefx.contains("chorus", Qt::CaseInsensitive));
ui->enableCompressorCheck->setChecked(!excludefx.contains("compressor", Qt::CaseInsensitive));
ui->enableDistortionCheck->setChecked(!excludefx.contains("distortion", Qt::CaseInsensitive));
ui->enableEchoCheck->setChecked(!excludefx.contains("echo", Qt::CaseInsensitive));
ui->enableEqualizerCheck->setChecked(!excludefx.contains("equalizer", Qt::CaseInsensitive));
ui->enableFlangerCheck->setChecked(!excludefx.contains("flanger", Qt::CaseInsensitive));
+ ui->enableFrequencyShifterCheck->setChecked(!excludefx.contains("fshifter", Qt::CaseInsensitive));
ui->enableModulatorCheck->setChecked(!excludefx.contains("modulator", Qt::CaseInsensitive));
ui->enableDedicatedCheck->setChecked(!excludefx.contains("dedicated", Qt::CaseInsensitive));
+ ui->enablePitchShifterCheck->setChecked(!excludefx.contains("pshifter", Qt::CaseInsensitive));
+
+ ui->pulseAutospawnCheckBox->setChecked(settings.value("pulse/spawn-server", true).toBool());
+ ui->pulseAllowMovesCheckBox->setChecked(settings.value("pulse/allow-moves", false).toBool());
+ ui->pulseFixRateCheckBox->setChecked(settings.value("pulse/fix-rate", false).toBool());
+
+ ui->jackAutospawnCheckBox->setChecked(settings.value("jack/spawn-server", false).toBool());
+ ui->jackBufferSizeLine->setText(settings.value("jack/buffer-size", QString()).toString());
+ updateJackBufferSizeSlider();
+
+ ui->alsaDefaultDeviceLine->setText(settings.value("alsa/device", QString()).toString());
+ ui->alsaDefaultCaptureLine->setText(settings.value("alsa/capture", QString()).toString());
+ ui->alsaResamplerCheckBox->setChecked(settings.value("alsa/allow-resampler", false).toBool());
+ ui->alsaMmapCheckBox->setChecked(settings.value("alsa/mmap", true).toBool());
+
+ ui->ossDefaultDeviceLine->setText(settings.value("oss/device", QString()).toString());
+ ui->ossDefaultCaptureLine->setText(settings.value("oss/capture", QString()).toString());
+
+ ui->solarisDefaultDeviceLine->setText(settings.value("solaris/device", QString()).toString());
+
+ ui->waveOutputLine->setText(settings.value("wave/file", QString()).toString());
+ ui->waveBFormatCheckBox->setChecked(settings.value("wave/bformat", false).toBool());
+
+ ui->applyButton->setEnabled(false);
+ ui->closeCancelButton->setText(tr("Close"));
+ mNeedsSave = false;
}
void MainWindow::saveCurrentConfig()
{
saveConfig(getDefaultConfigName());
+ ui->applyButton->setEnabled(false);
+ ui->closeCancelButton->setText(tr("Close"));
+ mNeedsSave = false;
QMessageBox::information(this, tr("Information"),
tr("Applications using OpenAL need to be restarted for changes to take effect."));
}
@@ -514,7 +892,11 @@ void MainWindow::saveConfigAsFile()
{
QString fname = QFileDialog::getOpenFileName(this, tr("Select Files"));
if(fname.isEmpty() == false)
+ {
saveConfig(fname);
+ ui->applyButton->setEnabled(false);
+ mNeedsSave = false;
+ }
}
void MainWindow::saveConfig(const QString &fname) const
@@ -530,25 +912,8 @@ void MainWindow::saveConfig(const QString &fname) const
settings.setValue(key, vals.join(QChar(',')));
}
- QString str = ui->sampleFormatCombo->currentText();
- for(int i = 0;sampleTypeList[i].name[0];i++)
- {
- if(str == sampleTypeList[i].name)
- {
- settings.setValue("sample-type", sampleTypeList[i].value);
- break;
- }
- }
-
- str = ui->channelConfigCombo->currentText();
- for(int i = 0;speakerModeList[i].name[0];i++)
- {
- if(str == speakerModeList[i].name)
- {
- settings.setValue("channels", speakerModeList[i].value);
- break;
- }
- }
+ settings.setValue("sample-type", getValueFromName(sampleTypeList, ui->sampleFormatCombo->currentText()));
+ settings.setValue("channels", getValueFromName(speakerModeList, ui->channelConfigCombo->currentText()));
uint rate = ui->sampleRateCombo->currentText().toUInt();
if(!(rate > 0))
@@ -562,25 +927,46 @@ void MainWindow::saveConfig(const QString &fname) const
settings.setValue("sources", ui->srcCountLineEdit->text());
settings.setValue("slots", ui->effectSlotLineEdit->text());
- str = ui->resamplerComboBox->currentText();
- for(int i = 0;resamplerList[i].name[0];i++)
- {
- if(str == resamplerList[i].name)
- {
- settings.setValue("resampler", resamplerList[i].value);
- break;
- }
- }
-
- str = ui->stereoModeCombo->currentText();
- for(int i = 0;stereoModeList[i].name[0];i++)
- {
- if(str == stereoModeList[i].name)
- {
- settings.setValue("stereo-mode", stereoModeList[i].value);
- break;
- }
- }
+ settings.setValue("resampler", resamplerList[ui->resamplerSlider->value()].value);
+
+ settings.setValue("stereo-mode", getValueFromName(stereoModeList, ui->stereoModeCombo->currentText()));
+ settings.setValue("stereo-encoding", getValueFromName(stereoEncList, ui->stereoEncodingComboBox->currentText()));
+ settings.setValue("ambi-format", getValueFromName(ambiFormatList, ui->ambiFormatComboBox->currentText()));
+
+ Qt::CheckState limiter = ui->outputLimiterCheckBox->checkState();
+ if(limiter == Qt::PartiallyChecked)
+ settings.setValue("output-limiter", QString());
+ else if(limiter == Qt::Checked)
+ settings.setValue("output-limiter", QString("true"));
+ else if(limiter == Qt::Unchecked)
+ settings.setValue("output-limiter", QString("false"));
+
+ Qt::CheckState dither = ui->outputDitherCheckBox->checkState();
+ if(dither == Qt::PartiallyChecked)
+ settings.setValue("dither", QString());
+ else if(dither == Qt::Checked)
+ settings.setValue("dither", QString("true"));
+ else if(dither == Qt::Unchecked)
+ settings.setValue("dither", QString("false"));
+
+ settings.setValue("decoder/hq-mode",
+ ui->decoderHQModeCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
+ );
+ settings.setValue("decoder/distance-comp",
+ ui->decoderDistCompCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
+ );
+ settings.setValue("decoder/nfc",
+ ui->decoderNFEffectsCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
+ );
+ double refdelay = ui->decoderNFRefDelaySpinBox->value();
+ settings.setValue("decoder/nfc-ref-delay",
+ (refdelay > 0.0) ? QString::number(refdelay) : QString()
+ );
+
+ settings.setValue("decoder/quad", ui->decoderQuadLineEdit->text());
+ settings.setValue("decoder/surround51", ui->decoder51LineEdit->text());
+ settings.setValue("decoder/surround61", ui->decoder61LineEdit->text());
+ settings.setValue("decoder/surround71", ui->decoder71LineEdit->text());
QStringList strlist;
if(!ui->enableSSECheckBox->isChecked())
@@ -602,19 +988,46 @@ void MainWindow::saveConfig(const QString &fname) const
else
settings.setValue("hrtf", QString());
+ if(ui->preferredHrtfComboBox->currentIndex() == 0)
+ settings.setValue("default-hrtf", QString());
+ else
+ {
+ QString str = ui->preferredHrtfComboBox->currentText();
+ settings.setValue("default-hrtf", str);
+ }
+
strlist.clear();
- QList<QListWidgetItem*> items = ui->hrtfFileList->findItems("*", Qt::MatchWildcard);
- foreach(const QListWidgetItem *item, items)
- strlist.append(item->text());
- settings.setValue("hrtf_tables", strlist.join(QChar(',')));
+ for(int i = 0;i < ui->hrtfFileList->count();i++)
+ strlist.append(ui->hrtfFileList->item(i)->text());
+ if(!strlist.empty() && ui->defaultHrtfPathsCheckBox->isChecked())
+ strlist.append(QString());
+ settings.setValue("hrtf-paths", strlist.join(QChar(',')));
strlist.clear();
- items = ui->enabledBackendList->findItems("*", Qt::MatchWildcard);
- foreach(const QListWidgetItem *item, items)
- strlist.append(item->text());
- items = ui->disabledBackendList->findItems("*", Qt::MatchWildcard);
- foreach(const QListWidgetItem *item, items)
- strlist.append(QChar('-')+item->text());
+ for(int i = 0;i < ui->enabledBackendList->count();i++)
+ {
+ QString label = ui->enabledBackendList->item(i)->text();
+ for(int j = 0;backendList[j].backend_name[0];j++)
+ {
+ if(label == backendList[j].full_string)
+ {
+ strlist.append(backendList[j].backend_name);
+ break;
+ }
+ }
+ }
+ for(int i = 0;i < ui->disabledBackendList->count();i++)
+ {
+ QString label = ui->disabledBackendList->item(i)->text();
+ for(int j = 0;backendList[j].backend_name[0];j++)
+ {
+ if(label == backendList[j].full_string)
+ {
+ strlist.append(QChar('-')+QString(backendList[j].backend_name));
+ break;
+ }
+ }
+ }
if(strlist.size() == 0 && !ui->backendCheckBox->isChecked())
strlist.append("-all");
else if(ui->backendCheckBox->isChecked())
@@ -626,20 +1039,17 @@ void MainWindow::saveConfig(const QString &fname) const
settings.setValue("default-reverb", QString());
else
{
- str = ui->defaultReverbComboBox->currentText().toLower();
+ QString str = ui->defaultReverbComboBox->currentText().toLower();
settings.setValue("default-reverb", str);
}
- if(ui->emulateEaxCheckBox->isChecked())
- settings.setValue("reverb/emulate-eax", "true");
- else
- settings.setValue("reverb/emulate-eax", QString()/*"false"*/);
-
strlist.clear();
if(!ui->enableEaxReverbCheck->isChecked())
strlist.append("eaxreverb");
if(!ui->enableStdReverbCheck->isChecked())
strlist.append("reverb");
+ if(!ui->enableAutowahCheck->isChecked())
+ strlist.append("autowah");
if(!ui->enableChorusCheck->isChecked())
strlist.append("chorus");
if(!ui->enableDistortionCheck->isChecked())
@@ -652,25 +1062,79 @@ void MainWindow::saveConfig(const QString &fname) const
strlist.append("equalizer");
if(!ui->enableFlangerCheck->isChecked())
strlist.append("flanger");
+ if(!ui->enableFrequencyShifterCheck->isChecked())
+ strlist.append("fshifter");
if(!ui->enableModulatorCheck->isChecked())
strlist.append("modulator");
if(!ui->enableDedicatedCheck->isChecked())
strlist.append("dedicated");
+ if(!ui->enablePitchShifterCheck->isChecked())
+ strlist.append("pshifter");
settings.setValue("excludefx", strlist.join(QChar(',')));
+ settings.setValue("pulse/spawn-server",
+ ui->pulseAutospawnCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
+ );
+ settings.setValue("pulse/allow-moves",
+ ui->pulseAllowMovesCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
+ );
+ settings.setValue("pulse/fix-rate",
+ ui->pulseFixRateCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
+ );
+
+ settings.setValue("jack/spawn-server",
+ ui->jackAutospawnCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
+ );
+ settings.setValue("jack/buffer-size", ui->jackBufferSizeLine->text());
+
+ settings.setValue("alsa/device", ui->alsaDefaultDeviceLine->text());
+ settings.setValue("alsa/capture", ui->alsaDefaultCaptureLine->text());
+ settings.setValue("alsa/allow-resampler",
+ ui->alsaResamplerCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
+ );
+ settings.setValue("alsa/mmap",
+ ui->alsaMmapCheckBox->isChecked() ? QString(/*"true"*/) : QString("false")
+ );
+
+ settings.setValue("oss/device", ui->ossDefaultDeviceLine->text());
+ settings.setValue("oss/capture", ui->ossDefaultCaptureLine->text());
+
+ settings.setValue("solaris/device", ui->solarisDefaultDeviceLine->text());
+
+ settings.setValue("wave/file", ui->waveOutputLine->text());
+ settings.setValue("wave/bformat",
+ ui->waveBFormatCheckBox->isChecked() ? QString("true") : QString(/*"false"*/)
+ );
+
/* Remove empty keys
* FIXME: Should only remove keys whose value matches the globally-specified value.
*/
allkeys = settings.allKeys();
foreach(const QString &key, allkeys)
{
- str = settings.value(key).toString();
+ QString str = settings.value(key).toString();
if(str == QString())
settings.remove(key);
}
}
+void MainWindow::enableApplyButton()
+{
+ if(!mNeedsSave)
+ ui->applyButton->setEnabled(true);
+ mNeedsSave = true;
+ ui->closeCancelButton->setText(tr("Cancel"));
+}
+
+
+void MainWindow::updateResamplerLabel(int num)
+{
+ ui->resamplerLabel->setText(resamplerList[num].name);
+ enableApplyButton();
+}
+
+
void MainWindow::updatePeriodSizeEdit(int size)
{
ui->periodSizeEdit->clear();
@@ -679,6 +1143,7 @@ void MainWindow::updatePeriodSizeEdit(int size)
size = (size+32)&~0x3f;
ui->periodSizeEdit->insert(QString::number(size));
}
+ enableApplyButton();
}
void MainWindow::updatePeriodSizeSlider()
@@ -690,6 +1155,7 @@ void MainWindow::updatePeriodSizeSlider()
pos = 8192;
ui->periodSizeSlider->setSliderPosition(pos);
}
+ enableApplyButton();
}
void MainWindow::updatePeriodCountEdit(int count)
@@ -697,6 +1163,7 @@ void MainWindow::updatePeriodCountEdit(int count)
ui->periodCountEdit->clear();
if(count >= 2)
ui->periodCountEdit->insert(QString::number(count));
+ enableApplyButton();
}
void MainWindow::updatePeriodCountSlider()
@@ -707,48 +1174,81 @@ void MainWindow::updatePeriodCountSlider()
else if(pos > 16)
pos = 16;
ui->periodCountSlider->setSliderPosition(pos);
+ enableApplyButton();
}
-void MainWindow::addHrtfFile()
+void MainWindow::selectQuadDecoderFile()
+{ selectDecoderFile(ui->decoderQuadLineEdit, "Select Quadraphonic Decoder");}
+void MainWindow::select51DecoderFile()
+{ selectDecoderFile(ui->decoder51LineEdit, "Select 5.1 Surround Decoder");}
+void MainWindow::select61DecoderFile()
+{ selectDecoderFile(ui->decoder61LineEdit, "Select 6.1 Surround Decoder");}
+void MainWindow::select71DecoderFile()
+{ selectDecoderFile(ui->decoder71LineEdit, "Select 7.1 Surround Decoder");}
+void MainWindow::selectDecoderFile(QLineEdit *line, const char *caption)
{
- const QStringList datapaths = getAllDataPaths("/openal/hrtf");
- QStringList fnames = QFileDialog::getOpenFileNames(this, tr("Select Files"),
- datapaths.empty() ? QString() : datapaths[0],
- "HRTF Datasets(*.mhr);;All Files(*.*)");
- if(fnames.isEmpty() == false)
+ QString dir = line->text();
+ if(dir.isEmpty() || QDir::isRelativePath(dir))
{
- for(QStringList::iterator iter = fnames.begin();iter != fnames.end();iter++)
+ QStringList paths = getAllDataPaths("/openal/presets");
+ while(!paths.isEmpty())
{
- QStringList::const_iterator path = datapaths.constBegin();
- for(;path != datapaths.constEnd();path++)
+ if(QDir(paths.last()).exists())
{
- QDir hrtfdir(*path);
- if(!hrtfdir.isAbsolute())
- continue;
-
- const QString relname = hrtfdir.relativeFilePath(*iter);
- if(!relname.startsWith(".."))
- {
- // If filename is within this path, use the relative pathname
- ui->hrtfFileList->addItem(relname);
- break;
- }
- }
- if(path == datapaths.constEnd())
- {
- // Filename is not within any data path, use the absolute pathname
- ui->hrtfFileList->addItem(*iter);
+ dir = paths.last();
+ break;
}
+ paths.removeLast();
}
}
+ QString fname = QFileDialog::getOpenFileName(this, tr(caption),
+ dir, tr("AmbDec Files (*.ambdec);;All Files (*.*)")
+ );
+ if(!fname.isEmpty())
+ {
+ line->setText(fname);
+ enableApplyButton();
+ }
+}
+
+
+void MainWindow::updateJackBufferSizeEdit(int size)
+{
+ ui->jackBufferSizeLine->clear();
+ if(size > 0)
+ ui->jackBufferSizeLine->insert(QString::number(1<<size));
+ enableApplyButton();
+}
+
+void MainWindow::updateJackBufferSizeSlider()
+{
+ int value = ui->jackBufferSizeLine->text().toInt();
+ int pos = (int)floor(log2(value) + 0.5);
+ ui->jackBufferSizeSlider->setSliderPosition(pos);
+ enableApplyButton();
+}
+
+
+void MainWindow::addHrtfFile()
+{
+ QString path = QFileDialog::getExistingDirectory(this, tr("Select HRTF Path"));
+ if(path.isEmpty() == false && !getAllDataPaths("/openal/hrtf").contains(path))
+ {
+ ui->hrtfFileList->addItem(path);
+ enableApplyButton();
+ }
}
void MainWindow::removeHrtfFile()
{
QList<QListWidgetItem*> selected = ui->hrtfFileList->selectedItems();
- foreach(QListWidgetItem *item, selected)
- delete item;
+ if(!selected.isEmpty())
+ {
+ foreach(QListWidgetItem *item, selected)
+ delete item;
+ enableApplyButton();
+ }
}
void MainWindow::updateHrtfRemoveButton()
@@ -767,12 +1267,13 @@ void MainWindow::showEnabledBackendMenu(QPoint pt)
if(ui->enabledBackendList->selectedItems().size() == 0)
removeAction->setEnabled(false);
ctxmenu.addSeparator();
- for(size_t i = 0;backendMenuList[i].backend_name[0];i++)
+ for(size_t i = 0;backendList[i].backend_name[0];i++)
{
- QAction *action = ctxmenu.addAction(backendMenuList[i].menu_string);
- actionMap[action] = backendMenuList[i].backend_name;
- if(ui->enabledBackendList->findItems(backendMenuList[i].backend_name, Qt::MatchFixedString).size() != 0 ||
- ui->disabledBackendList->findItems(backendMenuList[i].backend_name, Qt::MatchFixedString).size() != 0)
+ QString backend = backendList[i].full_string;
+ QAction *action = ctxmenu.addAction(QString("Add ")+backend);
+ actionMap[action] = backend;
+ if(ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 ||
+ ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0)
action->setEnabled(false);
}
@@ -782,12 +1283,14 @@ void MainWindow::showEnabledBackendMenu(QPoint pt)
QList<QListWidgetItem*> selected = ui->enabledBackendList->selectedItems();
foreach(QListWidgetItem *item, selected)
delete item;
+ enableApplyButton();
}
else if(gotAction != NULL)
{
QMap<QAction*,QString>::const_iterator iter = actionMap.find(gotAction);
if(iter != actionMap.end())
ui->enabledBackendList->addItem(iter.value());
+ enableApplyButton();
}
}
@@ -802,12 +1305,13 @@ void MainWindow::showDisabledBackendMenu(QPoint pt)
if(ui->disabledBackendList->selectedItems().size() == 0)
removeAction->setEnabled(false);
ctxmenu.addSeparator();
- for(size_t i = 0;backendMenuList[i].backend_name[0];i++)
+ for(size_t i = 0;backendList[i].backend_name[0];i++)
{
- QAction *action = ctxmenu.addAction(backendMenuList[i].menu_string);
- actionMap[action] = backendMenuList[i].backend_name;
- if(ui->disabledBackendList->findItems(backendMenuList[i].backend_name, Qt::MatchFixedString).size() != 0 ||
- ui->enabledBackendList->findItems(backendMenuList[i].backend_name, Qt::MatchFixedString).size() != 0)
+ QString backend = backendList[i].full_string;
+ QAction *action = ctxmenu.addAction(QString("Add ")+backend);
+ actionMap[action] = backend;
+ if(ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 ||
+ ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0)
action->setEnabled(false);
}
@@ -817,11 +1321,61 @@ void MainWindow::showDisabledBackendMenu(QPoint pt)
QList<QListWidgetItem*> selected = ui->disabledBackendList->selectedItems();
foreach(QListWidgetItem *item, selected)
delete item;
+ enableApplyButton();
}
else if(gotAction != NULL)
{
QMap<QAction*,QString>::const_iterator iter = actionMap.find(gotAction);
if(iter != actionMap.end())
ui->disabledBackendList->addItem(iter.value());
+ enableApplyButton();
+ }
+}
+
+void MainWindow::selectOSSPlayback()
+{
+ QString current = ui->ossDefaultDeviceLine->text();
+ if(current.isEmpty()) current = ui->ossDefaultDeviceLine->placeholderText();
+ QString fname = QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current);
+ if(!fname.isEmpty())
+ {
+ ui->ossDefaultDeviceLine->setText(fname);
+ enableApplyButton();
+ }
+}
+
+void MainWindow::selectOSSCapture()
+{
+ QString current = ui->ossDefaultCaptureLine->text();
+ if(current.isEmpty()) current = ui->ossDefaultCaptureLine->placeholderText();
+ QString fname = QFileDialog::getOpenFileName(this, tr("Select Capture Device"), current);
+ if(!fname.isEmpty())
+ {
+ ui->ossDefaultCaptureLine->setText(fname);
+ enableApplyButton();
+ }
+}
+
+void MainWindow::selectSolarisPlayback()
+{
+ QString current = ui->solarisDefaultDeviceLine->text();
+ if(current.isEmpty()) current = ui->solarisDefaultDeviceLine->placeholderText();
+ QString fname = QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current);
+ if(!fname.isEmpty())
+ {
+ ui->solarisDefaultDeviceLine->setText(fname);
+ enableApplyButton();
+ }
+}
+
+void MainWindow::selectWaveOutput()
+{
+ QString fname = QFileDialog::getSaveFileName(this, tr("Select Wave File Output"),
+ ui->waveOutputLine->text(), tr("Wave Files (*.wav *.amb);;All Files (*.*)")
+ );
+ if(!fname.isEmpty())
+ {
+ ui->waveOutputLine->setText(fname);
+ enableApplyButton();
}
}
diff --git a/utils/alsoft-config/mainwindow.h b/utils/alsoft-config/mainwindow.h
index b5a1ae7c..8b763845 100644
--- a/utils/alsoft-config/mainwindow.h
+++ b/utils/alsoft-config/mainwindow.h
@@ -17,16 +17,32 @@ public:
~MainWindow();
private slots:
+ void cancelCloseAction();
+
void saveCurrentConfig();
void saveConfigAsFile();
void loadConfigFromFile();
+ void showAboutPage();
+
+ void enableApplyButton();
+
+ void updateResamplerLabel(int num);
+
void updatePeriodSizeEdit(int size);
void updatePeriodSizeSlider();
void updatePeriodCountEdit(int size);
void updatePeriodCountSlider();
+ void selectQuadDecoderFile();
+ void select51DecoderFile();
+ void select61DecoderFile();
+ void select71DecoderFile();
+
+ void updateJackBufferSizeEdit(int size);
+ void updateJackBufferSizeSlider();
+
void addHrtfFile();
void removeHrtfFile();
@@ -35,6 +51,13 @@ private slots:
void showEnabledBackendMenu(QPoint pt);
void showDisabledBackendMenu(QPoint pt);
+ void selectOSSPlayback();
+ void selectOSSCapture();
+
+ void selectSolarisPlayback();
+
+ void selectWaveOutput();
+
private:
Ui::MainWindow *ui;
@@ -44,6 +67,15 @@ private:
QValidator *mEffectSlotValidator;
QValidator *mSourceSendValidator;
QValidator *mSampleRateValidator;
+ QValidator *mJackBufferValidator;
+
+ bool mNeedsSave;
+
+ void closeEvent(QCloseEvent *event);
+
+ void selectDecoderFile(QLineEdit *line, const char *name);
+
+ QStringList collectHrtfs();
void loadConfig(const QString &fname);
void saveConfig(const QString &fname) const;
diff --git a/utils/alsoft-config/mainwindow.ui b/utils/alsoft-config/mainwindow.ui
index 78564ada..9c89cbc7 100644
--- a/utils/alsoft-config/mainwindow.ui
+++ b/utils/alsoft-config/mainwindow.ui
@@ -7,9 +7,15 @@
<x>0</x>
<y>0</y>
<width>564</width>
- <height>454</height>
+ <height>460</height>
</rect>
</property>
+ <property name="minimumSize">
+ <size>
+ <width>564</width>
+ <height>460</height>
+ </size>
+ </property>
<property name="windowTitle">
<string>OpenAL Soft Configuration</string>
</property>
@@ -25,7 +31,7 @@
<x>470</x>
<y>405</y>
<width>81</width>
- <height>25</height>
+ <height>21</height>
</rect>
</property>
<property name="text">
@@ -47,7 +53,7 @@
</rect>
</property>
<property name="currentIndex">
- <number>0</number>
+ <number>5</number>
</property>
<widget class="QWidget" name="tab_3">
<attribute name="title">
@@ -56,10 +62,10 @@
<widget class="QComboBox" name="sampleFormatCombo">
<property name="geometry">
<rect>
- <x>120</x>
+ <x>110</x>
<y>50</y>
<width>78</width>
- <height>22</height>
+ <height>21</height>
</rect>
</property>
<property name="toolTip">
@@ -73,7 +79,7 @@ float and converted to the output sample type as needed.</string>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
- <x>10</x>
+ <x>0</x>
<y>50</y>
<width>101</width>
<height>21</height>
@@ -89,7 +95,7 @@ float and converted to the output sample type as needed.</string>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
- <x>10</x>
+ <x>0</x>
<y>20</y>
<width>101</width>
<height>21</height>
@@ -105,10 +111,10 @@ float and converted to the output sample type as needed.</string>
<widget class="QComboBox" name="channelConfigCombo">
<property name="geometry">
<rect>
- <x>120</x>
+ <x>110</x>
<y>20</y>
<width>78</width>
- <height>22</height>
+ <height>21</height>
</rect>
</property>
<property name="toolTip">
@@ -123,10 +129,10 @@ to stereo output.</string>
<widget class="QComboBox" name="sampleRateCombo">
<property name="geometry">
<rect>
- <x>370</x>
+ <x>380</x>
<y>20</y>
- <width>96</width>
- <height>22</height>
+ <width>80</width>
+ <height>20</height>
</rect>
</property>
<property name="toolTip">
@@ -185,7 +191,7 @@ to stereo output.</string>
<widget class="QLabel" name="label_7">
<property name="geometry">
<rect>
- <x>280</x>
+ <x>290</x>
<y>20</y>
<width>81</width>
<height>21</height>
@@ -198,339 +204,1496 @@ to stereo output.</string>
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
+ <widget class="QLabel" name="label_14">
+ <property name="geometry">
+ <rect>
+ <x>290</x>
+ <y>50</y>
+ <width>81</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Stereo Mode:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ <widget class="QComboBox" name="stereoModeCombo">
+ <property name="geometry">
+ <rect>
+ <x>380</x>
+ <y>50</y>
+ <width>78</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>How to treat stereo output. As headphones, HRTF or crossfeed
+filters may be used to improve binaural quality, which may not
+otherwise be suitable for speakers.</string>
+ </property>
+ </widget>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
- <x>10</x>
+ <x>-11</x>
<y>180</y>
- <width>511</width>
- <height>191</height>
+ <width>551</width>
+ <height>201</height>
</rect>
</property>
<property name="title">
- <string>HRTF (Stereo only)</string>
+ <string>Advanced Settings</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
</property>
- <widget class="QListWidget" name="hrtfFileList">
+ <widget class="QGroupBox" name="groupBox_3">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
- <width>391</width>
- <height>121</height>
+ <width>511</width>
+ <height>91</height>
+ </rect>
+ </property>
+ <property name="title">
+ <string>Buffer Metrics</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ <widget class="QWidget" name="widget" native="true">
+ <property name="geometry">
+ <rect>
+ <x>260</x>
+ <y>20</y>
+ <width>241</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>The number of update periods. Higher values create a larger
+mix ahead, which helps protect against skips when the CPU is
+under load, but increases the delay between a sound getting
+mixed and being heard.</string>
+ </property>
+ <widget class="QLabel" name="label_11">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>0</y>
+ <width>201</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Period Count</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ <widget class="QSlider" name="periodCountSlider">
+ <property name="geometry">
+ <rect>
+ <x>80</x>
+ <y>20</y>
+ <width>160</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>16</number>
+ </property>
+ <property name="singleStep">
+ <number>1</number>
+ </property>
+ <property name="pageStep">
+ <number>2</number>
+ </property>
+ <property name="value">
+ <number>1</number>
+ </property>
+ <property name="tracking">
+ <bool>true</bool>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="tickPosition">
+ <enum>QSlider::TicksBelow</enum>
+ </property>
+ <property name="tickInterval">
+ <number>1</number>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="periodCountEdit">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>20</y>
+ <width>51</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="placeholderText">
+ <string>3</string>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QWidget" name="widget_2" native="true">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>20</y>
+ <width>241</width>
+ <height>51</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>The update period size, in sample frames. This is the number of
+frames needed for each mixing update.</string>
+ </property>
+ <widget class="QSlider" name="periodSizeSlider">
+ <property name="geometry">
+ <rect>
+ <x>60</x>
+ <y>20</y>
+ <width>160</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="minimum">
+ <number>0</number>
+ </property>
+ <property name="maximum">
+ <number>8192</number>
+ </property>
+ <property name="singleStep">
+ <number>64</number>
+ </property>
+ <property name="pageStep">
+ <number>1024</number>
+ </property>
+ <property name="value">
+ <number>0</number>
+ </property>
+ <property name="tracking">
+ <bool>true</bool>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="tickPosition">
+ <enum>QSlider::TicksBelow</enum>
+ </property>
+ <property name="tickInterval">
+ <number>512</number>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_10">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>0</y>
+ <width>201</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Period Samples</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="periodSizeEdit">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>20</y>
+ <width>51</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="placeholderText">
+ <string>1024</string>
+ </property>
+ </widget>
+ </widget>
+ </widget>
+ <widget class="QComboBox" name="stereoEncodingComboBox">
+ <property name="geometry">
+ <rect>
+ <x>130</x>
+ <y>130</y>
+ <width>131</width>
+ <height>21</height>
</rect>
</property>
<property name="toolTip">
- <string>A list of files containing HRTF data sets. The listed data sets
-are used in place of the default sets. The filenames may
-contain these markers, which will be replaced as needed:
-%r - Device sampling rate
-%% - Percent sign (%)</string>
+ <string>Pan Pot uses standard amplitude panning (aka
+pair-wise, stereo pair, etc) between -30 and +30
+degrees, while UHJ creates a stereo-compatible
+two-channel UHJ mix, which encodes some
+surround sound information into stereo output
+that can be decoded with a surround sound
+receiver.</string>
</property>
- <property name="dragEnabled">
- <bool>false</bool>
+ </widget>
+ <widget class="QLabel" name="label_19">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>130</y>
+ <width>101</width>
+ <height>21</height>
+ </rect>
</property>
- <property name="dragDropMode">
- <enum>QAbstractItemView::InternalMove</enum>
+ <property name="text">
+ <string>Stereo Encoding:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
- <property name="alternatingRowColors">
+ </widget>
+ <widget class="QLabel" name="label_30">
+ <property name="geometry">
+ <rect>
+ <x>270</x>
+ <y>130</y>
+ <width>111</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Ambisonic Format:</string>
+ </property>
+ </widget>
+ <widget class="QComboBox" name="ambiFormatComboBox">
+ <property name="geometry">
+ <rect>
+ <x>390</x>
+ <y>130</y>
+ <width>131</width>
+ <height>21</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="outputLimiterCheckBox">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>160</y>
+ <width>231</width>
+ <height>20</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>Applies a gain limiter on the final mixed output. This reduces the
+volume when the output samples would otherwise be clamped,
+avoiding excessive clipping noise.</string>
+ </property>
+ <property name="text">
+ <string>Enable Gain Limiter</string>
+ </property>
+ <property name="tristate">
<bool>true</bool>
</property>
- <property name="selectionMode">
- <enum>QAbstractItemView::ExtendedSelection</enum>
+ </widget>
+ <widget class="QCheckBox" name="outputDitherCheckBox">
+ <property name="geometry">
+ <rect>
+ <x>270</x>
+ <y>160</y>
+ <width>261</width>
+ <height>21</height>
+ </rect>
</property>
- <property name="textElideMode">
- <enum>Qt::ElideNone</enum>
+ <property name="toolTip">
+ <string>Applies dithering on the final mix for 8- and 16-bit output.
+This replaces the distortion created by nearest-value
+quantization with low-level whitenoise.</string>
+ </property>
+ <property name="text">
+ <string>Enable Dithering</string>
+ </property>
+ <property name="tristate">
+ <bool>true</bool>
</property>
</widget>
- <widget class="QPushButton" name="hrtfAddButton">
+ </widget>
+ <widget class="QGroupBox" name="groupBox_4">
+ <property name="geometry">
+ <rect>
+ <x>60</x>
+ <y>80</y>
+ <width>421</width>
+ <height>81</height>
+ </rect>
+ </property>
+ <property name="title">
+ <string>Resampler Quality</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ <widget class="QLabel" name="resamplerLabel">
<property name="geometry">
<rect>
- <x>420</x>
+ <x>50</x>
+ <y>50</y>
+ <width>321</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Default</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ <widget class="QSlider" name="resamplerSlider">
+ <property name="geometry">
+ <rect>
+ <x>80</x>
<y>30</y>
- <width>81</width>
- <height>25</height>
+ <width>251</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_9">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>30</y>
+ <width>51</width>
+ <height>21</height>
</rect>
</property>
<property name="text">
- <string>Add...</string>
+ <string>Speed</string>
</property>
- <property name="icon">
- <iconset theme="list-add">
- <normaloff/>
- </iconset>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
- <property name="flat">
- <bool>false</bool>
+ </widget>
+ <widget class="QLabel" name="label_15">
+ <property name="geometry">
+ <rect>
+ <x>340</x>
+ <y>30</y>
+ <width>51</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Quality</string>
</property>
</widget>
- <widget class="QPushButton" name="hrtfRemoveButton">
+ </widget>
+ </widget>
+ <widget class="QWidget" name="tab_6">
+ <attribute name="title">
+ <string>Renderer</string>
+ </attribute>
+ <widget class="QCheckBox" name="decoderHQModeCheckBox">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>20</y>
+ <width>181</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>Enables high-quality ambisonic rendering. This mode is
+capable of frequency-dependent processing, creating a
+better reproduction of 3D sound rendering over
+surround sound speakers. Enabling this also requires
+specifying decoder configuration files for the
+appropriate speaker configuration you intend to use.</string>
+ </property>
+ <property name="layoutDirection">
+ <enum>Qt::RightToLeft</enum>
+ </property>
+ <property name="text">
+ <string>High Quality Mode:</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="decoderDistCompCheckBox">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>50</y>
+ <width>181</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>This applies the necessary delays and attenuation
+to make the speakers behave as though they are
+all equidistant, which is important for proper
+playback of 3D sound rendering. Requires the
+proper distances to be specified in the decoder
+configuration file.</string>
+ </property>
+ <property name="layoutDirection">
+ <enum>Qt::RightToLeft</enum>
+ </property>
+ <property name="text">
+ <string>Distance Compensation:</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget class="QGroupBox" name="groupBox_8">
+ <property name="geometry">
+ <rect>
+ <x>-10</x>
+ <y>160</y>
+ <width>551</width>
+ <height>161</height>
+ </rect>
+ </property>
+ <property name="title">
+ <string>Decoder Configurations</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ <widget class="QLineEdit" name="decoderQuadLineEdit">
+ <property name="geometry">
+ <rect>
+ <x>120</x>
+ <y>30</y>
+ <width>311</width>
+ <height>21</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_25">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>30</y>
+ <width>91</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Quadraphonic:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="decoderQuadButton">
+ <property name="geometry">
+ <rect>
+ <x>440</x>
+ <y>30</y>
+ <width>91</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Browse...</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="decoder51LineEdit">
<property name="geometry">
<rect>
- <x>420</x>
+ <x>120</x>
<y>60</y>
- <width>81</width>
- <height>25</height>
+ <width>311</width>
+ <height>21</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="decoder51Button">
+ <property name="geometry">
+ <rect>
+ <x>440</x>
+ <y>60</y>
+ <width>91</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Browse...</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_26">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>60</y>
+ <width>91</width>
+ <height>21</height>
</rect>
</property>
<property name="text">
- <string>Remove</string>
+ <string>5.1 Surround:</string>
</property>
- <property name="icon">
- <iconset theme="list-remove">
- <normaloff/>
- </iconset>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
- <widget class="QComboBox" name="hrtfStateComboBox">
+ <widget class="QLabel" name="label_28">
<property name="geometry">
<rect>
- <x>110</x>
- <y>160</y>
- <width>161</width>
- <height>22</height>
+ <x>20</x>
+ <y>90</y>
+ <width>91</width>
+ <height>21</height>
</rect>
</property>
- <property name="sizeAdjustPolicy">
- <enum>QComboBox::AdjustToContentsOnFirstShow</enum>
+ <property name="text">
+ <string>6.1 Surround:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
- <item>
- <property name="text">
- <string>Application preference</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Force on</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Force off</string>
- </property>
- </item>
</widget>
- <widget class="QLabel" name="label_15">
+ <widget class="QLineEdit" name="decoder61LineEdit">
<property name="geometry">
<rect>
- <x>30</x>
- <y>160</y>
- <width>71</width>
+ <x>120</x>
+ <y>90</y>
+ <width>311</width>
+ <height>21</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="decoder61Button">
+ <property name="geometry">
+ <rect>
+ <x>440</x>
+ <y>90</y>
+ <width>91</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Browse...</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="decoder71Button">
+ <property name="geometry">
+ <rect>
+ <x>440</x>
+ <y>120</y>
+ <width>91</width>
<height>21</height>
</rect>
</property>
<property name="text">
- <string>HRTF Mode:</string>
+ <string>Browse...</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="decoder71LineEdit">
+ <property name="geometry">
+ <rect>
+ <x>120</x>
+ <y>120</y>
+ <width>311</width>
+ <height>21</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_29">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>120</y>
+ <width>91</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>7.1 Surround:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</widget>
- <widget class="QGroupBox" name="groupBox_3">
+ <widget class="QCheckBox" name="decoderNFEffectsCheckBox">
<property name="geometry">
<rect>
<x>10</x>
- <y>90</y>
- <width>511</width>
- <height>91</height>
+ <y>80</y>
+ <width>181</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>Simulates and compensates for low-frequency effects
+caused by the curvature of nearby sound-waves, which
+creates a more realistic perception of sound distance.
+Note that the effect may be stronger or weaker than
+intended if the application doesn't use or specify an
+appropriate unit scale, or if incorrect speaker distances
+are set in the decoder configuration file. Requires High
+Quality Mode to be enabled.</string>
+ </property>
+ <property name="layoutDirection">
+ <enum>Qt::RightToLeft</enum>
+ </property>
+ <property name="text">
+ <string>Near-Field Effects:</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget class="QWidget" name="widget_3" native="true">
+ <property name="geometry">
+ <rect>
+ <x>-10</x>
+ <y>110</y>
+ <width>281</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>The reference delay value for ambisonic output. When
+Channels is set to one of the Ambisonic formats, this
+option enables NFC-HOA output with the specified
+Reference Delay parameter. The specified value can then
+be shared with an appropriate NFC-HOA decoder to
+reproduce correct near-field effects. Keep in mind that
+despite being designed for higher-order ambisonics, this
+applies to first-order output all the same. When left unset,
+normal output is created with no near-field simulation.</string>
+ </property>
+ <widget class="QLabel" name="label_27">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>0</y>
+ <width>151</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Near-Field Reference Delay:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ <widget class="QDoubleSpinBox" name="decoderNFRefDelaySpinBox">
+ <property name="geometry">
+ <rect>
+ <x>180</x>
+ <y>0</y>
+ <width>91</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="suffix">
+ <string>sec</string>
+ </property>
+ <property name="decimals">
+ <number>4</number>
+ </property>
+ <property name="maximum">
+ <double>1000.000000000000000</double>
+ </property>
+ <property name="singleStep">
+ <double>0.010000000000000</double>
+ </property>
+ </widget>
+ </widget>
+ </widget>
+ <widget class="QWidget" name="tab_5">
+ <attribute name="title">
+ <string>HRTF</string>
+ </attribute>
+ <widget class="QGroupBox" name="groupBox_2">
+ <property name="geometry">
+ <rect>
+ <x>-10</x>
+ <y>200</y>
+ <width>551</width>
+ <height>181</height>
</rect>
</property>
<property name="title">
- <string>Buffer Metrics</string>
+ <string>Advanced Settings</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
</property>
- <widget class="QWidget" name="widget" native="true">
+ <widget class="QGroupBox" name="groupBox_6">
<property name="geometry">
<rect>
- <x>260</x>
- <y>20</y>
- <width>241</width>
- <height>51</height>
+ <x>20</x>
+ <y>30</y>
+ <width>511</width>
+ <height>141</height>
</rect>
</property>
- <property name="toolTip">
- <string>The number of update periods. Higher values create a larger
-mix ahead, which helps protect against skips when the CPU is
-under load, but increases the delay between a sound getting
-mixed and being heard.</string>
+ <property name="title">
+ <string>HRTF Profile Paths</string>
</property>
- <widget class="QLabel" name="label_11">
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ <widget class="QListWidget" name="hrtfFileList">
<property name="geometry">
<rect>
<x>20</x>
- <y>0</y>
- <width>201</width>
+ <y>20</y>
+ <width>391</width>
+ <height>81</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>A list of additional paths containing HRTF data sets.</string>
+ </property>
+ <property name="dragDropMode">
+ <enum>QAbstractItemView::InternalMove</enum>
+ </property>
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
+ <property name="selectionMode">
+ <enum>QAbstractItemView::ExtendedSelection</enum>
+ </property>
+ <property name="textElideMode">
+ <enum>Qt::ElideNone</enum>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="hrtfAddButton">
+ <property name="geometry">
+ <rect>
+ <x>420</x>
+ <y>20</y>
+ <width>81</width>
<height>21</height>
</rect>
</property>
<property name="text">
- <string>Period Count</string>
+ <string>Add...</string>
</property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
+ <property name="icon">
+ <iconset theme="list-add">
+ <normaloff/>
+ </iconset>
+ </property>
+ <property name="flat">
+ <bool>false</bool>
</property>
</widget>
- <widget class="QSlider" name="periodCountSlider">
+ <widget class="QCheckBox" name="defaultHrtfPathsCheckBox">
<property name="geometry">
<rect>
- <x>70</x>
- <y>20</y>
- <width>160</width>
- <height>23</height>
+ <x>180</x>
+ <y>110</y>
+ <width>151</width>
+ <height>21</height>
</rect>
</property>
- <property name="minimum">
- <number>1</number>
+ <property name="toolTip">
+ <string>Include the default system paths in addition to any
+listed above.</string>
</property>
- <property name="maximum">
- <number>16</number>
+ <property name="text">
+ <string>Include Default Paths</string>
</property>
- <property name="singleStep">
- <number>1</number>
+ <property name="checked">
+ <bool>true</bool>
</property>
- <property name="pageStep">
- <number>2</number>
+ </widget>
+ <widget class="QPushButton" name="hrtfRemoveButton">
+ <property name="geometry">
+ <rect>
+ <x>420</x>
+ <y>50</y>
+ <width>81</width>
+ <height>21</height>
+ </rect>
</property>
- <property name="value">
- <number>1</number>
+ <property name="text">
+ <string>Remove</string>
+ </property>
+ <property name="icon">
+ <iconset theme="list-remove">
+ <normaloff/>
+ </iconset>
</property>
- <property name="tracking">
+ </widget>
+ </widget>
+ </widget>
+ <widget class="QLabel" name="label_16">
+ <property name="geometry">
+ <rect>
+ <x>40</x>
+ <y>50</y>
+ <width>71</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>HRTF Mode:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ <widget class="QComboBox" name="hrtfStateComboBox">
+ <property name="geometry">
+ <rect>
+ <x>130</x>
+ <y>50</y>
+ <width>161</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>Forces HRTF processing on or off, or leaves it to the
+application or system to determine if it should be used.</string>
+ </property>
+ <property name="sizeAdjustPolicy">
+ <enum>QComboBox::AdjustToContentsOnFirstShow</enum>
+ </property>
+ <item>
+ <property name="text">
+ <string>Application preference</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Force on</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Force off</string>
+ </property>
+ </item>
+ </widget>
+ <widget class="QLabel" name="label_12">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>20</y>
+ <width>91</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Preferred HRTF:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ <widget class="QComboBox" name="preferredHrtfComboBox">
+ <property name="geometry">
+ <rect>
+ <x>130</x>
+ <y>20</y>
+ <width>161</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>The default HRTF to use if the application doesn't request one.</string>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QWidget" name="tab">
+ <attribute name="title">
+ <string>Backends</string>
+ </attribute>
+ <widget class="QListWidget" name="backendListWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>11</y>
+ <width>111</width>
+ <height>361</height>
+ </rect>
+ </property>
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
+ <item>
+ <property name="text">
+ <string>General</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>PulseAudio</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>JACK</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>ALSA</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>OSS</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Solaris</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Wave Writer</string>
+ </property>
+ </item>
+ </widget>
+ <widget class="QStackedWidget" name="backendStackedWidget">
+ <property name="geometry">
+ <rect>
+ <x>110</x>
+ <y>10</y>
+ <width>421</width>
+ <height>361</height>
+ </rect>
+ </property>
+ <widget class="QWidget" name="page">
+ <widget class="QCheckBox" name="backendCheckBox">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>190</y>
+ <width>391</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>When checked, allows all other available backends not listed in the priority or disabled lists.</string>
+ </property>
+ <property name="text">
+ <string>Allow Other Backends</string>
+ </property>
+ <property name="checked">
<bool>true</bool>
</property>
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
+ </widget>
+ <widget class="QListWidget" name="disabledBackendList">
+ <property name="geometry">
+ <rect>
+ <x>220</x>
+ <y>30</y>
+ <width>191</width>
+ <height>151</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>Disabled backend driver list.</string>
+ </property>
+ </widget>
+ <widget class="QListWidget" name="enabledBackendList">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>30</y>
+ <width>191</width>
+ <height>151</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>The backend driver list order. Unknown backends and
+duplicated names are ignored.</string>
</property>
- <property name="tickPosition">
- <enum>QSlider::TicksBelow</enum>
+ <property name="dragDropMode">
+ <enum>QAbstractItemView::InternalMove</enum>
</property>
- <property name="tickInterval">
- <number>1</number>
+ </widget>
+ <widget class="QLabel" name="label_2">
+ <property name="geometry">
+ <rect>
+ <x>230</x>
+ <y>10</y>
+ <width>171</width>
+ <height>20</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Disabled Backends:</string>
</property>
</widget>
- <widget class="QLineEdit" name="periodCountEdit">
+ <widget class="QLabel" name="label">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>10</y>
+ <width>171</width>
+ <height>20</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Priority Backends:</string>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QWidget" name="page_2">
+ <widget class="QCheckBox" name="pulseAutospawnCheckBox">
<property name="geometry">
<rect>
<x>20</x>
- <y>20</y>
- <width>51</width>
- <height>22</height>
+ <y>10</y>
+ <width>141</width>
+ <height>21</height>
</rect>
</property>
- <property name="placeholderText">
- <string>4</string>
+ <property name="toolTip">
+ <string>Automatically spawn a PulseAudio server if one
+is not already running.</string>
+ </property>
+ <property name="text">
+ <string>AutoSpawn Server</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="pulseAllowMovesCheckBox">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>40</y>
+ <width>161</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>Allows moving PulseAudio streams to different
+devices during playback or capture. Note that the
+device specifier and device format will not change
+to match the new device.</string>
+ </property>
+ <property name="text">
+ <string>Allow Moving Streams</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="pulseFixRateCheckBox">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>70</y>
+ <width>121</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>When checked, fix the OpenAL device's sample
+rate to match the PulseAudio device.</string>
+ </property>
+ <property name="text">
+ <string>Fix Sample Rate</string>
</property>
</widget>
</widget>
- <widget class="QWidget" name="widget_2" native="true">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>20</y>
- <width>241</width>
- <height>51</height>
- </rect>
- </property>
- <property name="toolTip">
- <string>The update period size, in sample frames. This is the number of
-frames needed for each mixing update.</string>
- </property>
- <widget class="QSlider" name="periodSizeSlider">
+ <widget class="QWidget" name="page_7">
+ <widget class="QCheckBox" name="jackAutospawnCheckBox">
<property name="geometry">
<rect>
- <x>60</x>
- <y>20</y>
- <width>160</width>
- <height>23</height>
+ <x>20</x>
+ <y>10</y>
+ <width>141</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>AutoSpawn Server</string>
+ </property>
+ </widget>
+ <widget class="QGroupBox" name="groupBox_7">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>40</y>
+ <width>401</width>
+ <height>80</height>
</rect>
</property>
- <property name="minimum">
- <number>0</number>
+ <property name="toolTip">
+ <string>The update buffer size, in samples, that the backend
+will keep buffered to handle the server's real-time
+processing requests. Must be a power of 2.</string>
</property>
- <property name="maximum">
- <number>8192</number>
+ <property name="title">
+ <string>Buffer Size</string>
</property>
- <property name="singleStep">
- <number>64</number>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
</property>
- <property name="pageStep">
- <number>1024</number>
+ <widget class="QLineEdit" name="jackBufferSizeLine">
+ <property name="geometry">
+ <rect>
+ <x>320</x>
+ <y>30</y>
+ <width>71</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="placeholderText">
+ <string>0</string>
+ </property>
+ </widget>
+ <widget class="QSlider" name="jackBufferSizeSlider">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>30</y>
+ <width>301</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="maximum">
+ <number>13</number>
+ </property>
+ <property name="singleStep">
+ <number>1</number>
+ </property>
+ <property name="pageStep">
+ <number>4</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="tickPosition">
+ <enum>QSlider::TicksBelow</enum>
+ </property>
+ <property name="tickInterval">
+ <number>1</number>
+ </property>
+ </widget>
+ </widget>
+ </widget>
+ <widget class="QWidget" name="page_3">
+ <widget class="QLabel" name="label_17">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>30</y>
+ <width>141</width>
+ <height>21</height>
+ </rect>
</property>
- <property name="value">
- <number>0</number>
+ <property name="text">
+ <string>Default Playback Device:</string>
</property>
- <property name="tracking">
- <bool>true</bool>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="alsaDefaultDeviceLine">
+ <property name="geometry">
+ <rect>
+ <x>160</x>
+ <y>30</y>
+ <width>231</width>
+ <height>21</height>
+ </rect>
</property>
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
+ <property name="placeholderText">
+ <string>default</string>
</property>
- <property name="tickPosition">
- <enum>QSlider::TicksBelow</enum>
+ </widget>
+ <widget class="QLabel" name="label_18">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>60</y>
+ <width>141</width>
+ <height>21</height>
+ </rect>
</property>
- <property name="tickInterval">
- <number>512</number>
+ <property name="text">
+ <string>Default Capture Device:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
- <widget class="QLabel" name="label_10">
+ <widget class="QLineEdit" name="alsaDefaultCaptureLine">
+ <property name="geometry">
+ <rect>
+ <x>160</x>
+ <y>60</y>
+ <width>231</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="placeholderText">
+ <string>default</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="alsaResamplerCheckBox">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>100</y>
+ <width>191</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>Allow use of ALSA's software resampler. This lets
+the OpenAL device to be set to a different sample
+rate than the backend device, but incurs another
+resample pass on top of OpenAL's resampler.</string>
+ </property>
+ <property name="text">
+ <string>Allow Resampler</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="alsaMmapCheckBox">
+ <property name="geometry">
+ <rect>
+ <x>210</x>
+ <y>100</y>
+ <width>191</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="toolTip">
+ <string>Accesses the audio device buffer through an mmap,
+potentially avoiding an extra sample buffer copy
+during updates.</string>
+ </property>
+ <property name="text">
+ <string>MMap Buffer</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QWidget" name="page_4">
+ <widget class="QLabel" name="label_20">
<property name="geometry">
<rect>
<x>10</x>
- <y>0</y>
- <width>201</width>
+ <y>30</y>
+ <width>141</width>
<height>21</height>
</rect>
</property>
<property name="text">
- <string>Period Samples</string>
+ <string>Default Playback Device:</string>
</property>
<property name="alignment">
- <set>Qt::AlignCenter</set>
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
- <widget class="QLineEdit" name="periodSizeEdit">
+ <widget class="QLineEdit" name="ossDefaultDeviceLine">
+ <property name="geometry">
+ <rect>
+ <x>160</x>
+ <y>30</y>
+ <width>151</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="placeholderText">
+ <string>/dev/dsp</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_21">
<property name="geometry">
<rect>
<x>10</x>
- <y>20</y>
- <width>51</width>
- <height>22</height>
+ <y>60</y>
+ <width>141</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Default Capture Device:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="ossDefaultCaptureLine">
+ <property name="geometry">
+ <rect>
+ <x>160</x>
+ <y>60</y>
+ <width>151</width>
+ <height>21</height>
</rect>
</property>
<property name="placeholderText">
- <string>1024</string>
+ <string>/dev/dsp</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="ossPlaybackPushButton">
+ <property name="geometry">
+ <rect>
+ <x>320</x>
+ <y>30</y>
+ <width>91</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Browse...</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="ossCapturePushButton">
+ <property name="geometry">
+ <rect>
+ <x>320</x>
+ <y>60</y>
+ <width>91</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Browse...</string>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QWidget" name="page_5">
+ <widget class="QLineEdit" name="solarisDefaultDeviceLine">
+ <property name="geometry">
+ <rect>
+ <x>160</x>
+ <y>30</y>
+ <width>151</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="placeholderText">
+ <string>/dev/audio</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_22">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>30</y>
+ <width>141</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Default Playback Device:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="solarisPlaybackPushButton">
+ <property name="geometry">
+ <rect>
+ <x>320</x>
+ <y>30</y>
+ <width>91</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Browse...</string>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QWidget" name="page_6">
+ <widget class="QLabel" name="label_23">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>30</y>
+ <width>71</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Output File:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ <widget class="QLineEdit" name="waveOutputLine">
+ <property name="geometry">
+ <rect>
+ <x>90</x>
+ <y>30</y>
+ <width>221</width>
+ <height>21</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_24">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>90</y>
+ <width>421</width>
+ <height>71</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;Warning: The specified output file will be OVERWRITTEN WITHOUT&lt;/span&gt;&lt;/p&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;QUESTION when the Wave Writer device is opened.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="waveOutputButton">
+ <property name="geometry">
+ <rect>
+ <x>320</x>
+ <y>30</y>
+ <width>91</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Browse...</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="waveBFormatCheckBox">
+ <property name="geometry">
+ <rect>
+ <x>120</x>
+ <y>60</y>
+ <width>191</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Create .amb (B-Format) files</string>
</property>
</widget>
</widget>
- </widget>
- <widget class="QLabel" name="label_14">
- <property name="geometry">
- <rect>
- <x>280</x>
- <y>50</y>
- <width>81</width>
- <height>21</height>
- </rect>
- </property>
- <property name="text">
- <string>Stereo Mode:</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- </widget>
- <widget class="QComboBox" name="stereoModeCombo">
- <property name="geometry">
- <rect>
- <x>370</x>
- <y>50</y>
- <width>78</width>
- <height>22</height>
- </rect>
- </property>
- <property name="toolTip">
- <string>How to treat stereo output. As headphones, HRTF or crossfeed
-filters may be used to improve binaural quality, which may not
-otherwise be suitable for speakers.</string>
- </property>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
@@ -543,7 +1706,7 @@ otherwise be suitable for speakers.</string>
<x>190</x>
<y>20</y>
<width>51</width>
- <height>22</height>
+ <height>21</height>
</rect>
</property>
<property name="toolTip">
@@ -551,14 +1714,8 @@ otherwise be suitable for speakers.</string>
help for systems with apps that try to play more sounds than
the CPU can handle.</string>
</property>
- <property name="inputMask">
- <string/>
- </property>
<property name="maxLength">
- <number>3</number>
- </property>
- <property name="frame">
- <bool>true</bool>
+ <number>4</number>
</property>
<property name="placeholderText">
<string>256</string>
@@ -602,7 +1759,7 @@ the CPU can handle.</string>
<x>190</x>
<y>50</y>
<width>51</width>
- <height>22</height>
+ <height>21</height>
</rect>
</property>
<property name="toolTip">
@@ -611,17 +1768,11 @@ create. A slot can use a non-negligible amount of CPU time if
an effect is set on it even if no sources are feeding it, so this
may help when apps use more than the system can handle.</string>
</property>
- <property name="inputMask">
- <string/>
- </property>
<property name="maxLength">
- <number>1</number>
- </property>
- <property name="frame">
- <bool>true</bool>
+ <number>3</number>
</property>
<property name="placeholderText">
- <string>4</string>
+ <string>64</string>
</property>
</widget>
<widget class="QLabel" name="label_8">
@@ -646,55 +1797,25 @@ may help when apps use more than the system can handle.</string>
<x>190</x>
<y>80</y>
<width>51</width>
- <height>22</height>
+ <height>21</height>
</rect>
</property>
<property name="toolTip">
- <string>The number of auxiliary sends per source. When not specified,
-it allows the app to request how many it wants. The maximum
-value currently possible is 4.</string>
+ <string>Limits the number of auxiliary sends allowed per source.
+Setting this higher than the default has no effect.</string>
</property>
<property name="maxLength">
- <number>1</number>
+ <number>2</number>
</property>
<property name="placeholderText">
- <string>Auto</string>
- </property>
- </widget>
- <widget class="QLabel" name="label_9">
- <property name="geometry">
- <rect>
- <x>30</x>
- <y>120</y>
- <width>71</width>
- <height>21</height>
- </rect>
- </property>
- <property name="text">
- <string>Resampler:</string>
- </property>
- </widget>
- <widget class="QComboBox" name="resamplerComboBox">
- <property name="geometry">
- <rect>
- <x>110</x>
- <y>120</y>
- <width>78</width>
- <height>22</height>
- </rect>
- </property>
- <property name="toolTip">
- <string>The resampling method used when mixing sources.</string>
- </property>
- <property name="sizeAdjustPolicy">
- <enum>QComboBox::AdjustToContents</enum>
+ <string>16</string>
</property>
</widget>
<widget class="QGroupBox" name="cpuExtGroupBox">
<property name="geometry">
<rect>
<x>10</x>
- <y>150</y>
+ <y>120</y>
<width>511</width>
<height>121</height>
</rect>
@@ -802,118 +1923,17 @@ be useful for preventing those extensions from being used.</string>
</widget>
</widget>
</widget>
- <widget class="QWidget" name="tab">
- <attribute name="title">
- <string>Backends</string>
- </attribute>
- <widget class="QCheckBox" name="backendCheckBox">
- <property name="geometry">
- <rect>
- <x>170</x>
- <y>200</y>
- <width>161</width>
- <height>21</height>
- </rect>
- </property>
- <property name="toolTip">
- <string>When checked, allows all other available backends not listed in the priority or disabled lists.</string>
- </property>
- <property name="text">
- <string>Allow Other Backends</string>
- </property>
- <property name="checked">
- <bool>true</bool>
- </property>
- </widget>
- <widget class="QListWidget" name="enabledBackendList">
- <property name="geometry">
- <rect>
- <x>40</x>
- <y>40</y>
- <width>191</width>
- <height>151</height>
- </rect>
- </property>
- <property name="toolTip">
- <string>The backend driver list order. Unknown backends and
-duplicated names are ignored.</string>
- </property>
- <property name="dragDropMode">
- <enum>QAbstractItemView::InternalMove</enum>
- </property>
- </widget>
- <widget class="QLabel" name="label">
- <property name="geometry">
- <rect>
- <x>40</x>
- <y>20</y>
- <width>191</width>
- <height>20</height>
- </rect>
- </property>
- <property name="text">
- <string>Priority Backends:</string>
- </property>
- </widget>
- <widget class="QListWidget" name="disabledBackendList">
- <property name="geometry">
- <rect>
- <x>270</x>
- <y>40</y>
- <width>191</width>
- <height>151</height>
- </rect>
- </property>
- <property name="toolTip">
- <string>Disabled backend driver list.</string>
- </property>
- </widget>
- <widget class="QLabel" name="label_2">
- <property name="geometry">
- <rect>
- <x>270</x>
- <y>20</y>
- <width>191</width>
- <height>20</height>
- </rect>
- </property>
- <property name="text">
- <string>Disabled Backends:</string>
- </property>
- </widget>
- </widget>
<widget class="QWidget" name="tab_4">
<attribute name="title">
<string>Effects</string>
</attribute>
- <widget class="QCheckBox" name="emulateEaxCheckBox">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>60</y>
- <width>161</width>
- <height>21</height>
- </rect>
- </property>
- <property name="toolTip">
- <string>Uses a simpler reverb method to emulate the EAX reverb
-effect. This may slightly improve performance at the cost of
-some quality.</string>
- </property>
- <property name="layoutDirection">
- <enum>Qt::RightToLeft</enum>
- </property>
- <property name="text">
- <string>Emulate EAX Reverb:</string>
- </property>
- </widget>
<widget class="QGroupBox" name="groupBox_5">
<property name="geometry">
<rect>
<x>10</x>
<y>100</y>
<width>511</width>
- <height>191</height>
+ <height>241</height>
</rect>
</property>
<property name="toolTip">
@@ -991,8 +2011,8 @@ for the system to handle.</string>
<widget class="QCheckBox" name="enableEchoCheck">
<property name="geometry">
<rect>
- <x>320</x>
- <y>30</y>
+ <x>70</x>
+ <y>180</y>
<width>131</width>
<height>21</height>
</rect>
@@ -1008,7 +2028,7 @@ for the system to handle.</string>
<property name="geometry">
<rect>
<x>320</x>
- <y>60</y>
+ <y>30</y>
<width>131</width>
<height>21</height>
</rect>
@@ -1040,7 +2060,7 @@ for the system to handle.</string>
<property name="geometry">
<rect>
<x>320</x>
- <y>120</y>
+ <y>150</y>
<width>131</width>
<height>21</height>
</rect>
@@ -1056,7 +2076,7 @@ for the system to handle.</string>
<property name="geometry">
<rect>
<x>320</x>
- <y>150</y>
+ <y>180</y>
<width>131</width>
<height>21</height>
</rect>
@@ -1088,6 +2108,54 @@ added by the ALC_EXT_DEDICATED extension.</string>
<bool>true</bool>
</property>
</widget>
+ <widget class="QCheckBox" name="enablePitchShifterCheck">
+ <property name="geometry">
+ <rect>
+ <x>320</x>
+ <y>120</y>
+ <width>131</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Pitch Shifter</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="enableFrequencyShifterCheck">
+ <property name="geometry">
+ <rect>
+ <x>320</x>
+ <y>60</y>
+ <width>131</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Frequency Shifter</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget class="QCheckBox" name="enableAutowahCheck">
+ <property name="geometry">
+ <rect>
+ <x>70</x>
+ <y>210</y>
+ <width>131</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Autowah</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
</widget>
<widget class="QLabel" name="label_13">
<property name="geometry">
@@ -1110,8 +2178,8 @@ added by the ALC_EXT_DEDICATED extension.</string>
<rect>
<x>160</x>
<y>20</y>
- <width>131</width>
- <height>22</height>
+ <width>108</width>
+ <height>20</height>
</rect>
</property>
<property name="sizeAdjustPolicy">
@@ -1255,6 +2323,24 @@ added by the ALC_EXT_DEDICATED extension.</string>
</widget>
</widget>
</widget>
+ <widget class="QPushButton" name="closeCancelButton">
+ <property name="geometry">
+ <rect>
+ <x>370</x>
+ <y>405</y>
+ <width>91</width>
+ <height>21</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Cancel</string>
+ </property>
+ <property name="icon">
+ <iconset theme="window-close">
+ <normaloff/>
+ </iconset>
+ </property>
+ </widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
@@ -1262,7 +2348,7 @@ added by the ALC_EXT_DEDICATED extension.</string>
<x>0</x>
<y>0</y>
<width>564</width>
- <height>19</height>
+ <height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@@ -1274,7 +2360,14 @@ added by the ALC_EXT_DEDICATED extension.</string>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
+ <widget class="QMenu" name="menuHelp">
+ <property name="title">
+ <string>&amp;Help</string>
+ </property>
+ <addaction name="actionAbout"/>
+ </widget>
<addaction name="menuFile"/>
+ <addaction name="menuHelp"/>
</widget>
<action name="actionQuit">
<property name="icon">
@@ -1312,6 +2405,11 @@ added by the ALC_EXT_DEDICATED extension.</string>
<string>Load Configuration File</string>
</property>
</action>
+ <action name="actionAbout">
+ <property name="text">
+ <string>&amp;About...</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
@@ -1332,6 +2430,22 @@ added by the ALC_EXT_DEDICATED extension.</string>
</hint>
</hints>
</connection>
+ <connection>
+ <sender>backendListWidget</sender>
+ <signal>currentRowChanged(int)</signal>
+ <receiver>backendStackedWidget</receiver>
+ <slot>setCurrentIndex(int)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>69</x>
+ <y>233</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>329</x>
+ <y>232</y>
+ </hint>
+ </hints>
+ </connection>
</connections>
<slots>
<slot>ShowHRTFContextMenu(QPoint)</slot>
diff --git a/utils/bsincgen.c b/utils/bsincgen.c
index d53b3cb5..03421da9 100644
--- a/utils/bsincgen.c
+++ b/utils/bsincgen.c
@@ -33,20 +33,32 @@
* accessed October 2012.
*/
+#define _UNICODE
#include <stdio.h>
#include <math.h>
#include <string.h>
+#include <stdlib.h>
+
+#include "win_main_utf8.h"
+
#ifndef M_PI
#define M_PI (3.14159265358979323846)
#endif
+#if defined(__ANDROID__) && !(defined(_ISOC99_SOURCE) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L))
+#define log2(x) (log(x) / log(2.0))
+#endif
+
// The number of distinct scale and phase intervals within the filter table.
+// Must be the same as in alu.h!
#define BSINC_SCALE_COUNT (16)
#define BSINC_PHASE_COUNT (16)
-#define BSINC_REJECTION (60.0)
-#define BSINC_POINTS_MIN (12)
+/* 48 points includes the doubling for downsampling, so the maximum number of
+ * base sample points is 24, which is 23rd order.
+ */
+#define BSINC_POINTS_MAX (48)
static double MinDouble(double a, double b)
{ return (a <= b) ? a : b; }
@@ -93,18 +105,13 @@ static double BesselI_0(const double x)
*/
static double Kaiser(const double b, const double k)
{
- double k2;
-
- if((k < -1.0) || (k > 1.0))
+ if(!(k >= -1.0 && k <= 1.0))
return 0.0;
-
- k2 = MaxDouble(1.0 - (k * k), 0.0);
-
- return BesselI_0(b * sqrt(k2)) / BesselI_0(b);
+ return BesselI_0(b * sqrt(1.0 - k*k)) / BesselI_0(b);
}
-/* NOTE: Calculates the transition width of the Kaiser window. Rejection is
- * in dB.
+/* Calculates the (normalized frequency) transition width of the Kaiser window.
+ * Rejection is in dB.
*/
static double CalcKaiserWidth(const double rejection, const int order)
{
@@ -112,7 +119,7 @@ static double CalcKaiserWidth(const double rejection, const int order)
if(rejection > 21.0)
return (rejection - 7.95) / (order * 2.285 * w_t);
-
+ /* This enforces a minimum rejection of just above 21.18dB */
return 5.79 / (order * w_t);
}
@@ -127,14 +134,15 @@ static double CalcKaiserBeta(const double rejection)
}
/* Generates the coefficient, delta, and index tables required by the bsinc resampler */
-static void BsiGenerateTables()
+static void BsiGenerateTables(FILE *output, const char *tabname, const double rejection, const int order)
{
- static double filter[BSINC_SCALE_COUNT][BSINC_PHASE_COUNT + 1][2 * BSINC_POINTS_MIN];
- static double scDeltas[BSINC_SCALE_COUNT - 1][BSINC_PHASE_COUNT][2 * BSINC_POINTS_MIN];
- static double phDeltas[BSINC_SCALE_COUNT][BSINC_PHASE_COUNT + 1][2 * BSINC_POINTS_MIN];
- static double spDeltas[BSINC_SCALE_COUNT - 1][BSINC_PHASE_COUNT][2 * BSINC_POINTS_MIN];
+ static double filter[BSINC_SCALE_COUNT][BSINC_PHASE_COUNT + 1][BSINC_POINTS_MAX];
+ static double scDeltas[BSINC_SCALE_COUNT][BSINC_PHASE_COUNT ][BSINC_POINTS_MAX];
+ static double phDeltas[BSINC_SCALE_COUNT][BSINC_PHASE_COUNT + 1][BSINC_POINTS_MAX];
+ static double spDeltas[BSINC_SCALE_COUNT][BSINC_PHASE_COUNT ][BSINC_POINTS_MAX];
static int mt[BSINC_SCALE_COUNT];
static double at[BSINC_SCALE_COUNT];
+ const int num_points_min = order + 1;
double width, beta, scaleBase, scaleRange;
int si, pi, i;
@@ -147,8 +155,8 @@ static void BsiGenerateTables()
band, but it may vary due to the linear interpolation between scales
of the filter.
*/
- width = CalcKaiserWidth(BSINC_REJECTION, BSINC_POINTS_MIN);
- beta = CalcKaiserBeta(BSINC_REJECTION);
+ width = CalcKaiserWidth(rejection, order);
+ beta = CalcKaiserBeta(rejection);
scaleBase = width / 2.0;
scaleRange = 1.0 - scaleBase;
@@ -156,11 +164,8 @@ static void BsiGenerateTables()
for(si = 0; si < BSINC_SCALE_COUNT; si++)
{
const double scale = scaleBase + (scaleRange * si / (BSINC_SCALE_COUNT - 1));
- const double a = MinDouble(BSINC_POINTS_MIN, BSINC_POINTS_MIN / (2.0 * scale));
- int m = 2 * (int)floor(a);
-
- // Make sure the number of points is a multiple of 4 (for SSE).
- m += ~(m - 1) & 3;
+ const double a = MinDouble(floor(num_points_min / (2.0 * scale)), num_points_min);
+ const int m = 2 * (int)a;
mt[si] = m;
at[si] = a;
@@ -172,7 +177,7 @@ static void BsiGenerateTables()
for(si = 0; si < BSINC_SCALE_COUNT; si++)
{
const int m = mt[si];
- const int o = BSINC_POINTS_MIN - (m / 2);
+ const int o = num_points_min - (m / 2);
const int l = (m / 2) - 1;
const double a = at[si];
const double scale = scaleBase + (scaleRange * si / (BSINC_SCALE_COUNT - 1));
@@ -199,7 +204,7 @@ static void BsiGenerateTables()
for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++)
{
const int m = mt[si];
- const int o = BSINC_POINTS_MIN - (m / 2);
+ const int o = num_points_min - (m / 2);
for(pi = 0; pi < BSINC_PHASE_COUNT; pi++)
{
@@ -212,7 +217,7 @@ static void BsiGenerateTables()
for(si = 0; si < BSINC_SCALE_COUNT; si++)
{
const int m = mt[si];
- const int o = BSINC_POINTS_MIN - (m / 2);
+ const int o = num_points_min - (m / 2);
for(pi = 0; pi < BSINC_PHASE_COUNT; pi++)
{
@@ -227,7 +232,7 @@ static void BsiGenerateTables()
for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++)
{
const int m = mt[si];
- const int o = BSINC_POINTS_MIN - (m / 2);
+ const int o = num_points_min - (m / 2);
for(pi = 0; pi < BSINC_PHASE_COUNT; pi++)
{
@@ -236,139 +241,164 @@ static void BsiGenerateTables()
}
}
- // Calculate the table size.
- i = mt[0];
- for(si = 1; si < BSINC_SCALE_COUNT; si++)
- i += BSINC_PHASE_COUNT * mt[si];
- for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++)
- i += 2 * BSINC_PHASE_COUNT * mt[si];
- for(si = 1; si < BSINC_SCALE_COUNT; si++)
- i += BSINC_PHASE_COUNT * mt[si];
-
- fprintf(stdout, "static const float bsincTab[%d] =\n{\n", i);
+ // Make sure the number of points is a multiple of 4 (for SIMD).
+ for(si = 0; si < BSINC_SCALE_COUNT; si++)
+ mt[si] = (mt[si]+3) & ~3;
+
+ fprintf(output,
+"/* This %d%s order filter has a rejection of -%.0fdB, yielding a transition width\n"
+" * of ~%.3f (normalized frequency). Order increases when downsampling to a\n"
+" * limit of one octave, after which the quality of the filter (transition\n"
+" * width) suffers to reduce the CPU cost. The bandlimiting will cut all sound\n"
+" * after downsampling by ~%.2f octaves.\n"
+" */\n"
+"const BSincTable %s = {\n",
+ order, (((order%100)/10) == 1) ? "th" :
+ ((order%10) == 1) ? "st" :
+ ((order%10) == 2) ? "nd" :
+ ((order%10) == 3) ? "rd" : "th",
+ rejection, width, log2(1.0/scaleBase), tabname);
- /* Only output enough coefficients for the first (cut) scale as needed to
- perform interpolation without extra branching.
+ /* The scaleBase is calculated from the Kaiser window transition width.
+ It represents the absolute limit to the filter before it fully cuts
+ the signal. The limit in octaves can be calculated by taking the
+ base-2 logarithm of its inverse: log_2(1 / scaleBase)
*/
- fprintf(stdout, " /* %2d,%2d */", mt[0], 0);
- for(i = 0; i < mt[0]; i++)
- fprintf(stdout, " %+14.9ef,", filter[0][0][i]);
- fprintf(stdout, "\n\n");
+ fprintf(output, " /* scaleBase */ %.9ef, /* scaleRange */ %.9ef,\n", scaleBase, 1.0 / scaleRange);
+ fprintf(output, " /* m */ {");
+ fprintf(output, " %d", mt[0]);
for(si = 1; si < BSINC_SCALE_COUNT; si++)
- {
- const int m = mt[si];
- const int o = BSINC_POINTS_MIN - (m / 2);
+ fprintf(output, ", %d", mt[si]);
+ fprintf(output, " },\n");
- for(pi = 0; pi < BSINC_PHASE_COUNT; pi++)
- {
- fprintf(stdout, " /* %2d,%2d */", m, pi);
- for(i = 0; i < m; i++)
- fprintf(stdout, " %+14.9ef,", filter[si][pi][o + i]);
- fprintf(stdout, "\n");
- }
+ fprintf(output, " /* filterOffset */ {");
+ fprintf(output, " %d", 0);
+ i = mt[0]*4*BSINC_PHASE_COUNT;
+ for(si = 1; si < BSINC_SCALE_COUNT; si++)
+ {
+ fprintf(output, ", %d", i);
+ i += mt[si]*4*BSINC_PHASE_COUNT;
}
- fprintf(stdout, "\n");
- // There are N-1 scale deltas for N scales.
- for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++)
- {
- const int m = mt[si];
- const int o = BSINC_POINTS_MIN - (m / 2);
+ fprintf(output, " },\n");
- for(pi = 0; pi < BSINC_PHASE_COUNT; pi++)
- {
- fprintf(stdout, " /* %2d,%2d */", m, pi);
- for(i = 0; i < m; i++)
- fprintf(stdout, " %+14.9ef,", scDeltas[si][pi][o + i]);
- fprintf(stdout, "\n");
- }
- }
- fprintf(stdout, "\n");
+ // Calculate the table size.
+ i = 0;
+ for(si = 0; si < BSINC_SCALE_COUNT; si++)
+ i += 4 * BSINC_PHASE_COUNT * mt[si];
- // Exclude phases for the first (cut) scale.
- for(si = 1; si < BSINC_SCALE_COUNT; si++)
+ fprintf(output, "\n /* Tab (%d entries) */ {\n", i);
+ for(si = 0; si < BSINC_SCALE_COUNT; si++)
{
const int m = mt[si];
- const int o = BSINC_POINTS_MIN - (m / 2);
+ const int o = num_points_min - (m / 2);
for(pi = 0; pi < BSINC_PHASE_COUNT; pi++)
{
- fprintf(stdout, " /* %2d,%2d */", m, pi);
+ fprintf(output, " /* %2d,%2d (%d) */", si, pi, m);
+ fprintf(output, "\n ");
+ for(i = 0; i < m; i++)
+ fprintf(output, " %+14.9ef,", filter[si][pi][o + i]);
+ fprintf(output, "\n ");
+ for(i = 0; i < m; i++)
+ fprintf(output, " %+14.9ef,", scDeltas[si][pi][o + i]);
+ fprintf(output, "\n ");
for(i = 0; i < m; i++)
- fprintf(stdout, " %+14.9ef,", phDeltas[si][pi][o + i]);
- fprintf(stdout, "\n");
+ fprintf(output, " %+14.9ef,", phDeltas[si][pi][o + i]);
+ fprintf(output, "\n ");
+ for(i = 0; i < m; i++)
+ fprintf(output, " %+14.9ef,", spDeltas[si][pi][o + i]);
+ fprintf(output, "\n");
}
}
- fprintf(stdout, "\n");
+ fprintf(output, " }\n};\n\n");
+}
- for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++)
+
+/* These methods generate a much simplified 4-point sinc interpolator using a
+ * Kaiser window. This is much simpler to process at run-time, but has notably
+ * more aliasing noise.
+ */
+
+/* Same as in alu.h! */
+#define FRACTIONBITS (12)
+#define FRACTIONONE (1<<FRACTIONBITS)
+
+static void Sinc4GenerateTables(FILE *output, const double rejection)
+{
+ static double filter[FRACTIONONE][4];
+
+ const double width = CalcKaiserWidth(rejection, 3);
+ const double beta = CalcKaiserBeta(rejection);
+ const double scaleBase = width / 2.0;
+ const double scaleRange = 1.0 - scaleBase;
+ const double scale = scaleBase + scaleRange;
+ const double a = MinDouble(4.0, floor(4.0 / (2.0*scale)));
+ const int m = 2 * (int)a;
+ const int l = (m/2) - 1;
+ int pi;
+ for(pi = 0;pi < FRACTIONONE;pi++)
{
- const int m = mt[si];
- const int o = BSINC_POINTS_MIN - (m / 2);
+ const double phase = l + ((double)pi / FRACTIONONE);
+ int i;
- for(pi = 0; pi < BSINC_PHASE_COUNT; pi++)
+ for(i = 0;i < m;i++)
{
- fprintf(stdout, " /* %2d,%2d */", m, pi);
- for(i = 0; i < m; i++)
- fprintf(stdout, " %+14.9ef,", spDeltas[si][pi][o + i]);
- fprintf(stdout, "\n");
+ double x = i - phase;
+ filter[pi][i] = Kaiser(beta, x / a) * Sinc(x);
}
}
- fprintf(stdout, "};\n\n");
- /* The scaleBase is calculated from the Kaiser window transition width.
- It represents the absolute limit to the filter before it fully cuts
- the signal. The limit in octaves can be calculated by taking the
- base-2 logarithm of its inverse: log_2(1 / scaleBase)
- */
- fprintf(stdout, " static const ALfloat scaleBase = %.9ef, scaleRange = %.9ef;\n", scaleBase, 1.0 / scaleRange);
- fprintf(stdout, " static const ALuint m[BSINC_SCALE_COUNT] = {");
+ fprintf(output, "alignas(16) static const float sinc4Tab[FRACTIONONE][4] = {\n");
+ for(pi = 0;pi < FRACTIONONE;pi++)
+ fprintf(output, " { %+14.9ef, %+14.9ef, %+14.9ef, %+14.9ef },\n",
+ filter[pi][0], filter[pi][1], filter[pi][2], filter[pi][3]);
+ fprintf(output, "};\n\n");
+}
- fprintf(stdout, " %d", mt[0]);
- for(si = 1; si < BSINC_SCALE_COUNT; si++)
- fprintf(stdout, ", %d", mt[si]);
- fprintf(stdout, " };\n");
- fprintf(stdout, " static const ALuint to[4][BSINC_SCALE_COUNT] =\n {\n { 0");
+int main(int argc, char *argv[])
+{
+ FILE *output;
- i = mt[0];
- for(si = 1; si < BSINC_SCALE_COUNT; si++)
- {
- fprintf(stdout, ", %d", i);
- i += BSINC_PHASE_COUNT * mt[si];
- }
- fprintf(stdout, " },\n {");
- for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++)
- {
- fprintf(stdout, " %d,", i);
- i += BSINC_PHASE_COUNT * mt[si];
- }
- fprintf(stdout, " 0 },\n { 0");
- for(si = 1; si < BSINC_SCALE_COUNT; si++)
+ if(argc > 2)
{
- fprintf(stdout, ", %d", i);
- i += BSINC_PHASE_COUNT * mt[si];
+ fprintf(stderr, "Usage: %s [output file]\n", argv[0]);
+ return 1;
}
- fprintf (stdout, " },\n {");
- for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++)
+
+ if(argc == 2)
{
- fprintf(stdout, " %d,", i);
- i += BSINC_PHASE_COUNT * mt[si];
+ output = fopen(argv[1], "wb");
+ if(!output)
+ {
+ fprintf(stderr, "Failed to open %s for writing\n", argv[1]);
+ return 1;
+ }
}
- fprintf(stdout, " 0 }\n };\n");
+ else
+ output = stdout;
+
+ fprintf(output, "/* Generated by bsincgen, do not edit! */\n\n"
+"static_assert(BSINC_SCALE_COUNT == %d, \"Unexpected BSINC_SCALE_COUNT value!\");\n"
+"static_assert(BSINC_PHASE_COUNT == %d, \"Unexpected BSINC_PHASE_COUNT value!\");\n"
+"static_assert(FRACTIONONE == %d, \"Unexpected FRACTIONONE value!\");\n\n"
+"typedef struct BSincTable {\n"
+" const float scaleBase, scaleRange;\n"
+" const int m[BSINC_SCALE_COUNT];\n"
+" const int filterOffset[BSINC_SCALE_COUNT];\n"
+" alignas(16) const float Tab[];\n"
+"} BSincTable;\n\n", BSINC_SCALE_COUNT, BSINC_PHASE_COUNT, FRACTIONONE);
+ /* A 23rd order filter with a -60dB drop at nyquist. */
+ BsiGenerateTables(output, "bsinc24", 60.0, 23);
+ /* An 11th order filter with a -60dB drop at nyquist. */
+ BsiGenerateTables(output, "bsinc12", 60.0, 11);
+ Sinc4GenerateTables(output, 60.0);
+
+ if(output != stdout)
+ fclose(output);
+ output = NULL;
- fprintf(stdout, " static const ALuint tm[2][BSINC_SCALE_COUNT] = \n {\n { 0");
- for(si = 1; si < BSINC_SCALE_COUNT; si++)
- fprintf(stdout, ", %d", mt[si]);
- fprintf(stdout, " },\n {");
- for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++)
- fprintf(stdout, " %d,", mt[si]);
- fprintf(stdout, " 0 }\n };\n");
-}
-
-int main(void)
-{
- BsiGenerateTables();
return 0;
}
diff --git a/utils/getopt.c b/utils/getopt.c
new file mode 100644
index 00000000..ab1a246e
--- /dev/null
+++ b/utils/getopt.c
@@ -0,0 +1,137 @@
+/* $NetBSD: getopt.c,v 1.26 2003/08/07 16:43:40 agc Exp $ */
+
+/*
+ * Copyright (c) 1987, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95";
+#endif /* LIBC_SCCS and not lint */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "getopt.h"
+
+int opterr = 1, /* if error message should be printed */
+ optind = 1, /* index into parent argv vector */
+ optopt, /* character checked for validity */
+ optreset; /* reset getopt */
+char *optarg; /* argument associated with option */
+
+#define BADCH (int)'?'
+#define BADARG (int)':'
+#define EMSG ""
+
+/*
+ * Get program name in Windows
+ */
+const char * _getprogname(void);
+
+/*
+ * getopt --
+ * Parse argc/argv argument vector.
+ */
+int
+getopt(int nargc, char * const nargv[], const char *ostr)
+{
+ static char *place = EMSG; /* option letter processing */
+ char *oli; /* option letter list index */
+
+ if (optreset || *place == 0) { /* update scanning pointer */
+ optreset = 0;
+ place = nargv[optind];
+ if (optind >= nargc || *place++ != '-') {
+ /* Argument is absent or is not an option */
+ place = EMSG;
+ return (-1);
+ }
+ optopt = *place++;
+ if (optopt == '-' && *place == 0) {
+ /* "--" => end of options */
+ ++optind;
+ place = EMSG;
+ return (-1);
+ }
+ if (optopt == 0) {
+ /* Solitary '-', treat as a '-' option
+ if the program (eg su) is looking for it. */
+ place = EMSG;
+ if (strchr(ostr, '-') == NULL)
+ return (-1);
+ optopt = '-';
+ }
+ } else
+ optopt = *place++;
+
+ /* See if option letter is one the caller wanted... */
+ if (optopt == ':' || (oli = strchr(ostr, optopt)) == NULL) {
+ if (*place == 0)
+ ++optind;
+ if (opterr && *ostr != ':')
+ (void)fprintf(stderr,
+ "%s: illegal option -- %c\n", _getprogname(),
+ optopt);
+ return (BADCH);
+ }
+
+ /* Does this option need an argument? */
+ if (oli[1] != ':') {
+ /* don't need argument */
+ optarg = NULL;
+ if (*place == 0)
+ ++optind;
+ } else {
+ /* Option-argument is either the rest of this argument or the
+ entire next argument. */
+ if (*place)
+ optarg = place;
+ else if (nargc > ++optind)
+ optarg = nargv[optind];
+ else {
+ /* option-argument absent */
+ place = EMSG;
+ if (*ostr == ':')
+ return (BADARG);
+ if (opterr)
+ (void)fprintf(stderr,
+ "%s: option requires an argument -- %c\n",
+ _getprogname(), optopt);
+ return (BADCH);
+ }
+ place = EMSG;
+ ++optind;
+ }
+ return (optopt); /* return option letter */
+}
+
+const char * _getprogname() {
+ char *pgmptr = NULL;
+ _get_pgmptr(&pgmptr);
+ return strrchr(pgmptr,'\\')+1;
+}
+
diff --git a/utils/getopt.h b/utils/getopt.h
new file mode 100644
index 00000000..f894d9d9
--- /dev/null
+++ b/utils/getopt.h
@@ -0,0 +1,26 @@
+#ifndef GETOPT_H
+#define GETOPT_H
+
+#ifndef _WIN32
+
+#include <unistd.h>
+
+#else /* _WIN32 */
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+extern char *optarg;
+extern int optind, opterr, optopt, optreset;
+
+int getopt(int nargc, char * const nargv[], const char *ostr);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* !_WIN32 */
+
+#endif /* !GETOPT_H */
+
diff --git a/utils/makehrtf.c b/utils/makehrtf.c
index 57d8a91a..0bd36849 100644
--- a/utils/makehrtf.c
+++ b/utils/makehrtf.c
@@ -2,7 +2,7 @@
* HRTF utility for producing and demonstrating the process of creating an
* OpenAL Soft compatible HRIR data set.
*
- * Copyright (C) 2011-2014 Christopher Fitzgerald
+ * Copyright (C) 2011-2017 Christopher Fitzgerald
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -60,19 +60,38 @@
#include "config.h"
+#define _UNICODE
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <stddef.h>
#include <string.h>
+#include <limits.h>
#include <ctype.h>
#include <math.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
+#ifdef HAVE_GETOPT
+#include <unistd.h>
+#else
+#include "getopt.h"
+#endif
-// Rely (if naively) on OpenAL's header for the types used for serialization.
-#include "AL/al.h"
-#include "AL/alext.h"
+#include "win_main_utf8.h"
+
+/* Define int64_t and uint64_t types */
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#include <inttypes.h>
+#elif defined(_WIN32) && defined(__GNUC__)
+#include <stdint.h>
+#elif defined(_WIN32)
+typedef __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+#else
+/* Fallback if nothing above works */
+#include <inttypes.h>
+#endif
#ifndef M_PI
#define M_PI (3.14159265358979323846)
@@ -82,8 +101,9 @@
#define HUGE_VAL (1.0 / 0.0)
#endif
+
// The epsilon used to maintain signal stability.
-#define EPSILON (1e-15)
+#define EPSILON (1e-9)
// Constants for accessing the token reader's ring buffer.
#define TR_RING_BITS (16)
@@ -109,6 +129,9 @@
#define MIN_POINTS (16)
#define MAX_POINTS (8192)
+// The limit to the number of 'distances' listed in the data set definition.
+#define MAX_FD_COUNT (16)
+
// The limits to the number of 'azimuths' listed in the data set definition.
#define MIN_EV_COUNT (5)
#define MAX_EV_COUNT (128)
@@ -121,10 +144,10 @@
#define MIN_RADIUS (0.05)
#define MAX_RADIUS (0.15)
-// The limits for the 'distance' from source to listener in the definition
-// file.
-#define MIN_DISTANCE (0.5)
-#define MAX_DISTANCE (2.5)
+// The limits for the 'distance' from source to listener for each field in
+// the definition file.
+#define MIN_DISTANCE (0.05)
+#define MAX_DISTANCE (2.50)
// The maximum number of channels that can be addressed for a WAVE file
// source listed in the data set definition.
@@ -145,16 +168,16 @@
#define MAX_ASCII_BITS (32)
// The limits to the FFT window size override on the command line.
-#define MIN_FFTSIZE (512)
-#define MAX_FFTSIZE (16384)
+#define MIN_FFTSIZE (65536)
+#define MAX_FFTSIZE (131072)
// The limits to the equalization range limit on the command line.
#define MIN_LIMIT (2.0)
#define MAX_LIMIT (120.0)
// The limits to the truncation window size on the command line.
-#define MIN_TRUNCSIZE (8)
-#define MAX_TRUNCSIZE (128)
+#define MIN_TRUNCSIZE (16)
+#define MAX_TRUNCSIZE (512)
// The limits to the custom head radius on the command line.
#define MIN_CUSTOM_RADIUS (0.05)
@@ -165,6 +188,7 @@
#define MOD_TRUNCSIZE (8)
// The defaults for the command line options.
+#define DEFAULT_FFTSIZE (65536)
#define DEFAULT_EQUALIZE (1)
#define DEFAULT_SURFACE (1)
#define DEFAULT_LIMIT (24.0)
@@ -191,267 +215,378 @@
#define MAX_HRTD (63.0)
// The OpenAL Soft HRTF format marker. It stands for minimum-phase head
-// response protocol 01.
-#define MHR_FORMAT ("MinPHR01")
+// response protocol 02.
+#define MHR_FORMAT ("MinPHR02")
+
+// Sample and channel type enum values.
+typedef enum SampleTypeT {
+ ST_S16 = 0,
+ ST_S24 = 1
+} SampleTypeT;
+
+// Certain iterations rely on these integer enum values.
+typedef enum ChannelTypeT {
+ CT_NONE = -1,
+ CT_MONO = 0,
+ CT_STEREO = 1
+} ChannelTypeT;
// Byte order for the serialization routines.
-enum ByteOrderT {
- BO_NONE = 0,
- BO_LITTLE ,
- BO_BIG
-};
+typedef enum ByteOrderT {
+ BO_NONE,
+ BO_LITTLE,
+ BO_BIG
+} ByteOrderT;
// Source format for the references listed in the data set definition.
-enum SourceFormatT {
- SF_NONE = 0,
- SF_WAVE , // RIFF/RIFX WAVE file.
- SF_BIN_LE , // Little-endian binary file.
- SF_BIN_BE , // Big-endian binary file.
- SF_ASCII // ASCII text file.
-};
+typedef enum SourceFormatT {
+ SF_NONE,
+ SF_WAVE, // RIFF/RIFX WAVE file.
+ SF_BIN_LE, // Little-endian binary file.
+ SF_BIN_BE, // Big-endian binary file.
+ SF_ASCII // ASCII text file.
+} SourceFormatT;
// Element types for the references listed in the data set definition.
-enum ElementTypeT {
- ET_NONE = 0,
- ET_INT , // Integer elements.
- ET_FP // Floating-point elements.
-};
+typedef enum ElementTypeT {
+ ET_NONE,
+ ET_INT, // Integer elements.
+ ET_FP // Floating-point elements.
+} ElementTypeT;
// Head model used for calculating the impulse delays.
-enum HeadModelT {
- HM_NONE = 0,
- HM_DATASET , // Measure the onset from the dataset.
- HM_SPHERE // Calculate the onset using a spherical head model.
-};
-
-// Desired output format from the command line.
-enum OutputFormatT {
- OF_NONE = 0,
- OF_MHR // OpenAL Soft MHR data set file.
-};
+typedef enum HeadModelT {
+ HM_NONE,
+ HM_DATASET, // Measure the onset from the dataset.
+ HM_SPHERE // Calculate the onset using a spherical head model.
+} HeadModelT;
// Unsigned integer type.
-typedef unsigned int uint;
+typedef unsigned int uint;
// Serialization types. The trailing digit indicates the number of bits.
-typedef ALubyte uint8;
-
-typedef ALint int32;
-typedef ALuint uint32;
-typedef ALuint64SOFT uint64;
-
-typedef enum ByteOrderT ByteOrderT;
-typedef enum SourceFormatT SourceFormatT;
-typedef enum ElementTypeT ElementTypeT;
-typedef enum HeadModelT HeadModelT;
-typedef enum OutputFormatT OutputFormatT;
-
-typedef struct TokenReaderT TokenReaderT;
-typedef struct SourceRefT SourceRefT;
-typedef struct HrirDataT HrirDataT;
-typedef struct ResamplerT ResamplerT;
+typedef unsigned char uint8;
+typedef int int32;
+typedef unsigned int uint32;
+typedef uint64_t uint64;
// Token reader state for parsing the data set definition.
-struct TokenReaderT {
- FILE * mFile;
- const char * mName;
- uint mLine,
- mColumn;
- char mRing [TR_RING_SIZE];
- size_t mIn,
- mOut;
-};
+typedef struct TokenReaderT {
+ FILE *mFile;
+ const char *mName;
+ uint mLine;
+ uint mColumn;
+ char mRing[TR_RING_SIZE];
+ size_t mIn;
+ size_t mOut;
+} TokenReaderT;
// Source reference state used when loading sources.
-struct SourceRefT {
- SourceFormatT mFormat;
- ElementTypeT mType;
- uint mSize;
- int mBits;
- uint mChannel,
- mSkip,
- mOffset;
- char mPath [MAX_PATH_LEN + 1];
-};
+typedef struct SourceRefT {
+ SourceFormatT mFormat;
+ ElementTypeT mType;
+ uint mSize;
+ int mBits;
+ uint mChannel;
+ uint mSkip;
+ uint mOffset;
+ char mPath[MAX_PATH_LEN+1];
+} SourceRefT;
+
+// Structured HRIR storage for stereo azimuth pairs, elevations, and fields.
+typedef struct HrirAzT {
+ double mAzimuth;
+ uint mIndex;
+ double mDelays[2];
+ double *mIrs[2];
+} HrirAzT;
+
+typedef struct HrirEvT {
+ double mElevation;
+ uint mIrCount;
+ uint mAzCount;
+ HrirAzT *mAzs;
+} HrirEvT;
+
+typedef struct HrirFdT {
+ double mDistance;
+ uint mIrCount;
+ uint mEvCount;
+ uint mEvStart;
+ HrirEvT *mEvs;
+} HrirFdT;
// The HRIR metrics and data set used when loading, processing, and storing
// the resulting HRTF.
-struct HrirDataT {
- uint mIrRate,
- mIrCount,
- mIrSize,
- mIrPoints,
- mFftSize,
- mEvCount,
- mEvStart,
- mAzCount [MAX_EV_COUNT],
- mEvOffset [MAX_EV_COUNT];
- double mRadius,
- mDistance,
- * mHrirs,
- * mHrtds,
- mMaxHrtd;
-};
+typedef struct HrirDataT {
+ uint mIrRate;
+ SampleTypeT mSampleType;
+ ChannelTypeT mChannelType;
+ uint mIrPoints;
+ uint mFftSize;
+ uint mIrSize;
+ double mRadius;
+ uint mIrCount;
+ uint mFdCount;
+ HrirFdT *mFds;
+} HrirDataT;
// The resampler metrics and FIR filter.
-struct ResamplerT {
- uint mP,
- mQ,
- mM,
- mL;
- double * mF;
-};
-
-/* Token reader routines for parsing text files. Whitespace is not
- * significant. It can process tokens as identifiers, numbers (integer and
- * floating-point), strings, and operators. Strings must be encapsulated by
- * double-quotes and cannot span multiple lines.
+typedef struct ResamplerT {
+ uint mP, mQ, mM, mL;
+ double *mF;
+} ResamplerT;
+
+
+/****************************************
+ *** Complex number type and routines ***
+ ****************************************/
+
+typedef struct {
+ double Real, Imag;
+} Complex;
+
+static Complex MakeComplex(double r, double i)
+{
+ Complex c = { r, i };
+ return c;
+}
+
+static Complex c_add(Complex a, Complex b)
+{
+ Complex r;
+ r.Real = a.Real + b.Real;
+ r.Imag = a.Imag + b.Imag;
+ return r;
+}
+
+static Complex c_sub(Complex a, Complex b)
+{
+ Complex r;
+ r.Real = a.Real - b.Real;
+ r.Imag = a.Imag - b.Imag;
+ return r;
+}
+
+static Complex c_mul(Complex a, Complex b)
+{
+ Complex r;
+ r.Real = a.Real*b.Real - a.Imag*b.Imag;
+ r.Imag = a.Imag*b.Real + a.Real*b.Imag;
+ return r;
+}
+
+static Complex c_muls(Complex a, double s)
+{
+ Complex r;
+ r.Real = a.Real * s;
+ r.Imag = a.Imag * s;
+ return r;
+}
+
+static double c_abs(Complex a)
+{
+ return sqrt(a.Real*a.Real + a.Imag*a.Imag);
+}
+
+static Complex c_exp(Complex a)
+{
+ Complex r;
+ double e = exp(a.Real);
+ r.Real = e * cos(a.Imag);
+ r.Imag = e * sin(a.Imag);
+ return r;
+}
+
+/*****************************
+ *** Token reader routines ***
+ *****************************/
+
+/* Whitespace is not significant. It can process tokens as identifiers, numbers
+ * (integer and floating-point), strings, and operators. Strings must be
+ * encapsulated by double-quotes and cannot span multiple lines.
*/
// Setup the reader on the given file. The filename can be NULL if no error
// output is desired.
-static void TrSetup (FILE * fp, const char * filename, TokenReaderT * tr) {
- const char * name = NULL;
- char ch;
-
- tr -> mFile = fp;
- name = filename;
- // If a filename was given, store a pointer to the base name.
- if (filename != NULL) {
- while ((ch = (* filename)) != '\0') {
- if ((ch == '/') || (ch == '\\'))
- name = filename + 1;
- filename ++;
- }
- }
- tr -> mName = name;
- tr -> mLine = 1;
- tr -> mColumn = 1;
- tr -> mIn = 0;
- tr -> mOut = 0;
+static void TrSetup(FILE *fp, const char *filename, TokenReaderT *tr)
+{
+ const char *name = NULL;
+
+ if(filename)
+ {
+ const char *slash = strrchr(filename, '/');
+ if(slash)
+ {
+ const char *bslash = strrchr(slash+1, '\\');
+ if(bslash) name = bslash+1;
+ else name = slash+1;
+ }
+ else
+ {
+ const char *bslash = strrchr(filename, '\\');
+ if(bslash) name = bslash+1;
+ else name = filename;
+ }
+ }
+
+ tr->mFile = fp;
+ tr->mName = name;
+ tr->mLine = 1;
+ tr->mColumn = 1;
+ tr->mIn = 0;
+ tr->mOut = 0;
}
// Prime the reader's ring buffer, and return a result indicating that there
// is text to process.
-static int TrLoad (TokenReaderT * tr) {
- size_t toLoad, in, count;
-
- toLoad = TR_RING_SIZE - (tr -> mIn - tr -> mOut);
- if ((toLoad >= TR_LOAD_SIZE) && (! feof (tr -> mFile))) {
- // Load TR_LOAD_SIZE (or less if at the end of the file) per read.
- toLoad = TR_LOAD_SIZE;
- in = tr -> mIn & TR_RING_MASK;
- count = TR_RING_SIZE - in;
- if (count < toLoad) {
- tr -> mIn += fread (& tr -> mRing [in], 1, count, tr -> mFile);
- tr -> mIn += fread (& tr -> mRing [0], 1, toLoad - count, tr -> mFile);
- } else {
- tr -> mIn += fread (& tr -> mRing [in], 1, toLoad, tr -> mFile);
- }
- if (tr -> mOut >= TR_RING_SIZE) {
- tr -> mOut -= TR_RING_SIZE;
- tr -> mIn -= TR_RING_SIZE;
- }
- }
- if (tr -> mIn > tr -> mOut)
- return (1);
- return (0);
+static int TrLoad(TokenReaderT *tr)
+{
+ size_t toLoad, in, count;
+
+ toLoad = TR_RING_SIZE - (tr->mIn - tr->mOut);
+ if(toLoad >= TR_LOAD_SIZE && !feof(tr->mFile))
+ {
+ // Load TR_LOAD_SIZE (or less if at the end of the file) per read.
+ toLoad = TR_LOAD_SIZE;
+ in = tr->mIn&TR_RING_MASK;
+ count = TR_RING_SIZE - in;
+ if(count < toLoad)
+ {
+ tr->mIn += fread(&tr->mRing[in], 1, count, tr->mFile);
+ tr->mIn += fread(&tr->mRing[0], 1, toLoad-count, tr->mFile);
+ }
+ else
+ tr->mIn += fread(&tr->mRing[in], 1, toLoad, tr->mFile);
+
+ if(tr->mOut >= TR_RING_SIZE)
+ {
+ tr->mOut -= TR_RING_SIZE;
+ tr->mIn -= TR_RING_SIZE;
+ }
+ }
+ if(tr->mIn > tr->mOut)
+ return 1;
+ return 0;
}
// Error display routine. Only displays when the base name is not NULL.
-static void TrErrorVA (const TokenReaderT * tr, uint line, uint column, const char * format, va_list argPtr) {
- if (tr -> mName != NULL) {
- fprintf (stderr, "Error (%s:%u:%u): ", tr -> mName, line, column);
- vfprintf (stderr, format, argPtr);
- }
+static void TrErrorVA(const TokenReaderT *tr, uint line, uint column, const char *format, va_list argPtr)
+{
+ if(!tr->mName)
+ return;
+ fprintf(stderr, "Error (%s:%u:%u): ", tr->mName, line, column);
+ vfprintf(stderr, format, argPtr);
}
// Used to display an error at a saved line/column.
-static void TrErrorAt (const TokenReaderT * tr, uint line, uint column, const char * format, ...) {
- va_list argPtr;
+static void TrErrorAt(const TokenReaderT *tr, uint line, uint column, const char *format, ...)
+{
+ va_list argPtr;
- va_start (argPtr, format);
- TrErrorVA (tr, line, column, format, argPtr);
- va_end (argPtr);
+ va_start(argPtr, format);
+ TrErrorVA(tr, line, column, format, argPtr);
+ va_end(argPtr);
}
// Used to display an error at the current line/column.
-static void TrError (const TokenReaderT * tr, const char * format, ...) {
- va_list argPtr;
+static void TrError(const TokenReaderT *tr, const char *format, ...)
+{
+ va_list argPtr;
- va_start (argPtr, format);
- TrErrorVA (tr, tr -> mLine, tr -> mColumn, format, argPtr);
- va_end (argPtr);
+ va_start(argPtr, format);
+ TrErrorVA(tr, tr->mLine, tr->mColumn, format, argPtr);
+ va_end(argPtr);
}
// Skips to the next line.
-static void TrSkipLine (TokenReaderT * tr) {
- char ch;
+static void TrSkipLine(TokenReaderT *tr)
+{
+ char ch;
- while (TrLoad (tr)) {
- ch = tr -> mRing [tr -> mOut & TR_RING_MASK];
- tr -> mOut ++;
- if (ch == '\n') {
- tr -> mLine ++;
- tr -> mColumn = 1;
- break;
+ while(TrLoad(tr))
+ {
+ ch = tr->mRing[tr->mOut&TR_RING_MASK];
+ tr->mOut++;
+ if(ch == '\n')
+ {
+ tr->mLine++;
+ tr->mColumn = 1;
+ break;
+ }
+ tr->mColumn ++;
}
- tr -> mColumn ++;
- }
}
// Skips to the next token.
-static int TrSkipWhitespace (TokenReaderT * tr) {
- char ch;
-
- while (TrLoad (tr)) {
- ch = tr -> mRing [tr -> mOut & TR_RING_MASK];
- if (isspace (ch)) {
- tr -> mOut ++;
- if (ch == '\n') {
- tr -> mLine ++;
- tr -> mColumn = 1;
- } else {
- tr -> mColumn ++;
- }
- } else if (ch == '#') {
- TrSkipLine (tr);
- } else {
- return (1);
- }
- }
- return (0);
+static int TrSkipWhitespace(TokenReaderT *tr)
+{
+ char ch;
+
+ while(TrLoad(tr))
+ {
+ ch = tr->mRing[tr->mOut&TR_RING_MASK];
+ if(isspace(ch))
+ {
+ tr->mOut++;
+ if(ch == '\n')
+ {
+ tr->mLine++;
+ tr->mColumn = 1;
+ }
+ else
+ tr->mColumn++;
+ }
+ else if(ch == '#')
+ TrSkipLine(tr);
+ else
+ return 1;
+ }
+ return 0;
}
// Get the line and/or column of the next token (or the end of input).
-static void TrIndication (TokenReaderT * tr, uint * line, uint * column) {
- TrSkipWhitespace (tr);
- if (line != NULL)
- (* line) = tr -> mLine;
- if (column != NULL)
- (* column) = tr -> mColumn;
+static void TrIndication(TokenReaderT *tr, uint *line, uint *column)
+{
+ TrSkipWhitespace(tr);
+ if(line) *line = tr->mLine;
+ if(column) *column = tr->mColumn;
+}
+
+// Checks to see if a token is (likely to be) an identifier. It does not
+// display any errors and will not proceed to the next token.
+static int TrIsIdent(TokenReaderT *tr)
+{
+ char ch;
+
+ if(!TrSkipWhitespace(tr))
+ return 0;
+ ch = tr->mRing[tr->mOut&TR_RING_MASK];
+ return ch == '_' || isalpha(ch);
}
+
// Checks to see if a token is the given operator. It does not display any
// errors and will not proceed to the next token.
-static int TrIsOperator (TokenReaderT * tr, const char * op) {
- size_t out, len;
- char ch;
-
- if (! TrSkipWhitespace (tr))
- return (0);
- out = tr -> mOut;
- len = 0;
- while ((op [len] != '\0') && (out < tr -> mIn)) {
- ch = tr -> mRing [out & TR_RING_MASK];
- if (ch != op [len])
- break;
- len ++;
- out ++;
- }
- if (op [len] == '\0')
- return (1);
- return (0);
+static int TrIsOperator(TokenReaderT *tr, const char *op)
+{
+ size_t out, len;
+ char ch;
+
+ if(!TrSkipWhitespace(tr))
+ return 0;
+ out = tr->mOut;
+ len = 0;
+ while(op[len] != '\0' && out < tr->mIn)
+ {
+ ch = tr->mRing[out&TR_RING_MASK];
+ if(ch != op[len]) break;
+ len++;
+ out++;
+ }
+ if(op[len] == '\0')
+ return 1;
+ return 0;
}
/* The TrRead*() routines obtain the value of a matching token type. They
@@ -460,322 +595,377 @@ static int TrIsOperator (TokenReaderT * tr, const char * op) {
*/
// Reads and validates an identifier token.
-static int TrReadIdent (TokenReaderT * tr, const uint maxLen, char * ident) {
- uint col, len;
- char ch;
-
- col = tr -> mColumn;
- if (TrSkipWhitespace (tr)) {
- col = tr -> mColumn;
- ch = tr -> mRing [tr -> mOut & TR_RING_MASK];
- if ((ch == '_') || isalpha (ch)) {
- len = 0;
- do {
- if (len < maxLen)
- ident [len] = ch;
- len ++;
- tr -> mOut ++;
- if (! TrLoad (tr))
- break;
- ch = tr -> mRing [tr -> mOut & TR_RING_MASK];
- } while ((ch == '_') || isdigit (ch) || isalpha (ch));
- tr -> mColumn += len;
- if (len > maxLen) {
- TrErrorAt (tr, tr -> mLine, col, "Identifier is too long.\n");
- return (0);
- }
- ident [len] = '\0';
- return (1);
- }
- }
- TrErrorAt (tr, tr -> mLine, col, "Expected an identifier.\n");
- return (0);
+static int TrReadIdent(TokenReaderT *tr, const uint maxLen, char *ident)
+{
+ uint col, len;
+ char ch;
+
+ col = tr->mColumn;
+ if(TrSkipWhitespace(tr))
+ {
+ col = tr->mColumn;
+ ch = tr->mRing[tr->mOut&TR_RING_MASK];
+ if(ch == '_' || isalpha(ch))
+ {
+ len = 0;
+ do {
+ if(len < maxLen)
+ ident[len] = ch;
+ len++;
+ tr->mOut++;
+ if(!TrLoad(tr))
+ break;
+ ch = tr->mRing[tr->mOut&TR_RING_MASK];
+ } while(ch == '_' || isdigit(ch) || isalpha(ch));
+
+ tr->mColumn += len;
+ if(len < maxLen)
+ {
+ ident[len] = '\0';
+ return 1;
+ }
+ TrErrorAt(tr, tr->mLine, col, "Identifier is too long.\n");
+ return 0;
+ }
+ }
+ TrErrorAt(tr, tr->mLine, col, "Expected an identifier.\n");
+ return 0;
}
// Reads and validates (including bounds) an integer token.
-static int TrReadInt (TokenReaderT * tr, const int loBound, const int hiBound, int * value) {
- uint col, digis, len;
- char ch, temp [64 + 1];
-
- col = tr -> mColumn;
- if (TrSkipWhitespace (tr)) {
- col = tr -> mColumn;
- len = 0;
- ch = tr -> mRing [tr -> mOut & TR_RING_MASK];
- if ((ch == '+') || (ch == '-')) {
- temp [len] = ch;
- len ++;
- tr -> mOut ++;
- }
- digis = 0;
- while (TrLoad (tr)) {
- ch = tr -> mRing [tr -> mOut & TR_RING_MASK];
- if (! isdigit (ch))
- break;
- if (len < 64)
- temp [len] = ch;
- len ++;
- digis ++;
- tr -> mOut ++;
- }
- tr -> mColumn += len;
- if ((digis > 0) && (ch != '.') && (! isalpha (ch))) {
- if (len > 64) {
- TrErrorAt (tr, tr -> mLine, col, "Integer is too long.");
- return (0);
- }
- temp [len] = '\0';
- (* value) = strtol (temp, NULL, 10);
- if (((* value) < loBound) || ((* value) > hiBound)) {
- TrErrorAt (tr, tr -> mLine, col, "Expected a value from %d to %d.\n", loBound, hiBound);
- return (0);
- }
- return (1);
- }
- }
- TrErrorAt (tr, tr -> mLine, col, "Expected an integer.\n");
- return (0);
+static int TrReadInt(TokenReaderT *tr, const int loBound, const int hiBound, int *value)
+{
+ uint col, digis, len;
+ char ch, temp[64+1];
+
+ col = tr->mColumn;
+ if(TrSkipWhitespace(tr))
+ {
+ col = tr->mColumn;
+ len = 0;
+ ch = tr->mRing[tr->mOut&TR_RING_MASK];
+ if(ch == '+' || ch == '-')
+ {
+ temp[len] = ch;
+ len++;
+ tr->mOut++;
+ }
+ digis = 0;
+ while(TrLoad(tr))
+ {
+ ch = tr->mRing[tr->mOut&TR_RING_MASK];
+ if(!isdigit(ch)) break;
+ if(len < 64)
+ temp[len] = ch;
+ len++;
+ digis++;
+ tr->mOut++;
+ }
+ tr->mColumn += len;
+ if(digis > 0 && ch != '.' && !isalpha(ch))
+ {
+ if(len > 64)
+ {
+ TrErrorAt(tr, tr->mLine, col, "Integer is too long.");
+ return 0;
+ }
+ temp[len] = '\0';
+ *value = strtol(temp, NULL, 10);
+ if(*value < loBound || *value > hiBound)
+ {
+ TrErrorAt(tr, tr->mLine, col, "Expected a value from %d to %d.\n", loBound, hiBound);
+ return 0;
+ }
+ return 1;
+ }
+ }
+ TrErrorAt(tr, tr->mLine, col, "Expected an integer.\n");
+ return 0;
}
// Reads and validates (including bounds) a float token.
-static int TrReadFloat (TokenReaderT * tr, const double loBound, const double hiBound, double * value) {
- uint col, digis, len;
- char ch, temp [64 + 1];
-
- col = tr -> mColumn;
- if (TrSkipWhitespace (tr)) {
- col = tr -> mColumn;
- len = 0;
- ch = tr -> mRing [tr -> mOut & TR_RING_MASK];
- if ((ch == '+') || (ch == '-')) {
- temp [len] = ch;
- len ++;
- tr -> mOut ++;
- }
- digis = 0;
- while (TrLoad (tr)) {
- ch = tr -> mRing [tr -> mOut & TR_RING_MASK];
- if (! isdigit (ch))
- break;
- if (len < 64)
- temp [len] = ch;
- len ++;
- digis ++;
- tr -> mOut ++;
- }
- if (ch == '.') {
- if (len < 64)
- temp [len] = ch;
- len ++;
- tr -> mOut ++;
- }
- while (TrLoad (tr)) {
- ch = tr -> mRing [tr -> mOut & TR_RING_MASK];
- if (! isdigit (ch))
- break;
- if (len < 64)
- temp [len] = ch;
- len ++;
- digis ++;
- tr -> mOut ++;
- }
- if (digis > 0) {
- if ((ch == 'E') || (ch == 'e')) {
- if (len < 64)
- temp [len] = ch;
- len ++;
- digis = 0;
- tr -> mOut ++;
- if ((ch == '+') || (ch == '-')) {
- if (len < 64)
- temp [len] = ch;
- len ++;
- tr -> mOut ++;
- }
- while (TrLoad (tr)) {
- ch = tr -> mRing [tr -> mOut & TR_RING_MASK];
- if (! isdigit (ch))
- break;
- if (len < 64)
- temp [len] = ch;
- len ++;
- digis ++;
- tr -> mOut ++;
- }
- }
- tr -> mColumn += len;
- if ((digis > 0) && (ch != '.') && (! isalpha (ch))) {
- if (len > 64) {
- TrErrorAt (tr, tr -> mLine, col, "Float is too long.");
- return (0);
- }
- temp [len] = '\0';
- (* value) = strtod (temp, NULL);
- if (((* value) < loBound) || ((* value) > hiBound)) {
- TrErrorAt (tr, tr -> mLine, col, "Expected a value from %f to %f.\n", loBound, hiBound);
- return (0);
- }
- return (1);
- }
- } else {
- tr -> mColumn += len;
- }
- }
- TrErrorAt (tr, tr -> mLine, col, "Expected a float.\n");
- return (0);
+static int TrReadFloat(TokenReaderT *tr, const double loBound, const double hiBound, double *value)
+{
+ uint col, digis, len;
+ char ch, temp[64+1];
+
+ col = tr->mColumn;
+ if(TrSkipWhitespace(tr))
+ {
+ col = tr->mColumn;
+ len = 0;
+ ch = tr->mRing[tr->mOut&TR_RING_MASK];
+ if(ch == '+' || ch == '-')
+ {
+ temp[len] = ch;
+ len++;
+ tr->mOut++;
+ }
+
+ digis = 0;
+ while(TrLoad(tr))
+ {
+ ch = tr->mRing[tr->mOut&TR_RING_MASK];
+ if(!isdigit(ch)) break;
+ if(len < 64)
+ temp[len] = ch;
+ len++;
+ digis++;
+ tr->mOut++;
+ }
+ if(ch == '.')
+ {
+ if(len < 64)
+ temp[len] = ch;
+ len++;
+ tr->mOut++;
+ }
+ while(TrLoad(tr))
+ {
+ ch = tr->mRing[tr->mOut&TR_RING_MASK];
+ if(!isdigit(ch)) break;
+ if(len < 64)
+ temp[len] = ch;
+ len++;
+ digis++;
+ tr->mOut++;
+ }
+ if(digis > 0)
+ {
+ if(ch == 'E' || ch == 'e')
+ {
+ if(len < 64)
+ temp[len] = ch;
+ len++;
+ digis = 0;
+ tr->mOut++;
+ if(ch == '+' || ch == '-')
+ {
+ if(len < 64)
+ temp[len] = ch;
+ len++;
+ tr->mOut++;
+ }
+ while(TrLoad(tr))
+ {
+ ch = tr->mRing[tr->mOut&TR_RING_MASK];
+ if(!isdigit(ch)) break;
+ if(len < 64)
+ temp[len] = ch;
+ len++;
+ digis++;
+ tr->mOut++;
+ }
+ }
+ tr->mColumn += len;
+ if(digis > 0 && ch != '.' && !isalpha(ch))
+ {
+ if(len > 64)
+ {
+ TrErrorAt(tr, tr->mLine, col, "Float is too long.");
+ return 0;
+ }
+ temp[len] = '\0';
+ *value = strtod(temp, NULL);
+ if(*value < loBound || *value > hiBound)
+ {
+ TrErrorAt(tr, tr->mLine, col, "Expected a value from %f to %f.\n", loBound, hiBound);
+ return 0;
+ }
+ return 1;
+ }
+ }
+ else
+ tr->mColumn += len;
+ }
+ TrErrorAt(tr, tr->mLine, col, "Expected a float.\n");
+ return 0;
}
// Reads and validates a string token.
-static int TrReadString (TokenReaderT * tr, const uint maxLen, char * text) {
- uint col, len;
- char ch;
-
- col = tr -> mColumn;
- if (TrSkipWhitespace (tr)) {
- col = tr -> mColumn;
- ch = tr -> mRing [tr -> mOut & TR_RING_MASK];
- if (ch == '\"') {
- tr -> mOut ++;
- len = 0;
- while (TrLoad (tr)) {
- ch = tr -> mRing [tr -> mOut & TR_RING_MASK];
- tr -> mOut ++;
- if (ch == '\"')
- break;
- if (ch == '\n') {
- TrErrorAt (tr, tr -> mLine, col, "Unterminated string at end of line.\n");
- return (0);
- }
- if (len < maxLen)
- text [len] = ch;
- len ++;
- }
- if (ch != '\"') {
- tr -> mColumn += 1 + len;
- TrErrorAt (tr, tr -> mLine, col, "Unterminated string at end of input.\n");
- return (0);
- }
- tr -> mColumn += 2 + len;
- if (len > maxLen) {
- TrErrorAt (tr, tr -> mLine, col, "String is too long.\n");
- return (0);
- }
- text [len] = '\0';
- return (1);
- }
- }
- TrErrorAt (tr, tr -> mLine, col, "Expected a string.\n");
- return (0);
+static int TrReadString(TokenReaderT *tr, const uint maxLen, char *text)
+{
+ uint col, len;
+ char ch;
+
+ col = tr->mColumn;
+ if(TrSkipWhitespace(tr))
+ {
+ col = tr->mColumn;
+ ch = tr->mRing[tr->mOut&TR_RING_MASK];
+ if(ch == '\"')
+ {
+ tr->mOut++;
+ len = 0;
+ while(TrLoad(tr))
+ {
+ ch = tr->mRing[tr->mOut&TR_RING_MASK];
+ tr->mOut++;
+ if(ch == '\"')
+ break;
+ if(ch == '\n')
+ {
+ TrErrorAt(tr, tr->mLine, col, "Unterminated string at end of line.\n");
+ return 0;
+ }
+ if(len < maxLen)
+ text[len] = ch;
+ len++;
+ }
+ if(ch != '\"')
+ {
+ tr->mColumn += 1 + len;
+ TrErrorAt(tr, tr->mLine, col, "Unterminated string at end of input.\n");
+ return 0;
+ }
+ tr->mColumn += 2 + len;
+ if(len > maxLen)
+ {
+ TrErrorAt(tr, tr->mLine, col, "String is too long.\n");
+ return 0;
+ }
+ text[len] = '\0';
+ return 1;
+ }
+ }
+ TrErrorAt(tr, tr->mLine, col, "Expected a string.\n");
+ return 0;
}
// Reads and validates the given operator.
-static int TrReadOperator (TokenReaderT * tr, const char * op) {
- uint col, len;
- char ch;
-
- col = tr -> mColumn;
- if (TrSkipWhitespace (tr)) {
- col = tr -> mColumn;
- len = 0;
- while ((op [len] != '\0') && TrLoad (tr)) {
- ch = tr -> mRing [tr -> mOut & TR_RING_MASK];
- if (ch != op [len])
- break;
- len ++;
- tr -> mOut ++;
- }
- tr -> mColumn += len;
- if (op [len] == '\0')
- return (1);
- }
- TrErrorAt (tr, tr -> mLine, col, "Expected '%s' operator.\n", op);
- return (0);
+static int TrReadOperator(TokenReaderT *tr, const char *op)
+{
+ uint col, len;
+ char ch;
+
+ col = tr->mColumn;
+ if(TrSkipWhitespace(tr))
+ {
+ col = tr->mColumn;
+ len = 0;
+ while(op[len] != '\0' && TrLoad(tr))
+ {
+ ch = tr->mRing[tr->mOut&TR_RING_MASK];
+ if(ch != op[len]) break;
+ len++;
+ tr->mOut++;
+ }
+ tr->mColumn += len;
+ if(op[len] == '\0')
+ return 1;
+ }
+ TrErrorAt(tr, tr->mLine, col, "Expected '%s' operator.\n", op);
+ return 0;
}
/* Performs a string substitution. Any case-insensitive occurrences of the
* pattern string are replaced with the replacement string. The result is
* truncated if necessary.
*/
-static int StrSubst (const char * in, const char * pat, const char * rep, const size_t maxLen, char * out) {
- size_t inLen, patLen, repLen;
- size_t si, di;
- int truncated;
-
- inLen = strlen (in);
- patLen = strlen (pat);
- repLen = strlen (rep);
- si = 0;
- di = 0;
- truncated = 0;
- while ((si < inLen) && (di < maxLen)) {
- if (patLen <= (inLen - si)) {
- if (strncasecmp (& in [si], pat, patLen) == 0) {
- if (repLen > (maxLen - di)) {
- repLen = maxLen - di;
- truncated = 1;
- }
- strncpy (& out [di], rep, repLen);
- si += patLen;
- di += repLen;
- }
- }
- out [di] = in [si];
- si ++;
- di ++;
- }
- if (si < inLen)
- truncated = 1;
- out [di] = '\0';
- return (! truncated);
+static int StrSubst(const char *in, const char *pat, const char *rep, const size_t maxLen, char *out)
+{
+ size_t inLen, patLen, repLen;
+ size_t si, di;
+ int truncated;
+
+ inLen = strlen(in);
+ patLen = strlen(pat);
+ repLen = strlen(rep);
+ si = 0;
+ di = 0;
+ truncated = 0;
+ while(si < inLen && di < maxLen)
+ {
+ if(patLen <= inLen-si)
+ {
+ if(strncasecmp(&in[si], pat, patLen) == 0)
+ {
+ if(repLen > maxLen-di)
+ {
+ repLen = maxLen - di;
+ truncated = 1;
+ }
+ strncpy(&out[di], rep, repLen);
+ si += patLen;
+ di += repLen;
+ }
+ }
+ out[di] = in[si];
+ si++;
+ di++;
+ }
+ if(si < inLen)
+ truncated = 1;
+ out[di] = '\0';
+ return !truncated;
}
+
+/*********************
+ *** Math routines ***
+ *********************/
+
// Provide missing math routines for MSVC versions < 1800 (Visual Studio 2013).
#if defined(_MSC_VER) && _MSC_VER < 1800
-static double round (double val) {
- if (val < 0.0)
- return (ceil (val - 0.5));
- return (floor (val + 0.5));
+static double round(double val)
+{
+ if(val < 0.0)
+ return ceil(val-0.5);
+ return floor(val+0.5);
}
-static double fmin (double a, double b) {
- return ((a < b) ? a : b);
+static double fmin(double a, double b)
+{
+ return (a<b) ? a : b;
}
-static double fmax (double a, double b) {
- return ((a > b) ? a : b);
+static double fmax(double a, double b)
+{
+ return (a>b) ? a : b;
}
#endif
// Simple clamp routine.
-static double Clamp (const double val, const double lower, const double upper) {
- return (fmin (fmax (val, lower), upper));
+static double Clamp(const double val, const double lower, const double upper)
+{
+ return fmin(fmax(val, lower), upper);
}
// Performs linear interpolation.
-static double Lerp (const double a, const double b, const double f) {
- return (a + (f * (b - a)));
+static double Lerp(const double a, const double b, const double f)
+{
+ return a + f * (b - a);
+}
+
+static inline uint dither_rng(uint *seed)
+{
+ *seed = *seed * 96314165 + 907633515;
+ return *seed;
}
-// Performs a high-passed triangular probability density function dither from
-// a double to an integer. It assumes the input sample is already scaled.
-static int HpTpdfDither (const double in, int * hpHist) {
- const double PRNG_SCALE = 1.0 / (RAND_MAX + 1.0);
- int prn;
- double out;
+// Performs a triangular probability density function dither. The input samples
+// should be normalized (-1 to +1).
+static void TpdfDither(double *restrict out, const double *restrict in, const double scale,
+ const int count, const int step, uint *seed)
+{
+ static const double PRNG_SCALE = 1.0 / UINT_MAX;
+ uint prn0, prn1;
+ int i;
- prn = rand ();
- out = round (in + (PRNG_SCALE * (prn - (* hpHist))));
- (* hpHist) = prn;
- return ((int) out);
+ for(i = 0;i < count;i++)
+ {
+ prn0 = dither_rng(seed);
+ prn1 = dither_rng(seed);
+ out[i*step] = round(in[i]*scale + (prn0*PRNG_SCALE - prn1*PRNG_SCALE));
+ }
}
// Allocates an array of doubles.
-static double *CreateArray(size_t n)
+static double *CreateDoubles(size_t n)
{
double *a;
- if(n == 0) n = 1;
- a = calloc(n, sizeof(double));
+ a = calloc(n?n:1, sizeof(*a));
if(a == NULL)
{
fprintf(stderr, "Error: Out of memory.\n");
@@ -784,168 +974,117 @@ static double *CreateArray(size_t n)
return a;
}
-// Frees an array of doubles.
-static void DestroyArray(double *a)
-{ free(a); }
-
-// Complex number routines. All outputs must be non-NULL.
-
-// Magnitude/absolute value.
-static double ComplexAbs (const double r, const double i) {
- return (sqrt ((r * r) + (i * i)));
-}
-
-// Multiply.
-static void ComplexMul (const double aR, const double aI, const double bR, const double bI, double * outR, double * outI) {
- (* outR) = (aR * bR) - (aI * bI);
- (* outI) = (aI * bR) + (aR * bI);
-}
-
-// Base-e exponent.
-static void ComplexExp (const double inR, const double inI, double * outR, double * outI) {
- double e;
+// Allocates an array of complex numbers.
+static Complex *CreateComplexes(size_t n)
+{
+ Complex *a;
- e = exp (inR);
- (* outR) = e * cos (inI);
- (* outI) = e * sin (inI);
+ a = calloc(n?n:1, sizeof(*a));
+ if(a == NULL)
+ {
+ fprintf(stderr, "Error: Out of memory.\n");
+ exit(-1);
+ }
+ return a;
}
-/* Fast Fourier transform routines. The number of points must be a power of
- * two. In-place operation is possible only if both the real and imaginary
- * parts are in-place together.
+/* Fast Fourier transform routines. The number of points must be a power of
+ * two.
*/
// Performs bit-reversal ordering.
-static void FftArrange (const uint n, const double * inR, const double * inI, double * outR, double * outI) {
- uint rk, k, m;
- double tempR, tempI;
-
- if ((inR == outR) && (inI == outI)) {
- // Handle in-place arrangement.
- rk = 0;
- for (k = 0; k < n; k ++) {
- if (rk > k) {
- tempR = inR [rk];
- tempI = inI [rk];
- outR [rk] = inR [k];
- outI [rk] = inI [k];
- outR [k] = tempR;
- outI [k] = tempI;
- }
- m = n;
- while (rk & (m >>= 1))
- rk &= ~m;
- rk |= m;
- }
- } else {
- // Handle copy arrangement.
- rk = 0;
- for (k = 0; k < n; k ++) {
- outR [rk] = inR [k];
- outI [rk] = inI [k];
- m = n;
- while (rk & (m >>= 1))
- rk &= ~m;
- rk |= m;
- }
- }
+static void FftArrange(const uint n, Complex *inout)
+{
+ uint rk, k, m;
+
+ // Handle in-place arrangement.
+ rk = 0;
+ for(k = 0;k < n;k++)
+ {
+ if(rk > k)
+ {
+ Complex temp = inout[rk];
+ inout[rk] = inout[k];
+ inout[k] = temp;
+ }
+
+ m = n;
+ while(rk&(m >>= 1))
+ rk &= ~m;
+ rk |= m;
+ }
}
// Performs the summation.
-static void FftSummation (const uint n, const double s, double * re, double * im) {
- double pi;
- uint m, m2;
- double vR, vI, wR, wI;
- uint i, k, mk;
- double tR, tI;
-
- pi = s * M_PI;
- for (m = 1, m2 = 2; m < n; m <<= 1, m2 <<= 1) {
- // v = Complex (-2.0 * sin (0.5 * pi / m) * sin (0.5 * pi / m), -sin (pi / m))
- vR = sin (0.5 * pi / m);
- vR = -2.0 * vR * vR;
- vI = -sin (pi / m);
- // w = Complex (1.0, 0.0)
- wR = 1.0;
- wI = 0.0;
- for (i = 0; i < m; i ++) {
- for (k = i; k < n; k += m2) {
- mk = k + m;
- // t = ComplexMul (w, out [km2])
- tR = (wR * re [mk]) - (wI * im [mk]);
- tI = (wR * im [mk]) + (wI * re [mk]);
- // out [mk] = ComplexSub (out [k], t)
- re [mk] = re [k] - tR;
- im [mk] = im [k] - tI;
- // out [k] = ComplexAdd (out [k], t)
- re [k] += tR;
- im [k] += tI;
- }
- // t = ComplexMul (v, w)
- tR = (vR * wR) - (vI * wI);
- tI = (vR * wI) + (vI * wR);
- // w = ComplexAdd (w, t)
- wR += tR;
- wI += tI;
- }
- }
+static void FftSummation(const int n, const double s, Complex *cplx)
+{
+ double pi;
+ int m, m2;
+ int i, k, mk;
+
+ pi = s * M_PI;
+ for(m = 1, m2 = 2;m < n; m <<= 1, m2 <<= 1)
+ {
+ // v = Complex (-2.0 * sin (0.5 * pi / m) * sin (0.5 * pi / m), -sin (pi / m))
+ double sm = sin(0.5 * pi / m);
+ Complex v = MakeComplex(-2.0*sm*sm, -sin(pi / m));
+ Complex w = MakeComplex(1.0, 0.0);
+ for(i = 0;i < m;i++)
+ {
+ for(k = i;k < n;k += m2)
+ {
+ Complex t;
+ mk = k + m;
+ t = c_mul(w, cplx[mk]);
+ cplx[mk] = c_sub(cplx[k], t);
+ cplx[k] = c_add(cplx[k], t);
+ }
+ w = c_add(w, c_mul(v, w));
+ }
+ }
}
// Performs a forward FFT.
-static void FftForward (const uint n, const double * inR, const double * inI, double * outR, double * outI) {
- FftArrange (n, inR, inI, outR, outI);
- FftSummation (n, 1.0, outR, outI);
+static void FftForward(const uint n, Complex *inout)
+{
+ FftArrange(n, inout);
+ FftSummation(n, 1.0, inout);
}
// Performs an inverse FFT.
-static void FftInverse (const uint n, const double * inR, const double * inI, double * outR, double * outI) {
- double f;
- uint i;
-
- FftArrange (n, inR, inI, outR, outI);
- FftSummation (n, -1.0, outR, outI);
- f = 1.0 / n;
- for (i = 0; i < n; i ++) {
- outR [i] *= f;
- outI [i] *= f;
- }
-}
-
-/* Calculate the complex helical sequence (or discrete-time analytical
- * signal) of the given input using the Hilbert transform. Given the
- * negative natural logarithm of a signal's magnitude response, the imaginary
- * components can be used as the angles for minimum-phase reconstruction.
+static void FftInverse(const uint n, Complex *inout)
+{
+ double f;
+ uint i;
+
+ FftArrange(n, inout);
+ FftSummation(n, -1.0, inout);
+ f = 1.0 / n;
+ for(i = 0;i < n;i++)
+ inout[i] = c_muls(inout[i], f);
+}
+
+/* Calculate the complex helical sequence (or discrete-time analytical signal)
+ * of the given input using the Hilbert transform. Given the natural logarithm
+ * of a signal's magnitude response, the imaginary components can be used as
+ * the angles for minimum-phase reconstruction.
*/
-static void Hilbert (const uint n, const double * in, double * outR, double * outI) {
- uint i;
-
- if (in == outR) {
- // Handle in-place operation.
- for (i = 0; i < n; i ++)
- outI [i] = 0.0;
- } else {
- // Handle copy operation.
- for (i = 0; i < n; i ++) {
- outR [i] = in [i];
- outI [i] = 0.0;
- }
- }
- FftForward (n, outR, outI, outR, outI);
- /* Currently the Fourier routines operate only on point counts that are
- * powers of two. If that changes and n is odd, the following conditional
- * should be: i < (n + 1) / 2.
- */
- for (i = 1; i < (n / 2); i ++) {
- outR [i] *= 2.0;
- outI [i] *= 2.0;
- }
- // If n is odd, the following increment should be skipped.
- i ++;
- for (; i < n; i ++) {
- outR [i] = 0.0;
- outI [i] = 0.0;
- }
- FftInverse (n, outR, outI, outR, outI);
+static void Hilbert(const uint n, Complex *inout)
+{
+ uint i;
+
+ // Handle in-place operation.
+ for(i = 0;i < n;i++)
+ inout[i].Imag = 0.0;
+
+ FftInverse(n, inout);
+ for(i = 1;i < (n+1)/2;i++)
+ inout[i] = c_muls(inout[i], 2.0);
+ /* Increment i if n is even. */
+ i += (n&1)^1;
+ for(;i < n;i++)
+ inout[i] = MakeComplex(0.0, 0.0);
+ FftForward(n, inout);
}
/* Calculate the magnitude response of the given input. This is used in
@@ -953,41 +1092,41 @@ static void Hilbert (const uint n, const double * in, double * outR, double * ou
* minimum phase reconstruction. The mirrored half of the response is also
* discarded.
*/
-static void MagnitudeResponse (const uint n, const double * inR, const double * inI, double * out) {
- const uint m = 1 + (n / 2);
- uint i;
-
- for (i = 0; i < m; i ++)
- out [i] = fmax (ComplexAbs (inR [i], inI [i]), EPSILON);
+static void MagnitudeResponse(const uint n, const Complex *in, double *out)
+{
+ const uint m = 1 + (n / 2);
+ uint i;
+ for(i = 0;i < m;i++)
+ out[i] = fmax(c_abs(in[i]), EPSILON);
}
/* Apply a range limit (in dB) to the given magnitude response. This is used
* to adjust the effects of the diffuse-field average on the equalization
* process.
*/
-static void LimitMagnitudeResponse (const uint n, const double limit, const double * in, double * out) {
- const uint m = 1 + (n / 2);
- double halfLim;
- uint i, lower, upper;
- double ave;
-
- halfLim = limit / 2.0;
- // Convert the response to dB.
- for (i = 0; i < m; i ++)
- out [i] = 20.0 * log10 (in [i]);
- // Use six octaves to calculate the average magnitude of the signal.
- lower = ((uint) ceil (n / pow (2.0, 8.0))) - 1;
- upper = ((uint) floor (n / pow (2.0, 2.0))) - 1;
- ave = 0.0;
- for (i = lower; i <= upper; i ++)
- ave += out [i];
- ave /= upper - lower + 1;
- // Keep the response within range of the average magnitude.
- for (i = 0; i < m; i ++)
- out [i] = Clamp (out [i], ave - halfLim, ave + halfLim);
- // Convert the response back to linear magnitude.
- for (i = 0; i < m; i ++)
- out [i] = pow (10.0, out [i] / 20.0);
+static void LimitMagnitudeResponse(const uint n, const uint m, const double limit, const double *in, double *out)
+{
+ double halfLim;
+ uint i, lower, upper;
+ double ave;
+
+ halfLim = limit / 2.0;
+ // Convert the response to dB.
+ for(i = 0;i < m;i++)
+ out[i] = 20.0 * log10(in[i]);
+ // Use six octaves to calculate the average magnitude of the signal.
+ lower = ((uint)ceil(n / pow(2.0, 8.0))) - 1;
+ upper = ((uint)floor(n / pow(2.0, 2.0))) - 1;
+ ave = 0.0;
+ for(i = lower;i <= upper;i++)
+ ave += out[i];
+ ave /= upper - lower + 1;
+ // Keep the response within range of the average magnitude.
+ for(i = 0;i < m;i++)
+ out[i] = Clamp(out[i], ave - halfLim, ave + halfLim);
+ // Convert the response back to linear magnitude.
+ for(i = 0;i < m;i++)
+ out[i] = pow(10.0, out[i] / 20.0);
}
/* Reconstructs the minimum-phase component for the given magnitude response
@@ -995,41 +1134,49 @@ static void LimitMagnitudeResponse (const uint n, const double limit, const doub
* residuals (which were discarded). The mirrored half of the response is
* reconstructed.
*/
-static void MinimumPhase (const uint n, const double * in, double * outR, double * outI) {
- const uint m = 1 + (n / 2);
- double * mags = NULL;
- uint i;
- double aR, aI;
-
- mags = CreateArray (n);
- for (i = 0; i < m; i ++) {
- mags [i] = fmax (in [i], EPSILON);
- outR [i] = -log (mags [i]);
- }
- for (; i < n; i ++) {
- mags [i] = mags [n - i];
- outR [i] = outR [n - i];
- }
- Hilbert (n, outR, outR, outI);
- // Remove any DC offset the filter has.
- outR [0] = 0.0;
- outI [0] = 0.0;
- for (i = 1; i < n; i ++) {
- ComplexExp (0.0, outI [i], & aR, & aI);
- ComplexMul (mags [i], 0.0, aR, aI, & outR [i], & outI [i]);
- }
- DestroyArray (mags);
+static void MinimumPhase(const uint n, const double *in, Complex *out)
+{
+ const uint m = 1 + (n / 2);
+ double *mags;
+ uint i;
+
+ mags = CreateDoubles(n);
+ for(i = 0;i < m;i++)
+ {
+ mags[i] = fmax(EPSILON, in[i]);
+ out[i] = MakeComplex(log(mags[i]), 0.0);
+ }
+ for(;i < n;i++)
+ {
+ mags[i] = mags[n - i];
+ out[i] = out[n - i];
+ }
+ Hilbert(n, out);
+ // Remove any DC offset the filter has.
+ mags[0] = EPSILON;
+ for(i = 0;i < n;i++)
+ {
+ Complex a = c_exp(MakeComplex(0.0, out[i].Imag));
+ out[i] = c_mul(MakeComplex(mags[i], 0.0), a);
+ }
+ free(mags);
}
+
+/***************************
+ *** Resampler functions ***
+ ***************************/
+
/* This is the normalized cardinal sine (sinc) function.
*
* sinc(x) = { 1, x = 0
* { sin(pi x) / (pi x), otherwise.
*/
-static double Sinc (const double x) {
- if (fabs (x) < EPSILON)
- return (1.0);
- return (sin (M_PI * x) / (M_PI * x));
+static double Sinc(const double x)
+{
+ if(fabs(x) < EPSILON)
+ return 1.0;
+ return sin(M_PI * x) / (M_PI * x);
}
/* The zero-order modified Bessel function of the first kind, used for the
@@ -1038,25 +1185,27 @@ static double Sinc (const double x) {
* I_0(x) = sum_{k=0}^inf (1 / k!)^2 (x / 2)^(2 k)
* = sum_{k=0}^inf ((x / 2)^k / k!)^2
*/
-static double BesselI_0 (const double x) {
- double term, sum, x2, y, last_sum;
- int k;
-
- // Start at k=1 since k=0 is trivial.
- term = 1.0;
- sum = 1.0;
- x2 = x / 2.0;
- k = 1;
- // Let the integration converge until the term of the sum is no longer
- // significant.
- do {
- y = x2 / k;
- k ++;
- last_sum = sum;
- term *= y * y;
- sum += term;
- } while (sum != last_sum);
- return (sum);
+static double BesselI_0(const double x)
+{
+ double term, sum, x2, y, last_sum;
+ int k;
+
+ // Start at k=1 since k=0 is trivial.
+ term = 1.0;
+ sum = 1.0;
+ x2 = x/2.0;
+ k = 1;
+
+ // Let the integration converge until the term of the sum is no longer
+ // significant.
+ do {
+ y = x2 / k;
+ k++;
+ last_sum = sum;
+ term *= y * y;
+ sum += term;
+ } while(sum != last_sum);
+ return sum;
}
/* Calculate a Kaiser window from the given beta value and a normalized k
@@ -1073,28 +1222,23 @@ static double BesselI_0 (const double x) {
*
* k = 2 i / M - 1, where 0 <= i <= M.
*/
-static double Kaiser (const double b, const double k) {
- double k2;
-
- k2 = Clamp (k, -1.0, 1.0);
- if ((k < -1.0) || (k > 1.0))
- return (0.0);
- k2 *= k2;
- return (BesselI_0 (b * sqrt (1.0 - k2)) / BesselI_0 (b));
+static double Kaiser(const double b, const double k)
+{
+ if(!(k >= -1.0 && k <= 1.0))
+ return 0.0;
+ return BesselI_0(b * sqrt(1.0 - k*k)) / BesselI_0(b);
}
// Calculates the greatest common divisor of a and b.
-static uint Gcd (const uint a, const uint b) {
- uint x, y, z;
-
- x = a;
- y = b;
- while (y > 0) {
- z = y;
- y = x % y;
- x = z;
- }
- return (x);
+static uint Gcd(uint x, uint y)
+{
+ while(y > 0)
+ {
+ uint z = y;
+ y = x % y;
+ x = z;
+ }
+ return x;
}
/* Calculates the size (order) of the Kaiser window. Rejection is in dB and
@@ -1104,24 +1248,23 @@ static uint Gcd (const uint a, const uint b) {
* { ceil(5.79 / 2 pi f_t), r <= 21.
*
*/
-static uint CalcKaiserOrder (const double rejection, const double transition) {
- double w_t;
-
- w_t = 2.0 * M_PI * transition;
- if (rejection > 21.0)
- return ((uint) ceil ((rejection - 7.95) / (2.285 * w_t)));
- return ((uint) ceil (5.79 / w_t));
+static uint CalcKaiserOrder(const double rejection, const double transition)
+{
+ double w_t = 2.0 * M_PI * transition;
+ if(rejection > 21.0)
+ return (uint)ceil((rejection - 7.95) / (2.285 * w_t));
+ return (uint)ceil(5.79 / w_t);
}
// Calculates the beta value of the Kaiser window. Rejection is in dB.
-static double CalcKaiserBeta (const double rejection) {
- if (rejection > 50.0)
- return (0.1102 * (rejection - 8.7));
- else if (rejection >= 21.0)
- return ((0.5842 * pow (rejection - 21.0, 0.4)) +
- (0.07886 * (rejection - 21.0)));
- else
- return (0.0);
+static double CalcKaiserBeta(const double rejection)
+{
+ if(rejection > 50.0)
+ return 0.1102 * (rejection - 8.7);
+ if(rejection >= 21.0)
+ return (0.5842 * pow(rejection - 21.0, 0.4)) +
+ (0.07886 * (rejection - 21.0));
+ return 0.0;
}
/* Calculates a point on the Kaiser-windowed sinc filter for the given half-
@@ -1136,8 +1279,9 @@ static double CalcKaiserBeta (const double rejection) {
* p -- gain compensation factor when sampling
* f_t -- normalized center frequency (or cutoff; 0.5 is nyquist)
*/
-static double SincFilter (const int l, const double b, const double gain, const double cutoff, const int i) {
- return (Kaiser (b, ((double) (i - l)) / l) * 2.0 * gain * cutoff * Sinc (2.0 * cutoff * (i - l)));
+static double SincFilter(const int l, const double b, const double gain, const double cutoff, const int i)
+{
+ return Kaiser(b, (double)(i - l) / l) * 2.0 * gain * cutoff * Sinc(2.0 * cutoff * (i - l));
}
/* This is a polyphase sinc-filtered resampler.
@@ -1168,176 +1312,157 @@ static double SincFilter (const int l, const double b, const double gain, const
// Calculate the resampling metrics and build the Kaiser-windowed sinc filter
// that's used to cut frequencies above the destination nyquist.
-static void ResamplerSetup (ResamplerT * rs, const uint srcRate, const uint dstRate) {
- uint gcd, l;
- double cutoff, width, beta;
- int i;
-
- gcd = Gcd (srcRate, dstRate);
- rs -> mP = dstRate / gcd;
- rs -> mQ = srcRate / gcd;
- /* The cutoff is adjusted by half the transition width, so the transition
- * ends before the nyquist (0.5). Both are scaled by the downsampling
- * factor.
- */
- if (rs -> mP > rs -> mQ) {
- cutoff = 0.45 / rs -> mP;
- width = 0.1 / rs -> mP;
- } else {
- cutoff = 0.45 / rs -> mQ;
- width = 0.1 / rs -> mQ;
- }
- // A rejection of -180 dB is used for the stop band.
- l = CalcKaiserOrder (180.0, width) / 2;
- beta = CalcKaiserBeta (180.0);
- rs -> mM = (2 * l) + 1;
- rs -> mL = l;
- rs -> mF = CreateArray (rs -> mM);
- for (i = 0; i < ((int) rs -> mM); i ++)
- rs -> mF [i] = SincFilter ((int) l, beta, rs -> mP, cutoff, i);
+static void ResamplerSetup(ResamplerT *rs, const uint srcRate, const uint dstRate)
+{
+ double cutoff, width, beta;
+ uint gcd, l;
+ int i;
+
+ gcd = Gcd(srcRate, dstRate);
+ rs->mP = dstRate / gcd;
+ rs->mQ = srcRate / gcd;
+ /* The cutoff is adjusted by half the transition width, so the transition
+ * ends before the nyquist (0.5). Both are scaled by the downsampling
+ * factor.
+ */
+ if(rs->mP > rs->mQ)
+ {
+ cutoff = 0.475 / rs->mP;
+ width = 0.05 / rs->mP;
+ }
+ else
+ {
+ cutoff = 0.475 / rs->mQ;
+ width = 0.05 / rs->mQ;
+ }
+ // A rejection of -180 dB is used for the stop band. Round up when
+ // calculating the left offset to avoid increasing the transition width.
+ l = (CalcKaiserOrder(180.0, width)+1) / 2;
+ beta = CalcKaiserBeta(180.0);
+ rs->mM = l*2 + 1;
+ rs->mL = l;
+ rs->mF = CreateDoubles(rs->mM);
+ for(i = 0;i < ((int)rs->mM);i++)
+ rs->mF[i] = SincFilter((int)l, beta, rs->mP, cutoff, i);
}
// Clean up after the resampler.
-static void ResamplerClear (ResamplerT * rs) {
- DestroyArray (rs -> mF);
- rs -> mF = NULL;
+static void ResamplerClear(ResamplerT *rs)
+{
+ free(rs->mF);
+ rs->mF = NULL;
}
// Perform the upsample-filter-downsample resampling operation using a
// polyphase filter implementation.
-static void ResamplerRun (ResamplerT * rs, const uint inN, const double * in, const uint outN, double * out) {
- const uint p = rs -> mP, q = rs -> mQ, m = rs -> mM, l = rs -> mL;
- const double * f = rs -> mF;
- double * work = NULL;
- uint i;
- double r;
- uint j_f, j_s;
-
- if (outN == 0)
- return;
-
- // Handle in-place operation.
- if (in == out)
- work = CreateArray (outN);
- else
- work = out;
- // Resample the input.
- for (i = 0; i < outN; i ++) {
- r = 0.0;
- // Input starts at l to compensate for the filter delay. This will
- // drop any build-up from the first half of the filter.
- j_f = (l + (q * i)) % p;
- j_s = (l + (q * i)) / p;
- while (j_f < m) {
- // Only take input when 0 <= j_s < inN. This single unsigned
- // comparison catches both cases.
- if (j_s < inN)
- r += f [j_f] * in [j_s];
- j_f += p;
- j_s --;
- }
- work [i] = r;
- }
- // Clean up after in-place operation.
- if (in == out) {
- for (i = 0; i < outN; i ++)
- out [i] = work [i];
- DestroyArray (work);
- }
+static void ResamplerRun(ResamplerT *rs, const uint inN, const double *in, const uint outN, double *out)
+{
+ const uint p = rs->mP, q = rs->mQ, m = rs->mM, l = rs->mL;
+ const double *f = rs->mF;
+ uint j_f, j_s;
+ double *work;
+ uint i;
+
+ if(outN == 0)
+ return;
+
+ // Handle in-place operation.
+ if(in == out)
+ work = CreateDoubles(outN);
+ else
+ work = out;
+ // Resample the input.
+ for(i = 0;i < outN;i++)
+ {
+ double r = 0.0;
+ // Input starts at l to compensate for the filter delay. This will
+ // drop any build-up from the first half of the filter.
+ j_f = (l + (q * i)) % p;
+ j_s = (l + (q * i)) / p;
+ while(j_f < m)
+ {
+ // Only take input when 0 <= j_s < inN. This single unsigned
+ // comparison catches both cases.
+ if(j_s < inN)
+ r += f[j_f] * in[j_s];
+ j_f += p;
+ j_s--;
+ }
+ work[i] = r;
+ }
+ // Clean up after in-place operation.
+ if(work != out)
+ {
+ for(i = 0;i < outN;i++)
+ out[i] = work[i];
+ free(work);
+ }
}
+/*************************
+ *** File source input ***
+ *************************/
+
// Read a binary value of the specified byte order and byte size from a file,
// storing it as a 32-bit unsigned integer.
-static int ReadBin4 (FILE * fp, const char * filename, const ByteOrderT order, const uint bytes, uint32 * out) {
- uint8 in [4];
- uint32 accum;
- uint i;
-
- if (fread (in, 1, bytes, fp) != bytes) {
- fprintf (stderr, "Error: Bad read from file '%s'.\n", filename);
- return (0);
- }
- accum = 0;
- switch (order) {
- case BO_LITTLE :
- for (i = 0; i < bytes; i ++)
- accum = (accum << 8) | in [bytes - i - 1];
- break;
- case BO_BIG :
- for (i = 0; i < bytes; i ++)
- accum = (accum << 8) | in [i];
- break;
- default :
- break;
- }
- (* out) = accum;
- return (1);
+static int ReadBin4(FILE *fp, const char *filename, const ByteOrderT order, const uint bytes, uint32 *out)
+{
+ uint8 in[4];
+ uint32 accum;
+ uint i;
+
+ if(fread(in, 1, bytes, fp) != bytes)
+ {
+ fprintf(stderr, "Error: Bad read from file '%s'.\n", filename);
+ return 0;
+ }
+ accum = 0;
+ switch(order)
+ {
+ case BO_LITTLE:
+ for(i = 0;i < bytes;i++)
+ accum = (accum<<8) | in[bytes - i - 1];
+ break;
+ case BO_BIG:
+ for(i = 0;i < bytes;i++)
+ accum = (accum<<8) | in[i];
+ break;
+ default:
+ break;
+ }
+ *out = accum;
+ return 1;
}
// Read a binary value of the specified byte order from a file, storing it as
// a 64-bit unsigned integer.
-static int ReadBin8 (FILE * fp, const char * filename, const ByteOrderT order, uint64 * out) {
- uint8 in [8];
- uint64 accum;
- uint i;
-
- if (fread (in, 1, 8, fp) != 8) {
- fprintf (stderr, "Error: Bad read from file '%s'.\n", filename);
- return (0);
- }
- accum = 0ULL;
- switch (order) {
- case BO_LITTLE :
- for (i = 0; i < 8; i ++)
- accum = (accum << 8) | in [8 - i - 1];
- break;
- case BO_BIG :
- for (i = 0; i < 8; i ++)
- accum = (accum << 8) | in [i];
- break;
- default :
- break;
- }
- (* out) = accum;
- return (1);
-}
-
-// Write an ASCII string to a file.
-static int WriteAscii (const char * out, FILE * fp, const char * filename) {
- size_t len;
-
- len = strlen (out);
- if (fwrite (out, 1, len, fp) != len) {
- fclose (fp);
- fprintf (stderr, "Error: Bad write to file '%s'.\n", filename);
- return (0);
- }
- return (1);
-}
+static int ReadBin8(FILE *fp, const char *filename, const ByteOrderT order, uint64 *out)
+{
+ uint8 in [8];
+ uint64 accum;
+ uint i;
-// Write a binary value of the given byte order and byte size to a file,
-// loading it from a 32-bit unsigned integer.
-static int WriteBin4 (const ByteOrderT order, const uint bytes, const uint32 in, FILE * fp, const char * filename) {
- uint8 out [4];
- uint i;
-
- switch (order) {
- case BO_LITTLE :
- for (i = 0; i < bytes; i ++)
- out [i] = (in >> (i * 8)) & 0x000000FF;
- break;
- case BO_BIG :
- for (i = 0; i < bytes; i ++)
- out [bytes - i - 1] = (in >> (i * 8)) & 0x000000FF;
- break;
- default :
- break;
- }
- if (fwrite (out, 1, bytes, fp) != bytes) {
- fprintf (stderr, "Error: Bad write to file '%s'.\n", filename);
- return (0);
- }
- return (1);
+ if(fread(in, 1, 8, fp) != 8)
+ {
+ fprintf(stderr, "Error: Bad read from file '%s'.\n", filename);
+ return 0;
+ }
+ accum = 0ULL;
+ switch(order)
+ {
+ case BO_LITTLE:
+ for(i = 0;i < 8;i++)
+ accum = (accum<<8) | in[8 - i - 1];
+ break;
+ case BO_BIG:
+ for(i = 0;i < 8;i++)
+ accum = (accum<<8) | in[i];
+ break;
+ default:
+ break;
+ }
+ *out = accum;
+ return 1;
}
/* Read a binary value of the specified type, byte order, and byte size from
@@ -1346,39 +1471,45 @@ static int WriteBin4 (const ByteOrderT order, const uint bytes, const uint32 in,
* whether they are padded toward the MSB (negative) or LSB (positive).
* Floating-point types are not normalized.
*/
-static int ReadBinAsDouble (FILE * fp, const char * filename, const ByteOrderT order, const ElementTypeT type, const uint bytes, const int bits, double * out) {
- union {
- uint32 ui;
- int32 i;
- float f;
- } v4;
- union {
- uint64 ui;
- double f;
- } v8;
-
- (* out) = 0.0;
- if (bytes > 4) {
- if (! ReadBin8 (fp, filename, order, & v8 . ui))
- return (0);
- if (type == ET_FP)
- (* out) = v8 . f;
- } else {
- if (! ReadBin4 (fp, filename, order, bytes, & v4 . ui))
- return (0);
- if (type == ET_FP) {
- (* out) = (double) v4 . f;
- } else {
- if (bits > 0)
- v4 . ui >>= (8 * bytes) - ((uint) bits);
+static int ReadBinAsDouble(FILE *fp, const char *filename, const ByteOrderT order, const ElementTypeT type, const uint bytes, const int bits, double *out)
+{
+ union {
+ uint32 ui;
+ int32 i;
+ float f;
+ } v4;
+ union {
+ uint64 ui;
+ double f;
+ } v8;
+
+ *out = 0.0;
+ if(bytes > 4)
+ {
+ if(!ReadBin8(fp, filename, order, &v8.ui))
+ return 0;
+ if(type == ET_FP)
+ *out = v8.f;
+ }
+ else
+ {
+ if(!ReadBin4(fp, filename, order, bytes, &v4.ui))
+ return 0;
+ if(type == ET_FP)
+ *out = v4.f;
else
- v4 . ui &= (0xFFFFFFFF >> (32 + bits));
- if (v4 . ui & ((uint) (1 << (abs (bits) - 1))))
- v4 . ui |= (0xFFFFFFFF << abs (bits));
- (* out) = v4 . i / ((double) (1 << (abs (bits) - 1)));
- }
- }
- return (1);
+ {
+ if(bits > 0)
+ v4.ui >>= (8*bytes) - ((uint)bits);
+ else
+ v4.ui &= (0xFFFFFFFF >> (32+bits));
+
+ if(v4.ui&(uint)(1<<(abs(bits)-1)))
+ v4.ui |= (0xFFFFFFFF << abs (bits));
+ *out = v4.i / (double)(1<<(abs(bits)-1));
+ }
+ }
+ return 1;
}
/* Read an ascii value of the specified type from a file, converting it to a
@@ -1386,391 +1517,585 @@ static int ReadBinAsDouble (FILE * fp, const char * filename, const ByteOrderT o
* result. The sign of the bits should always be positive. This also skips
* up to one separator character before the element itself.
*/
-static int ReadAsciiAsDouble (TokenReaderT * tr, const char * filename, const ElementTypeT type, const uint bits, double * out) {
- int v;
-
- if (TrIsOperator (tr, ","))
- TrReadOperator (tr, ",");
- else if (TrIsOperator (tr, ":"))
- TrReadOperator (tr, ":");
- else if (TrIsOperator (tr, ";"))
- TrReadOperator (tr, ";");
- else if (TrIsOperator (tr, "|"))
- TrReadOperator (tr, "|");
- if (type == ET_FP) {
- if (! TrReadFloat (tr, -HUGE_VAL, HUGE_VAL, out)) {
- fprintf (stderr, "Error: Bad read from file '%s'.\n", filename);
- return (0);
- }
- } else {
- if (! TrReadInt (tr, -(1 << (bits - 1)), (1 << (bits - 1)) - 1, & v)) {
- fprintf (stderr, "Error: Bad read from file '%s'.\n", filename);
- return (0);
- }
- (* out) = v / ((double) ((1 << (bits - 1)) - 1));
- }
- return (1);
+static int ReadAsciiAsDouble(TokenReaderT *tr, const char *filename, const ElementTypeT type, const uint bits, double *out)
+{
+ if(TrIsOperator(tr, ","))
+ TrReadOperator(tr, ",");
+ else if(TrIsOperator(tr, ":"))
+ TrReadOperator(tr, ":");
+ else if(TrIsOperator(tr, ";"))
+ TrReadOperator(tr, ";");
+ else if(TrIsOperator(tr, "|"))
+ TrReadOperator(tr, "|");
+
+ if(type == ET_FP)
+ {
+ if(!TrReadFloat(tr, -HUGE_VAL, HUGE_VAL, out))
+ {
+ fprintf(stderr, "Error: Bad read from file '%s'.\n", filename);
+ return 0;
+ }
+ }
+ else
+ {
+ int v;
+ if(!TrReadInt(tr, -(1<<(bits-1)), (1<<(bits-1))-1, &v))
+ {
+ fprintf(stderr, "Error: Bad read from file '%s'.\n", filename);
+ return 0;
+ }
+ *out = v / (double)((1<<(bits-1))-1);
+ }
+ return 1;
}
// Read the RIFF/RIFX WAVE format chunk from a file, validating it against
// the source parameters and data set metrics.
-static int ReadWaveFormat (FILE * fp, const ByteOrderT order, const uint hrirRate, SourceRefT * src) {
- uint32 fourCC, chunkSize;
- uint32 format, channels, rate, dummy, block, size, bits;
-
- chunkSize = 0;
- do {
- if (chunkSize > 0)
- fseek (fp, (long) chunkSize, SEEK_CUR);
- if ((! ReadBin4 (fp, src -> mPath, BO_LITTLE, 4, & fourCC)) ||
- (! ReadBin4 (fp, src -> mPath, order, 4, & chunkSize)))
- return (0);
- } while (fourCC != FOURCC_FMT);
- if ((! ReadBin4 (fp, src -> mPath, order, 2, & format)) ||
- (! ReadBin4 (fp, src -> mPath, order, 2, & channels)) ||
- (! ReadBin4 (fp, src -> mPath, order, 4, & rate)) ||
- (! ReadBin4 (fp, src -> mPath, order, 4, & dummy)) ||
- (! ReadBin4 (fp, src -> mPath, order, 2, & block)))
- return (0);
- block /= channels;
- if (chunkSize > 14) {
- if (! ReadBin4 (fp, src -> mPath, order, 2, & size))
- return (0);
- size /= 8;
- if (block > size)
+static int ReadWaveFormat(FILE *fp, const ByteOrderT order, const uint hrirRate, SourceRefT *src)
+{
+ uint32 fourCC, chunkSize;
+ uint32 format, channels, rate, dummy, block, size, bits;
+
+ chunkSize = 0;
+ do {
+ if(chunkSize > 0)
+ fseek (fp, (long) chunkSize, SEEK_CUR);
+ if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC) ||
+ !ReadBin4(fp, src->mPath, order, 4, &chunkSize))
+ return 0;
+ } while(fourCC != FOURCC_FMT);
+ if(!ReadBin4(fp, src->mPath, order, 2, &format) ||
+ !ReadBin4(fp, src->mPath, order, 2, &channels) ||
+ !ReadBin4(fp, src->mPath, order, 4, &rate) ||
+ !ReadBin4(fp, src->mPath, order, 4, &dummy) ||
+ !ReadBin4(fp, src->mPath, order, 2, &block))
+ return 0;
+ block /= channels;
+ if(chunkSize > 14)
+ {
+ if(!ReadBin4(fp, src->mPath, order, 2, &size))
+ return 0;
+ size /= 8;
+ if(block > size)
+ size = block;
+ }
+ else
size = block;
- } else {
- size = block;
- }
- if (format == WAVE_FORMAT_EXTENSIBLE) {
- fseek (fp, 2, SEEK_CUR);
- if (! ReadBin4 (fp, src -> mPath, order, 2, & bits))
- return (0);
- if (bits == 0)
+ if(format == WAVE_FORMAT_EXTENSIBLE)
+ {
+ fseek(fp, 2, SEEK_CUR);
+ if(!ReadBin4(fp, src->mPath, order, 2, &bits))
+ return 0;
+ if(bits == 0)
+ bits = 8 * size;
+ fseek(fp, 4, SEEK_CUR);
+ if(!ReadBin4(fp, src->mPath, order, 2, &format))
+ return 0;
+ fseek(fp, (long)(chunkSize - 26), SEEK_CUR);
+ }
+ else
+ {
bits = 8 * size;
- fseek (fp, 4, SEEK_CUR);
- if (! ReadBin4 (fp, src -> mPath, order, 2, & format))
- return (0);
- fseek (fp, (long) (chunkSize - 26), SEEK_CUR);
- } else {
- bits = 8 * size;
- if (chunkSize > 14)
- fseek (fp, (long) (chunkSize - 16), SEEK_CUR);
- else
- fseek (fp, (long) (chunkSize - 14), SEEK_CUR);
- }
- if ((format != WAVE_FORMAT_PCM) && (format != WAVE_FORMAT_IEEE_FLOAT)) {
- fprintf (stderr, "Error: Unsupported WAVE format in file '%s'.\n", src -> mPath);
- return (0);
- }
- if (src -> mChannel >= channels) {
- fprintf (stderr, "Error: Missing source channel in WAVE file '%s'.\n", src -> mPath);
- return (0);
- }
- if (rate != hrirRate) {
- fprintf (stderr, "Error: Mismatched source sample rate in WAVE file '%s'.\n", src -> mPath);
- return (0);
- }
- if (format == WAVE_FORMAT_PCM) {
- if ((size < 2) || (size > 4)) {
- fprintf (stderr, "Error: Unsupported sample size in WAVE file '%s'.\n", src -> mPath);
- return (0);
- }
- if ((bits < 16) || (bits > (8 * size))) {
- fprintf (stderr, "Error: Bad significant bits in WAVE file '%s'.\n", src -> mPath);
- return (0);
- }
- src -> mType = ET_INT;
- } else {
- if ((size != 4) && (size != 8)) {
- fprintf (stderr, "Error: Unsupported sample size in WAVE file '%s'.\n", src -> mPath);
- return (0);
- }
- src -> mType = ET_FP;
- }
- src -> mSize = size;
- src -> mBits = (int) bits;
- src -> mSkip = channels;
- return (1);
+ if(chunkSize > 14)
+ fseek(fp, (long)(chunkSize - 16), SEEK_CUR);
+ else
+ fseek(fp, (long)(chunkSize - 14), SEEK_CUR);
+ }
+ if(format != WAVE_FORMAT_PCM && format != WAVE_FORMAT_IEEE_FLOAT)
+ {
+ fprintf(stderr, "Error: Unsupported WAVE format in file '%s'.\n", src->mPath);
+ return 0;
+ }
+ if(src->mChannel >= channels)
+ {
+ fprintf(stderr, "Error: Missing source channel in WAVE file '%s'.\n", src->mPath);
+ return 0;
+ }
+ if(rate != hrirRate)
+ {
+ fprintf(stderr, "Error: Mismatched source sample rate in WAVE file '%s'.\n", src->mPath);
+ return 0;
+ }
+ if(format == WAVE_FORMAT_PCM)
+ {
+ if(size < 2 || size > 4)
+ {
+ fprintf(stderr, "Error: Unsupported sample size in WAVE file '%s'.\n", src->mPath);
+ return 0;
+ }
+ if(bits < 16 || bits > (8*size))
+ {
+ fprintf (stderr, "Error: Bad significant bits in WAVE file '%s'.\n", src->mPath);
+ return 0;
+ }
+ src->mType = ET_INT;
+ }
+ else
+ {
+ if(size != 4 && size != 8)
+ {
+ fprintf(stderr, "Error: Unsupported sample size in WAVE file '%s'.\n", src->mPath);
+ return 0;
+ }
+ src->mType = ET_FP;
+ }
+ src->mSize = size;
+ src->mBits = (int)bits;
+ src->mSkip = channels;
+ return 1;
}
// Read a RIFF/RIFX WAVE data chunk, converting all elements to doubles.
-static int ReadWaveData (FILE * fp, const SourceRefT * src, const ByteOrderT order, const uint n, double * hrir) {
- int pre, post, skip;
- uint i;
-
- pre = (int) (src -> mSize * src -> mChannel);
- post = (int) (src -> mSize * (src -> mSkip - src -> mChannel - 1));
- skip = 0;
- for (i = 0; i < n; i ++) {
- skip += pre;
- if (skip > 0)
- fseek (fp, skip, SEEK_CUR);
- if (! ReadBinAsDouble (fp, src -> mPath, order, src -> mType, src -> mSize, src -> mBits, & hrir [i]))
- return (0);
- skip = post;
- }
- if (skip > 0)
- fseek (fp, skip, SEEK_CUR);
- return (1);
+static int ReadWaveData(FILE *fp, const SourceRefT *src, const ByteOrderT order, const uint n, double *hrir)
+{
+ int pre, post, skip;
+ uint i;
+
+ pre = (int)(src->mSize * src->mChannel);
+ post = (int)(src->mSize * (src->mSkip - src->mChannel - 1));
+ skip = 0;
+ for(i = 0;i < n;i++)
+ {
+ skip += pre;
+ if(skip > 0)
+ fseek(fp, skip, SEEK_CUR);
+ if(!ReadBinAsDouble(fp, src->mPath, order, src->mType, src->mSize, src->mBits, &hrir[i]))
+ return 0;
+ skip = post;
+ }
+ if(skip > 0)
+ fseek(fp, skip, SEEK_CUR);
+ return 1;
}
// Read the RIFF/RIFX WAVE list or data chunk, converting all elements to
// doubles.
-static int ReadWaveList (FILE * fp, const SourceRefT * src, const ByteOrderT order, const uint n, double * hrir) {
- uint32 fourCC, chunkSize, listSize, count;
- uint block, skip, offset, i;
- double lastSample;
-
- for (;;) {
- if ((! ReadBin4 (fp, src -> mPath, BO_LITTLE, 4, & fourCC)) ||
- (! ReadBin4 (fp, src -> mPath, order, 4, & chunkSize)))
- return (0);
- if (fourCC == FOURCC_DATA) {
- block = src -> mSize * src -> mSkip;
- count = chunkSize / block;
- if (count < (src -> mOffset + n)) {
- fprintf (stderr, "Error: Bad read from file '%s'.\n", src -> mPath);
- return (0);
- }
- fseek (fp, (long) (src -> mOffset * block), SEEK_CUR);
- if (! ReadWaveData (fp, src, order, n, & hrir [0]))
- return (0);
- return (1);
- } else if (fourCC == FOURCC_LIST) {
- if (! ReadBin4 (fp, src -> mPath, BO_LITTLE, 4, & fourCC))
- return (0);
- chunkSize -= 4;
- if (fourCC == FOURCC_WAVL)
- break;
- }
- if (chunkSize > 0)
- fseek (fp, (long) chunkSize, SEEK_CUR);
- }
- listSize = chunkSize;
- block = src -> mSize * src -> mSkip;
- skip = src -> mOffset;
- offset = 0;
- lastSample = 0.0;
- while ((offset < n) && (listSize > 8)) {
- if ((! ReadBin4 (fp, src -> mPath, BO_LITTLE, 4, & fourCC)) ||
- (! ReadBin4 (fp, src -> mPath, order, 4, & chunkSize)))
- return (0);
- listSize -= 8 + chunkSize;
- if (fourCC == FOURCC_DATA) {
- count = chunkSize / block;
- if (count > skip) {
- fseek (fp, (long) (skip * block), SEEK_CUR);
- chunkSize -= skip * block;
- count -= skip;
- skip = 0;
- if (count > (n - offset))
- count = n - offset;
- if (! ReadWaveData (fp, src, order, count, & hrir [offset]))
- return (0);
- chunkSize -= count * block;
- offset += count;
- lastSample = hrir [offset - 1];
- } else {
- skip -= count;
- count = 0;
- }
- } else if (fourCC == FOURCC_SLNT) {
- if (! ReadBin4 (fp, src -> mPath, order, 4, & count))
- return (0);
- chunkSize -= 4;
- if (count > skip) {
- count -= skip;
- skip = 0;
- if (count > (n - offset))
- count = n - offset;
- for (i = 0; i < count; i ++)
- hrir [offset + i] = lastSample;
- offset += count;
- } else {
- skip -= count;
- count = 0;
- }
- }
- if (chunkSize > 0)
- fseek (fp, (long) chunkSize, SEEK_CUR);
- }
- if (offset < n) {
- fprintf (stderr, "Error: Bad read from file '%s'.\n", src -> mPath);
- return (0);
- }
- return (1);
+static int ReadWaveList(FILE *fp, const SourceRefT *src, const ByteOrderT order, const uint n, double *hrir)
+{
+ uint32 fourCC, chunkSize, listSize, count;
+ uint block, skip, offset, i;
+ double lastSample;
+
+ for(;;)
+ {
+ if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC) ||
+ !ReadBin4(fp, src->mPath, order, 4, &chunkSize))
+ return 0;
+
+ if(fourCC == FOURCC_DATA)
+ {
+ block = src->mSize * src->mSkip;
+ count = chunkSize / block;
+ if(count < (src->mOffset + n))
+ {
+ fprintf(stderr, "Error: Bad read from file '%s'.\n", src->mPath);
+ return 0;
+ }
+ fseek(fp, (long)(src->mOffset * block), SEEK_CUR);
+ if(!ReadWaveData(fp, src, order, n, &hrir[0]))
+ return 0;
+ return 1;
+ }
+ else if(fourCC == FOURCC_LIST)
+ {
+ if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC))
+ return 0;
+ chunkSize -= 4;
+ if(fourCC == FOURCC_WAVL)
+ break;
+ }
+ if(chunkSize > 0)
+ fseek(fp, (long)chunkSize, SEEK_CUR);
+ }
+ listSize = chunkSize;
+ block = src->mSize * src->mSkip;
+ skip = src->mOffset;
+ offset = 0;
+ lastSample = 0.0;
+ while(offset < n && listSize > 8)
+ {
+ if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC) ||
+ !ReadBin4(fp, src->mPath, order, 4, &chunkSize))
+ return 0;
+ listSize -= 8 + chunkSize;
+ if(fourCC == FOURCC_DATA)
+ {
+ count = chunkSize / block;
+ if(count > skip)
+ {
+ fseek(fp, (long)(skip * block), SEEK_CUR);
+ chunkSize -= skip * block;
+ count -= skip;
+ skip = 0;
+ if(count > (n - offset))
+ count = n - offset;
+ if(!ReadWaveData(fp, src, order, count, &hrir[offset]))
+ return 0;
+ chunkSize -= count * block;
+ offset += count;
+ lastSample = hrir [offset - 1];
+ }
+ else
+ {
+ skip -= count;
+ count = 0;
+ }
+ }
+ else if(fourCC == FOURCC_SLNT)
+ {
+ if(!ReadBin4(fp, src->mPath, order, 4, &count))
+ return 0;
+ chunkSize -= 4;
+ if(count > skip)
+ {
+ count -= skip;
+ skip = 0;
+ if(count > (n - offset))
+ count = n - offset;
+ for(i = 0; i < count; i ++)
+ hrir[offset + i] = lastSample;
+ offset += count;
+ }
+ else
+ {
+ skip -= count;
+ count = 0;
+ }
+ }
+ if(chunkSize > 0)
+ fseek(fp, (long)chunkSize, SEEK_CUR);
+ }
+ if(offset < n)
+ {
+ fprintf(stderr, "Error: Bad read from file '%s'.\n", src->mPath);
+ return 0;
+ }
+ return 1;
}
// Load a source HRIR from a RIFF/RIFX WAVE file.
-static int LoadWaveSource (FILE * fp, SourceRefT * src, const uint hrirRate, const uint n, double * hrir) {
- uint32 fourCC, dummy;
- ByteOrderT order;
-
- if ((! ReadBin4 (fp, src -> mPath, BO_LITTLE, 4, & fourCC)) ||
- (! ReadBin4 (fp, src -> mPath, BO_LITTLE, 4, & dummy)))
- return (0);
- if (fourCC == FOURCC_RIFF) {
- order = BO_LITTLE;
- } else if (fourCC == FOURCC_RIFX) {
- order = BO_BIG;
- } else {
- fprintf (stderr, "Error: No RIFF/RIFX chunk in file '%s'.\n", src -> mPath);
- return (0);
- }
- if (! ReadBin4 (fp, src -> mPath, BO_LITTLE, 4, & fourCC))
- return (0);
- if (fourCC != FOURCC_WAVE) {
- fprintf (stderr, "Error: Not a RIFF/RIFX WAVE file '%s'.\n", src -> mPath);
- return (0);
- }
- if (! ReadWaveFormat (fp, order, hrirRate, src))
- return (0);
- if (! ReadWaveList (fp, src, order, n, hrir))
- return (0);
- return (1);
+static int LoadWaveSource(FILE *fp, SourceRefT *src, const uint hrirRate, const uint n, double *hrir)
+{
+ uint32 fourCC, dummy;
+ ByteOrderT order;
+
+ if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC) ||
+ !ReadBin4(fp, src->mPath, BO_LITTLE, 4, &dummy))
+ return 0;
+ if(fourCC == FOURCC_RIFF)
+ order = BO_LITTLE;
+ else if(fourCC == FOURCC_RIFX)
+ order = BO_BIG;
+ else
+ {
+ fprintf(stderr, "Error: No RIFF/RIFX chunk in file '%s'.\n", src->mPath);
+ return 0;
+ }
+
+ if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC))
+ return 0;
+ if(fourCC != FOURCC_WAVE)
+ {
+ fprintf(stderr, "Error: Not a RIFF/RIFX WAVE file '%s'.\n", src->mPath);
+ return 0;
+ }
+ if(!ReadWaveFormat(fp, order, hrirRate, src))
+ return 0;
+ if(!ReadWaveList(fp, src, order, n, hrir))
+ return 0;
+ return 1;
}
// Load a source HRIR from a binary file.
-static int LoadBinarySource (FILE * fp, const SourceRefT * src, const ByteOrderT order, const uint n, double * hrir) {
- uint i;
+static int LoadBinarySource(FILE *fp, const SourceRefT *src, const ByteOrderT order, const uint n, double *hrir)
+{
+ uint i;
- fseek (fp, (long) src -> mOffset, SEEK_SET);
- for (i = 0; i < n; i ++) {
- if (! ReadBinAsDouble (fp, src -> mPath, order, src -> mType, src -> mSize, src -> mBits, & hrir [i]))
- return (0);
- if (src -> mSkip > 0)
- fseek (fp, (long) src -> mSkip, SEEK_CUR);
- }
- return (1);
+ fseek(fp, (long)src->mOffset, SEEK_SET);
+ for(i = 0;i < n;i++)
+ {
+ if(!ReadBinAsDouble(fp, src->mPath, order, src->mType, src->mSize, src->mBits, &hrir[i]))
+ return 0;
+ if(src->mSkip > 0)
+ fseek(fp, (long)src->mSkip, SEEK_CUR);
+ }
+ return 1;
}
// Load a source HRIR from an ASCII text file containing a list of elements
// separated by whitespace or common list operators (',', ';', ':', '|').
-static int LoadAsciiSource (FILE * fp, const SourceRefT * src, const uint n, double * hrir) {
- TokenReaderT tr;
- uint i, j;
- double dummy;
-
- TrSetup (fp, NULL, & tr);
- for (i = 0; i < src -> mOffset; i ++) {
- if (! ReadAsciiAsDouble (& tr, src -> mPath, src -> mType, (uint) src -> mBits, & dummy))
- return (0);
- }
- for (i = 0; i < n; i ++) {
- if (! ReadAsciiAsDouble (& tr, src -> mPath, src -> mType, (uint) src -> mBits, & hrir [i]))
- return (0);
- for (j = 0; j < src -> mSkip; j ++) {
- if (! ReadAsciiAsDouble (& tr, src -> mPath, src -> mType, (uint) src -> mBits, & dummy))
- return (0);
- }
- }
- return (1);
+static int LoadAsciiSource(FILE *fp, const SourceRefT *src, const uint n, double *hrir)
+{
+ TokenReaderT tr;
+ uint i, j;
+ double dummy;
+
+ TrSetup(fp, NULL, &tr);
+ for(i = 0;i < src->mOffset;i++)
+ {
+ if(!ReadAsciiAsDouble(&tr, src->mPath, src->mType, (uint)src->mBits, &dummy))
+ return 0;
+ }
+ for(i = 0;i < n;i++)
+ {
+ if(!ReadAsciiAsDouble(&tr, src->mPath, src->mType, (uint)src->mBits, &hrir[i]))
+ return 0;
+ for(j = 0;j < src->mSkip;j++)
+ {
+ if(!ReadAsciiAsDouble(&tr, src->mPath, src->mType, (uint)src->mBits, &dummy))
+ return 0;
+ }
+ }
+ return 1;
}
// Load a source HRIR from a supported file type.
-static int LoadSource (SourceRefT * src, const uint hrirRate, const uint n, double * hrir) {
- FILE * fp = NULL;
- int result;
-
- if (src -> mFormat == SF_ASCII)
- fp = fopen (src -> mPath, "r");
- else
- fp = fopen (src -> mPath, "rb");
- if (fp == NULL) {
- fprintf (stderr, "Error: Could not open source file '%s'.\n", src -> mPath);
- return (0);
- }
- if (src -> mFormat == SF_WAVE)
- result = LoadWaveSource (fp, src, hrirRate, n, hrir);
- else if (src -> mFormat == SF_BIN_LE)
- result = LoadBinarySource (fp, src, BO_LITTLE, n, hrir);
- else if (src -> mFormat == SF_BIN_BE)
- result = LoadBinarySource (fp, src, BO_BIG, n, hrir);
- else
- result = LoadAsciiSource (fp, src, n, hrir);
- fclose (fp);
- return (result);
+static int LoadSource(SourceRefT *src, const uint hrirRate, const uint n, double *hrir)
+{
+ int result;
+ FILE *fp;
+
+ if(src->mFormat == SF_ASCII)
+ fp = fopen(src->mPath, "r");
+ else
+ fp = fopen(src->mPath, "rb");
+ if(fp == NULL)
+ {
+ fprintf(stderr, "Error: Could not open source file '%s'.\n", src->mPath);
+ return 0;
+ }
+ if(src->mFormat == SF_WAVE)
+ result = LoadWaveSource(fp, src, hrirRate, n, hrir);
+ else if(src->mFormat == SF_BIN_LE)
+ result = LoadBinarySource(fp, src, BO_LITTLE, n, hrir);
+ else if(src->mFormat == SF_BIN_BE)
+ result = LoadBinarySource(fp, src, BO_BIG, n, hrir);
+ else
+ result = LoadAsciiSource(fp, src, n, hrir);
+ fclose(fp);
+ return result;
+}
+
+
+/***************************
+ *** File storage output ***
+ ***************************/
+
+// Write an ASCII string to a file.
+static int WriteAscii(const char *out, FILE *fp, const char *filename)
+{
+ size_t len;
+
+ len = strlen(out);
+ if(fwrite(out, 1, len, fp) != len)
+ {
+ fclose(fp);
+ fprintf(stderr, "Error: Bad write to file '%s'.\n", filename);
+ return 0;
+ }
+ return 1;
+}
+
+// Write a binary value of the given byte order and byte size to a file,
+// loading it from a 32-bit unsigned integer.
+static int WriteBin4(const ByteOrderT order, const uint bytes, const uint32 in, FILE *fp, const char *filename)
+{
+ uint8 out[4];
+ uint i;
+
+ switch(order)
+ {
+ case BO_LITTLE:
+ for(i = 0;i < bytes;i++)
+ out[i] = (in>>(i*8)) & 0x000000FF;
+ break;
+ case BO_BIG:
+ for(i = 0;i < bytes;i++)
+ out[bytes - i - 1] = (in>>(i*8)) & 0x000000FF;
+ break;
+ default:
+ break;
+ }
+ if(fwrite(out, 1, bytes, fp) != bytes)
+ {
+ fprintf(stderr, "Error: Bad write to file '%s'.\n", filename);
+ return 0;
+ }
+ return 1;
+}
+
+// Store the OpenAL Soft HRTF data set.
+static int StoreMhr(const HrirDataT *hData, const char *filename)
+{
+ uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1;
+ uint n = hData->mIrPoints;
+ FILE *fp;
+ uint fi, ei, ai, i;
+ uint dither_seed = 22222;
+
+ if((fp=fopen(filename, "wb")) == NULL)
+ {
+ fprintf(stderr, "Error: Could not open MHR file '%s'.\n", filename);
+ return 0;
+ }
+ if(!WriteAscii(MHR_FORMAT, fp, filename))
+ return 0;
+ if(!WriteBin4(BO_LITTLE, 4, (uint32)hData->mIrRate, fp, filename))
+ return 0;
+ if(!WriteBin4(BO_LITTLE, 1, (uint32)hData->mSampleType, fp, filename))
+ return 0;
+ if(!WriteBin4(BO_LITTLE, 1, (uint32)hData->mChannelType, fp, filename))
+ return 0;
+ if(!WriteBin4(BO_LITTLE, 1, (uint32)hData->mIrPoints, fp, filename))
+ return 0;
+ if(!WriteBin4(BO_LITTLE, 1, (uint32)hData->mFdCount, fp, filename))
+ return 0;
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ if(!WriteBin4(BO_LITTLE, 2, (uint32)(1000.0 * hData->mFds[fi].mDistance), fp, filename))
+ return 0;
+ if(!WriteBin4(BO_LITTLE, 1, (uint32)hData->mFds[fi].mEvCount, fp, filename))
+ return 0;
+ for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ if(!WriteBin4(BO_LITTLE, 1, (uint32)hData->mFds[fi].mEvs[ei].mAzCount, fp, filename))
+ return 0;
+ }
+ }
+
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ const double scale = (hData->mSampleType == ST_S16) ? 32767.0 :
+ ((hData->mSampleType == ST_S24) ? 8388607.0 : 0.0);
+ const int bps = (hData->mSampleType == ST_S16) ? 2 :
+ ((hData->mSampleType == ST_S24) ? 3 : 0);
+
+ for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ {
+ HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
+ double out[2 * MAX_TRUNCSIZE];
+
+ TpdfDither(out, azd->mIrs[0], scale, n, channels, &dither_seed);
+ if(hData->mChannelType == CT_STEREO)
+ TpdfDither(out+1, azd->mIrs[1], scale, n, channels, &dither_seed);
+ for(i = 0;i < (channels * n);i++)
+ {
+ int v = (int)Clamp(out[i], -scale-1.0, scale);
+ if(!WriteBin4(BO_LITTLE, bps, (uint32)v, fp, filename))
+ return 0;
+ }
+ }
+ }
+ }
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ {
+ HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
+ int v = (int)fmin(round(hData->mIrRate * azd->mDelays[0]), MAX_HRTD);
+
+ if(!WriteBin4(BO_LITTLE, 1, (uint32)v, fp, filename))
+ return 0;
+ if(hData->mChannelType == CT_STEREO)
+ {
+ v = (int)fmin(round(hData->mIrRate * azd->mDelays[1]), MAX_HRTD);
+
+ if(!WriteBin4(BO_LITTLE, 1, (uint32)v, fp, filename))
+ return 0;
+ }
+ }
+ }
+ }
+ fclose(fp);
+ return 1;
}
+
+/***********************
+ *** HRTF processing ***
+ ***********************/
+
// Calculate the onset time of an HRIR and average it with any existing
-// timing for its elevation and azimuth.
-static void AverageHrirOnset (const double * hrir, const double f, const uint ei, const uint ai, const HrirDataT * hData) {
- double mag;
- uint n, i, j;
-
- mag = 0.0;
- n = hData -> mIrPoints;
- for (i = 0; i < n; i ++)
- mag = fmax (fabs (hrir [i]), mag);
- mag *= 0.15;
- for (i = 0; i < n; i ++) {
- if (fabs (hrir [i]) >= mag)
- break;
- }
- j = hData -> mEvOffset [ei] + ai;
- hData -> mHrtds [j] = Lerp (hData -> mHrtds [j], ((double) i) / hData -> mIrRate, f);
+// timing for its field, elevation, azimuth, and ear.
+static double AverageHrirOnset(const uint rate, const uint n, const double *hrir, const double f, const double onset)
+{
+ double mag = 0.0;
+ uint i;
+
+ for(i = 0;i < n;i++)
+ mag = fmax(fabs(hrir[i]), mag);
+ mag *= 0.15;
+ for(i = 0;i < n;i++)
+ {
+ if(fabs(hrir[i]) >= mag)
+ break;
+ }
+ return Lerp(onset, (double)i / rate, f);
}
// Calculate the magnitude response of an HRIR and average it with any
-// existing responses for its elevation and azimuth.
-static void AverageHrirMagnitude (const double * hrir, const double f, const uint ei, const uint ai, const HrirDataT * hData) {
- double * re = NULL, * im = NULL;
- uint n, m, i, j;
-
- n = hData -> mFftSize;
- re = CreateArray (n);
- im = CreateArray (n);
- for (i = 0; i < hData -> mIrPoints; i ++) {
- re [i] = hrir [i];
- im [i] = 0.0;
- }
- for (; i < n; i ++) {
- re [i] = 0.0;
- im [i] = 0.0;
- }
- FftForward (n, re, im, re, im);
- MagnitudeResponse (n, re, im, re);
- m = 1 + (n / 2);
- j = (hData -> mEvOffset [ei] + ai) * hData -> mIrSize;
- for (i = 0; i < m; i ++)
- hData -> mHrirs [j + i] = Lerp (hData -> mHrirs [j + i], re [i], f);
- DestroyArray (im);
- DestroyArray (re);
+// existing responses for its field, elevation, azimuth, and ear.
+static void AverageHrirMagnitude(const uint points, const uint n, const double *hrir, const double f, double *mag)
+{
+ uint m = 1 + (n / 2), i;
+ Complex *h = CreateComplexes(n);
+ double *r = CreateDoubles(n);
+
+ for(i = 0;i < points;i++)
+ h[i] = MakeComplex(hrir[i], 0.0);
+ for(;i < n;i++)
+ h[i] = MakeComplex(0.0, 0.0);
+ FftForward(n, h);
+ MagnitudeResponse(n, h, r);
+ for(i = 0;i < m;i++)
+ mag[i] = Lerp(mag[i], r[i], f);
+ free(r);
+ free(h);
}
/* Calculate the contribution of each HRIR to the diffuse-field average based
* on the area of its surface patch. All patches are centered at the HRIR
* coordinates on the unit sphere and are measured by solid angle.
*/
-static void CalculateDfWeights (const HrirDataT * hData, double * weights) {
- uint ei;
- double evs, sum, ev, up_ev, down_ev, solidAngle;
-
- evs = 90.0 / (hData -> mEvCount - 1);
- sum = 0.0;
- for (ei = hData -> mEvStart; ei < hData -> mEvCount; ei ++) {
- // For each elevation, calculate the upper and lower limits of the
- // patch band.
- ev = -90.0 + (ei * 2.0 * evs);
- if (ei < (hData -> mEvCount - 1))
- up_ev = (ev + evs) * M_PI / 180.0;
- else
- up_ev = M_PI / 2.0;
- if (ei > 0)
- down_ev = (ev - evs) * M_PI / 180.0;
- else
- down_ev = -M_PI / 2.0;
- // Calculate the area of the patch band.
- solidAngle = 2.0 * M_PI * (sin (up_ev) - sin (down_ev));
- // Each weight is the area of one patch.
- weights [ei] = solidAngle / hData -> mAzCount [ei];
- // Sum the total surface area covered by the HRIRs.
- sum += solidAngle;
- }
- // Normalize the weights given the total surface coverage.
- for (ei = hData -> mEvStart; ei < hData -> mEvCount; ei ++)
- weights [ei] /= sum;
+static void CalculateDfWeights(const HrirDataT *hData, double *weights)
+{
+ double sum, evs, ev, upperEv, lowerEv, solidAngle;
+ uint fi, ei;
+
+ sum = 0.0;
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ evs = M_PI / 2.0 / (hData->mFds[fi].mEvCount - 1);
+ for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ // For each elevation, calculate the upper and lower limits of
+ // the patch band.
+ ev = hData->mFds[fi].mEvs[ei].mElevation;
+ lowerEv = fmax(-M_PI / 2.0, ev - evs);
+ upperEv = fmin(M_PI / 2.0, ev + evs);
+ // Calculate the area of the patch band.
+ solidAngle = 2.0 * M_PI * (sin(upperEv) - sin(lowerEv));
+ // Each weight is the area of one patch.
+ weights[(fi * MAX_EV_COUNT) + ei] = solidAngle / hData->mFds[fi].mEvs[ei].mAzCount;
+ // Sum the total surface area covered by the HRIRs of all fields.
+ sum += solidAngle;
+ }
+ }
+ /* TODO: It may be interesting to experiment with how a volume-based
+ weighting performs compared to the existing distance-indepenent
+ surface patches.
+ */
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ // Normalize the weights given the total surface coverage for all
+ // fields.
+ for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvCount;ei++)
+ weights[(fi * MAX_EV_COUNT) + ei] /= sum;
+ }
}
/* Calculate the diffuse-field average from the given magnitude responses of
@@ -1778,880 +2103,1353 @@ static void CalculateDfWeights (const HrirDataT * hData, double * weights) {
* surface area covered by each HRIR. The final average can then be limited
* by the specified magnitude range (in positive dB; 0.0 to skip).
*/
-static void CalculateDiffuseFieldAverage (const HrirDataT * hData, const int weighted, const double limit, double * dfa) {
- double * weights = NULL;
- uint ei, ai, count, step, start, end, m, j, i;
- double weight;
-
- weights = CreateArray (hData -> mEvCount);
- if (weighted) {
- // Use coverage weighting to calculate the average.
- CalculateDfWeights (hData, weights);
- } else {
- // If coverage weighting is not used, the weights still need to be
- // averaged by the number of HRIRs.
- count = 0;
- for (ei = hData -> mEvStart; ei < hData -> mEvCount; ei ++)
- count += hData -> mAzCount [ei];
- for (ei = hData -> mEvStart; ei < hData -> mEvCount; ei ++)
- weights [ei] = 1.0 / count;
- }
- ei = hData -> mEvStart;
- ai = 0;
- step = hData -> mIrSize;
- start = hData -> mEvOffset [ei] * step;
- end = hData -> mIrCount * step;
- m = 1 + (hData -> mFftSize / 2);
- for (i = 0; i < m; i ++)
- dfa [i] = 0.0;
- for (j = start; j < end; j += step) {
- // Get the weight for this HRIR's contribution.
- weight = weights [ei];
- // Add this HRIR's weighted power average to the total.
- for (i = 0; i < m; i ++)
- dfa [i] += weight * hData -> mHrirs [j + i] * hData -> mHrirs [j + i];
- // Determine the next weight to use.
- ai ++;
- if (ai >= hData -> mAzCount [ei]) {
- ei ++;
- ai = 0;
- }
- }
- // Finish the average calculation and keep it from being too small.
- for (i = 0; i < m; i ++)
- dfa [i] = fmax (sqrt (dfa [i]), EPSILON);
- // Apply a limit to the magnitude range of the diffuse-field average if
- // desired.
- if (limit > 0.0)
- LimitMagnitudeResponse (hData -> mFftSize, limit, dfa, dfa);
- DestroyArray (weights);
+static void CalculateDiffuseFieldAverage(const HrirDataT *hData, const uint channels, const uint m, const int weighted, const double limit, double *dfa)
+{
+ double *weights = CreateDoubles(hData->mFdCount * MAX_EV_COUNT);
+ uint count, ti, fi, ei, i, ai;
+
+ if(weighted)
+ {
+ // Use coverage weighting to calculate the average.
+ CalculateDfWeights(hData, weights);
+ }
+ else
+ {
+ double weight;
+
+ // If coverage weighting is not used, the weights still need to be
+ // averaged by the number of existing HRIRs.
+ count = hData->mIrCount;
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = 0;ei < hData->mFds[fi].mEvStart;ei++)
+ count -= hData->mFds[fi].mEvs[ei].mAzCount;
+ }
+ weight = 1.0 / count;
+
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvCount;ei++)
+ weights[(fi * MAX_EV_COUNT) + ei] = weight;
+ }
+ }
+ for(ti = 0;ti < channels;ti++)
+ {
+ for(i = 0;i < m;i++)
+ dfa[(ti * m) + i] = 0.0;
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ {
+ HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
+ // Get the weight for this HRIR's contribution.
+ double weight = weights[(fi * MAX_EV_COUNT) + ei];
+
+ // Add this HRIR's weighted power average to the total.
+ for(i = 0;i < m;i++)
+ dfa[(ti * m) + i] += weight * azd->mIrs[ti][i] * azd->mIrs[ti][i];
+ }
+ }
+ }
+ // Finish the average calculation and keep it from being too small.
+ for(i = 0;i < m;i++)
+ dfa[(ti * m) + i] = fmax(sqrt(dfa[(ti * m) + i]), EPSILON);
+ // Apply a limit to the magnitude range of the diffuse-field average
+ // if desired.
+ if(limit > 0.0)
+ LimitMagnitudeResponse(hData->mFftSize, m, limit, &dfa[ti * m], &dfa[ti * m]);
+ }
+ free(weights);
}
// Perform diffuse-field equalization on the magnitude responses of the HRIR
// set using the given average response.
-static void DiffuseFieldEqualize (const double * dfa, const HrirDataT * hData) {
- uint step, start, end, m, j, i;
+static void DiffuseFieldEqualize(const uint channels, const uint m, const double *dfa, const HrirDataT *hData)
+{
+ uint ti, fi, ei, ai, i;
- step = hData -> mIrSize;
- start = hData -> mEvOffset [hData -> mEvStart] * step;
- end = hData -> mIrCount * step;
- m = 1 + (hData -> mFftSize / 2);
- for (j = start; j < end; j += step) {
- for (i = 0; i < m; i ++)
- hData -> mHrirs [j + i] /= dfa [i];
- }
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ {
+ HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
+
+ for(ti = 0;ti < channels;ti++)
+ {
+ for(i = 0;i < m;i++)
+ azd->mIrs[ti][i] /= dfa[(ti * m) + i];
+ }
+ }
+ }
+ }
}
// Perform minimum-phase reconstruction using the magnitude responses of the
// HRIR set.
-static void ReconstructHrirs (const HrirDataT * hData) {
- double * re = NULL, * im = NULL;
- uint step, start, end, n, j, i;
-
- step = hData -> mIrSize;
- start = hData -> mEvOffset [hData -> mEvStart] * step;
- end = hData -> mIrCount * step;
- n = hData -> mFftSize;
- re = CreateArray (n);
- im = CreateArray (n);
- for (j = start; j < end; j += step) {
- MinimumPhase (n, & hData -> mHrirs [j], re, im);
- FftInverse (n, re, im, re, im);
- for (i = 0; i < hData -> mIrPoints; i ++)
- hData -> mHrirs [j + i] = re [i];
- }
- DestroyArray (im);
- DestroyArray (re);
+static void ReconstructHrirs(const HrirDataT *hData)
+{
+ uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1;
+ uint n = hData->mFftSize;
+ uint ti, fi, ei, ai, i;
+ Complex *h = CreateComplexes(n);
+ uint total, count, pcdone, lastpc;
+
+ total = hData->mIrCount;
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = 0;ei < hData->mFds[fi].mEvStart;ei++)
+ total -= hData->mFds[fi].mEvs[ei].mAzCount;
+ }
+ total *= channels;
+ count = pcdone = lastpc = 0;
+ printf("%3d%% done.", pcdone);
+ fflush(stdout);
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ {
+ HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
+
+ for(ti = 0;ti < channels;ti++)
+ {
+ MinimumPhase(n, azd->mIrs[ti], h);
+ FftInverse(n, h);
+ for(i = 0;i < hData->mIrPoints;i++)
+ azd->mIrs[ti][i] = h[i].Real;
+ pcdone = ++count * 100 / total;
+ if(pcdone != lastpc)
+ {
+ lastpc = pcdone;
+ printf("\r%3d%% done.", pcdone);
+ fflush(stdout);
+ }
+ }
+ }
+ }
+ }
+ printf("\n");
+ free(h);
}
// Resamples the HRIRs for use at the given sampling rate.
-static void ResampleHrirs (const uint rate, HrirDataT * hData) {
- ResamplerT rs;
- uint n, step, start, end, j;
-
- ResamplerSetup (& rs, hData -> mIrRate, rate);
- n = hData -> mIrPoints;
- step = hData -> mIrSize;
- start = hData -> mEvOffset [hData -> mEvStart] * step;
- end = hData -> mIrCount * step;
- for (j = start; j < end; j += step)
- ResamplerRun (& rs, n, & hData -> mHrirs [j], n, & hData -> mHrirs [j]);
- ResamplerClear (& rs);
- hData -> mIrRate = rate;
-}
-
-/* Given an elevation index and an azimuth, calculate the indices of the two
- * HRIRs that bound the coordinate along with a factor for calculating the
- * continous HRIR using interpolation.
+static void ResampleHrirs(const uint rate, HrirDataT *hData)
+{
+ uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1;
+ uint n = hData->mIrPoints;
+ uint ti, fi, ei, ai;
+ ResamplerT rs;
+
+ ResamplerSetup(&rs, hData->mIrRate, rate);
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ {
+ HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
+
+ for(ti = 0;ti < channels;ti++)
+ ResamplerRun(&rs, n, azd->mIrs[ti], n, azd->mIrs[ti]);
+ }
+ }
+ }
+ hData->mIrRate = rate;
+ ResamplerClear(&rs);
+}
+
+/* Given field and elevation indices and an azimuth, calculate the indices of
+ * the two HRIRs that bound the coordinate along with a factor for
+ * calculating the continuous HRIR using interpolation.
*/
-static void CalcAzIndices (const HrirDataT * hData, const uint ei, const double az, uint * j0, uint * j1, double * jf) {
- double af;
- uint ai;
-
- af = ((2.0 * M_PI) + az) * hData -> mAzCount [ei] / (2.0 * M_PI);
- ai = ((uint) af) % hData -> mAzCount [ei];
- af -= floor (af);
- (* j0) = hData -> mEvOffset [ei] + ai;
- (* j1) = hData -> mEvOffset [ei] + ((ai + 1) % hData -> mAzCount [ei]);
- (* jf) = af;
-}
-
-// Synthesize any missing onset timings at the bottom elevations. This just
-// blends between slightly exaggerated known onsets. Not an accurate model.
-static void SynthesizeOnsets (HrirDataT * hData) {
- uint oi, e, a, j0, j1;
- double t, of, jf;
-
- oi = hData -> mEvStart;
- t = 0.0;
- for (a = 0; a < hData -> mAzCount [oi]; a ++)
- t += hData -> mHrtds [hData -> mEvOffset [oi] + a];
- hData -> mHrtds [0] = 1.32e-4 + (t / hData -> mAzCount [oi]);
- for (e = 1; e < hData -> mEvStart; e ++) {
- of = ((double) e) / hData -> mEvStart;
- for (a = 0; a < hData -> mAzCount [e]; a ++) {
- CalcAzIndices (hData, oi, a * 2.0 * M_PI / hData -> mAzCount [e], & j0, & j1, & jf);
- hData -> mHrtds [hData -> mEvOffset [e] + a] = Lerp (hData -> mHrtds [0], Lerp (hData -> mHrtds [j0], hData -> mHrtds [j1], jf), of);
- }
- }
-}
-
-/* Attempt to synthesize any missing HRIRs at the bottom elevations. Right
- * now this just blends the lowest elevation HRIRs together and applies some
- * attenuation and high frequency damping. It is a simple, if inaccurate
- * model.
+static void CalcAzIndices(const HrirDataT *hData, const uint fi, const uint ei, const double az, uint *a0, uint *a1, double *af)
+{
+ double f = (2.0*M_PI + az) * hData->mFds[fi].mEvs[ei].mAzCount / (2.0*M_PI);
+ uint i = (uint)f % hData->mFds[fi].mEvs[ei].mAzCount;
+
+ f -= floor(f);
+ *a0 = i;
+ *a1 = (i + 1) % hData->mFds[fi].mEvs[ei].mAzCount;
+ *af = f;
+}
+
+// Synthesize any missing onset timings at the bottom elevations of each
+// field. This just blends between slightly exaggerated known onsets (not
+// an accurate model).
+static void SynthesizeOnsets(HrirDataT *hData)
+{
+ uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1;
+ uint ti, fi, oi, ai, ei, a0, a1;
+ double t, of, af;
+
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ if(hData->mFds[fi].mEvStart <= 0)
+ continue;
+ oi = hData->mFds[fi].mEvStart;
+
+ for(ti = 0;ti < channels;ti++)
+ {
+ t = 0.0;
+ for(ai = 0;ai < hData->mFds[fi].mEvs[oi].mAzCount;ai++)
+ t += hData->mFds[fi].mEvs[oi].mAzs[ai].mDelays[ti];
+ hData->mFds[fi].mEvs[0].mAzs[0].mDelays[ti] = 1.32e-4 + (t / hData->mFds[fi].mEvs[oi].mAzCount);
+ for(ei = 1;ei < hData->mFds[fi].mEvStart;ei++)
+ {
+ of = (double)ei / hData->mFds[fi].mEvStart;
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ {
+ CalcAzIndices(hData, fi, oi, hData->mFds[fi].mEvs[ei].mAzs[ai].mAzimuth, &a0, &a1, &af);
+ hData->mFds[fi].mEvs[ei].mAzs[ai].mDelays[ti] = Lerp(
+ hData->mFds[fi].mEvs[0].mAzs[0].mDelays[ti],
+ Lerp(hData->mFds[fi].mEvs[oi].mAzs[a0].mDelays[ti],
+ hData->mFds[fi].mEvs[oi].mAzs[a1].mDelays[ti], af),
+ of
+ );
+ }
+ }
+ }
+ }
+}
+
+/* Attempt to synthesize any missing HRIRs at the bottom elevations of each
+ * field. Right now this just blends the lowest elevation HRIRs together and
+ * applies some attenuation and high frequency damping. It is a simple, if
+ * inaccurate model.
*/
-static void SynthesizeHrirs (HrirDataT * hData) {
- uint oi, a, e, step, n, i, j;
- double of, b;
- uint j0, j1;
- double jf;
- double lp [4], s0, s1;
-
- if (hData -> mEvStart <= 0)
- return;
- step = hData -> mIrSize;
- oi = hData -> mEvStart;
- n = hData -> mIrPoints;
- for (i = 0; i < n; i ++)
- hData -> mHrirs [i] = 0.0;
- for (a = 0; a < hData -> mAzCount [oi]; a ++) {
- j = (hData -> mEvOffset [oi] + a) * step;
- for (i = 0; i < n; i ++)
- hData -> mHrirs [i] += hData -> mHrirs [j + i] / hData -> mAzCount [oi];
- }
- for (e = 1; e < hData -> mEvStart; e ++) {
- of = ((double) e) / hData -> mEvStart;
- b = (1.0 - of) * (3.5e-6 * hData -> mIrRate);
- for (a = 0; a < hData -> mAzCount [e]; a ++) {
- j = (hData -> mEvOffset [e] + a) * step;
- CalcAzIndices (hData, oi, a * 2.0 * M_PI / hData -> mAzCount [e], & j0, & j1, & jf);
- j0 *= step;
- j1 *= step;
- lp [0] = 0.0;
- lp [1] = 0.0;
- lp [2] = 0.0;
- lp [3] = 0.0;
- for (i = 0; i < n; i ++) {
- s0 = hData -> mHrirs [i];
- s1 = Lerp (hData -> mHrirs [j0 + i], hData -> mHrirs [j1 + i], jf);
- s0 = Lerp (s0, s1, of);
- lp [0] = Lerp (s0, lp [0], b);
- lp [1] = Lerp (lp [0], lp [1], b);
- lp [2] = Lerp (lp [1], lp [2], b);
- lp [3] = Lerp (lp [2], lp [3], b);
- hData -> mHrirs [j + i] = lp [3];
- }
- }
- }
- b = 3.5e-6 * hData -> mIrRate;
- lp [0] = 0.0;
- lp [1] = 0.0;
- lp [2] = 0.0;
- lp [3] = 0.0;
- for (i = 0; i < n; i ++) {
- s0 = hData -> mHrirs [i];
- lp [0] = Lerp (s0, lp [0], b);
- lp [1] = Lerp (lp [0], lp [1], b);
- lp [2] = Lerp (lp [1], lp [2], b);
- lp [3] = Lerp (lp [2], lp [3], b);
- hData -> mHrirs [i] = lp [3];
- }
- hData -> mEvStart = 0;
+static void SynthesizeHrirs(HrirDataT *hData)
+{
+ uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1;
+ uint n = hData->mIrPoints;
+ uint ti, fi, ai, ei, i;
+ double lp[4], s0, s1;
+ double of, b;
+ uint a0, a1;
+ double af;
+
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ const uint oi = hData->mFds[fi].mEvStart;
+ if(oi <= 0) continue;
+
+ for(ti = 0;ti < channels;ti++)
+ {
+ for(i = 0;i < n;i++)
+ hData->mFds[fi].mEvs[0].mAzs[0].mIrs[ti][i] = 0.0;
+ for(ai = 0;ai < hData->mFds[fi].mEvs[oi].mAzCount;ai++)
+ {
+ for(i = 0;i < n;i++)
+ hData->mFds[fi].mEvs[0].mAzs[0].mIrs[ti][i] += hData->mFds[fi].mEvs[oi].mAzs[ai].mIrs[ti][i] /
+ hData->mFds[fi].mEvs[oi].mAzCount;
+ }
+ for(ei = 1;ei < hData->mFds[fi].mEvStart;ei++)
+ {
+ of = (double)ei / hData->mFds[fi].mEvStart;
+ b = (1.0 - of) * (3.5e-6 * hData->mIrRate);
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ {
+ CalcAzIndices(hData, fi, oi, hData->mFds[fi].mEvs[ei].mAzs[ai].mAzimuth, &a0, &a1, &af);
+ lp[0] = 0.0;
+ lp[1] = 0.0;
+ lp[2] = 0.0;
+ lp[3] = 0.0;
+ for(i = 0;i < n;i++)
+ {
+ s0 = hData->mFds[fi].mEvs[0].mAzs[0].mIrs[ti][i];
+ s1 = Lerp(hData->mFds[fi].mEvs[oi].mAzs[a0].mIrs[ti][i],
+ hData->mFds[fi].mEvs[oi].mAzs[a1].mIrs[ti][i], af);
+ s0 = Lerp(s0, s1, of);
+ lp[0] = Lerp(s0, lp[0], b);
+ lp[1] = Lerp(lp[0], lp[1], b);
+ lp[2] = Lerp(lp[1], lp[2], b);
+ lp[3] = Lerp(lp[2], lp[3], b);
+ hData->mFds[fi].mEvs[ei].mAzs[ai].mIrs[ti][i] = lp[3];
+ }
+ }
+ }
+ b = 3.5e-6 * hData->mIrRate;
+ lp[0] = 0.0;
+ lp[1] = 0.0;
+ lp[2] = 0.0;
+ lp[3] = 0.0;
+ for(i = 0;i < n;i++)
+ {
+ s0 = hData->mFds[fi].mEvs[0].mAzs[0].mIrs[ti][i];
+ lp[0] = Lerp(s0, lp[0], b);
+ lp[1] = Lerp(lp[0], lp[1], b);
+ lp[2] = Lerp(lp[1], lp[2], b);
+ lp[3] = Lerp(lp[2], lp[3], b);
+ hData->mFds[fi].mEvs[0].mAzs[0].mIrs[ti][i] = lp[3];
+ }
+ }
+ hData->mFds[fi].mEvStart = 0;
+ }
}
// The following routines assume a full set of HRIRs for all elevations.
// Normalize the HRIR set and slightly attenuate the result.
-static void NormalizeHrirs (const HrirDataT * hData) {
- uint step, end, n, j, i;
- double maxLevel;
-
- step = hData -> mIrSize;
- end = hData -> mIrCount * step;
- n = hData -> mIrPoints;
- maxLevel = 0.0;
- for (j = 0; j < end; j += step) {
- for (i = 0; i < n; i ++)
- maxLevel = fmax (fabs (hData -> mHrirs [j + i]), maxLevel);
- }
- maxLevel = 1.01 * maxLevel;
- for (j = 0; j < end; j += step) {
- for (i = 0; i < n; i ++)
- hData -> mHrirs [j + i] /= maxLevel;
- }
+static void NormalizeHrirs(const HrirDataT *hData)
+{
+ uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1;
+ uint n = hData->mIrPoints;
+ uint ti, fi, ei, ai, i;
+ double maxLevel = 0.0;
+
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ {
+ HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
+
+ for(ti = 0;ti < channels;ti++)
+ {
+ for(i = 0;i < n;i++)
+ maxLevel = fmax(fabs(azd->mIrs[ti][i]), maxLevel);
+ }
+ }
+ }
+ }
+ maxLevel = 1.01 * maxLevel;
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ {
+ HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
+
+ for(ti = 0;ti < channels;ti++)
+ {
+ for(i = 0;i < n;i++)
+ azd->mIrs[ti][i] /= maxLevel;
+ }
+ }
+ }
+ }
}
// Calculate the left-ear time delay using a spherical head model.
-static double CalcLTD (const double ev, const double az, const double rad, const double dist) {
- double azp, dlp, l, al;
+static double CalcLTD(const double ev, const double az, const double rad, const double dist)
+{
+ double azp, dlp, l, al;
- azp = asin (cos (ev) * sin (az));
- dlp = sqrt ((dist * dist) + (rad * rad) + (2.0 * dist * rad * sin (azp)));
- l = sqrt ((dist * dist) - (rad * rad));
- al = (0.5 * M_PI) + azp;
- if (dlp > l)
- dlp = l + (rad * (al - acos (rad / dist)));
- return (dlp / 343.3);
+ azp = asin(cos(ev) * sin(az));
+ dlp = sqrt((dist*dist) + (rad*rad) + (2.0*dist*rad*sin(azp)));
+ l = sqrt((dist*dist) - (rad*rad));
+ al = (0.5 * M_PI) + azp;
+ if(dlp > l)
+ dlp = l + (rad * (al - acos(rad / dist)));
+ return dlp / 343.3;
}
// Calculate the effective head-related time delays for each minimum-phase
// HRIR.
-static void CalculateHrtds (const HeadModelT model, const double radius, HrirDataT * hData) {
- double minHrtd, maxHrtd;
- uint e, a, j;
- double t;
-
- minHrtd = 1000.0;
- maxHrtd = -1000.0;
- for (e = 0; e < hData -> mEvCount; e ++) {
- for (a = 0; a < hData -> mAzCount [e]; a ++) {
- j = hData -> mEvOffset [e] + a;
- if (model == HM_DATASET) {
- t = hData -> mHrtds [j] * radius / hData -> mRadius;
- } else {
- t = CalcLTD ((-90.0 + (e * 180.0 / (hData -> mEvCount - 1))) * M_PI / 180.0,
- (a * 360.0 / hData -> mAzCount [e]) * M_PI / 180.0,
- radius, hData -> mDistance);
- }
- hData -> mHrtds [j] = t;
- maxHrtd = fmax (t, maxHrtd);
- minHrtd = fmin (t, minHrtd);
- }
- }
- maxHrtd -= minHrtd;
- for (j = 0; j < hData -> mIrCount; j ++)
- hData -> mHrtds [j] -= minHrtd;
- hData -> mMaxHrtd = maxHrtd;
+static void CalculateHrtds(const HeadModelT model, const double radius, HrirDataT *hData)
+{
+ uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1;
+ double minHrtd = INFINITY, maxHrtd = -INFINITY;
+ uint ti, fi, ei, ai;
+ double t;
+
+ if(model == HM_DATASET)
+ {
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ {
+ HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
+
+ for(ti = 0;ti < channels;ti++)
+ {
+ t = azd->mDelays[ti] * radius / hData->mRadius;
+ azd->mDelays[ti] = t;
+ maxHrtd = fmax(t, maxHrtd);
+ minHrtd = fmin(t, minHrtd);
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ HrirEvT *evd = &hData->mFds[fi].mEvs[ei];
+
+ for(ai = 0;ai < evd->mAzCount;ai++)
+ {
+ HrirAzT *azd = &evd->mAzs[ai];
+
+ for(ti = 0;ti < channels;ti++)
+ {
+ t = CalcLTD(evd->mElevation, azd->mAzimuth, radius, hData->mFds[fi].mDistance);
+ azd->mDelays[ti] = t;
+ maxHrtd = fmax(t, maxHrtd);
+ minHrtd = fmin(t, minHrtd);
+ }
+ }
+ }
+ }
+ }
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ for(ti = 0;ti < channels;ti++)
+ {
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ hData->mFds[fi].mEvs[ei].mAzs[ai].mDelays[ti] -= minHrtd;
+ }
+ }
+ }
}
-// Store the OpenAL Soft HRTF data set.
-static int StoreMhr (const HrirDataT * hData, const char * filename) {
- FILE * fp = NULL;
- uint e, step, end, n, j, i;
- int hpHist, v;
-
- if ((fp = fopen (filename, "wb")) == NULL) {
- fprintf (stderr, "Error: Could not open MHR file '%s'.\n", filename);
- return (0);
- }
- if (! WriteAscii (MHR_FORMAT, fp, filename))
- return (0);
- if (! WriteBin4 (BO_LITTLE, 4, (uint32) hData -> mIrRate, fp, filename))
- return (0);
- if (! WriteBin4 (BO_LITTLE, 1, (uint32) hData -> mIrPoints, fp, filename))
- return (0);
- if (! WriteBin4 (BO_LITTLE, 1, (uint32) hData -> mEvCount, fp, filename))
- return (0);
- for (e = 0; e < hData -> mEvCount; e ++) {
- if (! WriteBin4 (BO_LITTLE, 1, (uint32) hData -> mAzCount [e], fp, filename))
- return (0);
- }
- step = hData -> mIrSize;
- end = hData -> mIrCount * step;
- n = hData -> mIrPoints;
- srand (0x31DF840C);
- for (j = 0; j < end; j += step) {
- hpHist = 0;
- for (i = 0; i < n; i ++) {
- v = HpTpdfDither (32767.0 * hData -> mHrirs [j + i], & hpHist);
- if (! WriteBin4 (BO_LITTLE, 2, (uint32) v, fp, filename))
- return (0);
- }
- }
- for (j = 0; j < hData -> mIrCount; j ++) {
- v = (int) fmin (round (hData -> mIrRate * hData -> mHrtds [j]), MAX_HRTD);
- if (! WriteBin4 (BO_LITTLE, 1, (uint32) v, fp, filename))
- return (0);
- }
- fclose (fp);
- return (1);
+// Clear the initial HRIR data state.
+static void ResetHrirData(HrirDataT *hData)
+{
+ hData->mIrRate = 0;
+ hData->mSampleType = ST_S24;
+ hData->mChannelType = CT_NONE;
+ hData->mIrPoints = 0;
+ hData->mFftSize = 0;
+ hData->mIrSize = 0;
+ hData->mRadius = 0.0;
+ hData->mIrCount = 0;
+ hData->mFdCount = 0;
+ hData->mFds = NULL;
+}
+
+// Allocate and configure dynamic HRIR structures.
+static int PrepareHrirData(const uint fdCount, const double distances[MAX_FD_COUNT], const uint evCounts[MAX_FD_COUNT], const uint azCounts[MAX_FD_COUNT * MAX_EV_COUNT], HrirDataT *hData)
+{
+ uint evTotal = 0, azTotal = 0, fi, ei, ai;
+
+ for(fi = 0;fi < fdCount;fi++)
+ {
+ evTotal += evCounts[fi];
+ for(ei = 0;ei < evCounts[fi];ei++)
+ azTotal += azCounts[(fi * MAX_EV_COUNT) + ei];
+ }
+ if(!fdCount || !evTotal || !azTotal)
+ return 0;
+
+ hData->mFds = calloc(fdCount, sizeof(*hData->mFds));
+ if(hData->mFds == NULL)
+ return 0;
+ hData->mFds[0].mEvs = calloc(evTotal, sizeof(*hData->mFds[0].mEvs));
+ if(hData->mFds[0].mEvs == NULL)
+ return 0;
+ hData->mFds[0].mEvs[0].mAzs = calloc(azTotal, sizeof(*hData->mFds[0].mEvs[0].mAzs));
+ if(hData->mFds[0].mEvs[0].mAzs == NULL)
+ return 0;
+ hData->mIrCount = azTotal;
+ hData->mFdCount = fdCount;
+ evTotal = 0;
+ azTotal = 0;
+ for(fi = 0;fi < fdCount;fi++)
+ {
+ hData->mFds[fi].mDistance = distances[fi];
+ hData->mFds[fi].mEvCount = evCounts[fi];
+ hData->mFds[fi].mEvStart = 0;
+ hData->mFds[fi].mEvs = &hData->mFds[0].mEvs[evTotal];
+ evTotal += evCounts[fi];
+ for(ei = 0;ei < evCounts[fi];ei++)
+ {
+ uint azCount = azCounts[(fi * MAX_EV_COUNT) + ei];
+
+ hData->mFds[fi].mIrCount += azCount;
+ hData->mFds[fi].mEvs[ei].mElevation = -M_PI / 2.0 + M_PI * ei / (evCounts[fi] - 1);
+ hData->mFds[fi].mEvs[ei].mIrCount += azCount;
+ hData->mFds[fi].mEvs[ei].mAzCount = azCount;
+ hData->mFds[fi].mEvs[ei].mAzs = &hData->mFds[0].mEvs[0].mAzs[azTotal];
+ for(ai = 0;ai < azCount;ai++)
+ {
+ hData->mFds[fi].mEvs[ei].mAzs[ai].mAzimuth = 2.0 * M_PI * ai / azCount;
+ hData->mFds[fi].mEvs[ei].mAzs[ai].mIndex = azTotal + ai;
+ hData->mFds[fi].mEvs[ei].mAzs[ai].mDelays[0] = 0.0;
+ hData->mFds[fi].mEvs[ei].mAzs[ai].mDelays[1] = 0.0;
+ hData->mFds[fi].mEvs[ei].mAzs[ai].mIrs[0] = NULL;
+ hData->mFds[fi].mEvs[ei].mAzs[ai].mIrs[1] = NULL;
+ }
+ azTotal += azCount;
+ }
+ }
+ return 1;
+}
+
+// Clean up HRIR data.
+static void FreeHrirData(HrirDataT *hData)
+{
+ if(hData->mFds != NULL)
+ {
+ if(hData->mFds[0].mEvs != NULL)
+ {
+ if(hData->mFds[0].mEvs[0].mAzs)
+ {
+ free(hData->mFds[0].mEvs[0].mAzs[0].mIrs[0]);
+ free(hData->mFds[0].mEvs[0].mAzs);
+ }
+ free(hData->mFds[0].mEvs);
+ }
+ free(hData->mFds);
+ hData->mFds = NULL;
+ }
+}
+
+// Match the channel type from a given identifier.
+static ChannelTypeT MatchChannelType(const char *ident)
+{
+ if(strcasecmp(ident, "mono") == 0)
+ return CT_MONO;
+ if(strcasecmp(ident, "stereo") == 0)
+ return CT_STEREO;
+ return CT_NONE;
}
// Process the data set definition to read and validate the data set metrics.
-static int ProcessMetrics (TokenReaderT * tr, const uint fftSize, const uint truncSize, HrirDataT * hData) {
- char ident [MAX_IDENT_LEN + 1];
- uint line, col;
- int intVal;
- uint points;
- double fpVal;
- int hasRate = 0, hasPoints = 0, hasAzimuths = 0;
- int hasRadius = 0, hasDistance = 0;
-
- while (! (hasRate && hasPoints && hasAzimuths && hasRadius && hasDistance)) {
- TrIndication (tr, & line, & col);
- if (! TrReadIdent (tr, MAX_IDENT_LEN, ident))
- return (0);
- if (strcasecmp (ident, "rate") == 0) {
- if (hasRate) {
- TrErrorAt (tr, line, col, "Redefinition of 'rate'.\n");
- return (0);
- }
- if (! TrReadOperator (tr, "="))
- return (0);
- if (! TrReadInt (tr, MIN_RATE, MAX_RATE, & intVal))
- return (0);
- hData -> mIrRate = (uint) intVal;
- hasRate = 1;
- } else if (strcasecmp (ident, "points") == 0) {
- if (hasPoints) {
- TrErrorAt (tr, line, col, "Redefinition of 'points'.\n");
- return (0);
- }
- if (! TrReadOperator (tr, "="))
- return (0);
- TrIndication (tr, & line, & col);
- if (! TrReadInt (tr, MIN_POINTS, MAX_POINTS, & intVal))
- return (0);
- points = (uint) intVal;
- if ((fftSize > 0) && (points > fftSize)) {
- TrErrorAt (tr, line, col, "Value exceeds the overridden FFT size.\n");
- return (0);
- }
- if (points < truncSize) {
- TrErrorAt (tr, line, col, "Value is below the truncation size.\n");
- return (0);
- }
- hData -> mIrPoints = points;
- hData -> mFftSize = fftSize;
- if (fftSize <= 0) {
- points = 1;
- while (points < (4 * hData -> mIrPoints))
- points <<= 1;
- hData -> mFftSize = points;
- hData -> mIrSize = 1 + (points / 2);
- } else {
- hData -> mFftSize = fftSize;
- hData -> mIrSize = 1 + (fftSize / 2);
- if (points > hData -> mIrSize)
- hData -> mIrSize = points;
- }
- hasPoints = 1;
- } else if (strcasecmp (ident, "azimuths") == 0) {
- if (hasAzimuths) {
- TrErrorAt (tr, line, col, "Redefinition of 'azimuths'.\n");
- return (0);
- }
- if (! TrReadOperator (tr, "="))
- return (0);
- hData -> mIrCount = 0;
- hData -> mEvCount = 0;
- hData -> mEvOffset [0] = 0;
- for (;;) {
- if (! TrReadInt (tr, MIN_AZ_COUNT, MAX_AZ_COUNT, & intVal))
- return (0);
- hData -> mAzCount [hData -> mEvCount] = (uint) intVal;
- hData -> mIrCount += (uint) intVal;
- hData -> mEvCount ++;
- if (! TrIsOperator (tr, ","))
- break;
- if (hData -> mEvCount >= MAX_EV_COUNT) {
- TrError (tr, "Exceeded the maximum of %d elevations.\n", MAX_EV_COUNT);
- return (0);
- }
- hData -> mEvOffset [hData -> mEvCount] = hData -> mEvOffset [hData -> mEvCount - 1] + ((uint) intVal);
- TrReadOperator (tr, ",");
- }
- if (hData -> mEvCount < MIN_EV_COUNT) {
- TrErrorAt (tr, line, col, "Did not reach the minimum of %d azimuth counts.\n", MIN_EV_COUNT);
- return (0);
- }
- hasAzimuths = 1;
- } else if (strcasecmp (ident, "radius") == 0) {
- if (hasRadius) {
- TrErrorAt (tr, line, col, "Redefinition of 'radius'.\n");
- return (0);
- }
- if (! TrReadOperator (tr, "="))
- return (0);
- if (! TrReadFloat (tr, MIN_RADIUS, MAX_RADIUS, & fpVal))
- return (0);
- hData -> mRadius = fpVal;
- hasRadius = 1;
- } else if (strcasecmp (ident, "distance") == 0) {
- if (hasDistance) {
- TrErrorAt (tr, line, col, "Redefinition of 'distance'.\n");
- return (0);
- }
- if (! TrReadOperator (tr, "="))
- return (0);
- if (! TrReadFloat (tr, MIN_DISTANCE, MAX_DISTANCE, & fpVal))
- return (0);
- hData -> mDistance = fpVal;
- hasDistance = 1;
- } else {
- TrErrorAt (tr, line, col, "Expected a metric name.\n");
- return (0);
- }
- TrSkipWhitespace (tr);
- }
- return (1);
-}
-
-// Parse an index pair from the data set definition.
-static int ReadIndexPair (TokenReaderT * tr, const HrirDataT * hData, uint * ei, uint * ai) {
- int intVal;
-
- if (! TrReadInt (tr, 0, (int) hData -> mEvCount, & intVal))
- return (0);
- (* ei) = (uint) intVal;
- if (! TrReadOperator (tr, ","))
- return (0);
- if (! TrReadInt (tr, 0, (int) hData -> mAzCount [(* ei)], & intVal))
- return (0);
- (* ai) = (uint) intVal;
- return (1);
+static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint truncSize, HrirDataT *hData)
+{
+ int hasRate = 0, hasType = 0, hasPoints = 0, hasRadius = 0;
+ int hasDistance = 0, hasAzimuths = 0;
+ char ident[MAX_IDENT_LEN+1];
+ uint line, col;
+ double fpVal;
+ uint points;
+ int intVal;
+ double distances[MAX_FD_COUNT];
+ uint fdCount = 0;
+ uint evCounts[MAX_FD_COUNT];
+ uint *azCounts = calloc(MAX_FD_COUNT * MAX_EV_COUNT, sizeof(*azCounts));
+
+ if(azCounts == NULL)
+ {
+ fprintf(stderr, "Error: Out of memory.\n");
+ exit(-1);
+ }
+ TrIndication(tr, &line, &col);
+ while(TrIsIdent(tr))
+ {
+ TrIndication(tr, &line, &col);
+ if(!TrReadIdent(tr, MAX_IDENT_LEN, ident))
+ goto error;
+ if(strcasecmp(ident, "rate") == 0)
+ {
+ if(hasRate)
+ {
+ TrErrorAt(tr, line, col, "Redefinition of 'rate'.\n");
+ goto error;
+ }
+ if(!TrReadOperator(tr, "="))
+ goto error;
+ if(!TrReadInt(tr, MIN_RATE, MAX_RATE, &intVal))
+ goto error;
+ hData->mIrRate = (uint)intVal;
+ hasRate = 1;
+ }
+ else if(strcasecmp(ident, "type") == 0)
+ {
+ char type[MAX_IDENT_LEN+1];
+
+ if(hasType)
+ {
+ TrErrorAt(tr, line, col, "Redefinition of 'type'.\n");
+ goto error;
+ }
+ if(!TrReadOperator(tr, "="))
+ goto error;
+
+ if(!TrReadIdent(tr, MAX_IDENT_LEN, type))
+ goto error;
+ hData->mChannelType = MatchChannelType(type);
+ if(hData->mChannelType == CT_NONE)
+ {
+ TrErrorAt(tr, line, col, "Expected a channel type.\n");
+ goto error;
+ }
+ hasType = 1;
+ }
+ else if(strcasecmp(ident, "points") == 0)
+ {
+ if(hasPoints)
+ {
+ TrErrorAt(tr, line, col, "Redefinition of 'points'.\n");
+ goto error;
+ }
+ if(!TrReadOperator(tr, "="))
+ goto error;
+ TrIndication(tr, &line, &col);
+ if(!TrReadInt(tr, MIN_POINTS, MAX_POINTS, &intVal))
+ goto error;
+ points = (uint)intVal;
+ if(fftSize > 0 && points > fftSize)
+ {
+ TrErrorAt(tr, line, col, "Value exceeds the overridden FFT size.\n");
+ goto error;
+ }
+ if(points < truncSize)
+ {
+ TrErrorAt(tr, line, col, "Value is below the truncation size.\n");
+ goto error;
+ }
+ hData->mIrPoints = points;
+ if(fftSize <= 0)
+ {
+ hData->mFftSize = DEFAULT_FFTSIZE;
+ hData->mIrSize = 1 + (DEFAULT_FFTSIZE / 2);
+ }
+ else
+ {
+ hData->mFftSize = fftSize;
+ hData->mIrSize = 1 + (fftSize / 2);
+ if(points > hData->mIrSize)
+ hData->mIrSize = points;
+ }
+ hasPoints = 1;
+ }
+ else if(strcasecmp(ident, "radius") == 0)
+ {
+ if(hasRadius)
+ {
+ TrErrorAt(tr, line, col, "Redefinition of 'radius'.\n");
+ goto error;
+ }
+ if(!TrReadOperator(tr, "="))
+ goto error;
+ if(!TrReadFloat(tr, MIN_RADIUS, MAX_RADIUS, &fpVal))
+ goto error;
+ hData->mRadius = fpVal;
+ hasRadius = 1;
+ }
+ else if(strcasecmp(ident, "distance") == 0)
+ {
+ uint count = 0;
+
+ if(hasDistance)
+ {
+ TrErrorAt(tr, line, col, "Redefinition of 'distance'.\n");
+ goto error;
+ }
+ if(!TrReadOperator(tr, "="))
+ goto error;
+
+ for(;;)
+ {
+ if(!TrReadFloat(tr, MIN_DISTANCE, MAX_DISTANCE, &fpVal))
+ goto error;
+ if(count > 0 && fpVal <= distances[count - 1])
+ {
+ TrError(tr, "Distances are not ascending.\n");
+ goto error;
+ }
+ distances[count++] = fpVal;
+ if(!TrIsOperator(tr, ","))
+ break;
+ if(count >= MAX_FD_COUNT)
+ {
+ TrError(tr, "Exceeded the maximum of %d fields.\n", MAX_FD_COUNT);
+ goto error;
+ }
+ TrReadOperator(tr, ",");
+ }
+ if(fdCount != 0 && count != fdCount)
+ {
+ TrError(tr, "Did not match the specified number of %d fields.\n", fdCount);
+ goto error;
+ }
+ fdCount = count;
+ hasDistance = 1;
+ }
+ else if(strcasecmp(ident, "azimuths") == 0)
+ {
+ uint count = 0;
+
+ if(hasAzimuths)
+ {
+ TrErrorAt(tr, line, col, "Redefinition of 'azimuths'.\n");
+ goto error;
+ }
+ if(!TrReadOperator(tr, "="))
+ goto error;
+
+ evCounts[0] = 0;
+ for(;;)
+ {
+ if(!TrReadInt(tr, MIN_AZ_COUNT, MAX_AZ_COUNT, &intVal))
+ goto error;
+ azCounts[(count * MAX_EV_COUNT) + evCounts[count]++] = (uint)intVal;
+ if(TrIsOperator(tr, ","))
+ {
+ if(evCounts[count] >= MAX_EV_COUNT)
+ {
+ TrError(tr, "Exceeded the maximum of %d elevations.\n", MAX_EV_COUNT);
+ goto error;
+ }
+ TrReadOperator(tr, ",");
+ }
+ else
+ {
+ if(evCounts[count] < MIN_EV_COUNT)
+ {
+ TrErrorAt(tr, line, col, "Did not reach the minimum of %d azimuth counts.\n", MIN_EV_COUNT);
+ goto error;
+ }
+ if(azCounts[count * MAX_EV_COUNT] != 1 || azCounts[(count * MAX_EV_COUNT) + evCounts[count] - 1] != 1)
+ {
+ TrError(tr, "Poles are not singular for field %d.\n", count - 1);
+ goto error;
+ }
+ count++;
+ if(TrIsOperator(tr, ";"))
+ {
+ if(count >= MAX_FD_COUNT)
+ {
+ TrError(tr, "Exceeded the maximum number of %d fields.\n", MAX_FD_COUNT);
+ goto error;
+ }
+ evCounts[count] = 0;
+ TrReadOperator(tr, ";");
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+ if(fdCount != 0 && count != fdCount)
+ {
+ TrError(tr, "Did not match the specified number of %d fields.\n", fdCount);
+ goto error;
+ }
+ fdCount = count;
+ hasAzimuths = 1;
+ }
+ else
+ {
+ TrErrorAt(tr, line, col, "Expected a metric name.\n");
+ goto error;
+ }
+ TrSkipWhitespace(tr);
+ }
+ if(!(hasRate && hasPoints && hasRadius && hasDistance && hasAzimuths))
+ {
+ TrErrorAt(tr, line, col, "Expected a metric name.\n");
+ goto error;
+ }
+ if(distances[0] < hData->mRadius)
+ {
+ TrError(tr, "Distance cannot start below head radius.\n");
+ goto error;
+ }
+ if(hData->mChannelType == CT_NONE)
+ hData->mChannelType = CT_MONO;
+ if(!PrepareHrirData(fdCount, distances, evCounts, azCounts, hData))
+ {
+ fprintf(stderr, "Error: Out of memory.\n");
+ exit(-1);
+ }
+ free(azCounts);
+ return 1;
+
+error:
+ free(azCounts);
+ return 0;
+}
+
+// Parse an index triplet from the data set definition.
+static int ReadIndexTriplet(TokenReaderT *tr, const HrirDataT *hData, uint *fi, uint *ei, uint *ai)
+{
+ int intVal;
+
+ if(hData->mFdCount > 1)
+ {
+ if(!TrReadInt(tr, 0, (int)hData->mFdCount - 1, &intVal))
+ return 0;
+ *fi = (uint)intVal;
+ if(!TrReadOperator(tr, ","))
+ return 0;
+ }
+ else
+ {
+ *fi = 0;
+ }
+ if(!TrReadInt(tr, 0, (int)hData->mFds[*fi].mEvCount - 1, &intVal))
+ return 0;
+ *ei = (uint)intVal;
+ if(!TrReadOperator(tr, ","))
+ return 0;
+ if(!TrReadInt(tr, 0, (int)hData->mFds[*fi].mEvs[*ei].mAzCount - 1, &intVal))
+ return 0;
+ *ai = (uint)intVal;
+ return 1;
}
// Match the source format from a given identifier.
-static SourceFormatT MatchSourceFormat (const char * ident) {
- if (strcasecmp (ident, "wave") == 0)
- return (SF_WAVE);
- else if (strcasecmp (ident, "bin_le") == 0)
- return (SF_BIN_LE);
- else if (strcasecmp (ident, "bin_be") == 0)
- return (SF_BIN_BE);
- else if (strcasecmp (ident, "ascii") == 0)
- return (SF_ASCII);
- return (SF_NONE);
+static SourceFormatT MatchSourceFormat(const char *ident)
+{
+ if(strcasecmp(ident, "wave") == 0)
+ return SF_WAVE;
+ if(strcasecmp(ident, "bin_le") == 0)
+ return SF_BIN_LE;
+ if(strcasecmp(ident, "bin_be") == 0)
+ return SF_BIN_BE;
+ if(strcasecmp(ident, "ascii") == 0)
+ return SF_ASCII;
+ return SF_NONE;
}
// Match the source element type from a given identifier.
-static ElementTypeT MatchElementType (const char * ident) {
- if (strcasecmp (ident, "int") == 0)
- return (ET_INT);
- else if (strcasecmp (ident, "fp") == 0)
- return (ET_FP);
- return (ET_NONE);
+static ElementTypeT MatchElementType(const char *ident)
+{
+ if(strcasecmp(ident, "int") == 0)
+ return ET_INT;
+ if(strcasecmp(ident, "fp") == 0)
+ return ET_FP;
+ return ET_NONE;
}
// Parse and validate a source reference from the data set definition.
-static int ReadSourceRef (TokenReaderT * tr, SourceRefT * src) {
- uint line, col;
- char ident [MAX_IDENT_LEN + 1];
- int intVal;
-
- TrIndication (tr, & line, & col);
- if (! TrReadIdent (tr, MAX_IDENT_LEN, ident))
- return (0);
- src -> mFormat = MatchSourceFormat (ident);
- if (src -> mFormat == SF_NONE) {
- TrErrorAt (tr, line, col, "Expected a source format.\n");
- return (0);
- }
- if (! TrReadOperator (tr, "("))
- return (0);
- if (src -> mFormat == SF_WAVE) {
- if (! TrReadInt (tr, 0, MAX_WAVE_CHANNELS, & intVal))
- return (0);
- src -> mType = ET_NONE;
- src -> mSize = 0;
- src -> mBits = 0;
- src -> mChannel = (uint) intVal;
- src -> mSkip = 0;
- } else {
- TrIndication (tr, & line, & col);
- if (! TrReadIdent (tr, MAX_IDENT_LEN, ident))
- return (0);
- src -> mType = MatchElementType (ident);
- if (src -> mType == ET_NONE) {
- TrErrorAt (tr, line, col, "Expected a source element type.\n");
- return (0);
- }
- if ((src -> mFormat == SF_BIN_LE) || (src -> mFormat == SF_BIN_BE)) {
- if (! TrReadOperator (tr, ","))
- return (0);
- if (src -> mType == ET_INT) {
- if (! TrReadInt (tr, MIN_BIN_SIZE, MAX_BIN_SIZE, & intVal))
- return (0);
- src -> mSize = (uint) intVal;
- if (TrIsOperator (tr, ",")) {
- TrReadOperator (tr, ",");
- TrIndication (tr, & line, & col);
- if (! TrReadInt (tr, -2147483647 - 1, 2147483647, & intVal))
- return (0);
- if ((abs (intVal) < MIN_BIN_BITS) || (((uint) abs (intVal)) > (8 * src -> mSize))) {
- TrErrorAt (tr, line, col, "Expected a value of (+/-) %d to %d.\n", MIN_BIN_BITS, 8 * src -> mSize);
- return (0);
- }
- src -> mBits = intVal;
- } else {
- src -> mBits = (int) (8 * src -> mSize);
- }
- } else {
- TrIndication (tr, & line, & col);
- if (! TrReadInt (tr, -2147483647 - 1, 2147483647, & intVal))
- return (0);
- if ((intVal != 4) && (intVal != 8)) {
- TrErrorAt (tr, line, col, "Expected a value of 4 or 8.\n");
- return (0);
- }
- src -> mSize = (uint) intVal;
- src -> mBits = 0;
- }
- } else if ((src -> mFormat == SF_ASCII) && (src -> mType == ET_INT)) {
- if (! TrReadOperator (tr, ","))
- return (0);
- if (! TrReadInt (tr, MIN_ASCII_BITS, MAX_ASCII_BITS, & intVal))
- return (0);
- src -> mSize = 0;
- src -> mBits = intVal;
- } else {
- src -> mSize = 0;
- src -> mBits = 0;
- }
- if (TrIsOperator (tr, ";")) {
- TrReadOperator (tr, ";");
- if (! TrReadInt (tr, 0, 0x7FFFFFFF, & intVal))
- return (0);
- src -> mSkip = (uint) intVal;
- } else {
- src -> mSkip = 0;
- }
- }
- if (! TrReadOperator (tr, ")"))
- return (0);
- if (TrIsOperator (tr, "@")) {
- TrReadOperator (tr, "@");
- if (! TrReadInt (tr, 0, 0x7FFFFFFF, & intVal))
- return (0);
- src -> mOffset = (uint) intVal;
- } else {
- src -> mOffset = 0;
- }
- if (! TrReadOperator (tr, ":"))
- return (0);
- if (! TrReadString (tr, MAX_PATH_LEN, src -> mPath))
- return (0);
- return (1);
+static int ReadSourceRef(TokenReaderT *tr, SourceRefT *src)
+{
+ char ident[MAX_IDENT_LEN+1];
+ uint line, col;
+ int intVal;
+
+ TrIndication(tr, &line, &col);
+ if(!TrReadIdent(tr, MAX_IDENT_LEN, ident))
+ return 0;
+ src->mFormat = MatchSourceFormat(ident);
+ if(src->mFormat == SF_NONE)
+ {
+ TrErrorAt(tr, line, col, "Expected a source format.\n");
+ return 0;
+ }
+ if(!TrReadOperator(tr, "("))
+ return 0;
+ if(src->mFormat == SF_WAVE)
+ {
+ if(!TrReadInt(tr, 0, MAX_WAVE_CHANNELS, &intVal))
+ return 0;
+ src->mType = ET_NONE;
+ src->mSize = 0;
+ src->mBits = 0;
+ src->mChannel = (uint)intVal;
+ src->mSkip = 0;
+ }
+ else
+ {
+ TrIndication(tr, &line, &col);
+ if(!TrReadIdent(tr, MAX_IDENT_LEN, ident))
+ return 0;
+ src->mType = MatchElementType(ident);
+ if(src->mType == ET_NONE)
+ {
+ TrErrorAt(tr, line, col, "Expected a source element type.\n");
+ return 0;
+ }
+ if(src->mFormat == SF_BIN_LE || src->mFormat == SF_BIN_BE)
+ {
+ if(!TrReadOperator(tr, ","))
+ return 0;
+ if(src->mType == ET_INT)
+ {
+ if(!TrReadInt(tr, MIN_BIN_SIZE, MAX_BIN_SIZE, &intVal))
+ return 0;
+ src->mSize = (uint)intVal;
+ if(!TrIsOperator(tr, ","))
+ src->mBits = (int)(8*src->mSize);
+ else
+ {
+ TrReadOperator(tr, ",");
+ TrIndication(tr, &line, &col);
+ if(!TrReadInt(tr, -2147483647-1, 2147483647, &intVal))
+ return 0;
+ if(abs(intVal) < MIN_BIN_BITS || (uint)abs(intVal) > (8*src->mSize))
+ {
+ TrErrorAt(tr, line, col, "Expected a value of (+/-) %d to %d.\n", MIN_BIN_BITS, 8*src->mSize);
+ return 0;
+ }
+ src->mBits = intVal;
+ }
+ }
+ else
+ {
+ TrIndication(tr, &line, &col);
+ if(!TrReadInt(tr, -2147483647-1, 2147483647, &intVal))
+ return 0;
+ if(intVal != 4 && intVal != 8)
+ {
+ TrErrorAt(tr, line, col, "Expected a value of 4 or 8.\n");
+ return 0;
+ }
+ src->mSize = (uint)intVal;
+ src->mBits = 0;
+ }
+ }
+ else if(src->mFormat == SF_ASCII && src->mType == ET_INT)
+ {
+ if(!TrReadOperator(tr, ","))
+ return 0;
+ if(!TrReadInt(tr, MIN_ASCII_BITS, MAX_ASCII_BITS, &intVal))
+ return 0;
+ src->mSize = 0;
+ src->mBits = intVal;
+ }
+ else
+ {
+ src->mSize = 0;
+ src->mBits = 0;
+ }
+
+ if(!TrIsOperator(tr, ";"))
+ src->mSkip = 0;
+ else
+ {
+ TrReadOperator(tr, ";");
+ if(!TrReadInt(tr, 0, 0x7FFFFFFF, &intVal))
+ return 0;
+ src->mSkip = (uint)intVal;
+ }
+ }
+ if(!TrReadOperator(tr, ")"))
+ return 0;
+ if(TrIsOperator(tr, "@"))
+ {
+ TrReadOperator(tr, "@");
+ if(!TrReadInt(tr, 0, 0x7FFFFFFF, &intVal))
+ return 0;
+ src->mOffset = (uint)intVal;
+ }
+ else
+ src->mOffset = 0;
+ if(!TrReadOperator(tr, ":"))
+ return 0;
+ if(!TrReadString(tr, MAX_PATH_LEN, src->mPath))
+ return 0;
+ return 1;
+}
+
+// Match the target ear (index) from a given identifier.
+static int MatchTargetEar(const char *ident)
+{
+ if(strcasecmp(ident, "left") == 0)
+ return 0;
+ if(strcasecmp(ident, "right") == 0)
+ return 1;
+ return -1;
}
// Process the list of sources in the data set definition.
-static int ProcessSources (const HeadModelT model, TokenReaderT * tr, HrirDataT * hData) {
- uint * setCount = NULL, * setFlag = NULL;
- double * hrir = NULL;
- uint line, col, ei, ai;
- SourceRefT src;
- double factor;
-
- setCount = (uint *) calloc (hData -> mEvCount, sizeof (uint));
- setFlag = (uint *) calloc (hData -> mIrCount, sizeof (uint));
- hrir = CreateArray (hData -> mIrPoints);
- while (TrIsOperator (tr, "[")) {
- TrIndication (tr, & line, & col);
- TrReadOperator (tr, "[");
- if (ReadIndexPair (tr, hData, & ei, & ai)) {
- if (TrReadOperator (tr, "]")) {
- if (! setFlag [hData -> mEvOffset [ei] + ai]) {
- if (TrReadOperator (tr, "=")) {
- factor = 1.0;
- for (;;) {
- if (ReadSourceRef (tr, & src)) {
- if (LoadSource (& src, hData -> mIrRate, hData -> mIrPoints, hrir)) {
- if (model == HM_DATASET)
- AverageHrirOnset (hrir, 1.0 / factor, ei, ai, hData);
- AverageHrirMagnitude (hrir, 1.0 / factor, ei, ai, hData);
- factor += 1.0;
- if (! TrIsOperator (tr, "+"))
- break;
- TrReadOperator (tr, "+");
- continue;
- }
- }
- DestroyArray (hrir);
- free (setFlag);
- free (setCount);
- return (0);
+static int ProcessSources(const HeadModelT model, TokenReaderT *tr, HrirDataT *hData)
+{
+ uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1;
+ double *hrirs = CreateDoubles(channels * hData->mIrCount * hData->mIrSize);
+ double *hrir = CreateDoubles(hData->mIrPoints);
+ uint line, col, fi, ei, ai, ti;
+ int count;
+
+ printf("Loading sources...");
+ fflush(stdout);
+ count = 0;
+ while(TrIsOperator(tr, "["))
+ {
+ double factor[2] = { 1.0, 1.0 };
+
+ TrIndication(tr, &line, &col);
+ TrReadOperator(tr, "[");
+ if(!ReadIndexTriplet(tr, hData, &fi, &ei, &ai))
+ goto error;
+ if(!TrReadOperator(tr, "]"))
+ goto error;
+ HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
+
+ if(azd->mIrs[0] != NULL)
+ {
+ TrErrorAt(tr, line, col, "Redefinition of source.\n");
+ goto error;
+ }
+ if(!TrReadOperator(tr, "="))
+ goto error;
+
+ for(;;)
+ {
+ SourceRefT src;
+ uint ti = 0;
+
+ if(!ReadSourceRef(tr, &src))
+ goto error;
+
+ // TODO: Would be nice to display 'x of y files', but that would
+ // require preparing the source refs first to get a total count
+ // before loading them.
+ ++count;
+ printf("\rLoading sources... %d file%s", count, (count==1)?"":"s");
+ fflush(stdout);
+
+ if(!LoadSource(&src, hData->mIrRate, hData->mIrPoints, hrir))
+ goto error;
+
+ if(hData->mChannelType == CT_STEREO)
+ {
+ char ident[MAX_IDENT_LEN+1];
+
+ if(!TrReadIdent(tr, MAX_IDENT_LEN, ident))
+ goto error;
+ ti = MatchTargetEar(ident);
+ if((int)ti < 0)
+ {
+ TrErrorAt(tr, line, col, "Expected a target ear.\n");
+ goto error;
}
- setFlag [hData -> mEvOffset [ei] + ai] = 1;
- setCount [ei] ++;
- continue;
- }
- } else {
- TrErrorAt (tr, line, col, "Redefinition of source.\n");
- }
- }
- }
- DestroyArray (hrir);
- free (setFlag);
- free (setCount);
- return (0);
- }
- ei = 0;
- while ((ei < hData -> mEvCount) && (setCount [ei] < 1))
- ei ++;
- if (ei < hData -> mEvCount) {
- hData -> mEvStart = ei;
- while ((ei < hData -> mEvCount) && (setCount [ei] == hData -> mAzCount [ei]))
- ei ++;
- if (ei >= hData -> mEvCount) {
- if (! TrLoad (tr)) {
- DestroyArray (hrir);
- free (setFlag);
- free (setCount);
- return (1);
- } else {
- TrError (tr, "Errant data at end of source list.\n");
- }
- } else {
- TrError (tr, "Missing sources for elevation index %d.\n", ei);
- }
- } else {
- TrError (tr, "Missing source references.\n");
- }
- DestroyArray (hrir);
- free (setFlag);
- free (setCount);
- return (0);
+ }
+ azd->mIrs[ti] = &hrirs[hData->mIrSize * (ti * hData->mIrCount + azd->mIndex)];
+ if(model == HM_DATASET)
+ azd->mDelays[ti] = AverageHrirOnset(hData->mIrRate, hData->mIrPoints, hrir, 1.0 / factor[ti], azd->mDelays[ti]);
+ AverageHrirMagnitude(hData->mIrPoints, hData->mFftSize, hrir, 1.0 / factor[ti], azd->mIrs[ti]);
+ factor[ti] += 1.0;
+ if(!TrIsOperator(tr, "+"))
+ break;
+ TrReadOperator(tr, "+");
+ }
+ if(hData->mChannelType == CT_STEREO)
+ {
+ if(azd->mIrs[0] == NULL)
+ {
+ TrErrorAt(tr, line, col, "Missing left ear source reference(s).\n");
+ goto error;
+ }
+ else if(azd->mIrs[1] == NULL)
+ {
+ TrErrorAt(tr, line, col, "Missing right ear source reference(s).\n");
+ goto error;
+ }
+ }
+ }
+ printf("\n");
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ {
+ HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
+
+ if(azd->mIrs[0] != NULL)
+ break;
+ }
+ if(ai < hData->mFds[fi].mEvs[ei].mAzCount)
+ break;
+ }
+ if(ei >= hData->mFds[fi].mEvCount)
+ {
+ TrError(tr, "Missing source references [ %d, *, * ].\n", fi);
+ goto error;
+ }
+ hData->mFds[fi].mEvStart = ei;
+ for(;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ {
+ HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
+
+ if(azd->mIrs[0] == NULL)
+ {
+ TrError(tr, "Missing source reference [ %d, %d, %d ].\n", fi, ei, ai);
+ goto error;
+ }
+ }
+ }
+ }
+ for(ti = 0;ti < channels;ti++)
+ {
+ for(fi = 0;fi < hData->mFdCount;fi++)
+ {
+ for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++)
+ {
+ for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++)
+ {
+ HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
+
+ azd->mIrs[ti] = &hrirs[hData->mIrSize * (ti * hData->mIrCount + azd->mIndex)];
+ }
+ }
+ }
+ }
+ if(!TrLoad(tr))
+ {
+ free(hrir);
+ return 1;
+ }
+ TrError(tr, "Errant data at end of source list.\n");
+
+error:
+ free(hrir);
+ return 0;
}
/* Parse the data set definition and process the source data, storing the
* resulting data set as desired. If the input name is NULL it will read
* from standard input.
*/
-static int ProcessDefinition (const char * inName, const uint outRate, const uint fftSize, const int equalize, const int surface, const double limit, const uint truncSize, const HeadModelT model, const double radius, const OutputFormatT outFormat, const char * outName) {
- FILE * fp = NULL;
- TokenReaderT tr;
- HrirDataT hData;
- double * dfa = NULL;
- char rateStr [8 + 1], expName [MAX_PATH_LEN];
-
- hData . mIrRate = 0;
- hData . mIrPoints = 0;
- hData . mFftSize = 0;
- hData . mIrSize = 0;
- hData . mIrCount = 0;
- hData . mEvCount = 0;
- hData . mRadius = 0;
- hData . mDistance = 0;
- fprintf (stdout, "Reading HRIR definition...\n");
- if (inName != NULL) {
- fp = fopen (inName, "r");
- if (fp == NULL) {
- fprintf (stderr, "Error: Could not open definition file '%s'\n", inName);
- return (0);
- }
- TrSetup (fp, inName, & tr);
- } else {
- fp = stdin;
- TrSetup (fp, "<stdin>", & tr);
- }
- if (! ProcessMetrics (& tr, fftSize, truncSize, & hData)) {
- if (inName != NULL)
- fclose (fp);
- return (0);
- }
- hData . mHrirs = CreateArray (hData . mIrCount * hData . mIrSize);
- hData . mHrtds = CreateArray (hData . mIrCount);
- if (! ProcessSources (model, & tr, & hData)) {
- DestroyArray (hData . mHrtds);
- DestroyArray (hData . mHrirs);
- if (inName != NULL)
- fclose (fp);
- return (0);
- }
- if (inName != NULL)
- fclose (fp);
- if (equalize) {
- dfa = CreateArray (1 + (hData . mFftSize / 2));
- fprintf (stdout, "Calculating diffuse-field average...\n");
- CalculateDiffuseFieldAverage (& hData, surface, limit, dfa);
- fprintf (stdout, "Performing diffuse-field equalization...\n");
- DiffuseFieldEqualize (dfa, & hData);
- DestroyArray (dfa);
- }
- fprintf (stdout, "Performing minimum phase reconstruction...\n");
- ReconstructHrirs (& hData);
- if ((outRate != 0) && (outRate != hData . mIrRate)) {
- fprintf (stdout, "Resampling HRIRs...\n");
- ResampleHrirs (outRate, & hData);
- }
- fprintf (stdout, "Truncating minimum-phase HRIRs...\n");
- hData . mIrPoints = truncSize;
- fprintf (stdout, "Synthesizing missing elevations...\n");
- if (model == HM_DATASET)
- SynthesizeOnsets (& hData);
- SynthesizeHrirs (& hData);
- fprintf (stdout, "Normalizing final HRIRs...\n");
- NormalizeHrirs (& hData);
- fprintf (stdout, "Calculating impulse delays...\n");
- CalculateHrtds (model, (radius > DEFAULT_CUSTOM_RADIUS) ? radius : hData . mRadius, & hData);
- snprintf (rateStr, 8, "%u", hData . mIrRate);
- StrSubst (outName, "%r", rateStr, MAX_PATH_LEN, expName);
- switch (outFormat) {
- case OF_MHR :
- fprintf (stdout, "Creating MHR data set file...\n");
- if (! StoreMhr (& hData, expName))
- return (0);
- break;
- default :
- break;
- }
- DestroyArray (hData . mHrtds);
- DestroyArray (hData . mHrirs);
- return (1);
+static int ProcessDefinition(const char *inName, const uint outRate, const uint fftSize, const int equalize, const int surface, const double limit, const uint truncSize, const HeadModelT model, const double radius, const char *outName)
+{
+ char rateStr[8+1], expName[MAX_PATH_LEN];
+ TokenReaderT tr;
+ HrirDataT hData;
+ FILE *fp;
+ int ret;
+
+ ResetHrirData(&hData);
+ fprintf(stdout, "Reading HRIR definition from %s...\n", inName?inName:"stdin");
+ if(inName != NULL)
+ {
+ fp = fopen(inName, "r");
+ if(fp == NULL)
+ {
+ fprintf(stderr, "Error: Could not open definition file '%s'\n", inName);
+ return 0;
+ }
+ TrSetup(fp, inName, &tr);
+ }
+ else
+ {
+ fp = stdin;
+ TrSetup(fp, "<stdin>", &tr);
+ }
+ if(!ProcessMetrics(&tr, fftSize, truncSize, &hData))
+ {
+ if(inName != NULL)
+ fclose(fp);
+ return 0;
+ }
+ if(!ProcessSources(model, &tr, &hData))
+ {
+ FreeHrirData(&hData);
+ if(inName != NULL)
+ fclose(fp);
+ return 0;
+ }
+ if(fp != stdin)
+ fclose(fp);
+ if(equalize)
+ {
+ uint c = (hData.mChannelType == CT_STEREO) ? 2 : 1;
+ uint m = 1 + hData.mFftSize / 2;
+ double *dfa = CreateDoubles(c * m);
+
+ fprintf(stdout, "Calculating diffuse-field average...\n");
+ CalculateDiffuseFieldAverage(&hData, c, m, surface, limit, dfa);
+ fprintf(stdout, "Performing diffuse-field equalization...\n");
+ DiffuseFieldEqualize(c, m, dfa, &hData);
+ free(dfa);
+ }
+ fprintf(stdout, "Performing minimum phase reconstruction...\n");
+ ReconstructHrirs(&hData);
+ if(outRate != 0 && outRate != hData.mIrRate)
+ {
+ fprintf(stdout, "Resampling HRIRs...\n");
+ ResampleHrirs(outRate, &hData);
+ }
+ fprintf(stdout, "Truncating minimum-phase HRIRs...\n");
+ hData.mIrPoints = truncSize;
+ fprintf(stdout, "Synthesizing missing elevations...\n");
+ if(model == HM_DATASET)
+ SynthesizeOnsets(&hData);
+ SynthesizeHrirs(&hData);
+ fprintf(stdout, "Normalizing final HRIRs...\n");
+ NormalizeHrirs(&hData);
+ fprintf(stdout, "Calculating impulse delays...\n");
+ CalculateHrtds(model, (radius > DEFAULT_CUSTOM_RADIUS) ? radius : hData.mRadius, &hData);
+ snprintf(rateStr, 8, "%u", hData.mIrRate);
+ StrSubst(outName, "%r", rateStr, MAX_PATH_LEN, expName);
+ fprintf(stdout, "Creating MHR data set %s...\n", expName);
+ ret = StoreMhr(&hData, expName);
+
+ FreeHrirData(&hData);
+ return ret;
+}
+
+static void PrintHelp(const char *argv0, FILE *ofile)
+{
+ fprintf(ofile, "Usage: %s [<option>...]\n\n", argv0);
+ fprintf(ofile, "Options:\n");
+ fprintf(ofile, " -m Ignored for compatibility.\n");
+ fprintf(ofile, " -r <rate> Change the data set sample rate to the specified value and\n");
+ fprintf(ofile, " resample the HRIRs accordingly.\n");
+ fprintf(ofile, " -f <points> Override the FFT window size (default: %u).\n", DEFAULT_FFTSIZE);
+ fprintf(ofile, " -e {on|off} Toggle diffuse-field equalization (default: %s).\n", (DEFAULT_EQUALIZE ? "on" : "off"));
+ fprintf(ofile, " -s {on|off} Toggle surface-weighted diffuse-field average (default: %s).\n", (DEFAULT_SURFACE ? "on" : "off"));
+ fprintf(ofile, " -l {<dB>|none} Specify a limit to the magnitude range of the diffuse-field\n");
+ fprintf(ofile, " average (default: %.2f).\n", DEFAULT_LIMIT);
+ fprintf(ofile, " -w <points> Specify the size of the truncation window that's applied\n");
+ fprintf(ofile, " after minimum-phase reconstruction (default: %u).\n", DEFAULT_TRUNCSIZE);
+ fprintf(ofile, " -d {dataset| Specify the model used for calculating the head-delay timing\n");
+ fprintf(ofile, " sphere} values (default: %s).\n", ((DEFAULT_HEAD_MODEL == HM_DATASET) ? "dataset" : "sphere"));
+ fprintf(ofile, " -c <size> Use a customized head radius measured ear-to-ear in meters.\n");
+ fprintf(ofile, " -i <filename> Specify an HRIR definition file to use (defaults to stdin).\n");
+ fprintf(ofile, " -o <filename> Specify an output file. Use of '%%r' will be substituted with\n");
+ fprintf(ofile, " the data set sample rate.\n");
}
// Standard command line dispatch.
-int main (const int argc, const char * argv []) {
- const char * inName = NULL, * outName = NULL;
- OutputFormatT outFormat;
- int argi;
- uint outRate, fftSize;
- int equalize, surface;
- double limit;
- uint truncSize;
- HeadModelT model;
- double radius;
- char * end = NULL;
-
- if (argc < 2) {
- fprintf (stderr, "Error: No command specified. See '%s -h' for help.\n", argv [0]);
- return (-1);
- }
- if ((strcmp (argv [1], "--help") == 0) || (strcmp (argv [1], "-h") == 0)) {
- fprintf (stdout, "HRTF Processing and Composition Utility\n\n");
- fprintf (stdout, "Usage: %s <command> [<option>...]\n\n", argv [0]);
- fprintf (stdout, "Commands:\n");
- fprintf (stdout, " -m, --make-mhr Makes an OpenAL Soft compatible HRTF data set.\n");
- fprintf (stdout, " Defaults output to: ./oalsoft_hrtf_%%r.mhr\n");
- fprintf (stdout, " -h, --help Displays this help information.\n\n");
- fprintf (stdout, "Options:\n");
- fprintf (stdout, " -r=<rate> Change the data set sample rate to the specified value and\n");
- fprintf (stdout, " resample the HRIRs accordingly.\n");
- fprintf (stdout, " -f=<points> Override the FFT window size (defaults to the first power-\n");
- fprintf (stdout, " of-two that fits four times the number of HRIR points).\n");
- fprintf (stdout, " -e={on|off} Toggle diffuse-field equalization (default: %s).\n", (DEFAULT_EQUALIZE ? "on" : "off"));
- fprintf (stdout, " -s={on|off} Toggle surface-weighted diffuse-field average (default: %s).\n", (DEFAULT_SURFACE ? "on" : "off"));
- fprintf (stdout, " -l={<dB>|none} Specify a limit to the magnitude range of the diffuse-field\n");
- fprintf (stdout, " average (default: %.2f).\n", DEFAULT_LIMIT);
- fprintf (stdout, " -w=<points> Specify the size of the truncation window that's applied\n");
- fprintf (stdout, " after minimum-phase reconstruction (default: %u).\n", DEFAULT_TRUNCSIZE);
- fprintf (stdout, " -d={dataset| Specify the model used for calculating the head-delay timing\n");
- fprintf (stdout, " sphere} values (default: %s).\n", ((DEFAULT_HEAD_MODEL == HM_DATASET) ? "dataset" : "sphere"));
- fprintf (stdout, " -c=<size> Use a customized head radius measured ear-to-ear in meters.\n");
- fprintf (stdout, " -i=<filename> Specify an HRIR definition file to use (defaults to stdin).\n");
- fprintf (stdout, " -o=<filename> Specify an output file. Overrides command-selected default.\n");
- fprintf (stdout, " Use of '%%r' will be substituted with the data set sample rate.\n");
- return (0);
- }
- if ((strcmp (argv [1], "--make-mhr") == 0) || (strcmp (argv [1], "-m") == 0)) {
- if (argc > 3)
- outName = argv [3];
- else
- outName = "./oalsoft_hrtf_%r.mhr";
- outFormat = OF_MHR;
- } else {
- fprintf (stderr, "Error: Invalid command '%s'.\n", argv [1]);
- return (-1);
- }
- argi = 2;
- outRate = 0;
- fftSize = 0;
- equalize = DEFAULT_EQUALIZE;
- surface = DEFAULT_SURFACE;
- limit = DEFAULT_LIMIT;
- truncSize = DEFAULT_TRUNCSIZE;
- model = DEFAULT_HEAD_MODEL;
- radius = DEFAULT_CUSTOM_RADIUS;
- while (argi < argc) {
- if (strncmp (argv [argi], "-r=", 3) == 0) {
- outRate = strtoul (& argv [argi] [3], & end, 10);
- if ((end [0] != '\0') || (outRate < MIN_RATE) || (outRate > MAX_RATE)) {
- fprintf (stderr, "Error: Expected a value from %u to %u for '-r'.\n", MIN_RATE, MAX_RATE);
- return (-1);
- }
- } else if (strncmp (argv [argi], "-f=", 3) == 0) {
- fftSize = strtoul (& argv [argi] [3], & end, 10);
- if ((end [0] != '\0') || (fftSize & (fftSize - 1)) || (fftSize < MIN_FFTSIZE) || (fftSize > MAX_FFTSIZE)) {
- fprintf (stderr, "Error: Expected a power-of-two value from %u to %u for '-f'.\n", MIN_FFTSIZE, MAX_FFTSIZE);
- return (-1);
- }
- } else if (strncmp (argv [argi], "-e=", 3) == 0) {
- if (strcmp (& argv [argi] [3], "on") == 0) {
- equalize = 1;
- } else if (strcmp (& argv [argi] [3], "off") == 0) {
- equalize = 0;
- } else {
- fprintf (stderr, "Error: Expected 'on' or 'off' for '-e'.\n");
- return (-1);
- }
- } else if (strncmp (argv [argi], "-s=", 3) == 0) {
- if (strcmp (& argv [argi] [3], "on") == 0) {
- surface = 1;
- } else if (strcmp (& argv [argi] [3], "off") == 0) {
- surface = 0;
- } else {
- fprintf (stderr, "Error: Expected 'on' or 'off' for '-s'.\n");
- return (-1);
- }
- } else if (strncmp (argv [argi], "-l=", 3) == 0) {
- if (strcmp (& argv [argi] [3], "none") == 0) {
- limit = 0.0;
- } else {
- limit = strtod (& argv [argi] [3], & end);
- if ((end [0] != '\0') || (limit < MIN_LIMIT) || (limit > MAX_LIMIT)) {
- fprintf (stderr, "Error: Expected 'none' or a value from %.2f to %.2f for '-l'.\n", MIN_LIMIT, MAX_LIMIT);
- return (-1);
- }
- }
- } else if (strncmp (argv [argi], "-w=", 3) == 0) {
- truncSize = strtoul (& argv [argi] [3], & end, 10);
- if ((end [0] != '\0') || (truncSize < MIN_TRUNCSIZE) || (truncSize > MAX_TRUNCSIZE) || (truncSize % MOD_TRUNCSIZE)) {
- fprintf (stderr, "Error: Expected a value from %u to %u in multiples of %u for '-w'.\n", MIN_TRUNCSIZE, MAX_TRUNCSIZE, MOD_TRUNCSIZE);
- return (-1);
- }
- } else if (strncmp (argv [argi], "-d=", 3) == 0) {
- if (strcmp (& argv [argi] [3], "dataset") == 0) {
- model = HM_DATASET;
- } else if (strcmp (& argv [argi] [3], "sphere") == 0) {
- model = HM_SPHERE;
- } else {
- fprintf (stderr, "Error: Expected 'dataset' or 'sphere' for '-d'.\n");
- return (-1);
- }
- } else if (strncmp (argv [argi], "-c=", 3) == 0) {
- radius = strtod (& argv [argi] [3], & end);
- if ((end [0] != '\0') || (radius < MIN_CUSTOM_RADIUS) || (radius > MAX_CUSTOM_RADIUS)) {
- fprintf (stderr, "Error: Expected a value from %.2f to %.2f for '-c'.\n", MIN_CUSTOM_RADIUS, MAX_CUSTOM_RADIUS);
- return (-1);
- }
- } else if (strncmp (argv [argi], "-i=", 3) == 0) {
- inName = & argv [argi] [3];
- } else if (strncmp (argv [argi], "-o=", 3) == 0) {
- outName = & argv [argi] [3];
- } else {
- fprintf (stderr, "Error: Invalid option '%s'.\n", argv [argi]);
- return (-1);
- }
- argi ++;
- }
- if (! ProcessDefinition (inName, outRate, fftSize, equalize, surface, limit, truncSize, model, radius, outFormat, outName))
- return (-1);
- fprintf (stdout, "Operation completed.\n");
- return (0);
-}
+int main(int argc, char *argv[])
+{
+ const char *inName = NULL, *outName = NULL;
+ uint outRate, fftSize;
+ int equalize, surface;
+ char *end = NULL;
+ HeadModelT model;
+ uint truncSize;
+ double radius;
+ double limit;
+ int opt;
+
+ GET_UNICODE_ARGS(&argc, &argv);
+
+ if(argc < 2)
+ {
+ fprintf(stdout, "HRTF Processing and Composition Utility\n\n");
+ PrintHelp(argv[0], stdout);
+ exit(EXIT_SUCCESS);
+ }
+
+ outName = "./oalsoft_hrtf_%r.mhr";
+ outRate = 0;
+ fftSize = 0;
+ equalize = DEFAULT_EQUALIZE;
+ surface = DEFAULT_SURFACE;
+ limit = DEFAULT_LIMIT;
+ truncSize = DEFAULT_TRUNCSIZE;
+ model = DEFAULT_HEAD_MODEL;
+ radius = DEFAULT_CUSTOM_RADIUS;
+
+ while((opt=getopt(argc, argv, "mr:f:e:s:l:w:d:c:e:i:o:h")) != -1)
+ {
+ switch(opt)
+ {
+ case 'm':
+ fprintf(stderr, "Ignoring unused command '-m'.\n");
+ break;
+
+ case 'r':
+ outRate = strtoul(optarg, &end, 10);
+ if(end[0] != '\0' || outRate < MIN_RATE || outRate > MAX_RATE)
+ {
+ fprintf(stderr, "Error: Got unexpected value \"%s\" for option -%c, expected between %u to %u.\n", optarg, opt, MIN_RATE, MAX_RATE);
+ exit(EXIT_FAILURE);
+ }
+ break;
+
+ case 'f':
+ fftSize = strtoul(optarg, &end, 10);
+ if(end[0] != '\0' || (fftSize&(fftSize-1)) || fftSize < MIN_FFTSIZE || fftSize > MAX_FFTSIZE)
+ {
+ fprintf(stderr, "Error: Got unexpected value \"%s\" for option -%c, expected a power-of-two between %u to %u.\n", optarg, opt, MIN_FFTSIZE, MAX_FFTSIZE);
+ exit(EXIT_FAILURE);
+ }
+ break;
+
+ case 'e':
+ if(strcmp(optarg, "on") == 0)
+ equalize = 1;
+ else if(strcmp(optarg, "off") == 0)
+ equalize = 0;
+ else
+ {
+ fprintf(stderr, "Error: Got unexpected value \"%s\" for option -%c, expected on or off.\n", optarg, opt);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 's':
+ if(strcmp(optarg, "on") == 0)
+ surface = 1;
+ else if(strcmp(optarg, "off") == 0)
+ surface = 0;
+ else
+ {
+ fprintf(stderr, "Error: Got unexpected value \"%s\" for option -%c, expected on or off.\n", optarg, opt);
+ exit(EXIT_FAILURE);
+ }
+ break;
+
+ case 'l':
+ if(strcmp(optarg, "none") == 0)
+ limit = 0.0;
+ else
+ {
+ limit = strtod(optarg, &end);
+ if(end[0] != '\0' || limit < MIN_LIMIT || limit > MAX_LIMIT)
+ {
+ fprintf(stderr, "Error: Got unexpected value \"%s\" for option -%c, expected between %.0f to %.0f.\n", optarg, opt, MIN_LIMIT, MAX_LIMIT);
+ exit(EXIT_FAILURE);
+ }
+ }
+ break;
+
+ case 'w':
+ truncSize = strtoul(optarg, &end, 10);
+ if(end[0] != '\0' || truncSize < MIN_TRUNCSIZE || truncSize > MAX_TRUNCSIZE || (truncSize%MOD_TRUNCSIZE))
+ {
+ fprintf(stderr, "Error: Got unexpected value \"%s\" for option -%c, expected multiple of %u between %u to %u.\n", optarg, opt, MOD_TRUNCSIZE, MIN_TRUNCSIZE, MAX_TRUNCSIZE);
+ exit(EXIT_FAILURE);
+ }
+ break;
+
+ case 'd':
+ if(strcmp(optarg, "dataset") == 0)
+ model = HM_DATASET;
+ else if(strcmp(optarg, "sphere") == 0)
+ model = HM_SPHERE;
+ else
+ {
+ fprintf(stderr, "Error: Got unexpected value \"%s\" for option -%c, expected dataset or sphere.\n", optarg, opt);
+ exit(EXIT_FAILURE);
+ }
+ break;
+
+ case 'c':
+ radius = strtod(optarg, &end);
+ if(end[0] != '\0' || radius < MIN_CUSTOM_RADIUS || radius > MAX_CUSTOM_RADIUS)
+ {
+ fprintf(stderr, "Error: Got unexpected value \"%s\" for option -%c, expected between %.2f to %.2f.\n", optarg, opt, MIN_CUSTOM_RADIUS, MAX_CUSTOM_RADIUS);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'i':
+ inName = optarg;
+ break;
+ case 'o':
+ outName = optarg;
+ break;
+ case 'h':
+ PrintHelp(argv[0], stdout);
+ exit(EXIT_SUCCESS);
+
+ default: /* '?' */
+ PrintHelp(argv[0], stderr);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if(!ProcessDefinition(inName, outRate, fftSize, equalize, surface, limit,
+ truncSize, model, radius, outName))
+ return -1;
+ fprintf(stdout, "Operation completed.\n");
+
+ return EXIT_SUCCESS;
+}
diff --git a/utils/openal-info.c b/utils/openal-info.c
index 5b45ceef..12dc6311 100644
--- a/utils/openal-info.c
+++ b/utils/openal-info.c
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include "AL/alc.h"
#include "AL/al.h"
@@ -41,6 +42,70 @@
#endif
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+static WCHAR *FromUTF8(const char *str)
+{
+ WCHAR *out = NULL;
+ int len;
+
+ if((len=MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0)) > 0)
+ {
+ out = calloc(sizeof(WCHAR), len);
+ MultiByteToWideChar(CP_UTF8, 0, str, -1, out, len);
+ }
+ return out;
+}
+
+/* Override printf, fprintf, and fwrite so we can print UTF-8 strings. */
+static void al_fprintf(FILE *file, const char *fmt, ...)
+{
+ char str[1024];
+ WCHAR *wstr;
+ va_list ap;
+
+ va_start(ap, fmt);
+ vsnprintf(str, sizeof(str), fmt, ap);
+ va_end(ap);
+
+ str[sizeof(str)-1] = 0;
+ wstr = FromUTF8(str);
+ if(!wstr)
+ fprintf(file, "<UTF-8 error> %s", str);
+ else
+ fprintf(file, "%ls", wstr);
+ free(wstr);
+}
+#define fprintf al_fprintf
+#define printf(...) al_fprintf(stdout, __VA_ARGS__)
+
+static size_t al_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *file)
+{
+ char str[1024];
+ WCHAR *wstr;
+ size_t len;
+
+ len = size * nmemb;
+ if(len > sizeof(str)-1)
+ len = sizeof(str)-1;
+ memcpy(str, ptr, len);
+ str[len] = 0;
+
+ wstr = FromUTF8(str);
+ if(!wstr)
+ fprintf(file, "<UTF-8 error> %s", str);
+ else
+ fprintf(file, "%ls", wstr);
+ free(wstr);
+
+ return len / size;
+}
+#define fwrite al_fwrite
+#endif
+
+
#define MAX_WIDTH 80
static void printList(const char *list, char separator)
@@ -186,6 +251,38 @@ static void printALInfo(void)
checkALErrors();
}
+static void printResamplerInfo(void)
+{
+ LPALGETSTRINGISOFT alGetStringiSOFT;
+ ALint num_resamplers;
+ ALint def_resampler;
+
+ if(!alIsExtensionPresent("AL_SOFT_source_resampler"))
+ {
+ printf("Resampler info not available\n");
+ return;
+ }
+
+ alGetStringiSOFT = alGetProcAddress("alGetStringiSOFT");
+
+ num_resamplers = alGetInteger(AL_NUM_RESAMPLERS_SOFT);
+ def_resampler = alGetInteger(AL_DEFAULT_RESAMPLER_SOFT);
+
+ if(!num_resamplers)
+ printf("!!! No resamplers found !!!\n");
+ else
+ {
+ ALint i;
+ printf("Available resamplers:\n");
+ for(i = 0;i < num_resamplers;++i)
+ {
+ const ALchar *name = alGetStringiSOFT(AL_RESAMPLER_NAME_SOFT, i);
+ printf(" %s%s\n", name, (i==def_resampler)?" *":"");
+ }
+ }
+ checkALErrors();
+}
+
static void printEFXInfo(ALCdevice *device)
{
ALCint major, minor, sends;
@@ -329,6 +426,7 @@ int main(int argc, char *argv[])
}
printALInfo();
+ printResamplerInfo();
printEFXInfo(device);
alcMakeContextCurrent(NULL);
diff --git a/version.cmake b/version.cmake
new file mode 100644
index 00000000..af7ff0a6
--- /dev/null
+++ b/version.cmake
@@ -0,0 +1,11 @@
+EXECUTE_PROCESS(
+ COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
+ OUTPUT_VARIABLE GIT_BRANCH
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+EXECUTE_PROCESS(
+ COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
+ OUTPUT_VARIABLE GIT_COMMIT_HASH
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+CONFIGURE_FILE(${SRC} ${DST})
diff --git a/version.h.in b/version.h.in
new file mode 100644
index 00000000..56f738a3
--- /dev/null
+++ b/version.h.in
@@ -0,0 +1,8 @@
+/* Define to the library version */
+#define ALSOFT_VERSION "${LIB_VERSION}"
+
+/* Define the branch being built */
+#define ALSOFT_GIT_BRANCH "${GIT_BRANCH}"
+
+/* Define the hash of the head commit */
+#define ALSOFT_GIT_COMMIT_HASH "${GIT_COMMIT_HASH}"