New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sf::Sound does not play mono sf::SoundBuffer when previously played stereo sf::SoundBuffer #2319
Comments
Can't reproduce this with SFML 2.5.1, the 2.6.x branch and latest master (thanks GPT Chat for the example code): #include <SFML/Audio.hpp>
int main()
{
// Load the stereo sound buffer
sf::SoundBuffer stereoBuffer;
if (!stereoBuffer.loadFromFile("stereo.wav"))
{
// Error loading the sound buffer
return 1;
}
// Load the mono sound buffer
sf::SoundBuffer monoBuffer;
if (!monoBuffer.loadFromFile("mono.wav"))
{
// Error loading the sound buffer
return 1;
}
// Create a sound instance
sf::Sound sound;
// Play the stereo sound
sound.setBuffer(stereoBuffer);
sound.play();
// Wait for the sound to finish playing
while (sound.getStatus() == sf::Sound::Playing)
{
// Do nothing
}
// Play the mono sound
sound.setBuffer(monoBuffer);
sound.play();
// Wait for the sound to finish playing
while (sound.getStatus() == sf::Sound::Playing)
{
// Do nothing
}
} Sound files used: mono-stereo.zip Does the posted example also cause the issue you're describing? |
Thanks to you and ChatGPT for trying this out :) |
Here's a link to my code: |
Some things one could try:
|
I have mono samples in my project which have not been played at all by my The only difference in my implementation when it comes to playing sound is that an Also:
|
If the position is not set, it will be at default (0, 0, 0). This is a problematic value as it's not particularly clear which direction from the listener (also defaults to 0, 0, 0) the mono sound should be (it does, in fact, have no direction since it's at the same location). Basically, mono sounds that originate from the same position as the listener can cause issues. The solution is to actively and purposefully move it away. Just a tiny amount can be enough; just place it in front of the listener (to get mono in both sides). |
Subject of the issue
sf::Sound does not play mono sf::SoundBuffer when previously played stereo sf::SoundBuffer.
Your environment
Steps to reproduce
I load an sf::SoundBuffer (a stereo sample) into my sf::Sound, play it, all good.
Later I decide to recycle the sf::Sound in order to play another sf::SoundBuffer (a mono sample this time) and play that.
Expected behavior
I can hear the 2nd sample.
Actual behavior
I can't hear the 2nd sample.
Workaround
Just converting all my samples to stereo resolves the problem.
The text was updated successfully, but these errors were encountered: