Пример #1
0
        /// <summary>
        /// Parses a AL attribute list.
        /// </summary>
        /// <param name="attributeArray">The AL context attribute list.</param>
        /// <returns>The parsed <see cref="AlcContextAttributes"/> object.</returns>
        internal static ALContextAttributes FromArray(int[] attributeArray)
        {
            var extra      = new List <int>();
            var attributes = new ALContextAttributes();

            void ParseAttribute(int @enum, int value)
            {
                switch (@enum)
                {
                case (int)AlcContextAttributes.Frequency: attributes.Frequency = value; break;

                case (int)AlcContextAttributes.MonoSources: attributes.MonoSources = value; break;

                case (int)AlcContextAttributes.StereoSources: attributes.StereoSources = value; break;

                case (int)AlcContextAttributes.Refresh: attributes.Refresh = value; break;

                case (int)AlcContextAttributes.Sync: attributes.Sync = value == 1; break;

                default: extra.Add(@enum); extra.Add(value); break;
                }
            }

            for (var i = 0; i < attributeArray.Length - 1; i += 2)
            {
                ParseAttribute(attributeArray[i], attributeArray[i + 1]);
            }

            attributes.AdditionalAttributes = extra.ToArray();

            return(attributes);
        }
Пример #2
0
        /// <summary>
        /// Returns a list of attributes for the current context of the specified device.
        /// </summary>
        /// <param name="device">The device to get attributes from.</param>
        /// <returns>A list of attributes for the device.</returns>
        public static ALContextAttributes GetContextAttributes(ALDevice device)
        {
            GetInteger(device, AlcGetInteger.AttributesSize, 1, out int size);
            var attributes = new int[size];

            GetInteger(device, AlcGetInteger.AllAttributes, size, attributes);
            return(ALContextAttributes.FromArray(attributes));
        }
Пример #3
0
 /// <summary>This function creates a context using a specified device.</summary>
 /// <param name="device">A pointer to a device.</param>
 /// <param name="attributes">The ALContext attributes to request.</param>
 /// <returns>Returns a pointer to the new context (NULL on failure).</returns>
 /// <remarks>The attribute list can be NULL, or a zero terminated list of integer pairs composed of valid ALC attribute tokens and requested values.</remarks>
 public static ALContext CreateContext(ALDevice device, ALContextAttributes attributes)
 => CreateContext(device, attributes.CreateAttributeArray());