Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Static & dynamic D bindings to OpenAL, compatible with BetterC,@nogc, and nothrow.

License

NotificationsYou must be signed in to change notification settings

BindBC/bindbc-openal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project provides both static and dynamic bindings to API version 1.1 ofthe OpenAL library and the alternativeOpenAL Soft implementation. They are@nogc andnothrow compatible and can be compiled for compatibility with-betterC. This package is intended as a replacement ofDerelictAL, which is not compatible with@nogc,nothrow, or-betterC.

Usage

By default,bindbc-openal is configured to compile as a dynamic binding that is not-betterC compatible. The dynamic binding has no link-time dependency on the OpenAL library, so the OpenAL shared library must be manually loaded at runtime. When configured as a static binding, there is a link-time dependency on the OpenAL library—either the static library or the appropriate file for linking with shared libraries on your platform (see below).

When using DUB to manage your project, the static binding can be enabled via a DUBsubConfiguration statement in your project's package file.-betterC compatibility is also enabled via subconfigurations.

To use OpenAL, addbindbc-openal as a dependency to your project's package config file. For example, the following is configured to use OpenAL via a dynamic binding that is not-betterC compatible:

dub.json

dependencies {    "bindbc-openal": "~>1.0.0",}

dub.sdl

dependency "bindbc-openal" version="~>1.0.0"

The dynamic binding

The dynamic binding requires no special configuration when using DUB to manage your project. There is no link-time dependency. At runtime, the OpenAL shared library is required to be on the shared library search path of the user's system. On Windows, this is typically handled by distributing the OpenAL Soft DLL with your program or running the OpenAL installer on the end-user's system. On other systems, it usually means the user must install the OpenAL shared library through a package manager.

