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.