<commit_before>#pragma once

namespace SaneAudioRenderer
{
    enum class DspFormat
    {
        Unknown,
        Pcm8,
        Pcm16,
        Pcm24,
        Pcm32,
        Float,
        Double,
    };

    template <DspFormat OutputFormat>
    struct DspFormatTraits;

    template <>
    struct DspFormatTraits<DspFormat::Pcm8>
    {
        typedef int8_t SampleType;
    };

    template <>
    struct DspFormatTraits<DspFormat::Pcm16>
    {
        typedef int16_t SampleType;
    };

    #pragma pack(push, 1)
    typedef struct { int8_t d[3]; } int24_t;
    #pragma pack(pop)

    static_assert(sizeof(int24_t) == 3, "Failed to pack the struct properly");

    template <>
    struct DspFormatTraits<DspFormat::Pcm24>
    {
        typedef int24_t SampleType;
    };

    template <>
    struct DspFormatTraits<DspFormat::Pcm32>
    {
        typedef int32_t SampleType;
    };

    template <>
    struct DspFormatTraits<DspFormat::Float>
    {
        typedef float SampleType;
    };

    template <>
    struct DspFormatTraits<DspFormat::Double>
    {
        typedef double SampleType;
    };

    inline uint32_t DspFormatSize(DspFormat format)
    {
        return (format == DspFormat::Unknown) ? 0 :
               (format == DspFormat::Pcm8) ? 1 :
               (format == DspFormat::Pcm16) ? 2 :
               (format == DspFormat::Pcm24) ? 3 :
               (format == DspFormat::Double) ? 8 : 4;
    }

    inline DspFormat DspFormatFromWaveFormat(const WAVEFORMATEX& format)
    {
        if (format.nSamplesPerSec == 0)
            return DspFormat::Unknown;

        if (format.wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
        {
            switch (format.wBitsPerSample)
            {
                case 32: return DspFormat::Float;
                case 64: return DspFormat::Double;
            }
        }
        else if (format.wFormatTag == WAVE_FORMAT_PCM)
        {
            switch (format.wBitsPerSample)
            {
                case 8:  return DspFormat::Pcm8;
                case 16: return DspFormat::Pcm16;
                case 24: return DspFormat::Pcm24;
                case 32: return DspFormat::Pcm32;
            }
        }
        else if (format.wFormatTag == WAVE_FORMAT_EXTENSIBLE)
        {
            const WAVEFORMATEXTENSIBLE& formatExtensible = (const WAVEFORMATEXTENSIBLE&)format;

            if (formatExtensible.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)
            {
                switch (format.wBitsPerSample)
                {
                    case 32: return DspFormat::Float;
                    case 64: return DspFormat::Double;
                }
            }
            else if (formatExtensible.SubFormat == KSDATAFORMAT_SUBTYPE_PCM)
            {
                switch (format.wBitsPerSample)
                {
                    case 8:  return DspFormat::Pcm8;
                    case 16: return DspFormat::Pcm16;
                    case 24: return DspFormat::Pcm24;
                    case 32: return DspFormat::Pcm32;
                }
            }
        }

        return DspFormat::Unknown;
    }
}
<commit_msg>Add static asserts for fp variable sizes<commit_after>#pragma once

namespace SaneAudioRenderer
{
    enum class DspFormat
    {
        Unknown,
        Pcm8,
        Pcm16,
        Pcm24,
        Pcm32,
        Float,
        Double,
    };

    template <DspFormat OutputFormat>
    struct DspFormatTraits;

    template <>
    struct DspFormatTraits<DspFormat::Pcm8>
    {
        typedef int8_t SampleType;
    };

    template <>
    struct DspFormatTraits<DspFormat::Pcm16>
    {
        typedef int16_t SampleType;
    };

    #pragma pack(push, 1)
    typedef struct { int8_t d[3]; } int24_t;
    #pragma pack(pop)

    static_assert(sizeof(int24_t) == 3, "Failed to pack the struct properly");

    template <>
    struct DspFormatTraits<DspFormat::Pcm24>
    {
        typedef int24_t SampleType;
    };

    template <>
    struct DspFormatTraits<DspFormat::Pcm32>
    {
        typedef int32_t SampleType;
    };

    template <>
    struct DspFormatTraits<DspFormat::Float>
    {
        typedef float SampleType;
    };

    template <>
    struct DspFormatTraits<DspFormat::Double>
    {
        typedef double SampleType;
    };

    static_assert(sizeof(float) == 4, "Floats are not IEEE compliant");
    static_assert(sizeof(double) == 8, "Floats are not IEEE compliant");

    inline uint32_t DspFormatSize(DspFormat format)
    {
        return (format == DspFormat::Unknown) ? 0 :
               (format == DspFormat::Pcm8) ? 1 :
               (format == DspFormat::Pcm16) ? 2 :
               (format == DspFormat::Pcm24) ? 3 :
               (format == DspFormat::Double) ? 8 : 4;
    }

    inline DspFormat DspFormatFromWaveFormat(const WAVEFORMATEX& format)
    {
        if (format.nSamplesPerSec == 0)
            return DspFormat::Unknown;

        if (format.wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
        {
            switch (format.wBitsPerSample)
            {
                case 32: return DspFormat::Float;
                case 64: return DspFormat::Double;
            }
        }
        else if (format.wFormatTag == WAVE_FORMAT_PCM)
        {
            switch (format.wBitsPerSample)
            {
                case 8:  return DspFormat::Pcm8;
                case 16: return DspFormat::Pcm16;
                case 24: return DspFormat::Pcm24;
                case 32: return DspFormat::Pcm32;
            }
        }
        else if (format.wFormatTag == WAVE_FORMAT_EXTENSIBLE)
        {
            const WAVEFORMATEXTENSIBLE& formatExtensible = (const WAVEFORMATEXTENSIBLE&)format;

            if (formatExtensible.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)
            {
                switch (format.wBitsPerSample)
                {
                    case 32: return DspFormat::Float;
                    case 64: return DspFormat::Double;
                }
            }
            else if (formatExtensible.SubFormat == KSDATAFORMAT_SUBTYPE_PCM)
            {
                switch (format.wBitsPerSample)
                {
                    case 8:  return DspFormat::Pcm8;
                    case 16: return DspFormat::Pcm16;
                    case 24: return DspFormat::Pcm24;
                    case 32: return DspFormat::Pcm32;
                }
            }
        }

        return DspFormat::Unknown;
    }
}

{'fraction_non_alphanumeric': 0.08481203007518796, 'fraction_numerical': 0.02406015037593985, 'mean_word_length': 1.5317853064331937, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4177377', 'n_tokens_mistral': 2134, 'n_tokens_neox': 1887, 'n_words': 390}