Basics of SFML sound

Anything audio related falls into one of two categories within SFML: sf::Sound that represents short sound effects, or sf::Music that is used to play longer audio tracks. It's prudent that we understand how these two classes are used before continuing further. Let's talk about each one individually.

Playing sounds

The sf::Sound class is extremely lightweight and should only ever be used to play short sound effects that don't take up a lot of memory. The way it stores and utilizes actual audio files is by using a sf::SoundBuffer instance. It is analogous to sf::Sprite and the way it uses an instance of sf::Texture for drawing. The sf::SoundBuffer is used to hold audio data in memory, which the sf::Sound class then reads and plays ...

Get SFML Game Development By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.