com.sky.sentis.neurosync / Runtime /NeuroSyncPostProcess.cs
Sky-Kim's picture
Initial release: NeuroSync audio-to-face for Unity Sentis 2.6.1 with ONNX models
35a3a87
Raw History Blame Contribute Delete
1.17 kB
using System;
namespace NeuroSync
{
/// <summary>
/// Port of the tail of audio_processing.py process_audio_features(). Frames are row-major [n, 68].
/// </summary>
public static class NeuroSyncPostProcess
{
const int O = NeuroSyncConstants.NumOutputs;
/// <summary>In place: /100 on channels 0..60, 0.1 s linear ease-in, zero_columns(). Returns <paramref name="frames"/>.</summary>
public static float[] Apply(float[] frames, int n)
{
for (int f = 0; f < n; f++)
for (int c = 0; c < NeuroSyncConstants.NumScaledChannels; c++)
frames[f * O + c] /= 100f;
// np.linspace(0, 1, ease)[:, None]
int ease = Math.Min(NeuroSyncConstants.EaseInFrames, n);
for (int f = 0; f < ease; f++)
{
float k = ease > 1 ? f / (float)(ease - 1) : 0f;
for (int c = 0; c < O; c++) frames[f * O + c] *= k;
}
for (int f = 0; f < n; f++)
foreach (int c in NeuroSyncConstants.ZeroColumns)
frames[f * O + c] = 0f;
return frames;
}
}
}