I came to Unity from Director, and now trying to find out, how to do some things with sound here. According to manual, Unity has very limited sound controlling functionality, and it’s very sad, cause much older sowtware has it. Hope i just missed something, and someone will point me in right direction.
What i need:
Loop control. I have sound with attack phase and loop phase (helicopter propeller starts spinning, and then spinning in loop). Of course i can play several sounds one by one, but in Director i just can use loop parameters and use one sound file.
Sound markers (cue points). It’s critical for me to read markers info from sound file, because i’m programming lipsynch animation this way. Director has callback on event “cuePassed”, i’m just waiting for the next marker, read it’s name, and switch to corresponding animation, fast and easy.
Alternative is to have datalists with all markers time for each sound, start a timer when sound starts playing, constantly querying it for the current time and comparing with markers list - much complicated and no so fast and optimized approach. By the way, how do you do lipsynch in your games?
Indeed you can set on the sound controls to make it looping, check this
I think you would have to separate the animations and the sounds, sadly there is no way to know when a sound has passed certain mark, what you can do is to know which part of the sound correspond to an animation and then trigger the animation.
you can know which part of the sound is playing with:
Hm, I suppose you could mimic a lot of the functionality using the AudioSource.time property, but maybe I misunderstood the problem. The solutions certainly qualify as “hack” though.
You could set the AudioSource.time property to the time of the attack/idle time (in seconds). And determine if the time is reaching the end (cue point) of that phase by looking at the same time property every update/fixedupdate.
The same way cue points could be implemented, by having an array of cue points, and then check if the AudioSource.time has just passed (or is at) the specified cue point. Again, every FixedUpdate() or Update().
But to be honest, I have no idea how it would work out at all.
Also: Right now I’m just playing a bit with FMod in Unity. It will break web player functionality though, and I’m not sure about Macs. I just want to toy around with it to get some small visual things going, driven by spectrums.
Unity’s timing resolution is not up to the task, to make this seamless. The best thing to do is to have an attack phase with a fade-out built in, then crossfade the loop phase into it using volume scripting. Then fade the loop out when you trigger the release sample. You could script the fades of the attack and release portions, but you might as well save some CPU cycles and do that externally, if you don’t need to have real-time control of them.
Also, use coroutines for this task, because although the precision isn’t great enough for scripted seamless synthesis, at least it will be more CPU-efficient and predictable then putting a check in Update() or FixedUpdate().
Don’t get discouraged by the lack of audio functionality and quality yet. Unity is still very young software, obviously originally created by people with a graphics background. They seem to be doing very well, and lots of us have complained about the state of audio in Unity, so better things are surely on the horizon.
Thanks!
Yes, it’ seems it’s all should be done via scripting and multiple files.
But second problem is still remains, and it’s much more important. In the next project i will have hundreds of speech files, and all of them should be lip-synched with characters. If, as you mentioned, Unity time resolution is not enough to query “time” property fast enough, i don’t know how to solve this problem at all. Maybe somebody already did lipsynch in their games, and have an advice on the matter?
I have seen some people’s lip sync attempts, and the ones I saw seemed like a lot of work to be put in for less than mediocre results. I would make sure your voice is heard at http://feedback.unity3d.com if I were you, because I doubt this kind of thing is even possible, unless you’re using plugins.
Currently, this is the highest-voted item I know of that would help you:
It’s not too complicated; this manual page explains it pretty well, I think. Coroutines are useful for a lot of things, but a great strength of theirs is their ability to perform actions at time intervals.
Sorry, i read this manual, and still can’t understand, how they can be used to “perform actions at time intervals”, to give more timing precision than Update()
All i found about time there, it’s WaitForSeconds(), and it’s even don’t clear, can it accept values less than 1 second ot not.
I need to know, is it can help me to call some function on constant interval 10ms?