From 39066900773e7857faf2d02e7ed51b71d219d97d Mon Sep 17 00:00:00 2001 From: godosa Date: Tue, 6 Oct 2026 23:39:36 +0200 Subject: godosa-engine: initial public history --- src/Godosa.Core/Audio/Pcm.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/Godosa.Core/Audio/Pcm.cs (limited to 'src/Godosa.Core/Audio/Pcm.cs') diff --git a/src/Godosa.Core/Audio/Pcm.cs b/src/Godosa.Core/Audio/Pcm.cs new file mode 100644 index 0000000..2af554a --- /dev/null +++ b/src/Godosa.Core/Audio/Pcm.cs @@ -0,0 +1,24 @@ +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); +} -- cgit