Skip to content

Group math

Math libraries and utilities.

Classes

Type Name
struct SparkyStudios::Audio::Amplitude::BarycentricCoordinates
Represents barycentric coordinates between a point and 3 vertices of a triangle.
struct SparkyStudios::Audio::Amplitude::BezierCurveControlPoints
A structure containing control points for a Bézier curve.
class SparkyStudios::Audio::Amplitude::BoxShape
A box shape, defined by a width, a height, and a depth.
class SparkyStudios::Audio::Amplitude::BoxZone
A Zone built with an innerBoxShape and an outerBoxShape .
class SparkyStudios::Audio::Amplitude::CapsuleShape
A capsule shape, defined by a radius and a height.
class SparkyStudios::Audio::Amplitude::CapsuleZone
A Zone built with an innerCapsuleShape and an outerCapsuleShape .
class SparkyStudios::Audio::Amplitude::CartesianCoordinateSystem
A class representing a cartesian coordinate system.
class SparkyStudios::Audio::Amplitude::ConeShape
A cone shape, defined by a radius and a height.
class SparkyStudios::Audio::Amplitude::ConeZone
A Zone built with an innerConeShape and an outerConeShape .
class SparkyStudios::Audio::Amplitude::Curve
A Curve that describes the variation of a value (on the Y-axis) according to another (on the X-axis).
class SparkyStudios::Audio::Amplitude::CurvePart
A segment of a Curve .
struct SparkyStudios::Audio::Amplitude::CurvePoint
A single point in a Curve .
struct SparkyStudios::Audio::Amplitude::Edge
Represents an edge.
struct SparkyStudios::Audio::Amplitude::Face
Represents a triangulated face.
struct SparkyStudios::Audio::Amplitude::Orientation
Represents an orientation in 3D space.
class SparkyStudios::Audio::Amplitude::Shape
A geometrical closed 3D shape.
class SparkyStudios::Audio::Amplitude::SphereShape
A sphere shape, defined by a radius.
class SparkyStudios::Audio::Amplitude::SphereZone
A Zone built with an innerSphereShape and an outerSphereShape .
struct SparkyStudios::Audio::Amplitude::SphericalPosition
Spherical coordinates representation.
class SparkyStudios::Audio::Amplitude::Zone
A tuple of shapes that represents a zone in the world.

Public Types

Type Name
union SparkyStudios::Audio::Amplitude::Triangle
Represent a triangle geometry.
typedef union SparkyStudios::Audio::Amplitude::Triangle Triangle
Represent a triangle geometry.

Public Attributes

Type Name
AmMatrix3 kMatrix3Identity = { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f }
An identity matrix in 3D space.
AmMatrix4 kMatrix4Identity = /* multi line expression */
An identity matrix in 4D space.
AmVector2 kVector2One = { 1.0f, 1.0f }
A unit vector in 2D space.
AmVector2 kVector2UnitX = { 1.0f, 0.0f }
A unit vector along the X-axis in 2D space.
AmVector2 kVector2UnitY = { 0.0f, 1.0f }
A unit vector along the Y-axis in 2D space.
AmVector2 kVector2Zero = { 0.0f, 0.0f }
A zero vector in 2D space.
AmVector3 kVector3One = { 1.0f, 1.0f, 1.0f }
A unit vector in 3D space.
AmVector3 kVector3UnitX = { 1.0f, 0.0f, 0.0f }
A unit vector along the X-axis in 3D space.
AmVector3 kVector3UnitY = { 0.0f, 1.0f, 0.0f }
A unit vector along the Y-axis in 3D space.
AmVector3 kVector3UnitZ = { 0.0f, 0.0f, 1.0f }
A unit vector along the Z-axis in 3D space.
AmVector3 kVector3Zero = { 0.0f, 0.0f, 0.0f }
A zero vector in 3D space.
AmVector4 kVector4One = { 1.0f, 1.0f, 1.0f, 1.0f }
A unit vector in 4D space.
AmVector4 kVector4UnitW = { 0.0f, 0.0f, 0.0f, 1.0f }
A unit vector along the W-axis in 4D space.
AmVector4 kVector4UnitX = { 1.0f, 0.0f, 0.0f, 0.0f }
A unit vector along the X-axis in 4D space.
AmVector4 kVector4UnitY = { 0.0f, 1.0f, 0.0f, 0.0f }
A unit vector along the Y-axis in 4D space.
AmVector4 kVector4UnitZ = { 0.0f, 0.0f, 1.0f, 0.0f }
A unit vector along the Z-axis in 4D space.
AmVector4 kVector4Zero = { 0.0f, 0.0f, 0.0f, 0.0f }
A zero vector in 4D space.

