Give sound to your C++ projects with fmod

When developing new applications or tiny games with SDL, OpenGL or small3D, a requested and valuable feature is adding sound effects, raising alarms or creating new atmospheres. With this feature in mind and thanks to the work of FMOD and Miguel Hernando we announce today a new block that incorporates all the functionality to your project: EasySound.

What does fmod do?

EasySound wraps the main functionality of the low-level fmod api and can deal with different kinds of sound files and formats: mp3, wav, ogg. FMOD is an audio tool developed by Firelight Technologies focused on the development of professional video games. It has been used in over 2000 games and has integration with well-known game engines such as Unity or Havok.

fmod logo

At EasySound block, there is a simple class called EasyPlayer which is a very straightforward way to handle sounds.

Developing a Virtual Player

We’ll develop a simple application using EasySound to make a virtual player with your keyboard, similar to sound keyboards used for live radio streams. This application uses SDL to show the simplicity of incorporating sounds into a game. It also handles key interruptions from keyboard making this project multi-platform compatible.

To start this new project create a block with the simple layout and place a main.cpp inside:

Now it’s time to create a new folder called “sounds” with plenty of sound files inside. You can find some sound effects here or use whatever you want. Add them to your biicode.conf [data] section, to create a link to the main file with your sound files.

NOTE: Add a cool png image for the background of your app.

This way the sounds folder is copied to bin/your_user/easysound_example/sounds/… So you have to follow this path to refer to your sounds in your code.

Add some code to your main.cpp:

Build your project:

As you can see, we just assigned sounds to the number keys on the keyboard. So just press the desired key and sound will come out immediately. You can play sounds simultaneously and create virtual effects. It is a great idea for musicians to create new atmospheres for their songs!

Open and build

I have developed my own virtual player, so just check Dani_MTB/easysound_example to see how it works:

fmod's virtual player with background

You can see another example at block miguel/test_easysound or develop your own application with #include miguel/easysound using the class EasyPlayer.

Go ahead and give sound to your projects!

IMPORTANT: FMOD is free to use for not commercial purposes. Please, check the fmod LICENSE when using this software.


Related Posts