SFML community forums
Help => Audio => Topic started by: jeffkilledjohn on November 05, 2018, 12:54:39 am
-
Hi at all! I'm trying to add sounds into my game, but I am getting into troubles.
I am currently using Irrlicht, and I know I can't mix these two engines without problems, but I want only to play audio (and maybe networking, later)!!!
I followed this guide (I am using Visual Studio 2017):
https://www.sfml-dev.org/tutorials/2.5/start-vc.php
I linked against these SFML libraries (Debug config):
sfml-system-d.lib
sfml-audio-d.lib
openal32.lib
flac.lib
vorbisenc.lib
vorbisfile.lib
vorbis.lib
ogg.lib
But no sounds comes out of my game when I copy-paste this code:
sf::SoundBuffer buffer;
if (!buffer.loadFromFile("sounds/select.ogg"))
return;
sf::Sound sound;
sound.setBuffer(buffer);
sound.setLoop(true);
sound.play();
No errors appear in console. Where is the problem?
Thanks in advance!!
-
Is your volume up? Also check it's not muted on an application level.
What's your complete code?
SoundBuffer and Sound objects need to stay alive as long as sound is playing.
-
Aaaaah thanks!!! I thought only sf::Sound must be alive, because you are passing the SoundBuffer to sf::Sound, so it would be implicit. Anyway, thanks!!
-
Just to clarify, the sf::Sound doesn't store the sf::SoundBuffer (or a copy) but does store a pointer to the one you passed. This makes the sf::Sound a rather lightweight object that can be passed around and created quite quickly. Also, multiple sounds can point to the same sound buffer; this reduces the amount of storage used.