SFML community forums

Help => Audio => Topic started by: jeffkilledjohn on November 05, 2018, 12:54:39 am

Title: No audio comes out of my program
Post 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!!
Title: Re: No audio comes out of my program
Post by: eXpl0it3r on November 05, 2018, 09:05:16 am
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.
Title: Re: No audio comes out of my program
Post by: jeffkilledjohn on November 05, 2018, 05:54:17 pm
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!!
Title: Re: No audio comes out of my program
Post by: Hapax on November 07, 2018, 11:00:27 pm
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.