class EE::Audio::Listener

Overview

The audio listener is the point in the scene from where all the sounds are heard. More…

#include <listener.hpp>

class Listener {
public:
    // methods

    static void setGlobalVolume(float volume);
    static float getGlobalVolume();
    static void setPosition(float x, float y, float z);
    static void setPosition(const Vector3f& position);
    static Vector3f getPosition();
    static void setDirection(float x, float y, float z);
    static void setDirection(const Vector3f& direction);
    static Vector3f getDirection();
    static void setUpVector(float x, float y, float z);
    static void setUpVector(const Vector3f& upVector);
    static Vector3f getUpVector();
};

Detailed Documentation

The audio listener is the point in the scene from where all the sounds are heard.

The audio listener defines the global properties of the audio environment, it defines where and how sounds and musics are heard. If View is the eyes of the user, then Listener is his ears (by the way, they are often linked together same position, orientation, etc.).

Listener is a simple interface, which allows to setup the listener in the 3D audio environment (position, direction and up vector), and to adjust the global volume.

Because the listener is unique in the scene, Listener only contains static functions and doesn’t have to be instantiated.

Usage example:

// Move the listener to the position (1, 0, -5)
Listener::setPosition(1, 0, -5);

// Make it face the right axis (1, 0, 0)
Listener::setDirection(1, 0, 0);

// Reduce the global volume
Listener::setGlobalVolume(50);

Methods

static void setGlobalVolume(float volume)

Change the global volume of all the sounds and musics.

The volume is a number between 0 and 100; it is combined with the individual volume of each sound / music. The default value for the volume is 100 (maximum).

Parameters:

volume

New global volume, in the range [0, 100]

See also:

getGlobalVolume

static float getGlobalVolume()

Get the current value of the global volume.

Returns:

Current global volume, in the range [0, 100]

See also:

setGlobalVolume

static void setPosition(float x, float y, float z)

Set the position of the listener in the scene.

The default listener’s position is (0, 0, 0).

Parameters:

x

X coordinate of the listener’s position

y

Y coordinate of the listener’s position

z

Z coordinate of the listener’s position

See also:

getPosition, setDirection

static void setPosition(const Vector3f& position)

Set the position of the listener in the scene.

The default listener’s position is (0, 0, 0).

Parameters:

position

New listener’s position

See also:

getPosition, setDirection

static Vector3f getPosition()

Get the current position of the listener in the scene.

Returns:

Listener ‘s position

See also:

setPosition

static void setDirection(float x, float y, float z)

Set the forward vector of the listener in the scene.

The direction (also called “at vector”) is the vector pointing forward from the listener’s perspective. Together with the up vector, it defines the 3D orientation of the listener in the scene. The direction vector doesn’t have to be normalized. The default listener’s direction is (0, 0, -1).

Parameters:

x

X coordinate of the listener’s direction

y

Y coordinate of the listener’s direction

z

Z coordinate of the listener’s direction

See also:

getDirection, setUpVector, setPosition

static void setDirection(const Vector3f& direction)

Set the forward vector of the listener in the scene.

The direction (also called “at vector”) is the vector pointing forward from the listener’s perspective. Together with the up vector, it defines the 3D orientation of the listener in the scene. The direction vector doesn’t have to be normalized. The default listener’s direction is (0, 0, -1).

Parameters:

direction

New listener’s direction

See also:

getDirection, setUpVector, setPosition

static Vector3f getDirection()

Get the current forward vector of the listener in the scene.

Returns:

Listener ‘s forward vector (not normalized)

See also:

setDirection

static void setUpVector(float x, float y, float z)

Set the upward vector of the listener in the scene.

The up vector is the vector that points upward from the listener’s perspective. Together with the direction, it defines the 3D orientation of the listener in the scene. The up vector doesn’t have to be normalized. The default listener’s up vector is (0, 1, 0). It is usually not necessary to change it, especially in 2D scenarios.

Parameters:

x

X coordinate of the listener’s up vector

y

Y coordinate of the listener’s up vector

z

Z coordinate of the listener’s up vector

See also:

getUpVector, setDirection, setPosition

static void setUpVector(const Vector3f& upVector)

Set the upward vector of the listener in the scene.

The up vector is the vector that points upward from the listener’s perspective. Together with the direction, it defines the 3D orientation of the listener in the scene. The up vector doesn’t have to be normalized. The default listener’s up vector is (0, 1, 0). It is usually not necessary to change it, especially in 2D scenarios.

Parameters:

upVector

New listener’s up vector

See also:

getUpVector, setDirection, setPosition

static Vector3f getUpVector()

Get the current upward vector of the listener in the scene.

Returns:

Listener ‘s upward vector (not normalized)

See also:

setUpVector