Example #1
0
        static Dictionary <double, float[]> GetGainDifferences(List <HRTFSetEntry> entries, List <double> hValues)
        {
            Dictionary <double, float[]> result = new Dictionary <double, float[]>(); // Distance; array by hValues

            for (int entry = 0, count = entries.Count; entry < count; ++entry)
            {
                HRTFSetEntry setEntry = entries[entry];
                float        maxGain = float.MinValue, minGain = float.MaxValue;
                for (int channel = 0; channel < setEntry.Data.Length; ++channel)
                {
                    float peak = QMath.GainToDb(WaveformUtils.GetRMS(setEntry.Data[channel]));
                    if (maxGain < peak)
                    {
                        maxGain = peak;
                    }
                    if (minGain > peak)
                    {
                        minGain = peak;
                    }
                }
                if (!result.ContainsKey(setEntry.Distance))
                {
                    result[setEntry.Distance] = new float[hValues.Count];
                }
                result[setEntry.Distance][hValues.IndexOf(setEntry.Azimuth)] = maxGain - minGain;
            }
            return(result);
        }
Example #2
0
        static Dictionary <double, int[]> GetDelayDifferences(List <HRTFSetEntry> entries, List <double> hValues)
        {
            Dictionary <double, int[]> result = new Dictionary <double, int[]>(); // Distance; array by hValues

            for (int entry = 0, count = entries.Count; entry < count; ++entry)
            {
                HRTFSetEntry setEntry = entries[entry];
                int          maxDelay = 0, minDelay = int.MaxValue;
                for (int channel = 0; channel < setEntry.Data.Length; ++channel)
                {
                    float[] data       = setEntry.Data[channel];
                    int     delay      = 0;
                    float   firstValid = WaveformUtils.GetPeak(data) * m20dB;
                    while (delay < data.Length && Math.Abs(data[delay]) < firstValid)
                    {
                        ++delay;
                    }
                    if (maxDelay < delay)
                    {
                        maxDelay = delay;
                    }
                    if (minDelay > delay)
                    {
                        minDelay = delay;
                    }
                }
                if (!result.ContainsKey(setEntry.Distance))
                {
                    result[setEntry.Distance] = new int[hValues.Count];
                }
                result[setEntry.Distance][hValues.IndexOf(setEntry.Azimuth)] = maxDelay - minDelay;
            }
            return(result);
        }