Пример #1
0
        // ALC_API const ALCchar * ALC_APIENTRY alcGetString( ALCdevice *device, ALCenum param );

        /// <summary>This function returns a List of strings related to the context.</summary>
        /// <remarks>
        /// ALC_DEVICE_SPECIFIER will return the name of the specified output device if a pointer is supplied, or will return a list of all available devices if a NULL device pointer is supplied. A list is a pointer to a series of strings separated by NULL characters, with the list terminated by two NULL characters. See Enumeration Extension for more details.
        /// ALC_CAPTURE_DEVICE_SPECIFIER will return the name of the specified capture device if a pointer is supplied, or will return a list of all available devices if a NULL device pointer is supplied.
        /// ALC_EXTENSIONS returns a list of available context extensions, with each extension separated by a space and the list terminated by a NULL character.
        /// </remarks>
        /// <param name="device">A pointer to the device to be queried.</param>
        /// <param name="param">An attribute to be retrieved: ALC_DEVICE_SPECIFIER, ALC_CAPTURE_DEVICE_SPECIFIER, ALC_ALL_DEVICES_SPECIFIER.</param>
        /// <returns>A List of strings containing the names of the Devices.</returns>
        public static IList <string> GetString(ALDevice device, AlcGetStringList param)
        {
            List <string> result = new List <string>();

            // We cannot use Marshal.PtrToStringAnsi(),
            //  because alcGetString is defined to return either a nul-terminated string,
            //  or an array of nul-terminated strings terminated by an extra nul.
            // Marshal.PtrToStringAnsi() will fail in the latter case (it will only
            // return the very first string in the array.)
            // We'll have to marshal this ourselves.
            unsafe
            {
                byte *currentPos = GetStringPtr(device, (AlcGetString)param);
                while (true)
                {
                    var currentString = Marshal.PtrToStringAnsi(new IntPtr(currentPos));

                    if (string.IsNullOrEmpty(currentString))
                    {
                        break;
                    }

                    result.Add(currentString);
                    currentPos += currentString.Length + 1;
                }
            }
            return(result);
        }
Пример #2
0
        /// <summary>This function returns a List of strings related to the context.</summary>
        /// <remarks>
        /// ALC_DEVICE_SPECIFIER will return the name of the specified output device if a pointer is supplied, or will return a list of all available devices if a NULL device pointer is supplied. A list is a pointer to a series of strings separated by NULL characters, with the list terminated by two NULL characters. See Enumeration Extension for more details.
        /// ALC_CAPTURE_DEVICE_SPECIFIER will return the name of the specified capture device if a pointer is supplied, or will return a list of all available devices if a NULL device pointer is supplied.
        /// ALC_EXTENSIONS returns a list of available context extensions, with each extension separated by a space and the list terminated by a NULL character.
        /// </remarks>
        /// <param name="device">a pointer to the device to be queried.</param>
        /// <param name="param">an attribute to be retrieved: ALC_DEVICE_SPECIFIER, ALC_CAPTURE_DEVICE_SPECIFIER, ALC_ALL_DEVICES_SPECIFIER</param>
        /// <returns>A List of strings containing the names of the Devices.</returns>
        public static IList <string> GetString(IntPtr device, AlcGetStringList param)
        {
            List <string> result = new List <string>();
            IntPtr        t      = GetStringPrivate(IntPtr.Zero, (AlcGetString)param);

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            byte b;
            int  offset = 0;

            do
            {
                b = Marshal.ReadByte(t, offset++);
                if (b != 0)
                {
                    sb.Append((char)b);
                }
                if (b == 0)
                {
                    result.Add(sb.ToString());
                    if (Marshal.ReadByte(t, offset) == 0) // offset already properly increased through ++
                    {
                        break;                            // 2x null
                    }
                    else
                    {
                        sb.Remove(0, sb.Length); // 1x null
                    }
                }
            } while (true);

            return((IList <string>)result);
        }
