File size: 1,174 Bytes
35a3a87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
        }
    }
}