Hello,
I tried to use SALSA to do lipsync.
For this, I rewired things and it usually work pretty good. Usually.
..Because when the user wants to set the volume to 0, then the system doesn’t get data (or a flat line).
The event is wired to a VCA, whose volume has been set to 0
The instance is retrieved by the lipsync system which creates a DSP to its channel group.
Here’s the code:
private void OnVoicePlaying(EventInstance eventInstance)
{
if (m_playingInstances == null)
return;
if (!ShouldHaveSalsaUponInit)
this.m_salsa = this.GetSalsa();
if (!this.m_salsa)
return;
/*if (stopRoutine != null)
StopCoroutine(stopRoutine);
stopRoutine = null;*/
// Define a basic DSP that receives a callback each mix to capture audio
FMOD.DSP_DESCRIPTION desc = new FMOD.DSP_DESCRIPTION();
desc.numinputbuffers = 1;
desc.numoutputbuffers = 1;
desc.read = m_readCallback;
desc.userdata = GCHandle.ToIntPtr(m_objHandle);
// Create an instance of the capture DSP and attach it to the master channel group to capture all audio
FMOD.ChannelGroup eventCG;
FMOD.DSP captureDSP;
FMOD.RESULT result;
result = eventInstance.getChannelGroup(out eventCG);
if (VerboseFmodResults)
Debug.Log("getChannelGroup => " + result);
result = FMODUnity.RuntimeManager.CoreSystem.createDSP(ref desc, out captureDSP);
if (VerboseFmodResults)
Debug.Log("createDSP => " + result);
result = captureDSP.setChannelFormat(FMOD.CHANNELMASK.MONO, 1, FMOD.SPEAKERMODE.MONO);
if (VerboseFmodResults)
Debug.Log("setChannelFormat => " + result);
result = eventCG.addDSP(0, captureDSP);
if (VerboseFmodResults)
Debug.Log("addDSP => " + result);
m_isPlaying = true;
m_salsa.getExternalAnalysis = null;
m_salsa.getTriggerIndex = null;
m_salsa.InitializeDelegates(); // ensures those two delegates to be at their init values.
m_salsa_getTriggerIndex = m_salsa.getTriggerIndex; // gets the previous delegate in our own ref.
m_salsa.getTriggerIndex = GetTriggerIndexForSalsa; // ..So that it would be called within our delegate override
m_salsa.getExternalAnalysis = GetAnalysisForSalsa;
m_playingInstances.Add(eventInstance, captureDSP);
}
How can I wire the DSP so it can get the data before the VCA fades the volume to 0?
Is there a tool that we could use to visualise the ChannelGroup ?
On this page: https://www.fmod.com/docs/2.02/api/using-dsp-effects-in-the-core-api.html
It feels like a tree