0
0

Hi there,
I’m new to fmod and have some basic questions using Event System and Designer.

Currently I am programming a project having objects moving in 3D space. I want to assign a sound loop for each of them. I assigned the sound loop using the Designer [i:3bjrhsbn]"loop mode"[/i:3bjrhsbn].
I also set the max playback amount to 3 and the max playback behavior to [i:3bjrhsbn]"steal quietest"[/i:3bjrhsbn]. In my project there can be a various number of objects (up to 10 objects). In order to keep the cpu usage low I want only 3 objects to be heard, that’s why I set max playback to 3.
At project initialization I create let’s say 10 objects each having an FMOD::Event pointer. I allocate the events by [i:3bjrhsbn]"GetEventByIndex"[/i:3bjrhsbn] and call event->play() to start the loop for each object.
In an update loop I update the position of the events and my listener position.
When updating the objects positions I get an [i:3bjrhsbn]ERR_INVALID_HANDLE[/i:3bjrhsbn] exception.

So here are my questions:
I’ve alerady read, that I have to set the max playback amount to the maximum number of objects I create in my project. Doing this I’d had to set the amount to 10 (because this is the maximum number that can be created), wouldn’t this use a lot more cpu usage?
I thought I could minimize the cpu usage by hearing only 3 objects and expected that the event system would update all 10 positions but playing only the 3 loudest events.
How much more cpu usage would it cost to set the max playback to let’s say 30, would the event system allocate memory for 30 events or for just the "real" 10 objects? Why should I ever set the max playback to a small amount, risking to get an [i:3bjrhsbn]ERR_INVALID_HANDLE[/i:3bjrhsbn] exception?

Reading the documentation of FMOD Ex I’ve read that there are virtual voices allowing me to create 10 sounds, and updating there position using channels which can be virtual if there are outside a given max distance. This concept seams to be excactly what I’d need for my project but I want to use the Event System instead of Ex. The Event System allows me to create my sounds much more comfortable using Designer.
So is there a possibility to use these virtual voices in the Event System? How can I set an amount for audible sounds allowing only the 3 loudest events to be heard?

Thanks in advance for your help

  • You must to post comments
0
0

Hi eberwolf,

The virtual voice system is per voice, so if your events only contain one soundef then you could initialize fmod with 3 real channels and let the virtual voice system handle the rest, a better way would be to use virtual events.

You can set up your own virtual events using the "just fail if quietest" max playback behaviour. The name doesn’t completely describe the behaviour it is more like: "just fail if quietest otherwise steal the quietest"

The way it works is you call getEvent every frame for every instance which is not currently active. You do this by setting the position on the INFO_ONLY instance first.
[code:273aquuu]
FMOD::Event evt;
eventSystem->getEvent("project/group/event", FMOD_EVENT_INFOONLY, &evt);
evt->set3DAttributes( pos, 0, 0 );
result = eventSystem->getEvent("project/group/event", FMOD_EVENT_DEFAULT, &evt);
if (result == FMOD_OK)
{
isVirtual = false;
}[/code:273aquuu]

Since the INFO_ONLY instance is positioned, when you call getEvent the second time it tries to create the instance at the position where you had the INFO_ONLY event, and if it is louder than any of the other 3 current events it will steal otherwise it will fail. That means only the 3 loudest will be active at any time.

  • You must to post comments
0
0

Hi Peter,
thank you for your feedback!
I implemented your code-snippet but it didn’t work for me. I could hear the sound just at the beginning of the scene. As the objects move away from their start position I can’t hear the sounds anymore.

[quote="peter":px4kfdpt]
The way it works is you call getEvent every frame for every instance which is not currently active.
[/quote:px4kfdpt]

What do you mean with not active? As I’ve written I have up to 10 objects which have a sound event playing in a loop. Aren’t all these events active?

I had the following construct:

[code:px4kfdpt]
Class My3DObject {
public
StartOnce3DSound(int eventIndex, Vector startPos, Vector startVel) {
SoundClass::eventProject->getEventByIndex(eventIndex, MOD_EVENT_DEFAULT, &myEvent);
myEvent->set3DAttributes(startPos, startVel);
myEvent->start();
}
Update3DSound() {
myEvent->set3DAttributes(myPos, myVel);
}
private
FMOD::Event *myEvent;
Vector myPos, myVel;
}

Class Game {
My3DObject *myObject = new My3DObject[10];
init() {
for (myObject.count) myObject[i].StartOnce3DSound(EVT1, pos, vel);
}
update() {
for (myObject.count) {
myObject[i].moveAround();
myObject[i].Update3DSound();
}
}
}
[/code:px4kfdpt]

As you can see, I start the event sound loops at the beginning of the scene and update the position in the game loop. There’s no stopping of the event so I guess they’re active all the time.

This is the new code construct regarding your feedback:

[code:px4kfdpt]
private
boolean soundLoopPlaying = false;

public
Update3DSound(int eventIndex, Vector pos, Vector vel) {
FMOD::Event *gotEvent;
SoundClass::eventProject->getEventByIndex(eventIndex, FMOD_EVENT_INFOONLY, &gotEvent);
gotEvent->set3DAttributes(pos, vel, 0);
result = SoundClass::eventProject->getEventByIndex(eventIndex, MOD_EVENT_DEFAULT, &gotEvent);
if (result == FMOD_OK && !soundLoopPlaying)
result = gotEvent->start();
if (result == OK) soundLoopPlaying = true;
else soundLoopPlaying = false;
}
Class Game {
My3DObject *myObject = new My3DObject[10];
init() {
for (myObject.count) myObject[i].Update3DSound(EVT1, pos, vel);
}
update() {
for (myObject.count) {
myObject[i].moveAround();
myObject[i].Update3DSound(EVT1, pos, vel);
}
}
}
[/code:px4kfdpt]

I don’t get any error messages but the sounds can’t be heard as the objects move away from their start position. Do you have any other ideas?
Thank you
eberwolf

  • You must to post comments
0
0

Try something like this:

[code:hv0gkp74]// First check if our instance is valid
bool unused;
result = myEvent->getMute(&unused);
if (result == FMOD_OK)
{
myEvent->set3DAttributes(pos, vel, 0)
}
else if (result == FMOD_ERR_INVALID_HANDLE)
{
// Attempt to steal
FMOD::Event *gotEvent;
SoundClass::eventProject->getEventByIndex(eventIndex, FMOD_EVENT_INFOONLY, &gotEvent);
gotEvent->set3DAttributes(pos, vel, 0);
result = SoundClass::eventProject->getEventByIndex(eventIndex, MOD_EVENT_DEFAULT, &gotEvent);
if (result == FMOD_OK)
{
// We successfully stole an instance
myEvent = gotEvent;
result = gotEvent->start();
}
}[/code:hv0gkp74]

  • You must to post comments
0
0

Thank you, peter 😀
Now it works!
Happy weekend!

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.