mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-27 21:48:25 +01:00
first
This commit is contained in:
parent
bd62d51ec9
commit
b578433e37
1 changed files with 784842 additions and 0 deletions
30
Brutal.OpenAl/Manual/CaptureDevice.Internal.cs
Normal file
30
Brutal.OpenAl/Manual/CaptureDevice.Internal.cs
Normal 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"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue