示例#1
0
        public static void Init()
        {
            try
            {
                var  src        = ConvertToUInt("dOut");
                uint theRunLoop = 0;
                var  property   = new AudioObjectPropertyAddress(
                    kAudioHardwarePropertyDefaultOutputDevice,
                    (uint)AudioObjectPropertyScope.Global,
                    (uint)AudioObjectPropertyElement.Master);

                AudioObjectAddPropertyListener(1, ref property, OutputDidChange, IntPtr.Zero);

                //var defaultDevice = GetCurrentOutputDevice();
                ////	var name = GetDeviceName (defaultDevice);
                //var sourceId = GetDeviceSourceId(defaultDevice);
                ////	var trasnport = ConvertToString (GetDeviceProperty (defaultDevice, AudioDevicePropertyTransportType));
                //var theAddress = new AudioObjectPropertyAddress(
                //	AudioDevicePropertyDataSource,
                //	(uint)AudioObjectPropertyScope.Output,
                //	(uint)AudioObjectPropertyElement.Master);
                //AudioObjectAddPropertyListener(1, ref theAddress, OutputDidChange, IntPtr.Zero);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
示例#2
0
 static extern int AudioObjectSetPropertyData(
     uint inObjectID,
     ref AudioObjectPropertyAddress inAddress,
     ref uint inQualifierDataSize,
     ref IntPtr inQualifierData,
     ref uint ioDataSize,
     ref uint inData
     );
示例#3
0
        public static uint GetDeviceId(uint deviceId)
        {
            uint dataSourceId;
            uint size       = (uint)Marshal.SizeOf(typeof(uint));
            var  theAddress = new AudioObjectPropertyAddress(
                AudioDevicePropertyDataSource,
                (uint)AudioObjectPropertyScope.Output,
                (uint)AudioObjectPropertyElement.Master);
            uint   inQualifierDataSize = 0;
            IntPtr inQualifierData     = IntPtr.Zero;

            var err = AudioObjectGetPropertyData(deviceId, ref theAddress, ref inQualifierDataSize, ref inQualifierData, ref size, out dataSourceId);

            //if (err != 0)
            //throw new AudioUnitException((int)err);
            return(dataSourceId);
        }
示例#4
0
        static bool SetDeviceProperty(AudioObjectPropertyAddress theAddress, uint deviceId, uint data)
        {
            uint   dataSourceId        = data;
            uint   size                = (uint)Marshal.SizeOf(typeof(UInt64));
            uint   inQualifierDataSize = 0;
            IntPtr inQualifierData     = IntPtr.Zero;

            var err = AudioObjectSetPropertyData(deviceId, ref theAddress, ref inQualifierDataSize, ref inQualifierData, ref size, ref dataSourceId);

            if (err != 0)
            {
                var error = new NSError(NSError.OsStatusErrorDomain, err);
                Console.WriteLine(error);
                return(false);
            }

            return(true);;
        }
示例#5
0
        public static uint GetDeviceProperty(uint deviceId, uint property)
        {
            uint dataSourceId;
            uint size       = (uint)Marshal.SizeOf(typeof(UInt64));
            var  theAddress = new AudioObjectPropertyAddress(
                property,
                (uint)AudioObjectPropertyScope.Output,
                (uint)AudioObjectPropertyElement.Master);
            uint   inQualifierDataSize = 0;
            IntPtr inQualifierData     = IntPtr.Zero;

            var err = AudioObjectGetPropertyData(deviceId, ref theAddress, ref inQualifierDataSize, ref inQualifierData, ref size, out dataSourceId);

            if (err != 0)
            {
                var error = new NSError(NSError.OsStatusErrorDomain, err);
                Console.WriteLine(error);
            }

            return(dataSourceId);
        }
示例#6
0
        public static uint GetCurrentOutputDevice()
        {
            uint outputDevice;
            uint size = (uint)Marshal.SizeOf(typeof(uint));

            var theAddress = new AudioObjectPropertyAddress(
                AudioObjectPropertySelector.DefaultSystemOutputDevice,
                AudioObjectPropertyScope.Global,
                AudioObjectPropertyElement.Master);

            uint   inQualifierDataSize = 0;
            IntPtr inQualifierData     = IntPtr.Zero;

            var err = AudioObjectGetPropertyData(1, ref theAddress, ref inQualifierDataSize, ref inQualifierData, ref size, out outputDevice);

            if (err != 0)
            {
                var status = (AudioUnitStatus)err;
                Console.WriteLine(status);
            }
            return(outputDevice);
        }
示例#7
0
 static extern int AudioObjectAddPropertyListener(uint inObjectID,
                                                  ref AudioObjectPropertyAddress inAddress,
                                                  OutputChange callback, IntPtr clientData);
示例#8
0
 static void OutputDidChange(uint inObjectID, uint inNumberAddresses, AudioObjectPropertyAddress inAddresses, IntPtr clientData)
 {
     Console.WriteLine("Output Changed");
     OutputChanged?.Invoke();
 }