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

Author Topic: Creating an instance of any audio object causes fps drop.  (Read 3846 times)

0 Members and 1 Guest are viewing this topic.

Nugsy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Creating an instance of any audio object causes fps drop.
« on: April 18, 2013, 02:14:30 am »
I have been trying to solve this all day with no luck unfortunately.
No matter where i create an instance of either a sf::Sound or an sf::SoundBuffer, there is a noticeable drop in the framerate of my project.

With no sound objects:
Uncapped framerate = 500+.
Capped framerate    = 60.

With at least one sound object:
Uncapped framerate = 500+.
Capped framerate    = 50.

I'm pretty sure this isn't an issue with my code as i've tried a large amount of tests over the course of today. Personally i believe it's an issue with either SFML or one of the libraries linked to by the Audio module. I'm not saying it definitely isn't my code 100% however haha.

I should also mention that when i ran the project on another system, the capped framerate of the project with a sound object is 60. So this could be an issue with my laptop, rather than an issue with either of the things i mentioned above.

I can provide minimal code if anyone needs it, however it is currently 1:15am and i really need to sleep!

Any help is greatly appreciated.

Thanks,
Nugsy.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: Creating an instance of any audio object causes fps drop.
« Reply #1 on: April 18, 2013, 02:21:51 am »
I can provide minimal code if anyone needs it, however it is currently 1:15am and i really need to sleep!
If you've been trying to solve this all day and still don't have a minimal example, then you've been doing it wrong. ;)
To test what has which effect from where on what, you always need to start cutting down and off or go the easier way and start new with the lowest number of things, i.e. a normal game loop and a way to tell the fps.
With that you can test how the FPS is, without a sound object and how it is with. You can then also run profilers, to potentially figure out where the application spends a lot of unnecessary time.

Are both, your audio and graphics driver uptodate?
Do you notice any problems when playing a sound with another application?

My best guess would be, either you're handling SFML's "sound system" wrong, or you might have a problem with the given OpenAL version.

What SFML version are you using (i.e. from where did you get it)?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nugsy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Creating an instance of any audio object causes fps drop.
« Reply #2 on: April 18, 2013, 02:44:43 am »
I actually just came back to edit some of that information into my original post but you beat me to it haha.

Im using the RC of SFML2 (downloaded from the main website), the problem occurs in both the Debug and Release versions of the project, and it doesn't matter whether SFML is statically or dynamically linked.
All graphics and audio drivers are up-to-date.

I've tried the project with the OpenAL32.dll and libsndfile-1.dll libraries included with SFML RC2 and with the latest freshly downloaded versions.

I'm not using my own laptop at the momet, but a minimal code reproduction of the problem would be along the lines of:

Code: [Select]
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

#include <iostream>

int main()
{
    sf::SoundBuffer* buf = new sf::SoundBuffer; //if this is commented out, the fps will be higher

    int frameCounter;
    int fps;
    sf::Clock clock;

    sf::RenderWindow win;
    win.setFramerateLimit(60)
    while (win.isOpen())
    {
        //poll events...

        //attempt at an in-browser fps counter
        if (clock.getElapsedTime().asMilliseconds() >= 1000)
        {
            fps = frameCounter;
            frameCounter = 0;
            clock.restart().asMilliseconds();
        }
        else
        {
            frameCounter++;
        }

        std::cout << fps << "\n";

    }
   
    delete buf;
    return 0;
}

That may not compile, as i've just written it in the reply. I'll have to give this example a go tomorrow and see if this gives me the fps drop as well as my actual project.

In hindsight i probably should have done this hours ago, but i was prett stressed so i wasn't thinking clearly haha.

Thanks for the speedy reply :).

Nugsy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Creating an instance of any audio object causes fps drop.
« Reply #3 on: April 18, 2013, 03:34:28 pm »
I have just done a minimal code test and i am still getting the same problem as last night.

Here is the code that i used for testing:

Code: [Select]
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

#include <iostream>
#include <sstream>

template <class T>
inline std::string ToString(const T& t)
{
    std::stringstream ss;
    ss << t;
    return ss.str();
}

int main()
{
int frameCounter;
int fps;
sf::Clock clock;

sf::RenderWindow Win(sf::VideoMode(200, 200), "test");
Win.setFramerateLimit(60);

//sf::SoundBuffer buf; //uncommenting this line will cause an fps drop

while (Win.isOpen())
{
sf::Event Event;
while (Win.pollEvent(Event))
{
if (Event.type == sf::Event::Closed)
{
Win.close();
}
}

        if (clock.getElapsedTime().asMilliseconds() >= 1000)
        {
            fps = frameCounter;
            frameCounter = 0;
            clock.restart().asMilliseconds();
        }
        else
        {
            frameCounter++;
        }


Win.clear();

sf::Text t;
t.setString(ToString(fps));
Win.draw(t);

Win.display();
}

return 0;
}

Line 26 is the problematic line.
I have also uploaded a compiled version of this program for easier testing, and in the hope that it will help us to resolve this issue faster.

7Zip archive: http://www.mediafire.com/?0qd2r39ensd0g1g
ZIP archive:  http://www.mediafire.com/?zansd2bsrba8x6b

Both archives contain the same files however i have provided both in the event that someone does not have 7Zip.



------------------------------------------------UPDATE------------------------------------------------

I have found the issue and have fixed it, i'll post what i did here incase anyone stumbles across this thread in the future.

It was a problem with the openal32.dll included with the SFML RC2 download. I replaced this file with another version of the same dll from a game installed on my system. Both my main project and the test project now run completely fine.

Here is a link to the .dll that i have used, again incase anyone stumbles across this thread:
http://www.mediafire.com/?l2qlp27hh5334hz

Cheers,
Nugsy.
« Last Edit: April 18, 2013, 04:21:09 pm by Nugsy »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: Creating an instance of any audio object causes fps drop.
« Reply #4 on: April 18, 2013, 04:16:17 pm »
You should use the code=cpp tag when posting code. ;)

Well since newer versions of SFML don't use a default font and I was too lazy to load one, I used an external application to measure it (i.e. PlayClaw), but I've not noticed any performance problems.
I get steady 60±2fps with setFramerateLimit or vsync and up to 3700ish fps without a limit. Also at high fps a drop of a few hundreds frames per second, isn't significant at all, because at such high rates the slightest thing can break it, besides that no application/game should be intended to run with 2000 fps anyways.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nugsy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Creating an instance of any audio object causes fps drop.
« Reply #5 on: April 18, 2013, 04:18:58 pm »
I have updated the above post with a fix for this issue, you posted just as i was updating that one haha.

Thanks for the help. :)

 

anything