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

Author Topic: Sound not played through left speaker  (Read 4337 times)

0 Members and 1 Guest are viewing this topic.

Babbzzz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Sound not played through left speaker
« on: January 19, 2015, 02:03:38 pm »
Hello

I am writing a program to play audio only through the right earphone. The code is below. Why is it not working? Audio plays through both.

#include <SFML/Audio.hpp>
#include <iostream>

using namespace std;
using namespace sf;

void playSound() {
    SoundBuffer Buffer;                            
   
    // Load a sound buffer from a wav file

    if (!Buffer.loadFromFile("right.wav"))                  
        cout << "ERROR!" << endl;
   
    sf::Listener::setPosition(10.f, 0.f, 5.f);
    sf::Listener::setDirection(1.f, 0.f, 0.f);

    // Load a sound buffer from a wav file

    Sound Sound(Buffer);                                    
    Sound.play();                                          

    // Loop while the sound is playing

    while (Sound.getStatus() == sf::Sound::Playing) {      
       
        sf::Time t1 = sf::seconds(0.1f);
        sf::sleep(t1);

        // Display the playing position

        cout << "\rPlaying... " << endl;
    }
}

int main() {
    playSound();
    cout << "Done" << endl;
    return EXIT_SUCCESS;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sound not played through left speaker
« Reply #1 on: January 19, 2015, 02:45:39 pm »
Is your sound file mono or stereo?
Laurent Gomila - SFML developer

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Sound not played through left speaker
« Reply #2 on: January 19, 2015, 10:20:54 pm »
To underline what Laurent said:
http://www.sfml-dev.org/tutorials/2.2/audio-spatialization.php#spatialized-sounds-are-mono

Also, you may want to consider setting a position for the actual sound (you have altered only the listener).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Babbzzz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Sound not played through left speaker
« Reply #3 on: January 20, 2015, 06:26:21 am »
Thanks for the heads up. I converted the audio to mono using Audacity but the problem still persists. Just to give a little more scenario. I am using Sublime Text and compiling using g++.

I changed the code to what is seen below. Still no change.

    sf::Listener::setPosition(0.f, 0.f, 0.f);
    sf::Listener::setDirection(1.f, 0.f, 0.f);
    sf::Sound::setPosition(10.f, 0.f, 0.f);
    sf::Sound::SetRelativeToListener(true);
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Sound not played through left speaker
« Reply #4 on: January 20, 2015, 07:47:15 am »
The sound is right in front of the listener, so I'm not surprised it is heard equally on left and right speakers ;)
Laurent Gomila - SFML developer

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Sound not played through left speaker
« Reply #5 on: January 20, 2015, 02:36:32 pm »
To clarify,
    sf::Listener::setDirection(1.f, 0.f, 0.f);
means that the listener is "turned to the right".
The position of the sound is relative to the listener but the orientation is not.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Babbzzz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Sound not played through left speaker
« Reply #6 on: June 15, 2015, 02:10:30 pm »
Thank you all for your help.

Sorry for the delay in replying.

I got it working on an ARM board like I wanted.

Cheers!