Public Functions

Type Name
AmReal32 AmDitherReal32 (const AmReal32 ditherMin, const AmReal32 ditherMax)
Generates a random number between ditherMin andditherMax .
AmInt32 AmFloatToFixedPoint (const AmReal32 x)
Converts a 32-bit floating-point audio sample to a fixed-point representation.
AmReal32 AmInt16ToReal32 (const AmInt16 x)
Converts a 16-bit signed integer audio sample to a 32-bit floating-point representation.
AmReal32 AmInt32ToReal32 (const AmInt32 x)
Converts a 32-bit signed integer audio sample to a 32-bit floating-point representation.
AmInt16 AmReal32ToInt16 (const AmReal32 x, bool dithering=false)
Converts a 32-bit floating-point audio sample to a 16-bit signed integer representation.
AmReal32 CatmullRom (const AmReal32 t, const AmReal32 p0, const AmReal32 p1, const AmReal32 p2, const AmReal32 p3)
Computes the Catmull-Rom interpolation value at a given time t between four points.
AmInt64 FindGCD (AmInt64 a, AmInt64 b)
Finds the greatest common divisor (GCD) of two integers.
T IntegerPow (T base, AmInt32 exp)
Computes the value base^exp using the squared exponentiation method.
AmReal32 InverseSquareRoot (AmReal32 x)
Calculates the inverse square root of a number using Quake III's implementation.
AmReal32 Lerp (const AmReal32 t, const AmReal32 p0, const AmReal32 p1)
Calculates the linear interpolation value at a given time t between two points.
T NextPowerOf2 (const T & val)
Returns the next power of 2 of a given number.

Macros

