aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-12-26 22:27:34 -0800
committerChris Robinson <[email protected]>2018-12-26 22:27:34 -0800
commitd367093c0616e561a14ca1c486aff99cde98f4be (patch)
tree42401356036220bdb993171a3da73ca9f1c97403
parenta4ac43b60294c5e21913c977942b19f174407d85 (diff)
Use std::array for appropriate source and listener properties
-rw-r--r--Alc/alu.cpp10
-rw-r--r--OpenAL32/Include/alListener.h18
-rw-r--r--OpenAL32/Include/alSource.h13
-rw-r--r--OpenAL32/Include/alu.h11
-rw-r--r--OpenAL32/alListener.cpp55
-rw-r--r--OpenAL32/alSource.cpp71
6 files changed, 87 insertions, 91 deletions
diff --git a/Alc/alu.cpp b/Alc/alu.cpp
index e9d251fc..dfbd15a9 100644
--- a/Alc/alu.cpp
+++ b/Alc/alu.cpp
@@ -334,9 +334,9 @@ bool CalcListenerParams(ALCcontext *Context)
if(!props) return false;
/* AT then UP */
- alu::Vector N{props->Forward[0], props->Forward[1], props->Forward[2], 0.0f};
+ alu::Vector N{props->OrientAt[0], props->OrientAt[1], props->OrientAt[2], 0.0f};
N.normalize();
- alu::Vector V{props->Up[0], props->Up[1], props->Up[2], 0.0f};
+ alu::Vector V{props->OrientUp[0], props->OrientUp[1], props->OrientUp[2], 0.0f};
V.normalize();
/* Build and normalize right-vector */
alu::Vector U{aluCrossproduct(N, V)};
@@ -681,11 +681,9 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat Azi, const ALfloat Elev
* to the orientation.
*/
/* AT then UP */
- alu::Vector N{props->Orientation[0][0], props->Orientation[0][1],
- props->Orientation[0][2], 0.0f};
+ alu::Vector N{props->OrientAt[0], props->OrientAt[1], props->OrientAt[2], 0.0f};
N.normalize();
- alu::Vector V{props->Orientation[1][0], props->Orientation[1][1],
- props->Orientation[1][2], 0.0f};
+ alu::Vector V{props->OrientUp[0], props->OrientUp[1], props->OrientUp[2], 0.0f};
V.normalize();
if(!props->HeadRelative)
{
diff --git a/OpenAL32/Include/alListener.h b/OpenAL32/Include/alListener.h
index 490f1594..0aa28a46 100644
--- a/OpenAL32/Include/alListener.h
+++ b/OpenAL32/Include/alListener.h
@@ -1,6 +1,8 @@
#ifndef _AL_LISTENER_H_
#define _AL_LISTENER_H_
+#include <array>
+
#include "AL/alc.h"
#include "AL/al.h"
#include "AL/alext.h"
@@ -12,20 +14,20 @@ enum class DistanceModel;
struct ALlistenerProps {
- ALfloat Position[3];
- ALfloat Velocity[3];
- ALfloat Forward[3];
- ALfloat Up[3];
+ std::array<ALfloat,3> Position;
+ std::array<ALfloat,3> Velocity;
+ std::array<ALfloat,3> OrientAt;
+ std::array<ALfloat,3> OrientUp;
ALfloat Gain;
std::atomic<ALlistenerProps*> next;
};
struct ALlistener {
- ALfloat Position[3]{0.0f, 0.0f, 0.0f};
- ALfloat Velocity[3]{0.0f, 0.0f, 0.0f};
- ALfloat Forward[3]{0.0f, 0.0f, -1.0f};
- ALfloat Up[3]{0.0f, 1.0f, 0.0f};
+ std::array<ALfloat,3> Position{{0.0f, 0.0f, 0.0f}};
+ std::array<ALfloat,3> Velocity{{0.0f, 0.0f, 0.0f}};
+ std::array<ALfloat,3> OrientAt{{0.0f, 0.0f, -1.0f}};
+ std::array<ALfloat,3> OrientUp{{0.0f, 1.0f, 0.0f}};
ALfloat Gain{1.0f};
std::atomic_flag PropsClean{true};
diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h
index 381e0a9b..ac17fc0d 100644
--- a/OpenAL32/Include/alSource.h
+++ b/OpenAL32/Include/alSource.h
@@ -1,6 +1,8 @@
#ifndef _AL_SOURCE_H_
#define _AL_SOURCE_H_
+#include <array>
+
#include "alMain.h"
#include "alu.h"
#include "hrtf.h"
@@ -34,10 +36,11 @@ struct ALsource {
ALfloat RefDistance;
ALfloat MaxDistance;
ALfloat RolloffFactor;
- ALfloat Position[3];
- ALfloat Velocity[3];
- ALfloat Direction[3];
- ALfloat Orientation[2][3];
+ std::array<ALfloat,3> Position;
+ std::array<ALfloat,3> Velocity;
+ std::array<ALfloat,3> Direction;
+ std::array<ALfloat,3> OrientAt;
+ std::array<ALfloat,3> OrientUp;
ALboolean HeadRelative;
ALboolean Looping;
DistanceModel mDistanceModel;
@@ -57,7 +60,7 @@ struct ALsource {
/* NOTE: Stereo pan angles are specified in radians, counter-clockwise
* rather than clockwise.
*/
- ALfloat StereoPan[2];
+ std::array<ALfloat,2> StereoPan;
ALfloat Radius;
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index 775d34f6..7a378562 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -155,10 +155,11 @@ struct ALvoicePropsBase {
ALfloat RefDistance;
ALfloat MaxDistance;
ALfloat RolloffFactor;
- ALfloat Position[3];
- ALfloat Velocity[3];
- ALfloat Direction[3];
- ALfloat Orientation[2][3];
+ std::array<ALfloat,3> Position;
+ std::array<ALfloat,3> Velocity;
+ std::array<ALfloat,3> Direction;
+ std::array<ALfloat,3> OrientAt;
+ std::array<ALfloat,3> OrientUp;
ALboolean HeadRelative;
DistanceModel mDistanceModel;
Resampler mResampler;
@@ -174,7 +175,7 @@ struct ALvoicePropsBase {
ALfloat RoomRolloffFactor;
ALfloat DopplerFactor;
- ALfloat StereoPan[2];
+ std::array<ALfloat,2> StereoPan;
ALfloat Radius;
diff --git a/OpenAL32/alListener.cpp b/OpenAL32/alListener.cpp
index b7fdf9ce..7ed36f14 100644
--- a/OpenAL32/alListener.cpp
+++ b/OpenAL32/alListener.cpp
@@ -134,12 +134,12 @@ AL_API ALvoid AL_APIENTRY alListenerfv(ALenum param, const ALfloat *values)
std::isfinite(values[3]) && std::isfinite(values[4]) && std::isfinite(values[5])))
SETERR_RETURN(context.get(), AL_INVALID_VALUE,, "Listener orientation out of range");
/* AT then UP */
- 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];
+ listener.OrientAt[0] = values[0];
+ listener.OrientAt[1] = values[1];
+ listener.OrientAt[2] = values[2];
+ listener.OrientUp[0] = values[3];
+ listener.OrientUp[1] = values[4];
+ listener.OrientUp[2] = values[5];
DO_UPDATEPROPS();
break;
@@ -303,12 +303,12 @@ AL_API ALvoid AL_APIENTRY alGetListenerfv(ALenum param, ALfloat *values)
{
case AL_ORIENTATION:
// AT then UP
- values[0] = listener.Forward[0];
- values[1] = listener.Forward[1];
- values[2] = listener.Forward[2];
- values[3] = listener.Up[0];
- values[4] = listener.Up[1];
- values[5] = listener.Up[2];
+ values[0] = listener.OrientAt[0];
+ values[1] = listener.OrientAt[1];
+ values[2] = listener.OrientAt[2];
+ values[3] = listener.OrientUp[0];
+ values[4] = listener.OrientUp[1];
+ values[5] = listener.OrientUp[2];
break;
default:
@@ -383,12 +383,12 @@ AL_API void AL_APIENTRY alGetListeneriv(ALenum param, ALint* values)
{
case AL_ORIENTATION:
// AT then UP
- values[0] = (ALint)listener.Forward[0];
- values[1] = (ALint)listener.Forward[1];
- values[2] = (ALint)listener.Forward[2];
- values[3] = (ALint)listener.Up[0];
- values[4] = (ALint)listener.Up[1];
- values[5] = (ALint)listener.Up[2];
+ values[0] = (ALint)listener.OrientAt[0];
+ values[1] = (ALint)listener.OrientAt[1];
+ values[2] = (ALint)listener.OrientAt[2];
+ values[3] = (ALint)listener.OrientUp[0];
+ values[4] = (ALint)listener.OrientUp[1];
+ values[5] = (ALint)listener.OrientUp[2];
break;
default:
@@ -414,21 +414,10 @@ void UpdateListenerProps(ALCcontext *context)
/* Copy in current property values. */
ALlistener &listener = context->Listener;
- 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->Position = listener.Position;
+ props->Velocity = listener.Velocity;
+ props->OrientAt = listener.OrientAt;
+ props->OrientUp = listener.OrientUp;
props->Gain = listener.Gain;
/* Set the new container for updating internal parameters. */
diff --git a/OpenAL32/alSource.cpp b/OpenAL32/alSource.cpp
index 6db7161a..ac2979a5 100644
--- a/OpenAL32/alSource.cpp
+++ b/OpenAL32/alSource.cpp
@@ -66,7 +66,7 @@ inline ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context)
return nullptr;
}
-void UpdateSourceProps(ALsource *source, ALvoice *voice, ALCcontext *context)
+void UpdateSourceProps(const ALsource *source, ALvoice *voice, ALCcontext *context)
{
/* Get an unused property container, or allocate a new one as needed. */
ALvoiceProps *props{context->FreeVoiceProps.load(std::memory_order_acquire)};
@@ -92,11 +92,11 @@ void UpdateSourceProps(ALsource *source, ALvoice *voice, ALCcontext *context)
props->RefDistance = source->RefDistance;
props->MaxDistance = source->MaxDistance;
props->RolloffFactor = source->RolloffFactor;
- std::copy(std::begin(source->Position), std::end(source->Position), props->Position);
- std::copy(std::begin(source->Velocity), std::end(source->Velocity), props->Velocity);
- std::copy(std::begin(source->Direction), std::end(source->Direction), props->Direction);
- std::copy(std::begin(source->Orientation[0]), std::end(source->Orientation[0]), props->Orientation[0]);
- std::copy(std::begin(source->Orientation[1]), std::end(source->Orientation[1]), props->Orientation[1]);
+ props->Position = source->Position;
+ props->Velocity = source->Velocity;
+ props->Direction = source->Direction;
+ props->OrientAt = source->OrientAt;
+ props->OrientUp = source->OrientUp;
props->HeadRelative = source->HeadRelative;
props->mDistanceModel = source->mDistanceModel;
props->mResampler = source->mResampler;
@@ -112,7 +112,7 @@ void UpdateSourceProps(ALsource *source, ALvoice *voice, ALCcontext *context)
props->RoomRolloffFactor = source->RoomRolloffFactor;
props->DopplerFactor = source->DopplerFactor;
- std::copy(std::begin(source->StereoPan), std::end(source->StereoPan), props->StereoPan);
+ props->StereoPan = source->StereoPan;
props->Radius = source->Radius;
@@ -122,15 +122,18 @@ void UpdateSourceProps(ALsource *source, ALvoice *voice, ALCcontext *context)
props->Direct.GainLF = source->Direct.GainLF;
props->Direct.LFReference = source->Direct.LFReference;
- for(size_t i{0u};i < source->Send.size();i++)
+ auto copy_send = [](const ALsource::SendData &srcsend) noexcept -> ALvoicePropsBase::SendData
{
- 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;
- }
+ ALvoicePropsBase::SendData ret;
+ ret.Slot = srcsend.Slot;
+ ret.Gain = srcsend.Gain;
+ ret.GainHF = srcsend.GainHF;
+ ret.HFReference = srcsend.HFReference;
+ ret.GainLF = srcsend.GainLF;
+ ret.LFReference = srcsend.LFReference;
+ return ret;
+ };
+ std::transform(source->Send.cbegin(), source->Send.cend(), props->Send, copy_send);
/* Set the new container for updating internal parameters. */
props = voice->Update.exchange(props, std::memory_order_acq_rel);
@@ -1157,12 +1160,12 @@ ALboolean SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, co
CHECKVAL(std::isfinite(values[0]) && std::isfinite(values[1]) && std::isfinite(values[2]) &&
std::isfinite(values[3]) && std::isfinite(values[4]) && std::isfinite(values[5]));
- 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];
+ Source->OrientAt[0] = values[0];
+ Source->OrientAt[1] = values[1];
+ Source->OrientAt[2] = values[2];
+ Source->OrientUp[0] = values[3];
+ Source->OrientUp[1] = values[4];
+ Source->OrientUp[2] = values[5];
DO_UPDATEPROPS();
return AL_TRUE;
@@ -1763,12 +1766,12 @@ ALboolean GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, AL
return AL_TRUE;
case AL_ORIENTATION:
- 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];
+ values[0] = Source->OrientAt[0];
+ values[1] = Source->OrientAt[1];
+ values[2] = Source->OrientAt[2];
+ values[3] = Source->OrientUp[0];
+ values[4] = Source->OrientUp[1];
+ values[5] = Source->OrientUp[2];
return AL_TRUE;
/* 1x int */
@@ -3311,14 +3314,14 @@ ALsource::ALsource(ALsizei num_sends)
Direction[0] = 0.0f;
Direction[1] = 0.0f;
Direction[2] = 0.0f;
- Orientation[0][0] = 0.0f;
- Orientation[0][1] = 0.0f;
- Orientation[0][2] = -1.0f;
- Orientation[1][0] = 0.0f;
- Orientation[1][1] = 1.0f;
- Orientation[1][2] = 0.0f;
+ OrientAt[0] = 0.0f;
+ OrientAt[1] = 0.0f;
+ OrientAt[2] = -1.0f;
+ OrientUp[0] = 0.0f;
+ OrientUp[1] = 1.0f;
+ OrientUp[2] = 0.0f;
RefDistance = 1.0f;
- MaxDistance = FLT_MAX;
+ MaxDistance = std::numeric_limits<float>::max();
RolloffFactor = 1.0f;
Gain = 1.0f;
MinGain = 0.0f;