mirror of https://github.com/bjornbytes/lovr.git
Effect;
Basically replace each individual accessor with a general one.
This commit is contained in:
parent
746735259c
commit
dd98b11b3f
|
@ -89,6 +89,7 @@ extern StringEntry lovrDeviceAxis[];
|
|||
extern StringEntry lovrDeviceButton[];
|
||||
extern StringEntry lovrDrawMode[];
|
||||
extern StringEntry lovrDrawStyle[];
|
||||
extern StringEntry lovrEffect[];
|
||||
extern StringEntry lovrEventType[];
|
||||
extern StringEntry lovrFilterMode[];
|
||||
extern StringEntry lovrHeadsetDriver[];
|
||||
|
|
|
@ -6,6 +6,16 @@
|
|||
#include "core/util.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
StringEntry lovrEffect[] = {
|
||||
[EFFECT_ABSORPTION] = ENTRY("absorption"),
|
||||
[EFFECT_FALLOFF] = ENTRY("falloff"),
|
||||
[EFFECT_OCCLUSION] = ENTRY("occlusion"),
|
||||
[EFFECT_REVERB] = ENTRY("reverb"),
|
||||
[EFFECT_SPATIALIZATION] = ENTRY("spatialization"),
|
||||
[EFFECT_TRANSMISSION] = ENTRY("transmission"),
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
StringEntry lovrAudioMaterial[] = {
|
||||
[MATERIAL_GENERIC] = ENTRY("generic"),
|
||||
[MATERIAL_BRICK] = ENTRY("brick"),
|
||||
|
|
|
@ -92,20 +92,6 @@ static int l_lovrSourceIsSpatial(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrSourceGetInterpolation(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
SourceInterpolation interpolation = lovrSourceGetInterpolation(source);
|
||||
luax_pushenum(L, SourceInterpolation, interpolation);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrSourceSetInterpolation(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
SourceInterpolation interpolation = luax_checkenum(L, 2, SourceInterpolation, NULL);
|
||||
lovrSourceSetInterpolation(source, interpolation);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrSourceGetPosition(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
float position[4], orientation[4];
|
||||
|
@ -202,73 +188,19 @@ static int l_lovrSourceSetRadius(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrSourceIsAbsorptionEnabled(lua_State* L) {
|
||||
static int l_lovrSourceIsEffectEnabled(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
bool enabled = lovrSourceIsAbsorptionEnabled(source);
|
||||
Effect effect = luax_checkenum(L, 2, Effect, NULL);
|
||||
bool enabled = lovrSourceIsEffectEnabled(source, effect);
|
||||
lua_pushboolean(L, enabled);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrSourceSetAbsorptionEnabled(lua_State* L) {
|
||||
static int l_lovrSourceSetEffectEnabled(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
bool enabled = lua_toboolean(L, 2);
|
||||
lovrSourceSetAbsorptionEnabled(source, enabled);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrSourceIsFalloffEnabled(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
bool enabled = lovrSourceIsFalloffEnabled(source);
|
||||
lua_pushboolean(L, enabled);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrSourceSetFalloffEnabled(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
bool enabled = lua_toboolean(L, 2);
|
||||
lovrSourceSetFalloffEnabled(source, enabled);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrSourceIsOcclusionEnabled(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
bool enabled = lovrSourceIsOcclusionEnabled(source);
|
||||
lua_pushboolean(L, enabled);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrSourceSetOcclusionEnabled(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
bool enabled = lua_toboolean(L, 2);
|
||||
lovrSourceSetOcclusionEnabled(source, enabled);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrSourceIsReverbEnabled(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
bool enabled = lovrSourceIsReverbEnabled(source);
|
||||
lua_pushboolean(L, enabled);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrSourceSetReverbEnabled(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
bool enabled = lua_toboolean(L, 2);
|
||||
lovrSourceSetReverbEnabled(source, enabled);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrSourceIsTransmissionEnabled(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
bool enabled = lovrSourceIsTransmissionEnabled(source);
|
||||
lua_pushboolean(L, enabled);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrSourceSetTransmissionEnabled(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
bool enabled = lua_toboolean(L, 2);
|
||||
lovrSourceSetTransmissionEnabled(source, enabled);
|
||||
Effect effect = luax_checkenum(L, 2, Effect, NULL);
|
||||
bool enabled = lua_isnoneornil(L, -1) ? true : lua_toboolean(L, -1);
|
||||
lovrSourceSetEffectEnabled(source, effect, enabled);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -286,8 +218,6 @@ const luaL_Reg lovrSource[] = {
|
|||
{ "tell", l_lovrSourceTell },
|
||||
{ "getDuration", l_lovrSourceGetDuration },
|
||||
{ "isSpatial", l_lovrSourceIsSpatial },
|
||||
{ "getInterpolation", l_lovrSourceGetInterpolation },
|
||||
{ "setInterpolation", l_lovrSourceSetInterpolation },
|
||||
{ "getPosition", l_lovrSourceGetPosition },
|
||||
{ "setPosition", l_lovrSourceSetPosition },
|
||||
{ "getOrientation", l_lovrSourceGetOrientation },
|
||||
|
@ -298,15 +228,7 @@ const luaL_Reg lovrSource[] = {
|
|||
{ "setRadius", l_lovrSourceSetRadius },
|
||||
{ "getDirectivity", l_lovrSourceGetDirectivity },
|
||||
{ "setDirectivity", l_lovrSourceSetDirectivity },
|
||||
{ "isAbsorptionEnabled", l_lovrSourceIsAbsorptionEnabled },
|
||||
{ "setAbsorptionEnabled", l_lovrSourceSetAbsorptionEnabled },
|
||||
{ "isFalloffEnabled", l_lovrSourceIsFalloffEnabled },
|
||||
{ "setFalloffEnabled", l_lovrSourceSetFalloffEnabled },
|
||||
{ "isOcclusionEnabled", l_lovrSourceIsOcclusionEnabled },
|
||||
{ "setOcclusionEnabled", l_lovrSourceSetOcclusionEnabled },
|
||||
{ "isReverbEnabled", l_lovrSourceIsReverbEnabled },
|
||||
{ "setReverbEnabled", l_lovrSourceSetReverbEnabled },
|
||||
{ "isTransmissionEnabled", l_lovrSourceIsTransmissionEnabled },
|
||||
{ "setTransmissionEnabled", l_lovrSourceSetTransmissionEnabled },
|
||||
{ "isEffectEnabled", l_lovrSourceIsEffectEnabled },
|
||||
{ "setEffectEnabled", l_lovrSourceSetEffectEnabled },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
|
|
@ -37,15 +37,10 @@ struct Source {
|
|||
float radius;
|
||||
float dipoleWeight;
|
||||
float dipolePower;
|
||||
bool absorption;
|
||||
bool falloff;
|
||||
bool occlusion;
|
||||
bool reverb;
|
||||
bool transmission;
|
||||
uint8_t effects;
|
||||
bool playing;
|
||||
bool looping;
|
||||
bool spatial;
|
||||
bool bilinear;
|
||||
};
|
||||
|
||||
static struct {
|
||||
|
@ -459,9 +454,7 @@ float lovrSourceGetVolume(Source* source) {
|
|||
}
|
||||
|
||||
void lovrSourceSetVolume(Source* source, float volume) {
|
||||
ma_mutex_lock(&state.lock);
|
||||
source->volume = volume;
|
||||
ma_mutex_unlock(&state.lock);
|
||||
}
|
||||
|
||||
void lovrSourceSeek(Source* source, double time, TimeUnit units) {
|
||||
|
@ -483,14 +476,6 @@ bool lovrSourceIsSpatial(Source *source) {
|
|||
return source->spatial;
|
||||
}
|
||||
|
||||
SourceInterpolation lovrSourceGetInterpolation(Source* source) {
|
||||
return source->bilinear ? SOURCE_BILINEAR : SOURCE_NEAREST;
|
||||
}
|
||||
|
||||
void lovrSourceSetInterpolation(Source* source, SourceInterpolation interpolation) {
|
||||
source->bilinear = interpolation == SOURCE_BILINEAR;
|
||||
}
|
||||
|
||||
void lovrSourceGetPose(Source *source, float position[4], float orientation[4]) {
|
||||
memcpy(position, source->position, sizeof(source->position));
|
||||
memcpy(orientation, source->orientation, sizeof(source->orientation));
|
||||
|
@ -521,44 +506,16 @@ void lovrSourceSetDirectivity(Source* source, float weight, float power) {
|
|||
source->dipolePower = power;
|
||||
}
|
||||
|
||||
bool lovrSourceIsAbsorptionEnabled(Source* source) {
|
||||
return source->absorption;
|
||||
bool lovrSourceIsEffectEnabled(Source* source, Effect effect) {
|
||||
return source->effects & (1 << effect);
|
||||
}
|
||||
|
||||
void lovrSourceSetAbsorptionEnabled(Source* source, bool enabled) {
|
||||
source->absorption = enabled;
|
||||
}
|
||||
|
||||
bool lovrSourceIsFalloffEnabled(Source* source) {
|
||||
return source->falloff;
|
||||
}
|
||||
|
||||
void lovrSourceSetFalloffEnabled(Source* source, bool enabled) {
|
||||
source->falloff = enabled;
|
||||
}
|
||||
|
||||
bool lovrSourceIsOcclusionEnabled(Source* source) {
|
||||
return source->occlusion;
|
||||
}
|
||||
|
||||
void lovrSourceSetOcclusionEnabled(Source* source, bool enabled) {
|
||||
source->occlusion = enabled;
|
||||
}
|
||||
|
||||
bool lovrSourceIsReverbEnabled(Source* source) {
|
||||
return source->reverb;
|
||||
}
|
||||
|
||||
void lovrSourceSetReverbEnabled(Source* source, bool enabled) {
|
||||
source->reverb = enabled;
|
||||
}
|
||||
|
||||
bool lovrSourceIsTransmissionEnabled(Source* source) {
|
||||
return source->transmission;
|
||||
}
|
||||
|
||||
void lovrSourceSetTransmissionEnabled(Source* source, bool enabled) {
|
||||
source->transmission = enabled;
|
||||
void lovrSourceSetEffectEnabled(Source* source, Effect effect, bool enabled) {
|
||||
if (enabled) {
|
||||
source->effects |= (1 << effect);
|
||||
} else {
|
||||
source->effects &= ~(1 << effect);
|
||||
}
|
||||
}
|
||||
|
||||
intptr_t* lovrSourceGetSpatializerMemoField(Source* source) {
|
||||
|
|
|
@ -11,6 +11,15 @@ struct Sound;
|
|||
|
||||
typedef struct Source Source;
|
||||
|
||||
typedef enum {
|
||||
EFFECT_ABSORPTION,
|
||||
EFFECT_FALLOFF,
|
||||
EFFECT_OCCLUSION,
|
||||
EFFECT_REVERB,
|
||||
EFFECT_SPATIALIZATION,
|
||||
EFFECT_TRANSMISSION
|
||||
} Effect;
|
||||
|
||||
typedef enum {
|
||||
MATERIAL_GENERIC,
|
||||
MATERIAL_BRICK,
|
||||
|
@ -74,21 +83,11 @@ void lovrSourceSeek(Source* source, double time, TimeUnit units);
|
|||
double lovrSourceTell(Source* source, TimeUnit units);
|
||||
double lovrSourceGetDuration(Source* source, TimeUnit units);
|
||||
bool lovrSourceIsSpatial(Source* source);
|
||||
SourceInterpolation lovrSourceGetInterpolation(Source* source);
|
||||
void lovrSourceSetInterpolation(Source* source, SourceInterpolation interpolation);
|
||||
void lovrSourceGetPose(Source* source, float position[4], float orientation[4]);
|
||||
void lovrSourceSetPose(Source* source, float position[4], float orientation[4]);
|
||||
float lovrSourceGetRadius(Source* source);
|
||||
void lovrSourceSetRadius(Source* source, float radius);
|
||||
void lovrSourceGetDirectivity(Source* source, float* weight, float* power);
|
||||
void lovrSourceSetDirectivity(Source* source, float weight, float power);
|
||||
bool lovrSourceIsAbsorptionEnabled(Source* source);
|
||||
void lovrSourceSetAbsorptionEnabled(Source* source, bool enabled);
|
||||
bool lovrSourceIsFalloffEnabled(Source* source);
|
||||
void lovrSourceSetFalloffEnabled(Source* source, bool enabled);
|
||||
bool lovrSourceIsOcclusionEnabled(Source* source);
|
||||
void lovrSourceSetOcclusionEnabled(Source* source, bool enabled);
|
||||
bool lovrSourceIsReverbEnabled(Source* source);
|
||||
void lovrSourceSetReverbEnabled(Source* source, bool enabled);
|
||||
bool lovrSourceIsTransmissionEnabled(Source* source);
|
||||
void lovrSourceSetTransmissionEnabled(Source* source, bool enabled);
|
||||
bool lovrSourceIsEffectEnabled(Source* source, Effect effect);
|
||||
void lovrSourceSetEffectEnabled(Source* Source, Effect effect, bool enabled);
|
||||
|
|
|
@ -228,8 +228,9 @@ uint32_t phonon_apply(Source* source, const float* input, float* output, uint32_
|
|||
float radius = 0.f;
|
||||
IPLint32 rays = 0;
|
||||
|
||||
if (lovrSourceIsOcclusionEnabled(source)) {
|
||||
occlusion = lovrSourceIsTransmissionEnabled(source) ? IPL_DIRECTOCCLUSION_TRANSMISSIONBYFREQUENCY : IPL_DIRECTOCCLUSION_NOTRANSMISSION;
|
||||
if (lovrSourceIsEffectEnabled(source, EFFECT_OCCLUSION)) {
|
||||
bool transmission = lovrSourceIsEffectEnabled(source, EFFECT_TRANSMISSION);
|
||||
occlusion = transmission ? IPL_DIRECTOCCLUSION_TRANSMISSIONBYFREQUENCY : IPL_DIRECTOCCLUSION_NOTRANSMISSION;
|
||||
radius = lovrSourceGetRadius(source);
|
||||
|
||||
if (radius > 0.f) {
|
||||
|
@ -241,8 +242,8 @@ uint32_t phonon_apply(Source* source, const float* input, float* output, uint32_
|
|||
IPLDirectSoundPath path = phonon_iplGetDirectSoundPath(state.environment, listener, forward, up, iplSource, radius, rays, occlusion, volumetric);
|
||||
|
||||
IPLDirectSoundEffectOptions options = {
|
||||
.applyDistanceAttenuation = lovrSourceIsFalloffEnabled(source) ? IPL_TRUE : IPL_FALSE,
|
||||
.applyAirAbsorption = lovrSourceIsAbsorptionEnabled(source) ? IPL_TRUE : IPL_FALSE,
|
||||
.applyDistanceAttenuation = lovrSourceIsEffectEnabled(source, EFFECT_FALLOFF) ? IPL_TRUE : IPL_FALSE,
|
||||
.applyAirAbsorption = lovrSourceIsEffectEnabled(source, EFFECT_ABSORPTION) ? IPL_TRUE : IPL_FALSE,
|
||||
.applyDirectivity = weight > 0.f && power > 0.f ? IPL_TRUE : IPL_FALSE,
|
||||
.directOcclusionMode = occlusion
|
||||
};
|
||||
|
@ -250,10 +251,10 @@ uint32_t phonon_apply(Source* source, const float* input, float* output, uint32_
|
|||
phonon_iplApplyDirectSoundEffect(state.directSoundEffect[index], in, path, options, tmp);
|
||||
|
||||
float blend = 1.f;
|
||||
IPLHrtfInterpolation interpolation = lovrSourceGetInterpolation(source) == SOURCE_BILINEAR ? IPL_HRTFINTERPOLATION_BILINEAR : IPL_HRTFINTERPOLATION_NEAREST;
|
||||
IPLHrtfInterpolation interpolation = IPL_HRTFINTERPOLATION_NEAREST;
|
||||
phonon_iplApplyBinauralEffect(state.binauralEffect[index], state.binauralRenderer, tmp, path.direction, interpolation, blend, out);
|
||||
|
||||
if (lovrSourceIsReverbEnabled(source)) {
|
||||
if (lovrSourceIsEffectEnabled(source, EFFECT_REVERB)) {
|
||||
phonon_iplSetDryAudioForConvolutionEffect(state.convolutionEffect[index], iplSource, in);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,16 +22,24 @@ uint32_t simple_apply(Source* source, const float* input, float* output, uint32_
|
|||
float listenerPos[4] = { 0.f };
|
||||
mat4_transform(state.listener, listenerPos);
|
||||
|
||||
float distance = vec3_distance(sourcePos, listenerPos);
|
||||
float leftEar[4] = { -0.1f, 0.0f, 0.0f, 1.0f };
|
||||
float rightEar[4] = { 0.1f, 0.0f, 0.0f, 1.0f };
|
||||
mat4_transform(state.listener, leftEar);
|
||||
mat4_transform(state.listener, rightEar);
|
||||
float ldistance = vec3_distance(sourcePos, leftEar);
|
||||
float rdistance = vec3_distance(sourcePos, rightEar);
|
||||
float distanceAttenuation = 1.f / MAX(distance, 1.f);
|
||||
float leftAttenuation = .5f + (rdistance - ldistance) * 2.5f;
|
||||
float rightAttenuation = .5f + (ldistance - rdistance) * 2.5f;
|
||||
float distanceAttenuation = 1.f;
|
||||
if (lovrSourceIsEffectEnabled(source, EFFECT_FALLOFF)) {
|
||||
float distance = vec3_distance(sourcePos, listenerPos);
|
||||
distanceAttenuation = 1.f / MAX(distance, 1.f);
|
||||
}
|
||||
|
||||
float leftAttenuation = 1.f;
|
||||
float rightAttenuation = 1.f;
|
||||
if (lovrSourceIsEffectEnabled(source, EFFECT_SPATIALIZATION)) {
|
||||
float leftEar[4] = { -0.1f, 0.0f, 0.0f, 1.0f };
|
||||
float rightEar[4] = { 0.1f, 0.0f, 0.0f, 1.0f };
|
||||
mat4_transform(state.listener, leftEar);
|
||||
mat4_transform(state.listener, rightEar);
|
||||
float ldistance = vec3_distance(sourcePos, leftEar);
|
||||
float rdistance = vec3_distance(sourcePos, rightEar);
|
||||
leftAttenuation = .5f + (rdistance - ldistance) * 2.5f;
|
||||
rightAttenuation = .5f + (ldistance - rdistance) * 2.5f;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < frames; i++) {
|
||||
output[i * 2 + 0] = input[i] * distanceAttenuation * leftAttenuation;
|
||||
|
|
Loading…
Reference in New Issue