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

Author Topic: sf::Sound and sfBufferSound failing on file load -- help?  (Read 2829 times)

0 Members and 1 Guest are viewing this topic.

bluestreak

  • Newbie
  • *
  • Posts: 1
    • View Profile
sf::Sound and sfBufferSound failing on file load -- help?
« on: July 12, 2017, 05:13:43 am »
I am using Visual Studio 2017 64-bit on Windows 10. My project is a Win32 windowed application with C++, which means I'm not using the console. I just want to take advantage of sfml-audio.lib, which meant also using its dependency sfml-system.lib. I downloaded the 64-bit build for C++14 (Visual C++ 2015). Everything compiles fine, but when the program starts, the sound buffer fails to load in my wav file. To test, I used an audio from SFML's audio demonstrations. It still fails on execution, although it runs fine in SFML's demonstration. This tells me I'm using a valid sound file. I tried this in a simplified console project, and had the same issue. I even used SFML's audio demonstration and copied the source files into the new console project, and it also failed, although its existing demo worked fine.

I'm not sure what the problem is. If SFML uses DirectSound underneath for Windows, this API has been deprecated a while ago and has some functionality that doesn't work in Windows 10. Microsoft currently recommends XAudio2. I'm not sure if that's related though to simple playback as attempting here.

I checked for the error message, and all I got back was an empty string. My working directory is in the correct path as well. I used to love SFML, and would enjoy to continue using it, but this is becoming frustrating. I get the impression SFML is also slowing down because it hasn't released any binaries for the latest Visual Studio, so maybe bugs are to be expected with using VS2017. I heard of some lazy solution of using CMake, but it's confusing to me. Still, I'm not 100% certain these are relatable issues because the graphics tutorials works fine with VS2017 (not of which I'm using, but was good to test it), but I'm having trouble only with loading in the audio.

I thought I'd check here as a last attempt before I use something else.

How I'm loading in the libraries
#pragma comment(lib, "sfml-system.lib")
#pragma comment(lib, "sfml-audio.lib")


My load member function:

bool SFMLSound::init(const std::string &filename)
{
   std::ostringstream output;
   std::cerr.rdbuf(output.rdbuf());

   // Read in sound from file -- fails here
   if (!m_buffer.loadFromFile(filename))
   {
      // Redirect to a file
      std::ofstream file("sfml-log.txt");
      
      std::ostringstream output;
      sf::err().rdbuf(output.rdbuf());
       
      std::string error = output.str();  // shows blank string ("")
      file << error << std::endl;   

      file.close();
      return false;
   }
   
   // Load the sound from file
   m_sound.setBuffer(m_buffer);

   return true;
}


How I'm calling the function (using the wave file from SFML's demo):

   if (!snd.init("sound\\canary.wav"))
      return false; 

Temporary Fix:
A temporary solution I found was switching over to CSFML in my C++ application, and the audio is working fine. I'm figuring then the C++ audio library is not compatible with the latest Visual Studio 2017.
« Last Edit: July 12, 2017, 11:52:10 pm by bluestreak »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::Sound and sfBufferSound failing on file load -- help?
« Reply #1 on: July 16, 2017, 01:10:00 pm »
SFML uses OpenAL underneath.

There have been reported issues of using audio with Windows 10 (I can't use audio with Windows 10 at all) so it's likely to be linked to that. Apparently, SFML needs to update the version of OpenAL it uses [1].

Note: it's probably not VS2017 that's the problem; more likely Windows 10. However, you may want to consider using these VS2017 builds (by eXpl0it3r) instead of the VS2015 builds; some people seem to have had problems using VS2015 builds with VS2017.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*