2

I've searched a lot, without luck particularly on which encoding to load a .OGG file on. I'm trying to add a audio file in .ogg format, and have no idea what the problem is.

Here's my steps on adding .OGG audio files to the project:

  1. I firstly add it to the audio assets in the project. When I open the .OGG file, I get an warning/error: enter image description here What encoding should i load an .OGG file in, if this is important?

    • I tried to just pick an encoding that didn't give me the warning, whitch was 'ISO-8859-1'. Note that i tried with other encodings, such as UTF-8, UTF-16, UTF-32, US-ASCII without any effect.

Here is a picture of the .OGG file in UTF-8 encoding (default): enter image description here

  1. I use SFML to load the sound files in a class i chose to call Sound:

Sound.cpp:

#include "Sound.h"

Sound::Sound() {
    const std::string pathToProject = "C:\\Users\\User\\projectName";

    exSongbuffer.loadFromFile(pathToProject + "\\projectContainer\\Assets\\Sounds\\ExampleSound.ogg");
        exampleSong.setBuffer(exSongbuffer);
    }

Sound.h:

#include <SFML/Audio/Sound.hpp>
#include <SFML/Audio/SoundBuffer.hpp>

class Sound {
public:
    Sound();

    sf::Sound ExampleSound;
    sf::SoundBuffer exSoundBuffer;
}

Configuration.h:

class Configuration {
public:
    Sound* sound = new Sound();
}

Machine.cpp:

StateMachine::StateMachine() {
    auto* sound = new Sound();
    config.sound = sound;
    sound->menuSong.play();
}

main.cpp:

int main() {
   StateMachine stateMachine;
   while (stateMachine.run()) { // run() just runs the program until the user exits.

   }
}    

Here is my error messages when trying to run the program:

enter image description here

RK_97
  • 61
  • 7
  • 1
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Alan Birtles Nov 21 '19 at 10:59
  • see also https://en.sfml-dev.org/forums/index.php?topic=13304.0. I don't know which text editor you are using but you shouldn't try to view a binary file in it – Alan Birtles Nov 21 '19 at 10:59
  • So this problem has to do with SFML not able to read the files? – RK_97 Nov 21 '19 at 11:15
  • No its to do with the way you are building your application, read the links I posted – Alan Birtles Nov 21 '19 at 11:31
  • 1
    First off: UTF-8 encoding only matters for text files, binary files are just binary and best viewed with a hex editor. Second: you need to adjust your compilation configuration to link with the `sfml-audio` library. I see you're using CMake so it should be a matter of adding `sfml-audio` to a `target_link_libraries` statement. If you do not know how to do that, please post your CMakeLists.txt file. – Botje Nov 21 '19 at 12:07
  • Thanks for advices! I had forgotten to add sfml audio to the target_link_libraries. I'lll check up the hexadecimal editor – RK_97 Nov 22 '19 at 09:40
  • Which editor (name) would work to this Botje? I've tried to reload the file with other editors, but did not work. – RK_97 Nov 22 '19 at 09:56

0 Answers0