# Soundengine basics

**URL:** https://qa.fmod.com/t/soundengine-basics/18419
**Category:** FMOD Engine
**Tags:** cpp
**Created:** [February 21, 2022, 10:51pm UTC](https://qa.fmod.com/t/soundengine-basics/18419 "2022-02-21T22:51:55Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mca2](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/mca2/32/3177_2.png) [@mca2](https://qa.fmod.com/u/mca2)
#### Post date: [February 21, 2022, 10:51pm UTC](https://qa.fmod.com/t/soundengine-basics/18419/1 "2022-02-21T22:51:55Z")

</div>

The more I read about FMOD (and especially FMOD studio), to more I think it will be great for our game. But unless you’re using UE/unity the documentation is somewhat limited and the examples dated or not useful.

So I have some questions on setting up the sound engine. Our 3D space game has a single listener and is moving around in a world with multiple objects (which can be other online players). Each object has its (engine)sound, quite a few identical and of course the usual rockets, explosions etc.

**Initialisation**  
So first the initialisation, after some reading I discovered `FMOD_INIT_VOL0_BECOMES_VIRTUAL` is pretty important, so I use the code below to initialise. and set `FMOD_ADVANCEDSETTINGS.vol0virtualvol` to 0.001. Are there any good practices/flags I should add?

`initialize(512, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL | FMOD_INIT_3D_RIGHTHANDED | FMOD_INIT_VOL0_BECOMES_VIRTUAL, nullptr);`

**Bank loading**  
Seems straight forward using `LoadBankFile()` and storing the ptr in a map `std::map<std::string,	FMOD::Studio::Bank*>`

**3D sounds**  
My idea was to work with event instances (a lot of example use channel maps? why?). As multiple instances can use the same event description, storing the ptr and description in a map, doesn’t work. So my idea was to store the event instance ptr created with `createInstance()` in the object and use this ptr (after checking if it’s still valid) to update the 3D position each tick.

The UE implementation seems to do it the other way round, and store (attach) the object ptr with the instance ptr. Is there a good reason to go for this model?

**Playing the sound**  
We have in cockpit (2D) sounds, one offs (flipping a switch, shooting a laser), sounds while pressed (opening canopy by holding a switch), constant sounds parameter dependent (engine sounds changing with speed) and more or less the same for the external (3D) sounds emitted by the objects.

The one-offs seem simple (play & release, and if short only initial 3D position to be set). But what are the guidelines for especially the looping (while pressed & constant sound)? And how to attenuate eg the engine sound when shooting a laser or receiving a message?

**Your help is appreciated**  
I would be really greateful to get some pointers on the above. And if I missed some essential elements (profiler? buses? vca?), please le me know. I don’t mind sharing the result in a public repo so others can learn from it as well when using FMOD.

---

<div class="post-metadata">

### Author: ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)
#### Post date: [February 28, 2022, 12:28am UTC](https://qa.fmod.com/t/soundengine-basics/18419/2 "2022-02-28T00:28:23Z")

</div>

> [@mca2](#):
>
> Are there any good practices/flags I should add?

Might be a good idea to enable logging as well, it makes it a lot easier to debug your game and liaise with support if necessary. You can do this by calling [`FMOD::Debug_Initialize`](https://fmod.com/resources/documentation-api?version=2.02&page=core-api-common.html#debug_initialize), passing in `FMOD_DEBUG_LEVEL_LOG` as the first argument for maximum logging.

> [@mca2](#):
>
> (a lot of example use channel maps? why?)

Not sure what you mean by channel maps, are you asking why some examples use channels and others use event instances?

> [@mca2](#):
>
> Is there a good reason to go for this model?

Off the top of my head, depends on whether you think you will have lots of objects with sound managed in the same way, or few objects with sounds managed in different ways. Having a generic sound manager that only requires an object’s transform lends itself better to the former because you will only need to create one sound manager class that can latch onto anything (as the UE integration does), whereas having specialized sound managers local to specific objects lends itself better to the latter because you will be able to have fine-grained control without needing to make many arbitrary sound manager specializations.

> [@mca2](#):
>
> But what are the guidelines for especially the looping (while pressed & constant sound)?

Probably a state machine that calls a looping event during the active state, and stops in the inactive state. There was some [discussion](https://qa.fmod.com/t/visual-scripting/18354/2) about this recently using Unity bolt scripting which conveniently illustrate this concept at a high level.

> [@mca2](#):
>
> And how to attenuate eg the engine sound when shooting a laser or receiving a message?

Setting up sidechain compression in FMOD Studio is the usual way to go. Here is a [video](https://www.youtube.com/watch?v=I3eCT6KCOBw) that explains the concept.

Please let me know if anything needs clarifying!
