Beispiel #1
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);
        }
Beispiel #2
0
        public AudioQueueStatus SetOfflineRenderFormat(AudioStreamBasicDescription desc, AudioChannelLayout layout)
        {
            int size;
            var h = layout == null ? IntPtr.Zero : AudioChannelLayout.ToBlock(layout, out size);

            try {
                return(AudioQueueSetOfflineRenderFormat(handle, ref desc, h));
            } finally {
                Marshal.FreeHGlobal(h);
            }
        }
Beispiel #3
0
        public AudioPanningInfo(AudioChannelLayout outputChannelMap)
        {
            if (outputChannelMap == null)
                throw new ArgumentNullException ("outputChannelMap");

            this.OutputChannelMap = outputChannelMap;
            Coordinates = new float[3];
        }
Beispiel #4
0
        public AudioBalanceFade(AudioChannelLayout channelLayout)
        {
            if (channelLayout == null)
                throw new ArgumentNullException ("channelLayout");

            this.ChannelLayout = channelLayout;
        }
Beispiel #5
0
        // The returned block must be released with FreeHGbloal
        internal static IntPtr ToBlock(AudioChannelLayout layout, out int size)
        {
            if (layout == null)
                throw new ArgumentNullException ("layout");
            if (layout.Channels == null)
                throw new ArgumentNullException ("layout.Channels");

            size = 12 + layout.Channels.Length * 20;
            IntPtr buffer = Marshal.AllocHGlobal (size);
            int p;
            Marshal.WriteInt32 (buffer, 0, (int) layout.AudioTag);
            Marshal.WriteInt32 (buffer, 4, layout.Bitmap);
            Marshal.WriteInt32 (buffer, 8, layout.Channels.Length);
            p = 12;
            foreach (var desc in layout.Channels){
                Marshal.WriteInt32 (buffer, p, (int) desc.Label);
                Marshal.WriteInt32 (buffer, p + 4, (int) desc.Flags);
                WriteFloat (buffer, p + 8, desc.Coords [0]);
                WriteFloat (buffer, p + 12, desc.Coords [1]);
                WriteFloat (buffer, p + 16, desc.Coords [2]);

                p += 20;
            }

            return buffer;
        }
Beispiel #6
0
        internal static AudioChannelLayout FromHandle(IntPtr h)
        {
            var layout = new AudioChannelLayout ();
            layout.AudioTag  = (AudioChannelLayoutTag) Marshal.ReadInt32 (h, 0);
            layout.Bitmap = Marshal.ReadInt32 (h, 4);
            layout.Channels = new AudioChannelDescription [Marshal.ReadInt32 (h, 8)];
            int p = 12;
            for (int i = 0; i < layout.Channels.Length; i++){
                var desc = new AudioChannelDescription ();
                desc.Label = (AudioChannelLabel) Marshal.ReadInt32 (h, p);
                desc.Flags = (AudioChannelFlags) Marshal.ReadInt32 (h, p+4);
                desc.Coords = new float [3];
                desc.Coords [0] = ReadFloat (h, p+8);
                desc.Coords [1] = ReadFloat (h, p+12);
                desc.Coords [2] = ReadFloat (h, p+16);
                layout.Channels [i] = desc;

                p += 20;
            }

            return layout;
        }
		public static AudioChannelLayoutTag? GetTagForChannelLayout (AudioChannelLayout layout)
		{
			if (layout == null)
				throw new ArgumentNullException ("layout");

			int ptr_size;
			var ptr = layout.ToBlock (out ptr_size);
			int size = sizeof (AudioChannelLayoutTag);
			int value;

			var res = AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.TagForChannelLayout, ptr_size, ptr, ref size, out value);
			Marshal.FreeHGlobal (ptr);
			return res != 0 ? null : (AudioChannelLayoutTag?) value;
		}
		public unsafe static float[,] GetMatrixMixMap (AudioChannelLayout inputLayout, AudioChannelLayout outputLayout)
		{
			if (inputLayout == null)
				throw new ArgumentNullException ("inputLayout");
			if (outputLayout == null)
				throw new ArgumentNullException ("outputLayout");

			var channels_count_output = GetNumberOfChannels (outputLayout);
			if (channels_count_output == null)
				throw new ArgumentException ("outputLayout");

			var channels_count_input = GetNumberOfChannels (inputLayout);
			if (channels_count_input == null)
				throw new ArgumentException ("inputLayout");

			int ptr_size;
			var input_ptr = inputLayout.ToBlock (out ptr_size);
			var output_ptr = outputLayout.ToBlock (out ptr_size);
			var array = new IntPtr[] { input_ptr, output_ptr };
			ptr_size = sizeof (IntPtr) * array.Length;

			float[,] value;
			AudioFormatError res;

			fixed (IntPtr* ptr = &array[0]) {
				value = new float[channels_count_input.Value, channels_count_output.Value];
				var size = sizeof (float) * channels_count_input.Value * channels_count_output.Value;
				fixed (float* value_ptr = &value[0, 0]) {
					res = AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.MatrixMixMap, ptr_size, ptr, ref size, value_ptr);
				}
			}

			Marshal.FreeHGlobal (input_ptr);
			Marshal.FreeHGlobal (output_ptr);

			return res == 0 ? value : null;
		}
		public static AudioFormatError Validate (AudioChannelLayout layout)
		{
			if (layout == null)
				throw new ArgumentNullException ("layout");

			int ptr_size;
			var ptr = layout.ToBlock (out ptr_size);

			var res = AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.ValidateChannelLayout, ptr_size, ptr, IntPtr.Zero, IntPtr.Zero);
			Marshal.FreeHGlobal (ptr);
			return res;
		}
Beispiel #10
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;
		}
Beispiel #11
0
        public unsafe static float[,] GetMatrixMixMap(AudioChannelLayout inputLayout, AudioChannelLayout outputLayout)
        {
            if (inputLayout == null)
            {
                throw new ArgumentNullException("inputLayout");
            }
            if (outputLayout == null)
            {
                throw new ArgumentNullException("outputLayout");
            }

            var channels_count_output = GetNumberOfChannels(outputLayout);

            if (channels_count_output == null)
            {
                throw new ArgumentException("outputLayout");
            }

            var channels_count_input = GetNumberOfChannels(inputLayout);

            if (channels_count_input == null)
            {
                throw new ArgumentException("inputLayout");
            }

            int ptr_size;
            var input_ptr  = inputLayout.ToBlock(out ptr_size);
            var output_ptr = outputLayout.ToBlock(out ptr_size);
            var array      = new IntPtr[] { input_ptr, output_ptr };

            ptr_size = sizeof(IntPtr) * array.Length;

            float[,] value;
            AudioFormatError res;

            fixed(IntPtr *ptr = &array[0])
            {
                value = new float[channels_count_input.Value, channels_count_output.Value];
                var size = sizeof(float) * channels_count_input.Value * channels_count_output.Value;

                fixed(float *value_ptr = &value[0, 0])
                {
                    res = AudioFormatPropertyNative.AudioFormatGetProperty(AudioFormatProperty.MatrixMixMap, ptr_size, ptr, ref size, value_ptr);
                }
            }

            Marshal.FreeHGlobal(input_ptr);
            Marshal.FreeHGlobal(output_ptr);

            return(res == 0 ? value : null);
        }