mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 12:38:24 +01:00
30 lines
1,007 B
C#
30 lines
1,007 B
C#
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"
|
|
);
|
|
}
|
|
}
|
|
}
|