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

Author Topic: Can I and how to change sf::Sound's panning  (Read 4098 times)

0 Members and 1 Guest are viewing this topic.

Sefiria30

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Can I and how to change sf::Sound's panning
« on: July 31, 2014, 07:31:34 pm »
Hi,
I'm student in a video games school, in France.
Do you know how it's possible to change the sf::Sound's panning without to use the sf::Listener ?
Sorry for my bad english, if is that case.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Can I and how to change sf::Sound's panning
« Reply #1 on: August 01, 2014, 10:25:01 am »
What do you exactly mean by panning? A sound has no orientation, only a position. The listener determines where sounds are perceived.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can I and how to change sf::Sound's panning
« Reply #2 on: August 02, 2014, 12:40:19 am »
What do you exactly mean by panning?
I would guess that panning in this context means changing the stereo positioning (left to right). The spatial positioning looks complicated if you just want stereo panning.

change the sf::Sound's panning without to use the sf::Listener ?
I think that the sf::Listener is getting used whenever you play any sounds so I don't think you will have to actually change sf::Listener. It should be okay to use sound.setPosition() to set the panning. The default position of sf::Listener is (0, 0, 0) so setting the sound's position to (1, 0, 0) would give you "right" and (-1, 0, 0) would give you "left". Note that those are hard pans though and I think that any positive number (x, 0, 0) would be hard right. If you need part panning, you should use adjust x and z together to. e.g. (0, 0, -1) would be in front (centred panning).

I haven't done enough with this stuff yet. I'm going to go and mess with it 8) If I make a panning function (I can't imagine it'll be hard), I'll let you know ;D Still, I'm sure you can figure it out :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can I and how to change sf::Sound's panning
« Reply #3 on: August 02, 2014, 02:35:39 am »
sf::Vector3f stereoPanPosition(float panAmount)
{
        // make sure that panAmount is in the range [-1, 1] (-1 is left; 1 is right)
        if (panAmount > 1.f) panAmount = 1.f;
        if (panAmount < -1.f) panAmount = -1.f;
        return{ panAmount, 0.f, panAmount < 0.f ? -panAmount - 1.f : panAmount - 1.f };
}
To use, you can set the panning of the sound by using:
sound.setPosition(stereoPanPosition(pan));
where pan is a value from -1 to 1, representing left to right.

Although this works fine, it's not perfect. The amount of panning is more severe nearer the sides. This is because this code 'moves' the sound linearly (diagonally between a side and the front).  It would work better if it was positioned using a curve instead. Homework for you... ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Sefiria30

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Can I and how to change sf::Sound's panning
« Reply #4 on: August 05, 2014, 07:34:10 pm »
Thinks for your responses !
In fact, I would change the "left-right" reception of the sound (panning) without to use sf::Listener.
But I think it isn't possible like that with SFML. Think you anyway !

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Can I and how to change sf::Sound's panning
« Reply #5 on: August 06, 2014, 04:48:41 pm »
Thinks for your responses !
change the "left-right" reception of the sound (panning) without [using] sf::Listener.
But I think it isn't possible like that with SFML.
The function I posted above will do that for you. There is then no need to use sf::Listener, only sound.setPosition, which is where you would change the panning.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything