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

Author Topic: Audio Artifact on First Play after Volume Change  (Read 13889 times)

0 Members and 1 Guest are viewing this topic.

Acumen

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Audio Artifact on First Play after Volume Change
« on: October 14, 2021, 08:51:45 pm »
So it has been a while since I have used SFML, but my build folder does say I am on 2.5.1.

I am trying to have a mute button, but am getting a strange artifact. It seems volumes will only change when the sound is actually playing.

So if volume is 100, set it to 0, it appears the next time the sound is played it will for a split second be at 100 then switch to 0, but it isn't before the sound starts so there is an audible blip. If that sound is played again (with no volume changes) this does not repeat. This happens individually for each effect, so it isn't one blip, but a blip for the first time each effect is played after change.

Sleep(1000);
sf::Listener::setGlobalVolume(100.0f);
effect[2].play();
Sleep(1000);
sf::Listener::setGlobalVolume(0.0f);
effect[2].play();
Sleep(1000);
effect[2].play();

Results in first play fine, second blip, third silent.

Sleep(1000);
sf::Listener::setGlobalVolume(100.0f);
effect[2].play();
Sleep(1000);
sf::Listener::setGlobalVolume(0.0f);
Sleep(1000);
effect[2].play();
Sleep(1000);
effect[2].play();

Results are the same as above, so a pause before playing doesn't help.

The same happens if I set the volume of individual effects rather than the listener.

Am I doing this incorrectly? Something with my system? With openal32? Seems unlikely that this would not already be in the forums that I could find if it wasn't something on my machine.

*EDIT*

I've been playing around a bunch, and gotten more clues. So I have some very short sounds, and so it is clear the volume change is only being applied while playing. Some are short enough where it takes 10 or 20 plays of the sound, progressively softer, for the volume to go to 0.

Doesn't seem like it should work this way.
« Last Edit: October 14, 2021, 09:53:08 pm by Acumen »

Acumen

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Re: Audio Artifact on First Play after Volume Change
« Reply #1 on: October 22, 2021, 04:39:02 pm »
Anyone able to confirm if this is SFML/openAL, or my build/system?

Possible work arounds?

Acumen

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Re: Audio Artifact on First Play after Volume Change
« Reply #2 on: November 22, 2021, 12:55:24 am »
#include <SFML/OpenGL.hpp> // For Sleep()
#include <SFML/Audio.hpp>

int main()
{
        sf::SoundBuffer SFMLSoundBuffer;
        sf::Sound SFMLSound;

        SFMLSoundBuffer.loadFromFile(std::string("audio/") + "blip1.wav");
        SFMLSound.setBuffer(SFMLSoundBuffer);

        Sleep(1000);
        sf::Listener::setGlobalVolume(100.0f);
        SFMLSound.play();
        Sleep(1000);
        sf::Listener::setGlobalVolume(0.0f);
        Sleep(1000);
        SFMLSound.play();
        Sleep(1000);
        SFMLSound.play();
        Sleep(1000);

        return (0);
}

Complete example where blip1.wav is any audio file where the audio starts right away, so no padding of silence at the start.
« Last Edit: November 22, 2021, 12:57:27 am by Acumen »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Audio Artifact on First Play after Volume Change
« Reply #3 on: December 02, 2021, 12:29:40 am »
Sorry for the delay, given that I promised to have a look the next day...

I've tested your code and I can't reproduce it.
For me there's only one sound being played and no blip when starting the next sound after a volume change.

Small modification to use sf::sleep(), but I guess this shouldn't really have an impact on it.

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

int main()
{
    sf::SoundBuffer SFMLSoundBuffer;
    sf::Sound SFMLSound;

    if (!SFMLSoundBuffer.loadFromFile("blip.wav"))
    {
        return -1;
    }
    SFMLSound.setBuffer(SFMLSoundBuffer);

    sf::sleep(sf::seconds(1.f));
    sf::Listener::setGlobalVolume(100.0f);
    SFMLSound.play();
    sf::sleep(sf::seconds(1.f));
    sf::Listener::setGlobalVolume(0.0f);
    sf::sleep(sf::seconds(1.f));
    SFMLSound.play();
    sf::sleep(sf::seconds(1.f));
    SFMLSound.play();
    sf::sleep(sf::seconds(1.f));
}

Attached is also the audio clip I used.

I ran with on VS 2022 and the latest master (today's commit level).
Are you also running on SFML master?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Acumen

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Re: Audio Artifact on First Play after Volume Change
« Reply #4 on: December 02, 2021, 11:35:52 pm »
Hey!

Thanks very much for confirming it was not reproducible. I dug into it and tracked down the culprit to be the openal32.dll I was using.

No idea how or why that would be the case after a bit of googling. One of the first things I did initially was check if it had been updated but seemed to me like 2009 was the last revision so I didn't bother swapping it. Guess that was way off, or I had a weird build of it somehow?

Appreciate it!





eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Audio Artifact on First Play after Volume Change
« Reply #5 on: December 03, 2021, 12:54:13 am »
Ah, always make sure to use the DLL that's shipped with SFML. But it right next to your executable to ensure, no system DLL is loaded.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything