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.