Ejemplo n.º 1
0
        static void OnError(Exception e)
        {
            string message = e.ToString();

            if (e is XtException xt)
            {
                message = XtAudio.GetErrorInfo(xt.GetError()).ToString();
            }
            MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Ejemplo n.º 2
0
        static void OnRunning(XtStream stream, bool running, ulong error, object user)
        {
            string evt = running ? "Started" : "Stopped";

            Console.WriteLine("Stream event: " + evt + ", new state: " + stream.IsRunning() + ".");
            if (error != 0)
            {
                Console.WriteLine(XtAudio.GetErrorInfo(error).ToString());
            }
        }
Ejemplo n.º 3
0
 void OnStart(object sender, EventArgs ea)
 {
     try
     {
         Start();
     } catch (XtException e)
     {
         Stop();
         var caption = "Failed to start stream.";
         var message = XtAudio.GetErrorInfo(e.GetError()).ToString();
         MessageBox.Show(this, message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 4
0
        public static void Main()
        {
            XtAudio.SetOnError(OnError);
            using XtPlatform platform = XtAudio.Init("Sample", IntPtr.Zero);
            try
            {
                XtVersion version = XtAudio.GetVersion();
                Console.WriteLine("Version: " + version.major + "." + version.minor);
                XtSystem pro = platform.SetupToSystem(XtSetup.ProAudio);
                Console.WriteLine("Pro Audio: " + pro + " (" + (platform.GetService(pro) != null) + ")");
                XtSystem system = platform.SetupToSystem(XtSetup.SystemAudio);
                Console.WriteLine("System Audio: " + system + " (" + (platform.GetService(system) != null) + ")");
                XtSystem consumer = platform.SetupToSystem(XtSetup.ConsumerAudio);
                Console.WriteLine("Consumer Audio: " + consumer + " (" + (platform.GetService(consumer) != null) + ")");

                foreach (XtSystem s in platform.GetSystems())
                {
                    XtService service = platform.GetService(s);
                    using XtDeviceList all = service.OpenDeviceList(XtEnumFlags.All);
                    Console.WriteLine("System: " + s);
                    Console.WriteLine("  Capabilities: " + service.GetCapabilities());
                    string defaultInput = service.GetDefaultDeviceId(false);
                    if (defaultInput != null)
                    {
                        string name = all.GetName(defaultInput);
                        Console.WriteLine("  Default input: " + name + " (" + defaultInput + ")");
                    }
                    string defaultOutput = service.GetDefaultDeviceId(true);
                    if (defaultOutput != null)
                    {
                        string name = all.GetName(defaultOutput);
                        Console.WriteLine("  Default output: " + name + " (" + defaultOutput + ")");
                    }
                    using XtDeviceList inputs = service.OpenDeviceList(XtEnumFlags.Input);
                    Console.WriteLine("  Input device count: " + inputs.GetCount());
                    PrintDevices(service, inputs);
                    using XtDeviceList outputs = service.OpenDeviceList(XtEnumFlags.Output);
                    Console.WriteLine("  Output device count: " + outputs.GetCount());
                    PrintDevices(service, outputs);
                }
            } catch (XtException e)
            { Console.WriteLine(XtAudio.GetErrorInfo(e.GetError())); } catch (Exception e)
            { Console.WriteLine(e.Message); }
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            int index = args.Length == 1 ? int.Parse(args[0]) : -1;

            try
            {
                if (index >= 0)
                {
                    RunSample(index);
                }
                else
                {
                    for (int i = 0; i < Samples.Length; i++)
                    {
                        RunSample(i);
                    }
                }
            } catch (XtException e)
            { Console.WriteLine(XtAudio.GetErrorInfo(e.GetError())); } catch (Exception e)
            { Console.WriteLine(e.Message); }
        }
Ejemplo n.º 6
0
        IList <DeviceInfo> GetDeviceInfos(XtService service, XtDeviceList list, string defaultId)
        {
            var result   = new List <DeviceInfo>();
            var noDevice = new DeviceInfo();

            noDevice.Id   = "None";
            noDevice.Name = "[None]";
            result.Add(noDevice);
            for (int i = 0; i < list.GetCount(); i++)
            {
                try
                {
                    var info = GetDeviceInfo(service, list, i, defaultId);
                    result.Insert(info.DefaultInput || info.DefaultInput ? 1 : result.Count, info);
                    _allDevices.Add(info);
                } catch (XtException e)
                {
                    AddMessage(() => XtAudio.GetErrorInfo(e.GetError()).ToString());
                }
            }
            return(result);
        }
Ejemplo n.º 7
0
 static void PrintDevices(XtService service, XtDeviceList list)
 {
     for (int d = 0; d < list.GetCount(); d++)
     {
         string id = list.GetId(d);
         try
         {
             using XtDevice device = service.OpenDevice(id);
             XtMix?mix = device.GetMix();
             Console.WriteLine("    Device " + id + ":");
             Console.WriteLine("      Name: " + list.GetName(id));
             Console.WriteLine("      Capabilities: " + list.GetCapabilities(id));
             Console.WriteLine("      Input channels: " + device.GetChannelCount(false));
             Console.WriteLine("      Output channels: " + device.GetChannelCount(true));
             Console.WriteLine("      Interleaved access: " + device.SupportsAccess(true));
             Console.WriteLine("      Non-interleaved access: " + device.SupportsAccess(false));
             if (mix != null)
             {
                 Console.WriteLine("      Current mix: " + mix.Value.rate + " " + mix.Value.sample);
             }
         } catch (XtException e)
         { Console.WriteLine(XtAudio.GetErrorInfo(e.GetError())); }
     }
 }
Ejemplo n.º 8
0
        void OnRunning(XtStream stream, bool running, ulong error, object user)
        {
            bool evt      = running;
            bool newState = stream.IsRunning();

            BeginInvoke(new Action(() => {
                string evtDesc = running ? "Started" : "Stopped";
                AddMessage(() => "Stream event: " + evtDesc + ", new state: " + newState + ".");
                if (error != 0)
                {
                    AddMessage(() => XtAudio.GetErrorInfo(error).ToString());
                }
                _stop.Enabled              = running;
                panel.Enabled              = !running;
                _start.Enabled             = !running;
                _bufferSize.Enabled        = !running;
                _streamType.Enabled        = !running;
                _streamNative.Enabled      = !running;
                _outputMaster.Enabled      = !running;
                _secondaryInput.Enabled    = !running;
                _secondaryOutput.Enabled   = !running;
                _streamInterleaved.Enabled = !running;
            }));
        }