To load the shared library, you need to call theloadOpenAL function. This returns a member of theALSupport enumeration (seethe README forbindbc.loader for the error handling API):

  • ALSupport.noLibrary indicates that the library failed to load (it couldn't be found)
  • ALSupport.badLibrary indicates that one or more symbols in the library failed to load
  • ALSupport.al11 indicates that the library loaded successfully
import bindbc.openal;/*This version attempts to load the OpenAL shared library using well-known variationsof the library name for the host system.*/ALSupport ret = loadOpenAL();if(ret!= ALSupport.al11) {// Handle error. For most use cases, its reasonable to use the error handling API in// bindbc-loader to retrieve error messages and then abort. If necessary, it's  possible// to determine the root cause via the return value:if(ret== ALSupport.noLibrary) {// OpenAL shared library failed to load    }elseif(ALSupport.badLibrary) {// One or more symbols failed to load.    }}/*This version attempts to load the OpenAL library using a user-supplied file name.Usually, the name and/or path will be platform specific, as in this examplewhich attempts to load `soft_oal.dll`, the default name of the OpenAL Soft sharedlibrary, from the `libs` subdirectory, relative to the executable, only on Windows.*/// version(Windows) loadOpenAL("libs/soft_oal.dll")

dub.json

"dependencies": {    "bindbc-openal": "~>1.0.0"}

dub.sdl

dependency "bindbc-openal" version="~>1.0.0"

The static binding

NOTE: The static binding may cause a crash at runtime when linking dynamically. This is an issue I've been unable to solve yet.

The static binding has a link-time dependency on either the shared or static OpenAL libraries. On Windows, you can link with the static library or, to use the shared library, with the import library. On other systems, you can link with either the static library or directly with the shared library.

Note that the OpenAL distribution does not contain a static library and the source is not available to build one. OpenAL Soft is open source and can be compiled as a static library.

When linking with the static library, there is no runtime dependency on OpenAL. When linking with the shared library (or the import library on Windows), the runtime dependency is the same as the dynamic binding, the difference being that the shared library is no longer loaded manually—loading is handled automatically by the system when the program is launched.

Enabling the static binding can be done in two ways.

Via the compiler's-version switch or DUB'sversions directive

Pass theBindOpenAL_Static version to the compiler and link with the appropriate library.

When using the compiler command line or a build system that doesn't support DUB, this is the only option. The-version=BindOpenAL_Static option should be passed to the compiler when building your program. All of the required C libraries, as well as thebindbc-openal andbindbc-loader static libraries, must also be passed to the compiler on the command line or via your build system's configuration.

When using DUB, itsversions directive is an option. For example, when using the static binding:

dub.json

"dependencies": {    "bindbc-openal": "~>1.0.0"},"versions": ["BindOpenAL_Static"],"libs-windows": ["OpenAL32"],"libs-posix": ["openal"]

dub.sdl

dependency "bindbc-openal" version="~>1.0.0"versions "BindOpenAL_Static"libs "OpenAL32" platform="windows"libs "openal" platform="posix"

Via DUB subconfigurations

Instead of using DUB'sversions directive, asubConfiguration can be used. Enable thestatic subconfiguration for thebindbc-openal dependency:

dub.json

"dependencies": {    "bindbc-openal": "~>1.0.0"},"subConfigurations": {    "bindbc-openal": "static"},"libs-windows": ["OpenAL32"],"libs-posix": ["openal"]

dub.sdl

dependency "bindbc-openal" version="~>1.0.0"subConfiguration "bindbc-openal" "static"libs "OpenAL32" platform="windows"libs "openal" platform="posix"

This has the benefit that it completely excludes from the build any source modules related to the dynamic binding, i.e., they will never be passed to the compiler.

betterC support

betterC support is enabled via thedynamicBC andstaticBC subconfigurations for dynamic and static bindings respectively. To enable the static binding with-betterC support:

dub.json

"dependencies": {    "bindbc-openal": "~>1.1.0"},"subConfigurations": {    "bindbc-openal": "staticBC"},"libs-windows": ["OpenAL32"],"libs-posix": ["openal"]

dub.sdl

dependency "bindbc-openal" version="~>1.1.0"subConfiguration "bindbc-openal" "staticBC"libs "OpenAL32" platform="windows"libs "openal" platform="posix"

When not using DUB to manage your project, first use DUB to compile the BindBC libraries with thedynamicBC orstaticBC configuration, then pass-betterC to the compiler when building your project.

EFX/EAX Extension

Experimental support for the EFX and EAX extensions can be enabled by specifying theAL_EFX version when compiling:

dub.json

"dependencies": {    "bindbc-openal": "~>1.0.0"    "versions": ["AL_EFX"],}

dub.sdl

dependency "bindbc-openal" version="~>1.0.0"versions "AL_EFX"

The following example can be used to test support for EFX/EAX:

bool usingEAXReverb =false;ALuintloadReverb(ref ReverbProperties r){    ALuint effect;    alGenEffects(1, &effect);if(alGetEnumValue("AL_EFFECT_EAXREVERB")!=0)    {/* EAX Reverb is available. Set the EAX effect type then load the         * reverb properties.*/        usingEAXReverb =true;        alEffecti(effect,AL_EFFECT_TYPE,AL_EFFECT_EAXREVERB);        ALfloat* reflecPan = &r.reflectionsPan[0];        ALfloat* lateRevPan = &r.lateReverbPan[0];        alEffectf(effect,AL_EAXREVERB_DENSITY, r.density);        alEffectf(effect,AL_EAXREVERB_DIFFUSION, r.diffusion);        alEffectf(effect,AL_EAXREVERB_GAIN, r.gain);        alEffectf(effect,AL_EAXREVERB_GAINHF, r.gainHF);        alEffectf(effect,AL_EAXREVERB_GAINLF, r.gainLF);        alEffectf(effect,AL_EAXREVERB_DECAY_TIME, r.decayTime);        alEffectf(effect,AL_EAXREVERB_DECAY_HFRATIO, r.decayHFRatio);        alEffectf(effect,AL_EAXREVERB_DECAY_LFRATIO, r.decayLFRatio);        alEffectf(effect,AL_EAXREVERB_REFLECTIONS_GAIN, r.reflectionsGain);        alEffectf(effect,AL_EAXREVERB_REFLECTIONS_DELAY, r.reflectionsDelay);        alEffectfv(effect,AL_EAXREVERB_REFLECTIONS_PAN, reflecPan);        alEffectf(effect,AL_EAXREVERB_LATE_REVERB_GAIN, r.lateReverbGain);        alEffectf(effect,AL_EAXREVERB_LATE_REVERB_DELAY, r.lateReverbDelay);        alEffectfv(effect,AL_EAXREVERB_LATE_REVERB_PAN, lateRevPan);        alEffectf(effect,AL_EAXREVERB_ECHO_TIME, r.echoTime);        alEffectf(effect,AL_EAXREVERB_ECHO_DEPTH, r.echoDepth);        alEffectf(effect,AL_EAXREVERB_MODULATION_TIME, r.modulationTime);        alEffectf(effect,AL_EAXREVERB_MODULATION_DEPTH, r.modulationDepth);        alEffectf(effect,AL_EAXREVERB_AIR_ABSORPTION_GAINHF, r.airAbsorptionGainHF);        alEffectf(effect,AL_EAXREVERB_HFREFERENCE, r.HFReference);        alEffectf(effect,AL_EAXREVERB_LFREFERENCE, r.LFReference);        alEffectf(effect,AL_EAXREVERB_ROOM_ROLLOFF_FACTOR, r.roomRolloffFactor);        alEffecti(effect,AL_EAXREVERB_DECAY_HFLIMIT, r.decayHFLimit);    }else    {/* No EAX Reverb. Set the standard reverb effect type then load the         * available reverb properties.*/        alEffecti(effect,AL_EFFECT_TYPE,AL_EFFECT_REVERB);        alEffectf(effect,AL_REVERB_DENSITY, r.density);        alEffectf(effect,AL_REVERB_DIFFUSION, r.diffusion);        alEffectf(effect,AL_REVERB_GAIN, r.gain);        alEffectf(effect,AL_REVERB_GAINHF, r.gainHF);        alEffectf(effect,AL_REVERB_DECAY_TIME, r.decayTime);        alEffectf(effect,AL_REVERB_DECAY_HFRATIO, r.decayHFRatio);        alEffectf(effect,AL_REVERB_REFLECTIONS_GAIN, r.reflectionsGain);        alEffectf(effect,AL_REVERB_REFLECTIONS_DELAY, r.reflectionsDelay);        alEffectf(effect,AL_REVERB_LATE_REVERB_GAIN, r.lateReverbGain);        alEffectf(effect,AL_REVERB_LATE_REVERB_DELAY, r.lateReverbDelay);        alEffectf(effect,AL_REVERB_AIR_ABSORPTION_GAINHF, r.airAbsorptionGainHF);        alEffectf(effect,AL_REVERB_ROOM_ROLLOFF_FACTOR, r.roomRolloffFactor);        alEffecti(effect,AL_REVERB_DECAY_HFLIMIT, r.decayHFLimit);    }/* Check if an error occured, and clean up if so.*/int err = alGetError();if(err!=AL_NO_ERROR)    {if(alIsEffect(effect))            alDeleteEffects(1, &effect);return0;    }return effect;}

ForReverbProperties presets, seesource/bindbc/openal/presets.d.

To reiterate, EFX/EAX support is experimental.Please report any issues you may encounter with the binding.

About

Static & dynamic D bindings to OpenAL, compatible with BetterC,@nogc, and nothrow.

Topics

Resources

License

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp