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

Author Topic: [SOLVED] Slow downs when using sounds  (Read 2868 times)

0 Members and 1 Guest are viewing this topic.

Ghi102

  • Newbie
  • *
  • Posts: 2
    • View Profile
[SOLVED] Slow downs when using sounds
« on: March 03, 2015, 09:43:35 pm »
Hi, I've been using the SFMl audio library to play sounds on a game and I noticed that the game started lagging.

I know that the sound starts playing in another thread so I don't really see why this would happen. Here's the relevent code:

// Constructor
PaletteAnimator::PaletteAnimator()
{
        a_angle_max_z = 60.0;
        a_angle_min_z = 0.0;
        a_angle_z = 0.0;
        m_acceleration = 15;

        if (!m_startSound.loadFromFile("./../bin/media/audio/sound/animation_palette_start.wav"))
                std::cout << "Error loading file <animation_palette_start.wav> \n";
                m_sound.setBuffer(m_startSound);

}

void PaletteAnimator::animate(float temps, bool animate)
{
        if (animate && a_angle_z < a_angle_max_z)
        {
                if (m_sound.getStatus() != m_sound.Playing) {
                        m_sound.play();
                }
               

                a_angle_z += temps * a_angle_max_z * m_acceleration;
        }
        else if (!animate && a_angle_z > a_angle_min_z)
        {
                a_angle_z -= temps * a_angle_max_z * m_acceleration;
        }

        validateParameters();
}

Commenting the line

m_sound.play();

will solve the problem, but, obviously, the sound will not play.


The animate() method is called once a frame and m_sound is a sf::Sound and m_startSound is a sf::SoundBuffer.
« Last Edit: March 04, 2015, 06:40:02 pm by Ghi102 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Slow downs when using sounds
« Reply #1 on: March 04, 2015, 07:50:31 am »
Lag is a rather broad term, as such you need to be more specific.
Are you running it in release mode?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ghi102

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Slow downs when using sounds
« Reply #2 on: March 04, 2015, 06:39:44 pm »
Ah... That was such a dumb mistake...

Yeah, it was running in debug mode, it explains everything now, thanks a lot.

Should've checked that -.-.

 

anything