This commit is contained in:
Rian Drake 2026-10-15 14:09:11 +13:00
commit b578433e37

View file

@ -0,0 +1,30 @@
namespace Brutal.OpenAlApi;
public sealed partial class CaptureDevice
{
// The four standard formats are the only values AlFormat defines; anything else is an
// extension or invalid format with no fixed frame size.
internal static int? FrameSize(AlFormat format) =>
format switch
{
AlFormat.Mono8 => 1,
AlFormat.Mono16 => 2,
AlFormat.Stereo8 => 2,
AlFormat.Stereo16 => 4,
_ => null,
};
// Multiply as long so the bound cannot overflow.
internal static void CheckBufferLength(int bytesPerFrame, int samples, int bufferLength)
{
ArgumentOutOfRangeException.ThrowIfNegative(samples);
if (bufferLength < (long)samples * bytesPerFrame)
{
throw new ArgumentException(
$"buffer must hold at least {samples} * {bytesPerFrame} = {(long)samples * bytesPerFrame} bytes, but was {bufferLength}.",
"buffer"
);
}
}
}