Type Name
define AM_ABS (a) ((a) > 0 ? (a) : -(a))
Gets the absolute version of a value.
define AM_BETWEEN (v, a, b) ((v) >= [**AM\_MIN**](group__math.md#define-am_min)(a, b) && (v) <= [**AM\_MAX**](group__math.md#define-am_max)(a, b))
Checks if a value is between a and b.
define AM_CLAMP (v, a, b) (((v) < (a)) ? (a) : ((v) > (b)) ? (b) : (v))
Clamps a value between a and b.
define AM_CUBED (x) ((x) \* (x) \* (x))
Compute the cube of a number.
define AM_MAX (a, b) ((a) > (b) ? (a) : (b))
Gets the maximum between two values.
define AM_MIN (a, b) ((a) < (b) ? (a) : (b))
Gets the minimum between two values.
define AM_MOD (a, m) (((a) % (m)) >= 0 ? ((a) % (m)) : (((a) % (m)) + (m)))
Compute modulo that always returns positive values.
define AM_SQUARED (x) ((x) \* (x))
Compute the square of a number.

Public Types Documentation

Triangle

Represent a triangle geometry.


A triangle is a collection of three vertices oriented in a Clock-Wise (CW) manner.

Triangle

Represent a triangle geometry.

typedef union SparkyStudios::Audio::Amplitude::Triangle SparkyStudios::Audio::Amplitude::Triangle;

A triangle is a collection of three vertices oriented in a Clock-Wise (CW) manner.

Public Attributes Documentation

kMatrix3Identity

An identity matrix in 3D space.

AmMatrix3 SparkyStudios::Audio::Amplitude::kMatrix3Identity;

This constant represents a 3x3 identity matrix, which is used to represent no transformation.

kMatrix4Identity

An identity matrix in 4D space.

AmMatrix4 SparkyStudios::Audio::Amplitude::kMatrix4Identity;

This constant represents a 4x4 identity matrix, which is used to represent no transformation.

kVector2One

A unit vector in 2D space.

AmVector2 SparkyStudios::Audio::Amplitude::kVector2One;

This constant represents a vector with all components set to one.

kVector2UnitX

A unit vector along the X-axis in 2D space.

AmVector2 SparkyStudios::Audio::Amplitude::kVector2UnitX;

This constant represents a basis vector pointing in the positive X direction.

kVector2UnitY

A unit vector along the Y-axis in 2D space.

AmVector2 SparkyStudios::Audio::Amplitude::kVector2UnitY;

This constant represents a basis vector pointing in the positive Y direction.

kVector2Zero

A zero vector in 2D space.

AmVector2 SparkyStudios::Audio::Amplitude::kVector2Zero;

This constant represents a vector with all components set to zero.

kVector3One

A unit vector in 3D space.

AmVector3 SparkyStudios::Audio::Amplitude::kVector3One;

This constant represents a vector with all components set to one.

kVector3UnitX

A unit vector along the X-axis in 3D space.

AmVector3 SparkyStudios::Audio::Amplitude::kVector3UnitX;

This constant represents a basis vector pointing in the positive X direction.

kVector3UnitY

A unit vector along the Y-axis in 3D space.

AmVector3 SparkyStudios::Audio::Amplitude::kVector3UnitY;

This constant represents a basis vector pointing in the positive Y direction.

kVector3UnitZ

A unit vector along the Z-axis in 3D space.

AmVector3 SparkyStudios::Audio::Amplitude::kVector3UnitZ;

This constant represents a basis vector pointing in the positive Z direction.

kVector3Zero

A zero vector in 3D space.

AmVector3 SparkyStudios::Audio::Amplitude::kVector3Zero;

This constant represents a vector with all components set to zero.

kVector4One

A unit vector in 4D space.

AmVector4 SparkyStudios::Audio::Amplitude::kVector4One;

This constant represents a vector with all components set to one.

kVector4UnitW

A unit vector along the W-axis in 4D space.

AmVector4 SparkyStudios::Audio::Amplitude::kVector4UnitW;

This constant represents a basis vector pointing in the positive W direction.

kVector4UnitX

A unit vector along the X-axis in 4D space.

AmVector4 SparkyStudios::Audio::Amplitude::kVector4UnitX;

This constant represents a basis vector pointing in the positive X direction.

kVector4UnitY

A unit vector along the Y-axis in 4D space.

AmVector4 SparkyStudios::Audio::Amplitude::kVector4UnitY;

This constant represents a basis vector pointing in the positive Y direction.

kVector4UnitZ

A unit vector along the Z-axis in 4D space.

AmVector4 SparkyStudios::Audio::Amplitude::kVector4UnitZ;

This constant represents a basis vector pointing in the positive Z direction.

kVector4Zero

A zero vector in 4D space.

AmVector4 SparkyStudios::Audio::Amplitude::kVector4Zero;

This constant represents a vector with all components set to zero.

Public Functions Documentation

AmDitherReal32

Generates a random number between ditherMin andditherMax .

inline AmReal32 AmDitherReal32 (
    const AmReal32 ditherMin,
    const AmReal32 ditherMax
) 

Parameters:

  • ditherMin The minimum value for the random number.
  • ditherMax The maximum value for the random number.

Returns:

A random number between ditherMin and ditherMax.

AmFloatToFixedPoint

Converts a 32-bit floating-point audio sample to a fixed-point representation.

inline AmInt32 AmFloatToFixedPoint (
    const AmReal32 x
) 

Parameters:

  • x The 32-bit floating-point audio sample to convert.

Returns:

The fixed-point representation of the input 32-bit floating-point audio sample.

AmInt16ToReal32

Converts a 16-bit signed integer audio sample to a 32-bit floating-point representation.

inline AmReal32 AmInt16ToReal32 (
    const AmInt16 x
) 

Parameters:

  • x The 16-bit signed integer audio sample to convert.

Returns:

The 32-bit floating-point representation of the input 16-bit signed integer audio sample.

Note:

For more accurate conversion, the SDK should be compiled with the AM_ACCURATE_CONVERSION macro defined.

AmInt32ToReal32

Converts a 32-bit signed integer audio sample to a 32-bit floating-point representation.

inline AmReal32 AmInt32ToReal32 (
    const AmInt32 x
) 

Parameters:

  • x The 32-bit signed integer audio sample to convert.

Returns:

The 32-bit floating-point representation of the input 32-bit signed integer audio sample.

Note:

For more accurate conversion, the SDK should be compiled with the AM_ACCURATE_CONVERSION macro defined.

AmReal32ToInt16

Converts a 32-bit floating-point audio sample to a 16-bit signed integer representation.

inline AmInt16 AmReal32ToInt16 (
    const AmReal32 x,
    bool dithering=false
) 

Parameters:

  • x The 32-bit floating-point audio sample to convert.
  • dithering If true, adds a dithering noise to the output.

Returns:

The 16-bit signed integer representation of the input 32-bit floating-point audio sample.

Note:

For more accurate conversion, the SDK should be compiled with the AM_ACCURATE_CONVERSION macro defined.

CatmullRom

Computes the Catmull-Rom interpolation value at a given time t between four points.

inline AmReal32 CatmullRom (
    const AmReal32 t,
    const AmReal32 p0,
    const AmReal32 p1,
    const AmReal32 p2,
    const AmReal32 p3
) 

Parameters:

  • t The time value between 0 and 1.
  • p0 The first point.
  • p1 The second point.
  • p2 The third point.
  • p3 The fourth point.

Returns:

The Catmull-Rom interpolation value at the given time t.

FindGCD

Finds the greatest common divisor (GCD) of two integers.

inline AmInt64 FindGCD (
    AmInt64 a,
    AmInt64 b
) 

Parameters:

  • a First integer.
  • b Second integer.

Returns:

The greatest common divisor of a and b.

IntegerPow

Computes the value base^exp using the squared exponentiation method.

template<typename T>
inline T IntegerPow (
    T base,
    AmInt32 exp
) 

Template parameters:

  • T An integer type, a floating-point type, or any other type where operator *= is defined.

Parameters:

  • base Input of the power function.
  • exp The exponent of the power function. Must be non-negative.

Returns:

The result of raising the base to the power of the exponent.

InverseSquareRoot

Calculates the inverse square root of a number using Quake III's implementation.

inline AmReal32 InverseSquareRoot (
    AmReal32 x
) 

Parameters:

  • x The number to calculate the inverse square root of.

Returns:

The inverse square root of the input number.

Lerp

Calculates the linear interpolation value at a given time t between two points.

inline AmReal32 Lerp (
    const AmReal32 t,
    const AmReal32 p0,
    const AmReal32 p1
) 

Parameters:

  • t The time value between 0 and 1.
  • p0 The first point.
  • p1 The second point.

Returns:

The linear interpolation value at the given time t.

NextPowerOf2

Returns the next power of 2 of a given number.

template<typename T>
inline T NextPowerOf2 (
    const T & val
) 

Template parameters:

  • T An integer type, a floating-point type, or any other type where operator *= is defined.

Parameters:

  • val The number.

Returns:

The next power of 2.

Macro Definition Documentation

AM_ABS

Gets the absolute version of a value.

#define AM_ABS (
    a
) `((a) > 0 ? (a) : -(a))`

Parameters:

  • a The value.

Returns:

A positive number if a was negative.

AM_BETWEEN

Checks if a value is between a and b.

#define AM_BETWEEN (
    v,
    a,
    b
) `((v) >= AM_MIN (a, b) && (v) <= AM_MAX (a, b))`

