コード例 #1
0
 public static AudioFormatError GetFormatInfo(ref AudioStreamBasicDescription format)
 {
     unsafe {
         var size = sizeof(AudioStreamBasicDescription);
         return(AudioFormatPropertyNative.AudioFormatGetProperty(AudioFormatProperty.FormatInfo, 0, IntPtr.Zero, ref size, ref format));
     }
 }
コード例 #2
0
        public static AudioStreamBasicDescription[] GetAvailableStreamDescriptions(AudioFileType fileType, AudioFormatType formatType)
        {
            AudioFileTypeAndFormatID input;

            input.FileType   = fileType;
            input.FormatType = formatType;

            uint size;

            if (AudioFileGetGlobalInfoSize(AudioFileGlobalProperty.AvailableStreamDescriptionsForFormat, (uint)sizeof(AudioFileTypeAndFormatID), ref input, out size) != 0)
            {
                return(null);
            }

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

            fixed(AudioStreamBasicDescription *ptr = data)
            {
                var res = AudioFileGetGlobalInfo(AudioFileGlobalProperty.AvailableStreamDescriptionsForFormat, (uint)sizeof(AudioFileTypeAndFormatID), ref input, ref size, ptr);

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

                return(data);
            }
        }
コード例 #3
0
        public static AudioConverter Create(AudioStreamBasicDescription sourceFormat, AudioStreamBasicDescription destinationFormat, out AudioConverterError error)
        {
            IntPtr ptr = new IntPtr();

            error = AudioConverterNew(ref sourceFormat, ref destinationFormat, ref ptr);
            if (error != AudioConverterError.None)
            {
                return(null);
            }

            return(new AudioConverter(ptr, true));
        }
コード例 #4
0
        public static AudioStreamBasicDescription CreateLinearPCM(double sampleRate = 44100, uint channelsPerFrame = 2, uint bitsPerChannel = 16, bool bigEndian = false)
        {
            var desc = new AudioStreamBasicDescription (AudioFormatType.LinearPCM);
            desc.SampleRate = sampleRate;
            desc.ChannelsPerFrame = (int) channelsPerFrame;
            desc.BitsPerChannel = (int) bitsPerChannel;
            desc.BytesPerPacket = desc.BytesPerFrame = (int) channelsPerFrame * sizeof (Int16);
            desc.FramesPerPacket = 1;
            desc.FormatFlags = AudioFormatFlags.IsSignedInteger | AudioFormatFlags.IsPacked;
            if (bigEndian)
                desc.FormatFlags |= AudioFormatFlags.IsBigEndian;

            return desc;
        }
コード例 #5
0
        public static unsafe 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;
            }
        }
コード例 #6
0
        public static AudioConverter Create(AudioStreamBasicDescription sourceFormat, AudioStreamBasicDescription destinationFormat, AudioClassDescription[] descriptions)
        {
            if (descriptions == null)
            {
                throw new ArgumentNullException("descriptions");
            }

            IntPtr ptr = new IntPtr();
            var    res = AudioConverterNewSpecific(ref sourceFormat, ref destinationFormat, descriptions.Length, ref descriptions, ref ptr);

            if (res != AudioConverterError.None)
            {
                return(null);
            }

            return(new AudioConverter(ptr, true));
        }
コード例 #7
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);
            }
        }
コード例 #8
0
 static extern AudioConverterError AudioConverterNewSpecific(ref AudioStreamBasicDescription inSourceFormat, ref AudioStreamBasicDescription inDestinationFormat,
                                                             int inNumberClassDescriptions, ref AudioClassDescription[] inClassDescriptions, ref IntPtr outAudioConverter);
コード例 #9
0
 static extern AudioConverterError AudioConverterNew(ref AudioStreamBasicDescription inSourceFormat, ref AudioStreamBasicDescription inDestinationFormat, ref IntPtr outAudioConverter);
コード例 #10
0
        public static AudioConverter Create(AudioStreamBasicDescription sourceFormat, AudioStreamBasicDescription destinationFormat)
        {
            AudioConverterError res;

            return(Create(sourceFormat, destinationFormat, out res));
        }