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

Author Topic: Music Plays but Sound wont - no symbols loaded for sfml-audio-d-2.dll?  (Read 3606 times)

0 Members and 1 Guest are viewing this topic.

practikalmagik

  • Newbie
  • *
  • Posts: 7
    • View Profile
I have been working on a game using SFML and have managed to implement Music objects without problems. However, I can't seem to get a Sound object to work. I've tried a bare bones SFML project as per code below to make sure it's not anything related to my game and it still doesn't play a sound. The program just runs through and returns at the end, with no error messages.

SFML version 2.3.2
Visual Studio 2015

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

int main()
{
        sf::SoundBuffer buffer;
        sf::Sound sound;

        if (!buffer.loadFromFile("assets/sounds/pickup.wav")) {
               //error handling
                std::cout << "can't find sound file" << std::endl;
        }
        sound.setBuffer(buffer);

        if (sound.getStatus() != sf::Sound::Playing) {
                sound.play();
        }
        return 0;
}

The error handling message doesn't trigger so it seems to be loading ok, and its from the same folder as the correctly working music wav file. During debugging I have set a breakpoint at the sound.play() function and it definitely calls this, with the sound object seeming to hold the correct data (e.g. sound duration looks right etc). However it does have the following message:
sound   <Information not available, no symbols loaded for sfml-audio-d-2.dll>   sf::Sound

I've tried googling and it seems that there might be an issue with the .dll or .lib so I've checked these again and I'm sure I have this right:

All sfml 2.3.2 dll files are all in the same folder as main.

Project properties:
Debug
C/C++ - Additional Include Directories = C:\Users\[name]\Documents\SFML-2.3.2\include
Linker - Additional Library Directories = C:\Users\[name]\Documents\SFML-2.3.2\lib
Linker - Additional Dependencies = sfml-audio-d.lib;sfml-graphics-d.lib;sfml-window-d.lib;sfml-system-d.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)

Release
C/C++ - Additional Include Directories = C:\Users\[name]\Documents\SFML-2.3.2\include
Linker - Additional Library Directories = C:\Users\[name]\Documents\SFML-2.3.2\lib
Linker - Additional Dependencies = sfml-audio.lib;sfml-graphics.lib;sfml-window.lib;sfml-system.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)

Can anyone advise as I feel like I'm banging my head against a wall here. I hope this is enough info but let me know if you want to know anything else about the setup.

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
In this code, you are immediately leaving the application after starting the sound playing so it doesn't really have enough time to make any sound.

Also, sf::Sound doesn't play automatically so you don't need the check to make sure it isn't playing.

Try something more like this:
    sound.setBuffer(buffer);
    sound.play();

    while (sound.getStatus() == sf::Sound::Playing)
    {
    }
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

practikalmagik

  • Newbie
  • *
  • Posts: 7
    • View Profile
Thanks for a quick response. I tried arranging the code as per your example and the Sound is now playing. Hurrah! It makes sense that the sound needs time to play before moving to the return statement. Thanks!  :D

This causes an issue when I'm running the full game as the game loop pauses while the sound is playing in that while loop but I'm sure I can probably figure the appropriate solution to that.

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
You're welcome. Glad you got it working :)

The sound itself runs in a separate thread so the while loop is not necessary if the application is going to be open anyway, even if it's busy doing things. That is, keep the application open as normal and trigger sounds by using sound.play() and then forget about it; it'll play while your application continues!
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

practikalmagik

  • Newbie
  • *
  • Posts: 7
    • View Profile
I appreciate your response and I feel like I'm getting a better understanding of how this works. Sorry to ask further but I'm struggling to figure out where to put the call to play the Sound in my game.
I have a standard game loop of:
eventHandler
update
draw
restart after certain time

and at the moment, the Sound.play() line is in the event handler (so when the player picks something up a sound plays). If I have the following code the sound does play, but it pauses the game loop until it's finished playing (as the while loop is holding everything up):
sf::Sound sound;
        sound.setBuffer(buffer);
        sound.play();
        while (sound.getStatus() == sf::Sound::Playing) {

        }

however if I remove the while loop it doesn't play at all, I assume as the game loop is much faster than the sound length so it doesn't get a chance to play, before the object is destroyed.

I'm struggling to figure out where to put this sound.play() call, as I essentially want it to run simultaneously to the game loop. I sure I'm overcomplicating things but I just can't seem to put this bit together in my head!

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
After calling sound.play(), the sound will continue to play until one of these* things happen:
  • the application ends,
  • the sound finishes,
  • the sound is re-played,
  • you call sound.stop(),
  • either the sound object or its sound buffer is destroyed.
*not necessarily complete list

The last one in the list means that the sound and sound buffer must still exist until (probably in your case) the end of the program. Assuming your sound buffer exists for the entire application, this means that you shouldn't create a temporary (in the scope of the event handling) sound to play something; the sound should exists longer than that and just be started when needed. It's a good idea to create permanent sound objects and use (and re-use) those.

(click to show/hide)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

practikalmagik

  • Newbie
  • *
  • Posts: 7
    • View Profile
Thank you, keeping the Sound object as a permanent part of the Game class is what worked!
 I had done the same with the background music so I'm feeling silly that I didn't just do the same with a Sound object too.

 

anything