using System.Runtime.InteropServices;
using NvAPIWrapper.Native.Helpers;
namespace NvAPIWrapper.Native.Display.Structures
{
///
/// Contains info-frame audio information
///
[StructLayout(LayoutKind.Explicit, Pack = 8)]
public struct InfoFrameAudio
{
[FieldOffset(0)] private readonly uint _WordAt0;
[FieldOffset(4)] private readonly uint _WordAt4;
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
[FieldOffset(8)] private readonly uint _WordAt8;
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
[FieldOffset(12)] private readonly byte _ByteAt12;
///
/// Creates an instance of .
///
/// The audio coding type (codec)
/// The audio codec from codec extension
/// The audio sample size (depth)
/// The audio sample rate (sampling frequency)
/// The number of audio channels
/// The audio channel allocation (speaker placements)
/// A value indicating if down-mix is prohibited
/// The Low Frequency Effects playback level value
/// The audio level shift value
public InfoFrameAudio(
InfoFrameAudioCodec codec,
InfoFrameAudioExtendedCodec codecExtension,
InfoFrameAudioSampleSize sampleSize,
InfoFrameAudioSampleRate sampleRate,
InfoFrameAudioChannelCount channelCount,
InfoFrameAudioChannelAllocation channelAllocation,
InfoFrameBoolean isDownMixProhibited,
InfoFrameAudioLFEPlaybackLevel lfePlaybackLevel,
InfoFrameAudioLevelShift levelShift
)
{
_WordAt0 = 0u
.SetBits(0, 5, (uint) codec)
.SetBits(5, 6, (uint) codecExtension)
.SetBits(11, 3, (uint) sampleSize)
.SetBits(14, 4, (uint) sampleRate)
.SetBits(18, 4, (uint) channelCount)
.SetBits(22, 9, (uint) channelAllocation);
_WordAt4 = 0u
.SetBits(0, 2, (uint) isDownMixProhibited)
.SetBits(2, 3, (uint) lfePlaybackLevel)
.SetBits(5, 5, (uint) levelShift);
_WordAt8 = 0;
_ByteAt12 = 0;
}
///
/// Gets the audio coding type (codec)
///
public InfoFrameAudioCodec Codec
{
get => (InfoFrameAudioCodec) _WordAt0.GetBits(0, 5);
}
///
/// Gets the audio codec from codec extension; only valid when
/// ==
///
public InfoFrameAudioExtendedCodec? ExtendedCodec
{
get
{
if (Codec != InfoFrameAudioCodec.UseExtendedCodecType)
{
return null;
}
return (InfoFrameAudioExtendedCodec) _WordAt0.GetBits(5, 6);
}
}
///
/// Gets the audio sample size (depth)
///
public InfoFrameAudioSampleSize SampleSize
{
get => (InfoFrameAudioSampleSize) _WordAt0.GetBits(11, 3);
}
///
/// Gets the audio sample rate (sampling frequency)
///
public InfoFrameAudioSampleRate SampleRate
{
get => (InfoFrameAudioSampleRate) _WordAt0.GetBits(14, 4);
}
///
/// Gets the number of audio channels
///
public InfoFrameAudioChannelCount ChannelCount
{
get => (InfoFrameAudioChannelCount) _WordAt0.GetBits(18, 4);
}
///
/// Gets the audio channel allocation (speaker placements)
///
public InfoFrameAudioChannelAllocation ChannelAllocation
{
get => (InfoFrameAudioChannelAllocation) _WordAt0.GetBits(22, 9);
}
///
/// Gets a value indicating if down-mix is prohibited
///
public InfoFrameBoolean IsDownMixProhibited
{
get => (InfoFrameBoolean) _WordAt4.GetBits(0, 2);
}
///
/// Gets the Low Frequency Effects playback level value
///
public InfoFrameAudioLFEPlaybackLevel LFEPlaybackLevel
{
get => (InfoFrameAudioLFEPlaybackLevel) _WordAt4.GetBits(2, 3);
}
///
/// Gets the audio level shift value
///
public InfoFrameAudioLevelShift LevelShift
{
get => (InfoFrameAudioLevelShift) _WordAt4.GetBits(5, 5);
}
}
}