Parameters:

  • v The value to check
  • a The minimum value
  • b The maximum value

Returns:

true if the value is between a and b, false otherwise.

AM_CLAMP

Clamps a value between a and b.

#define AM_CLAMP (
    v,
    a,
    b
) `(((v) < (a)) ? (a) : ((v) > (b)) ? (b) : (v))`

Parameters:

  • v The value to clamp
  • a The minimum value
  • b The maximum value

Returns:

The clamped value

AM_CUBED

Compute the cube of a number.

#define AM_CUBED (
    x
) `((x) * (x) * (x))`

Parameters:

  • x The number to cube

Returns:

The cubed value.

AM_MAX

Gets the maximum between two values.

#define AM_MAX (
    a,
    b
) `((a) > (b) ? (a) : (b))`

Parameters:

  • a The first value.
  • b The second value.

Returns:

The highest value between a and b.

AM_MIN

Gets the minimum between two values.

#define AM_MIN (
    a,
    b
) `((a) < (b) ? (a) : (b))`

Parameters:

  • a The first value
  • b The second value

Returns:

The lowest value between a and b.

AM_MOD

Compute modulo that always returns positive values.

#define AM_MOD (
    a,
    m
) `(((a) % (m)) >= 0 ? ((a) % (m)) : (((a) % (m)) + (m)))`

Parameters:

  • a The dividend
  • m The divisor

Returns:

The positive modulo result.

AM_SQUARED

Compute the square of a number.

#define AM_SQUARED (
    x
) `((x) * (x))`

Parameters:

  • x The number to square

Returns:

The squared value.