// PRE-GENERATED (design session). Pure logic.
using System;

namespace DansoriEQ.Core.Eq;

/// <summary>Samples the composite EQ magnitude over a log frequency axis (for the graph).</summary>
public static class FrequencyResponse
{
    public const double DefaultSampleRate = 48000.0;
    public const double MinHz = 20.0;
    public const double MaxHz = 20000.0;

    /// <summary>(freqHz, gainDb) points across [MinHz, MaxHz] on a log scale.</summary>
    public static (double Hz, double Db)[] Sample(EqState state, int points = 256, double fs = DefaultSampleRate)
    {
        if (points < 2) points = 2;
        var result = new (double, double)[points];
        double logMin = Math.Log10(MinHz);
        double logMax = Math.Log10(MaxHz);
        for (int i = 0; i < points; i++)
        {
            double t = (double)i / (points - 1);
            double hz = Math.Pow(10.0, logMin + t * (logMax - logMin));
            result[i] = (hz, state.GainDbAt(hz, fs));
        }
        return result;
    }
}
