Hi,
I need to know how long is a programmer sound that i’m playing. For this purpouse I’ve built a XML parser (I’m working with unity) that process all the file in the /Metadata/AudioFile and extract the length of every audio file used in the Project.
This worked fine until I noticed that some XML are missing. I mean that I have some audio files that are used in some events, but doesn’t have a related XML in the Metadata folder.
Is there a reason why some assets doesn’t have an XML?
PS: I know that I could use the callback system, but it’is a little bit buggy and sometimes it doesn’t call the programmer_sound_destroyed callback and I don’t know why. Don’t know if this is a problem with your api or a problem in my scripts, but I want a safety measure that assure me I can catch the end of a programmer sound, and knowing the length of the asset was a smoothly working solution.
I’m afraid we can’t provide help with the XML issue, that is a Unity issue so please check with them on the Unity forums.
The length of the programmer sound depends on two things:
If the programmer instrument in your event is set to be async or not
The length of the asset being used in the instrument
The easiest method would be to set the programmer instrument to be async and just use the length of the assets you’re using. You’d need to contact Unity about why some of your audio files don’t have XML.
You could also try using Sound::getLength within the programmer sound function(s) to get the length of the asset you are using, but this will only work at runtime.
In regards to the programmer sounds not creating the programmer_sound_destroyed callback, could you please post a snippet of your code to see if something is going wrong there? Our internal tests show all callbacks behaving normally.
Probably I wasn’t clear in my question.
The XMLs are the ones that FMOD studio produces in the metadata folder. It’s not something related to Unity, Unity is only the software where I run my parser.
I also noticed that when an XML is missing if I search the related asset name in the asset palette in FMOD studio, the search doesn’t give me results. So this is definitly an FMOD studio problem, not generating some asset XML.
Regarding the solution you proposed, the one related to une Sound::getLength for the async programmer sound, I’ve alredy tried, but I always get length=0. I’m doing this at runtime in the callback “FMOD.Studio.EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND” after I have created the sound.
Here is the script that is using the callbacks. We are using an enum that let us process the callback in the update because if I call a function directly in the callback Unity crashes.
The rest of the code is pretty straight, I copied it from an example that I found on the web and that was also in some tutorial on your website.
public class DialogueActor : BaseObject
{
public IActorDelegate actorDelegate;
[FMODUnity.EventRef]
public string asset;
// [HideInInspector]
private bool _isActing = false;
private EventInstance dialogueInstance;
public bool isActing {
get {
return _isActing;
}
}
private FMOD.Studio.EVENT_CALLBACK dialogueCallback;
private LaunchEventEnum launchEvent = LaunchEventEnum.none;
private string _lastKeyDebug = "Not Initialized";
// Update is called once per frame
void Update ()
{
switch (launchEvent) {
case LaunchEventEnum.audioStopped:
if (verboseMode) {
Debug.Log ("Audio stopped");
}
if (actorDelegate != null) {
actorDelegate.onActorStopTalking (this);
}
Debug.LogError (Time.frameCount + "\t" + _lastKeyDebug + "\tSTOP_EVENT");
if (verboseMode) {
}
launchEvent = LaunchEventEnum.none;
break;
case LaunchEventEnum.audioStarted:
launchEvent = LaunchEventEnum.none;
break;
default:
break;
}
}
/// <summary>
/// Plaies the dialogue.
/// </summary>
/// <param name="key">FMOD Key.</param>
public void PlayDialogue (string key)
{
// Debug.Log (“STOPPED”);
break;
case FMOD.Studio.EVENT_CALLBACK_TYPE.SOUND_STOPPED:
// Debug.Log (“SOUND_STOPPED”);
// StartCoroutine(launchOnActorStopTalking());
_isActing = false;
launchEvent = LaunchEventEnum.audioStopped;
break;
case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROYED:
// Now the event has been destroyed, unpin the string memory so it can be garbage collected
Debug.LogError ("DESTROY " + _lastKeyDebug);
stringHandle.Free ();
// Debug.Log (“Destroyed”);
// Debug.LogError (“[Actor] The Actor attached to the object " + this.gameObject.name + " can’t get the sound intensity, because the event is not initiazlized”);
return 0;
}
}
Your code looks fine, but it is sounding like you are placing your entire FMOD Studio project into your Unity project.
The XMLs are generated by your FMOD Studio project but ideally you shouldn’t be placing these files or parsing them within your game engine.
Also, I’m not sure how you are passing keys into this programmer sound system.
If FMOD::Sound is returning 0 but playing audio, it is likely you are using an audio table and passing keys into this. In this situation, the FMOD::Sound will return 0 as it is actually using a Bank rather than an actual sound file.
If you just need a static list of all the audio files you are using, I would recommend using the FMOD Studio scripting API from within your FMOD Studio project to get these.
I know I shouldn’t use the XMLs of the FMOD project, but I was trying to find a workaround for my problem. The missing XML is surely a bug that has effect in FMOD Studio to, like I was saying it makes the search of an asset file buggy.
“Also, I’m not sure how you are passing keys into this programmer sound system.” I don’t know what you mean with this, but I can confirm what you’ve said: “If FMOD::Sound is returning 0 but playing audio, it is likely you are using an audio table and passing keys into this. In this situation, the FMOD::Sound will return 0 as it is actually using a Bank rather than an actual sound file”.
Is there another way to do this? Am I doing something wrong in the implementation of using audioTables and programmer sounds?
However, I’ve looked at your solution to retrieve the static list of the sound length (that is actually what I need), but I wasn’t able to do that. I studied the documentation you linked and i wrote this script:
I get errors on this line: “studio.project.workspace.audioBinManager.masterAudioBinFolder.items;” but I cant understand how to get the list of the asset files to parse in for cycle.
I really appreciate your support!!
Regards,
Simone
The only time an asset will not be in the XML is if the asset is placed directly into the Assets folder and not added through FMOD Studio. It will appear in your assets browser with a question mark icon and a “New!” tag. This is by design and it won’t be truly imported until it is moved or you right click and choose “Import”.
If you have a few “New!” assets, search for “#unimported” to get a list in the assets browser. You can then bulk select and import them.
In regards to your code, first you should replace the items variable with this:
var items = studio.project.workspace.masterAssetFolder.assets;
You can also set isEnabled to just true to enable it all the time.
In regards to the programmer sound keys - you can also pass a path in as a key, which is why I was asking. If you are using audio tables and passing keys then you won’t be able to pull the length of the FMOD::Sound that way.