unsafe static AudioFormatType[] GetFormats(AudioFormatProperty prop)
        {
            int size;

            if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo(prop, 0, IntPtr.Zero, out size) != 0)
            {
                return(null);
            }

            var elementSize = sizeof(AudioFormatType);
            var data        = new AudioFormatType[size / elementSize];

            fixed(AudioFormatType *ptr = data)
            {
                var res = AudioFormatPropertyNative.AudioFormatGetProperty(prop, 0, IntPtr.Zero, ref size, (IntPtr)ptr);

                if (res != 0)
                {
                    return(null);
                }

                Array.Resize(ref data, elementSize);
                return(data);
            }
        }
Esempio n. 2
0
        public unsafe                           AudioFormat[] GetOutputFormatList(byte[] magicCookie = null)
        {
            var afi = new AudioFormatInfo();

            afi.AudioStreamBasicDescription = this;

            var  type_size = sizeof(AudioFormat);
            uint size;

            if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo(AudioFormatProperty.OutputFormatList, type_size, ref afi, out size) != 0)
            {
                return(null);
            }

            Debug.Assert(sizeof(AudioFormat) == type_size);

            var data = new AudioFormat[size / type_size];

            fixed(AudioFormat *ptr = &data[0])
            {
                var res = AudioFormatPropertyNative.AudioFormatGetProperty(AudioFormatProperty.OutputFormatList, type_size, ref afi, ref size, ptr);

                if (res != 0)
                {
                    return(null);
                }

                Array.Resize(ref data, (int)size / type_size);
                return(data);
            }
        }
        unsafe static T[] GetAvailable <T> (AudioFormatProperty prop, AudioFormatType format)
        {
            uint size;

            if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo(prop, sizeof(AudioFormatType), ref format, out size) != 0)
            {
                return(null);
            }

            var data         = new T[size / Marshal.SizeOf(typeof(T))];
            var array_handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            try {
                var ptr = array_handle.AddrOfPinnedObject();
                var res = AudioFormatPropertyNative.AudioFormatGetProperty(prop, sizeof(AudioFormatType), ref format, ref size, ptr);
                if (res != 0)
                {
                    return(null);
                }

                Array.Resize(ref data, (int)size / Marshal.SizeOf(typeof(T)));
                return(data);
            } finally {
                array_handle.Free();
            }
        }
Esempio n. 4
0
        public unsafe float[] GetBalanceFade()
        {
            var type_size = sizeof(Layout);

            var str = ToStruct();
            var ptr = Marshal.AllocHGlobal(type_size);

            (*(Layout *)ptr) = str;

            int size;

            if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo(AudioFormatProperty.BalanceFade, type_size, ptr, out size) != 0)
            {
                return(null);
            }

            AudioFormatError res;
            var data = new float[size / sizeof(float)];

            fixed(float *data_ptr = data)
            {
                res = AudioFormatPropertyNative.AudioFormatGetProperty(AudioFormatProperty.BalanceFade, type_size, ptr, ref size, data_ptr);
            }

            Marshal.FreeHGlobal(str.ChannelLayoutWeak);
            Marshal.FreeHGlobal(ptr);

            return(res == 0 ? data : null);
        }
Esempio n. 5
0
        unsafe static T[] GetAvailable <T> (AudioFormatProperty prop, AudioFormatType format)
        {
            uint size;

            if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo(prop, sizeof(AudioFormatType), ref format, out size) != 0)
            {
                return(null);
            }

            var data         = new T[size / Marshal.SizeOf(typeof(T))];
            var array_handle = GCHandle.Alloc(data, GCHandleType.Pinned);              // This requires a pinned GCHandle, since it's not possible to use unsafe code to get the address of a generic object.

            try {
                var ptr = array_handle.AddrOfPinnedObject();
                var res = AudioFormatPropertyNative.AudioFormatGetProperty(prop, sizeof(AudioFormatType), ref format, ref size, ptr);
                if (res != 0)
                {
                    return(null);
                }

                Array.Resize(ref data, (int)size / Marshal.SizeOf(typeof(T)));
                return(data);
            } finally {
                array_handle.Free();
            }
        }
Esempio n. 6
0
        public unsafe float[] GetPanningMatrix()
        {
            var type_size = sizeof(Layout);

            var str = ToStruct();
            var ptr = Marshal.AllocHGlobal(type_size);

            *((Layout *)ptr) = str;

            int size;

            if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo(AudioFormatProperty.PanningMatrix, type_size, ptr, out size) != 0)
                return(null); }
