SFML - Simple and Fast Multimedia Library

SFML 3.1.0
Loading...
Searching...
No Matches
Classes | Functions
sf::Listener Namespace Reference
Audio module

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

## Classes
struct | Cone
| Structure defining the properties of a directional cone. More...

## Functions
void | setGlobalVolume (float volume)
| Change the global volume of all the sounds and musics.
float | getGlobalVolume ()
| Get the current value of the global volume.
void | setPosition (const Vector3f &position)
| Set the position of the listener in the scene.
Vector3f | getPosition ()
| Get the current position of the listener in the scene.
void | setDirection (const Vector3f &direction)
| Set the forward vector of the listener in the scene.
Vector3f | getDirection ()
| Get the current forward vector of the listener in the scene.
void | setVelocity (const Vector3f &velocity)
| Set the velocity of the listener in the scene.
Vector3f | getVelocity ()
| Get the current forward vector of the listener in the scene.
void | setCone (const Listener::Cone &cone)
| Set the cone properties of the listener in the audio scene.
Listener::Cone | getCone ()
| Get the cone properties of the listener in the audio scene.
void | setUpVector (const Vector3f &upVector)
| Set the upward vector of the listener in the scene.
Vector3f | getUpVector ()
| Get the current upward vector of the listener in the scene.

## Detailed Description

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 sf::View is the eyes of the user, then sf::Listener are their ears (by the way, they are often linked together – same position, orientation, etc.).

sf::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.

Usage example:

// Move the listener to the position (1, 0, -5)
sf::Listener::setPosition({1, 0, -5});
// Make it face the right axis (1, 0, 0)
sf::Listener::setDirection({1, 0, 0});
// Reduce the global volume
sf::Listener::setGlobalVolume(50);
sf::Listener::setPosition
void setPosition(const Vector3f &position)
Set the position of the listener in the scene.
sf::Listener::setDirection
void setDirection(const Vector3f &direction)
Set the forward vector of the listener in the scene.
sf::Listener::setGlobalVolume
void setGlobalVolume(float volume)
Change the global volume of all the sounds and musics.

## Function Documentation

## ◆ getCone()

Listener::Cone sf::Listener::getCone | ( |  | ) |
| nodiscard

Get the cone properties of the listener in the audio scene.

Returns
  Cone properties of the listener

See also
  setCone

## ◆ getDirection()

Vector3f sf::Listener::getDirection | ( |  | ) |
| nodiscard

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

Returns
  Listener's forward vector (not normalized)

See also
  setDirection

## ◆ getGlobalVolume()

float sf::Listener::getGlobalVolume | ( |  | ) |
| nodiscard

Get the current value of the global volume.

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

See also
  setGlobalVolume

## ◆ getPosition()

Vector3f sf::Listener::getPosition | ( |  | ) |
| nodiscard

Get the current position of the listener in the scene.

Returns
  Listener's position

See also
  setPosition

## ◆ getUpVector()

Vector3f sf::Listener::getUpVector | ( |  | ) |
| nodiscard

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

Returns
  Listener's upward vector (not normalized)

See also
  setUpVector

## ◆ getVelocity()

Vector3f sf::Listener::getVelocity | ( |  | ) |
| nodiscard

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

Returns
  Listener's velocity

See also
  setVelocity

## ◆ setCone()

void sf::Listener::setCone | ( | const Listener::Cone & | cone | ) |

Set the cone properties of the listener in the audio scene.

The cone defines how directional attenuation is applied. The default cone of a sound is (2 * PI, 2 * PI, 1).

Parameters

  cone | Cone properties of the listener in the scene

See also
  getCone

## ◆ setDirection()

void sf::Listener::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

## ◆ setGlobalVolume()

void sf::Listener::setGlobalVolume | ( | float | volume | ) |

Change the global volume of all the sounds and musics.

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

## ◆ setPosition()

void sf::Listener::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

## ◆ setUpVector()

void sf::Listener::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

## ◆ setVelocity()

void sf::Listener::setVelocity | ( | const Vector3f & | velocity | ) |

Set the velocity of the listener in the scene.

The default listener's velocity is (0, 0, -1).

Parameters

  velocity | New listener's velocity

See also
  getVelocity, getDirection, setUpVector, setPosition