Пример #3
0
        public static string[] GetString(IntPtr device, AlcGetStringList param)
        {
            var strPtr = GetStringPrivate(device, (AlcGetString)param);

            if (strPtr == IntPtr.Zero)
            {
                return(EmptyStringArray);
            }

            var result = new List <string>();
            var sb     = new StringBuilder();
            var offset = 0;

            while (true)
            {
                var b = Marshal.ReadByte(strPtr, offset++);
                if (b != '\0')
                {
                    sb.Append((char)b);
                }
                else
                {
                    result.Add(sb.ToString());

                    if (Marshal.ReadByte(strPtr, offset) == 0)
                    {
                        break;
                    }

                    sb.Clear();
                }
            }

            return(result.ToArray());
        }
Пример #4
0
        public static unsafe IList <string> GetString(IntPtr device, AlcGetStringList param)
        {
            List <string> list   = new List <string>();
            byte *        numPtr = (byte *)Alc.GetStringPrivate(device, (AlcGetString)param).ToPointer();

            for (string str = Marshal.PtrToStringAnsi(new IntPtr((void *)numPtr)); !string.IsNullOrEmpty(str); str = Marshal.PtrToStringAnsi(new IntPtr((void *)numPtr)))
            {
                list.Add(str);
                numPtr += str.Length + 1;
            }
            return((IList <string>)list);
        }
Пример #5
0
        static AudioDevice[] ToDeviceList(AlcGetStringList source)
        {
            var names = Alc.GetString(IntPtr.Zero, source);

            AudioDevice[] list = new AudioDevice[names.Count];

            for (int index = 0; index < names.Count; index++)
            {
                list[index] = Get(names[index]);
            }
            return(list);
        }
Пример #6
0
        /// <summary>This function returns a List of strings related to the context.</summary>
        /// <remarks>
        /// ALC_DEVICE_SPECIFIER will return the name of the specified output device if a pointer is supplied, or will return a list of all available devices if a NULL device pointer is supplied. A list is a pointer to a series of strings separated by NULL characters, with the list terminated by two NULL characters. See Enumeration Extension for more details.
        /// ALC_CAPTURE_DEVICE_SPECIFIER will return the name of the specified capture device if a pointer is supplied, or will return a list of all available devices if a NULL device pointer is supplied.
        /// ALC_EXTENSIONS returns a list of available context extensions, with each extension separated by a space and the list terminated by a NULL character.
        /// </remarks>
        /// <param name="device">a pointer to the device to be queried.</param>
        /// <param name="param">an attribute to be retrieved: ALC_DEVICE_SPECIFIER, ALC_CAPTURE_DEVICE_SPECIFIER, ALC_ALL_DEVICES_SPECIFIER</param>
        /// <returns>A List of strings containing the names of the Devices.</returns>
        public static IList <string> GetString(IntPtr device, AlcGetStringList param)
        {
            List <string> result = new List <string>();

            // We cannot use Marshal.PtrToStringAnsi(),
            //  because alcGetString is defined to return either a nul-terminated string,
            //  or an array of nul-terminated strings terminated by an extra nul.
            // Marshal.PtrToStringAnsi() will fail in the latter case (it will only
            // return the very first string in the array.)
            // We'll have to marshal this ourselves.
            IntPtr t = GetStringPrivate(device, (AlcGetString)param);

            if (t != IntPtr.Zero)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                byte b;
                int  offset = 0;
                do
                {
                    b = Marshal.ReadByte(t, offset++);
                    if (b != 0)
                    {
                        sb.Append((char)b);
                    }
                    else
                    {
                        // One string from the array is complete
                        result.Add(sb.ToString());

                        // Check whether the array has finished
                        // Note: offset already been increased through offset++ above
                        if (Marshal.ReadByte(t, offset) == 0)
                        {
                            // 2x consecutive nuls, we've read the whole array
                            break;
                        }
                        else
                        {
                            // Another string is starting, clear the StringBuilder
                            sb.Remove(0, sb.Length);
                        }
                    }
                }while (true);
            }
            else
            {
                Debug.Print("[Audio] Alc.GetString({0}, {1}) returned null.",
                            device, param);
            }

            return(result);
        }
