SFML community forums

Help => Audio => Topic started by: TeGeek on January 12, 2020, 12:55:28 am

Title: Error loading audio file
Post by: TeGeek on January 12, 2020, 12:55:28 am
So i have an issue where when im trying to load my wav sound file into the soundbuffer it just doesnt work i have tried with multiple files and different types of file paths but i keep getting error while trying to link the file.

 
Code: [Select]
if (!buffer.loadFromFile("sample.wav"))
{
cout << "error loading the sound file" << endl;
}
deathSound.setBuffer(this->buffer);
Title: Re: Error loading audio file
Post by: eXpl0it3r on January 12, 2020, 09:04:52 am
What errors are you getting?
Title: Re: Error loading audio file
Post by: TeGeek on January 12, 2020, 09:18:09 am
i get the error i wrote to get when it fails to load which is "error loading the sound file"
Title: Re: Error loading audio file
Post by: eXpl0it3r on January 12, 2020, 12:22:18 pm
SFML will print out more error information to the console if fails to load a file.

Most common error is: wrong relative path (e.g. not in working directory).
Title: Re: Error loading audio file
Post by: TeGeek on January 12, 2020, 12:48:25 pm
ive tried several different types of pathing and what im expecting to be default would be in my x64 folder inside my bin.

is there any way to get it to show more info when it fails?
Title: Re: Error loading audio file
Post by: Laurent on January 12, 2020, 04:50:16 pm
Quote
ive tried several different types of pathing and what im expecting to be default would be in my x64 folder inside my bin.
If run from the IDE, it's "Project properties" > "Debugging" > "Working directory". This is usually set to $(ProjectDir) by default, I personnally replace it with $(TargetDir) so that it's the same directory as the created executable.

Quote
is there any way to get it to show more info when it fails?
As already said, SFML prints error details to the standard error output (so it shows in the console by default).
Title: Re: Error loading audio file
Post by: TeGeek on January 12, 2020, 05:06:44 pm
so i changed the working directory and put the sound file in that folder but im still unable to load the file
Title: Re: Error loading audio file
Post by: Laurent on January 13, 2020, 08:17:24 am
How many times do we have to ask for the what SFML prints to the standard error output? ;D
Title: Re: Error loading audio file
Post by: TeGeek on January 13, 2020, 02:59:36 pm
i dont know how to get sfml error to show since i currently am not getting any error apart from the error message i added to show when the file fails to load.

tried some stuff with sf::err() but im not sure if im using it properly currently have it like this

Code: [Select]
if (!buffer.loadFromFile("death.wav"))
{
std::ofstream file("sfml-log.txt");
std::streambuf* previous = sf::err().rdbuf(file.rdbuf());
}
Title: Re: Error loading audio file
Post by: Hapax on January 16, 2020, 01:55:02 am
Does the file work with a simple program that only loads the file and sets that buffer to a sound?

Does "buffer" and "this->buffer" refer to the same thing?
Title: Re: Error loading audio file
Post by: TeGeek on January 16, 2020, 08:01:11 am
im not able to get any sound file to work even in a program that just plays the sound

and yes they refer to the same thing
Title: Re: Error loading audio file
Post by: Laurent on January 16, 2020, 08:38:53 am
Does the "sound" example of the SFML SDK work? That should be your starting point.
Title: Re: Error loading audio file
Post by: TeGeek on January 16, 2020, 10:33:12 am
do you mean the sound example in the sfml folder?

if thats what you mean i cant run the exe file cause it says im missing OpenAL32.dll
Title: Re: Error loading audio file
Post by: Laurent on January 16, 2020, 12:57:24 pm
All the necessary DLLs are included, just copy them next to the executable.
Title: Re: Error loading audio file
Post by: TeGeek on January 16, 2020, 04:33:24 pm
i still get the same error after copying the dll to the executable
Title: Re: Error loading audio file
Post by: Laurent on January 17, 2020, 08:37:00 am
If you copied the right DLL at the right place, it can't say that anymore ;)
Title: Re: Error loading audio file
Post by: TeGeek on January 17, 2020, 10:03:22 am
ok so i got the sound example to work and it plays the sound without problem. i tried putting the sound file the the example used in my project at the working path location but it still fails to load.

what is the code i need to use to get sfml to print out error since what im trying to use isnt working.
Title: Re: Error loading audio file
Post by: eXpl0it3r on January 17, 2020, 10:37:50 am
Can you provide your code as a minimal example that still causes the issue?
Title: Re: Error loading audio file
Post by: TeGeek on January 17, 2020, 11:04:18 am
so this is from when i tried to get sound to work on a seperate file and its not working


Code: [Select]
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>z
#include <iostream>
#include <fstream>
#include <sstream>
#include <streambuf>


using namespace std;

#ifdef _DEBUG
#pragma comment(lib, "sfml-window-d.lib")
#pragma comment(lib, "sfml-system-d.lib")
#pragma comment(lib, "sfml-graphics-d.lib")
#pragma comment(lib, "sfml-audio-d.lib")
#else
#pragma comment(lib, "sfml-window.lib")
#pragma comment(lib, "sfml-system.lib")
#pragma comment(lib, "sfml-graphics.lib")
#pragma comment(lib, "sfml-audio.lib")
#endif


int main()
{

sf::SoundBuffer buffer;
if (!buffer.loadFromFile("sounds/canary.wav"))
{
std::ofstream file("sfml-log.txt");
std::streambuf* previous = sf::err().rdbuf(file.rdbuf());
cerr << "i wantt more debuf info than this";
return -1;
}

sf::Sound death;

death.setBuffer(buffer);

death.play();

getchar();
return 0;
}
Title: Re: Error loading audio file
Post by: eXpl0it3r on January 17, 2020, 11:39:16 am
Is this a typo or do you actually have that 'z' in your source code?

#include <SFML/Graphics.hpp>z
Title: Re: Error loading audio file
Post by: TeGeek on January 17, 2020, 11:44:23 am
its a type but that wasnt the issue got it solved by a friend. issue was with it being in debug instead of realease mode.