Getting length of Programming Sounds in Unreal Engine (from the Audio Table)

Hi, sorry for the duplicate in the topic, but I didn’t find any solution that works so far, and a little bit of help would be very much appreciated. I made the following 5 tries.

  1. I tried to use call-backs, like the code below, but they never get called:

Since I cannot insert multiple images in the post, I will continue in the replies down below.

  1. I tried modify the AudioComponent to get directly the value of the sound, but it is not ready yet with error 46:
  1. So, I tried to save the variable MyCustomSound, and try to access it later, but I get error 31:
  1. I tried to save the length in this way, but I get always the same number “8582624”:
  1. Finally, I tried accessing it in a different way (still, no luck), the code reaches the very end, so no errors, but the length is always zero:

Sorry for the long post, for so much code (in case I can also give you the code to copy and paste if images are not comfortable) and that it is divided in multiple answers. However, I wanted to make you understand all the attempts I did so far.

What am I doing wrong?

Thank you again for your help! :folded_hands:

1 Like

Hi,

Thanks for the images, code can be added in blocks with the formatted text option:

image

Under: Unreal Integration | User Guide - Using Programmer Instruments Via The Fmod Studio Api we outline how to set up custom programmer instrument callbacks, in the initial image I am thinking it may be an issue with calling setCallback() 3 times. More flags can be added to the argument with |.

The error: 46 - NOT READY from the fact we are loading the sound from an audio table. To solve that we can check the FMOD_OPENSTATE and wait till it is ready:

FMOD_OPENSTATE state = FMOD_OPENSTATE_MAX;
bool starving, diskBusy = false;
unsigned int percent = 0;
FMOD_RESULT result = Sound->getOpenState(&state, &percent, &starving, &diskBusy);
while (state != FMOD_OPENSTATE_READY && result == FMOD_OK)
{
    result = Sound->getOpenState(&state, &percent, &starving, &diskBusy);
}
if (result != FMOD_OK)
{
    // Log error here
}

(FMOD Engine | Core Api Sound - Sound::Getopenstate)

Since we are loading the sound from an Audio table, it wont actually be Sound that is the Master.bank. So we will need to retrieve actual sound with FMOD Engine | Core Api Sound - Sound::Getsubsound

FMOD::Sound* subSound1 = nullptr;
result = Sound->getSubSound(0, &subSound1);
unsigned int length = 0;
result = FMOD_Sound_GetLength((FMOD_SOUND*)subSound1, &length, FMOD_TIMEUNIT_MS);

This should return to correct length. You can add some more checks:

Hope this helps!

1 Like

Hi, thanks for the prompt reply!

For the code formatting, I even tried with different browsers, but it seems that the option to add code in the forum is missing on my side! :frowning:

As for the rest, everything was super clear, thanks! I was able to make it work by modifying the AudioComponent.cpp, storing the Sound in a variable, and upon request in another function, retrieve the subsound and getting the correct length.

As for the setCallback(), the three times where just an example, I tried one at the time. However, still no luck, it seems that the callback is never actually called.

I will mark your reply as the solution, as it actually solved the problem. In case I will need the callbacks, I will open another forum post.

Thank you so much once again for your kind help Connor, have a wonderful day ahead!

1 Like

Interesting, if you surround the code with ``` does that work?
e.g.

```
// Code here
```

Good the hear the issue is solved! If there is anything else we can assist with, please do not hesitate to reach out!