Пример #7
0
		static string[] QueryDevices(string label, AlcGetStringList type)
		{
			// Clear error bit
			AL.GetError();

			var devices = Alc.GetString(IntPtr.Zero, type).ToArray();
			if (AL.GetError() != ALError.NoError)
			{
				Log.Write("sound", "Failed to query OpenAL device list using {0}", label);
				return new string[] { };
			}

			return devices;
		}
Пример #8
0
        static string[] QueryDevices(string label, AlcGetStringList type)
        {
            // Clear error bit
            AL.GetError();

            var devices = Alc.GetString(IntPtr.Zero, type).ToArray();

            if (AL.GetError() != ALError.NoError)
            {
                Log.Write("sound", "Failed to query OpenAL device list using {0}", label);
                return(new string[] { });
            }

            return(devices);
        }
Пример #9
0
 /// <summary>This function returns a List of strings related to the context.</summary>
 /// <remarks>
 ///     ALC_DEVICE_SPECIFIER will return the name of the specified output device if a pointer is supplied, or will return a
 ///     list of all available devices if a NULL device pointer is supplied. A list is a pointer to a series of strings
 ///     separated by NULL characters, with the list terminated by two NULL characters. See Enumeration Extension for more
 ///     details.
 ///     ALC_CAPTURE_DEVICE_SPECIFIER will return the name of the specified capture device if a pointer is supplied, or will
 ///     return a list of all available devices if a NULL device pointer is supplied.
 ///     ALC_EXTENSIONS returns a list of available context extensions, with each extension separated by a space and the
 ///     list terminated by a NULL character.
 /// </remarks>
 /// <param name="param">
 ///     An attribute to be retrieved: ALC_DEVICE_SPECIFIER, ALC_CAPTURE_DEVICE_SPECIFIER,
 ///     ALC_ALL_DEVICES_SPECIFIER.
 /// </param>
 /// <returns>A List of strings containing the names of the Devices.</returns>
 public static List <string> GetString(AlcGetStringList param) => GetString(ALDevice.Null, param);
Пример #10
0
        // ALC_API const ALCchar * ALC_APIENTRY alcGetString( ALCdevice *device, ALCenum param );

        /// <summary>This function returns a List of strings related to the context.</summary>
        /// <remarks>
        ///     ALC_DEVICE_SPECIFIER will return the name of the specified output device if a pointer is supplied, or will return a
        ///     list of all available devices if a NULL device pointer is supplied. A list is a pointer to a series of strings
        ///     separated by NULL characters, with the list terminated by two NULL characters. See Enumeration Extension for more
        ///     details.
        ///     ALC_CAPTURE_DEVICE_SPECIFIER will return the name of the specified capture device if a pointer is supplied, or will
        ///     return a list of all available devices if a NULL device pointer is supplied.
        ///     ALC_EXTENSIONS returns a list of available context extensions, with each extension separated by a space and the
        ///     list terminated by a NULL character.
        /// </remarks>
        /// <param name="device">A pointer to the device to be queried.</param>
        /// <param name="param">
        ///     An attribute to be retrieved: ALC_DEVICE_SPECIFIER, ALC_CAPTURE_DEVICE_SPECIFIER,
        ///     ALC_ALL_DEVICES_SPECIFIER.
        /// </param>
        /// <returns>A List of strings containing the names of the Devices.</returns>
        public static unsafe List <string> GetString(ALDevice device, AlcGetStringList param)
        {
            byte *result = GetStringPtr(device, (AlcGetString)param);

            return(ALStringListToList(result));
        }
Пример #11
0
        public static IList<string> GetString(IntPtr device, AlcGetStringList param)
        {
            List<string> result = new List<string>();
            IntPtr t = GetStringPrivate(IntPtr.Zero, (AlcGetString)param);
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            int offset = 0;
            do {
                byte b = Marshal.ReadByte(t, offset++);
                if (b != 0)
                    sb.Append((char)b);
                if (b == 0)
                {
                    result.Add(sb.ToString());
                    if (Marshal.ReadByte(t, offset) == 0) // offset already properly increased through ++
                        break; // 2x null
                    else
                        sb.Remove(0, sb.Length); // 1x null
                }
            } while (true);

            return result;
        }