Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // The host lives in a singleton withing. It can not be created directly
            // and only one host can exists within an application context
            var host = RealtimeHost.Host;

            // host.Process is the callback method that processes audio data.
            // Assign the static process method in this class to be the callback
            host.Process = process;

            // Use the graphical editor to create a new config
            var config = RealtimeHostConfig.CreateConfig();

            // assign the config to the host
            host.SetConfig(config);

            // Open the stream and start processing
            host.OpenStream();
            host.StartStream();

            Console.WriteLine("\n\n\n\n");

            // allow the user to enter a new frequency or stop processing audio
            while (true)
            {
                Console.WriteLine("Enter frequency. type exit to processing audio");
                string input = Console.ReadLine();
                if (input.ToLower() == "exit")
                {
                    // break the loop and exit the application
                    break;
                }
                else
                {
                    try
                    {
                        freq = Convert.ToDouble(input);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Unable to parse '" + input + "' as a number");
                    }
                }
            }

            // close the stream and stop processing
            host.StopStream();
            host.CloseStream();
        }
Ejemplo n.º 2
0
        private void AudioSetup()
        {
            StopAudioEngine();

            lock (globalLock)
            {
                try
                {
                    // this is done because the devices and Ids go a bit t**s when you re-initialize...
                    string serialized = null;
                    if (realtimeConfig != null)
                    {
                        serialized = realtimeConfig.Serialize();
                    }

                    PortAudio.Pa_Terminate();
                    PortAudio.Pa_Initialize();

                    RealtimeHostConfig deserialized = null;
                    if (serialized != null)
                    {
                        deserialized = RealtimeHostConfig.Deserialize(serialized);
                    }

                    // Use the graphical editor to create a new config
                    var config = RealtimeHostConfig.CreateConfig(deserialized);
                    if (config != null)
                    {
                        realtimeConfig = config;
                    }
                }
                catch (InvalidFormatException ex)
                {
                    Logging.ShowMessage(ex.Message, LogType.Warning);
                }
                catch (Exception)
                {
                    realtimeConfig = RealtimeHostConfig.CreateConfig();
                }

                GetChannelNames(realtimeConfig);
                NotifyPropertyChanged(nameof(SamplerateWarning));
                SaveSettings();
            }

            UpdateMemoryMap();
            StartAudioEngine();
        }