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

Author Topic: Sound spatialization seems to be 0-1  (Read 2243 times)

0 Members and 2 Guests are viewing this topic.

gogep

  • Newbie
  • *
  • Posts: 3
    • View Profile
Sound spatialization seems to be 0-1
« on: February 13, 2023, 09:55:08 pm »
I'm trying to make use of sound's position, but unless it's perfectly on the listener it always puts 100% of the sound in either speaker.

For example:

sf::Listener::setPosition({0, 0, 0});
sf::Sound sound(/* sound buffer */);
sound.setPosition({0.0001, 0, 0});
sound.play();
 

Entirety of this sound will be in the right speaker. There's no value I can set to make it sound like it's just a bit to the right; it's always all or nothing. I'm on Linux if it matters

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Sound spatialization seems to be 0-1
« Reply #1 on: February 15, 2023, 03:22:10 am »
It's a mono sound and is coming from a specific direction.
For stereo output:
If it's exactly right of the listener - however close or far, it will be only in the right 'ear'.
If it's exactly left, only the left 'ear'.
If you want to hear the sound in both 'ears', it needs to be in front of the listener (or behind).
Basically, put the z value into positive values. I've found that it should never really be exactly zero (unless you need exactly only one side); it's too unpredictable. A very low positive value works well but if you're moving around the stereoscape, it should be in a relative scale to the movement of the x value.
For example, try a sound's position of { 0.5f, 0.f, 0.866f } (this should be about 30 degrees to the right, starting from in front of you as 0 degrees)

Have a look at this that shows sound orbiting around the listener:
https://github.com/Hapaxia/OrbitingSound
« Last Edit: February 15, 2023, 03:27:07 am by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

gogep

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Sound spatialization seems to be 0-1
« Reply #2 on: February 15, 2023, 04:21:51 am »
Thanks! It does indeed work

Quote
this should be about 30 degrees to the right, starting from in front of you as 0 degrees

If you think about it as the angle the sound comes from, it makes perfect sense why my example didn't work. And now that I think about it more, a person whispering in my right ear would be mostly "to the right" despite being very close; so setting a small value shouldn't work on its own. Thanks again