OpenRA.Platforms.Default.OpenAlSoundEngine.QueryDevices C# (CSharp) Method

QueryDevices() static private method

static private QueryDevices ( string label, int type ) : string[]
label string
type int
return string[]
        static string[] QueryDevices(string label, int type)
        {
            // Clear error bit
            AL10.alGetError();

            // Returns a null separated list of strings, terminated by two nulls.
            var devicesPtr = ALC10.alcGetString(IntPtr.Zero, type);
            if (devicesPtr == IntPtr.Zero || AL10.alGetError() != AL10.AL_NO_ERROR)
            {
                Log.Write("sound", "Failed to query OpenAL device list using {0}", label);
                return new string[0];
            }

            var devices = new List<string>();
            var buffer = new List<byte>();
            var offset = 0;

            while (true)
            {
                var b = Marshal.ReadByte(devicesPtr, offset++);
                if (b != 0)
                {
                    buffer.Add(b);
                    continue;
                }

                // A null indicates termination of that string, so add that to our list.
                devices.Add(Encoding.Default.GetString(buffer.ToArray()));
                buffer.Clear();

                // Two successive nulls indicates the end of the list.
                if (Marshal.ReadByte(devicesPtr, offset) == 0)
                    break;
            }

            return devices.ToArray();
        }