Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Spatialization  (Read 3552 times)

0 Members and 1 Guest are viewing this topic.

Strikerklm96

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Spatialization
« on: June 05, 2014, 03:48:23 am »
http://www.sfml-dev.org/tutorials/2.0/audio-spatialization.php
Quote
First, you can set the listener's position in the scene:

sf::Listener::setPosition(10.f, 0.f, 5.f); //////obvious what this does
If you have a 2D world you can just use the same Y value everywhere, usually 0.
 //////so the 2d sound world is in the XZ plane right?

In addition to its position, you can define the listener's orientation:

sf::Listener::setDirection(1.f, 0.f, 0.f);
 //////so it is facing +X right?

Here, the listener is oriented along the +X axis. This means that, for example, a sound emitted at (15, 0, 5) will be heard from the right speaker.
 //////What?

Note that the "up" vector of the listener is always set to (0, 1, 0), in other words his head is oriented towards +Y.
///////I would think an up vector would mean that "up" for the listener is the +Y axis, meaning the top of his head is facing +Y

So with the top of his head facing +Y and his face facing +X, and his given position, why is the sound going to his right ear?I don't understand this. I made this picture to show how I interpreted it, but my interpretation is wrong somehow:

Black dot is Listener, the Blue dot represents right ear, brown dot is left ear. Arrow represents direction. Green circles represent sound. From this picture, I would think the sound should be equal in both ears(speakers). To clarify, the Y axis isn't even needed in this image, because everything has a y coordinate of 0. (everything is on the X,Z plane)
Click for bigger image.

Can someone explain to me what is wrong with my depiction, or explain the quote differently?
« Last Edit: June 05, 2014, 05:55:56 pm by Strikerklm96 »

Strikerklm96

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: Spatialization
« Reply #1 on: June 14, 2014, 07:20:39 pm »
Bump?  :-\

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Spatialization
« Reply #2 on: June 14, 2014, 07:45:53 pm »
If we use the model of the user's head for the listener, we can assume the following coordinate system:
  • +X is right
  • +Y is up (not towards the screen)
  • +Z is away from the screen
The default listener orientation corresponds to your head in front of the monitor:
  • Direction = -Z (towards the screen)
  • Up = +Y (up)
Therefore, if you set the direction to +X (right), then the sound (15, 0, 5) has a positive Z coordinate, which means away from the screen. Since you are facing right, z=5 is on the right side of your head.

Furthermore, if you want a 2D world sound, you should not set its Z component to zero, because that would model the situation where your head is inside the monitor. As a result, you'll only hear sounds on one ear, even if they're very close.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Strikerklm96

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: Spatialization
« Reply #3 on: June 15, 2014, 05:35:33 am »
Thanks for replying!
sf::Listener::setPosition(10.f, 0.f, 5.f);
 sound emitted at (15, 0, 5)
      The listeners position is now ALSO 5 units away from the screen, meaning he has the same Z value as the sound.
      So the listener and the sound source only differ by their X coordinate, and since he is facing along positive X, the sound source is literally right in front of him is it not? Or are those sound emit coordinates relative to the listeners current position?

Furthermore, if you want a 2D world sound, you should not set its Z component to zero, because that would model the situation where your head is inside the monitor. As a result, you'll only hear sounds on one ear, even if they're very close.

If the listener is in this position:
  • Direction = -Z
  • Up = +Y
  • Coordinates = (0,0,0)
Then wouldn't a sound played at (-5,0,0) play in the listeners left ear? Why would the Z coordinate matter?[/list][/list]
« Last Edit: June 15, 2014, 05:45:52 am by Strikerklm96 »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Spatialization
« Reply #4 on: June 15, 2014, 10:59:02 am »
Quote
So the listener and the sound source only differ by their X coordinate, and since he is facing along positive X, the sound source is literally right in front of him is it not?
That's right, maybe this is a mistake or at least a confusing description in the tutorial. Have you tried it, where do you hear the sound from?

Quote
Then wouldn't a sound played at (-5,0,0) play in the listeners left ear?
Yes.

Quote
Why would the Z coordinate matter?
Because of 3D perception. (-0.1, 0, 0) would still play in the left ear, however it's likely that a sound that close to the player should also be heard in the right ear.

I'd suggest you experiment a bit with sounds and sf::Listener to see how it works in practice :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything