using System; namespace Godosa.Core.Audio; /// 16-bit mono PCM helpers. public static class Pcm { public const int SampleRate = 44100; /// Interleaved float frames (e.g. decoded OGG) → mono 16-bit. public static short[] Downmix(float[] interleaved, int channels) { var pcm = new short[interleaved.Length / channels]; for (int f = 0; f < pcm.Length; f++) { float sum = 0f; for (int c = 0; c < channels; c++) sum += interleaved[f * channels + c]; pcm[f] = ToShort(sum / channels); } return pcm; } public static short ToShort(float sample) => (short)Math.Clamp(MathF.Round(sample * short.MaxValue), -short.MaxValue, short.MaxValue); }