Esempio n. 7
0
        public unsafe                           AudioFormat[] GetFormatList(byte[] magicCookie)
        {
            if (magicCookie == null)
            {
                throw new ArgumentNullException("magicCookie");
            }

            var afi = new AudioFormatInfo();

            afi.AudioStreamBasicDescription = this;

            fixed(byte *b = magicCookie)
            {
                afi.MagicCookieWeak = b;
                afi.MagicCookieSize = magicCookie.Length;

                var  type_size = sizeof(AudioFormat);
                uint size;

                if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo(AudioFormatProperty.FormatList, type_size, ref afi, out size) != 0)
                {
                    return(null);
                }

                Debug.Assert(sizeof(AudioFormat) == type_size);

                var data = new AudioFormat[size / type_size];

                fixed(AudioFormat *ptr = &data[0])
                {
                    var res = AudioFormatPropertyNative.AudioFormatGetProperty(AudioFormatProperty.FormatList, type_size, ref afi, ref size, ptr);

                    if (res != 0)
                    {
                        return(null);
                    }

                    Array.Resize(ref data, (int)size / type_size);
                    return(data);
                }
            }
        }
Esempio n. 8
0
        static AudioChannelLayout GetChannelLayout(AudioFormatProperty property, int value)
        {
            int size;

            AudioFormatPropertyNative.AudioFormatGetPropertyInfo(property, sizeof(AudioFormatProperty), ref value, out size);

            AudioChannelLayout layout;
            IntPtr             ptr = Marshal.AllocHGlobal(size);

            if (AudioFormatPropertyNative.AudioFormatGetProperty(property, sizeof(AudioFormatProperty), ref value, ref size, ptr) == 0)
            {
                layout = new AudioChannelLayout(ptr);
            }
            else
            {
                layout = null;
            }

            Marshal.FreeHGlobal(ptr);
            return(layout);
        }
Esempio n. 9
0
        public unsafe static int[] GetAvailableEncodeNumberChannels(AudioStreamBasicDescription format)
        {
            uint size;

            if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo(AudioFormatProperty.AvailableEncodeNumberChannels, sizeof(AudioStreamBasicDescription), ref format, out size) != 0)
            {
                return(null);
            }

            var data = new int[size / sizeof(int)];

            fixed(int *ptr = data)
            {
                var res = AudioFormatPropertyNative.AudioFormatGetProperty(AudioFormatProperty.AvailableEncodeNumberChannels, sizeof(AudioStreamBasicDescription), ref format, ref size, ptr);

                if (res != 0)
                {
                    return(null);
                }

                return(data);
            }
        }
Esempio n. 10
0
        public unsafe static AudioChannelLayoutTag[] GetAvailableEncodeChannelLayoutTags(AudioStreamBasicDescription format)
        {
            var  type_size = sizeof(AudioStreamBasicDescription);
            uint size;

            if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo(AudioFormatProperty.AvailableEncodeChannelLayoutTags, type_size, ref format, out size) != 0)
            {
                return(null);
            }

            var data = new AudioChannelLayoutTag[size / sizeof(AudioChannelLayoutTag)];

            fixed(AudioChannelLayoutTag *ptr = data)
            {
                var res = AudioFormatPropertyNative.AudioFormatGetProperty(AudioFormatProperty.AvailableEncodeChannelLayoutTags, type_size, ref format, ref size, (int *)ptr);

                if (res != 0)
                {
                    return(null);
                }

                return(data);
            }
        }
Esempio n. 11
0
        public unsafe static AudioChannelLayoutTag[] GetTagsForNumberOfChannels(int count)
        {
            const int type_size = sizeof(uint);
            int       size;

            if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo(AudioFormatProperty.TagsForNumberOfChannels, type_size, ref count, out size) != 0)
            {
                return(null);
            }

            var data = new AudioChannelLayoutTag[size / type_size];

            fixed(AudioChannelLayoutTag *ptr = data)
            {
                var res = AudioFormatPropertyNative.AudioFormatGetProperty(AudioFormatProperty.TagsForNumberOfChannels, type_size, ref count, ref size, (int *)ptr);

                if (res != 0)
                {
                    return(null);
                }

                return(data);
            }
        }