Exemplo n.º 1
0
        private void GetChannelNames(RealtimeHostConfig config)
        {
            if (config == null)
            {
                InputNames  = new string[0];
                OutputNames = new string[0];
                return;
            }

            var inputDeviceInfo  = PortAudio.Pa_GetDeviceInfo(config.InputDeviceID);
            var outputDeviceInfo = PortAudio.Pa_GetDeviceInfo(config.OutputDeviceID);

            InputNames = Enumerable.Range(0, inputDeviceInfo.maxInputChannels)
                         .Select(ch =>
            {
                string chName = null;
                PortAudio.PaAsio_GetInputChannelName((PortAudio.PaDeviceIndex)config.InputDeviceID, ch, ref chName);
                return((ch + 1) + ": " + chName);
            })
                         .ToArray();

            OutputNames = Enumerable.Range(0, outputDeviceInfo.maxOutputChannels)
                          .Select(ch =>
            {
                string chName = null;
                PortAudio.PaAsio_GetOutputChannelName((PortAudio.PaDeviceIndex)config.OutputDeviceID, ch, ref chName);
                return((ch + 1) + ": " + chName);
            })
                          .ToArray();
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
        private void LoadAudioConfig(RealtimeHostConfig config)
        {
            Console.WriteLine("Loading RealtimeHostConfig with the following settings:");
            Console.WriteLine(config.Serialize());

            if (config != null)
            {
                host.SetConfig(config);
            }

            if (host.Config != null)
            {
                StartAudio();
                StopAudio();
                StartAudio();
            }
        }
Exemplo n.º 5
0
        private void Start()
        {
            selectedInputL  = 0;
            selectedInputR  = 0;
            selectedOutputL = 0;
            selectedOutputR = 1;

            // initialize PortAudio and get singleton host object
            host         = RealtimeHost.Host;
            host.Process = ProcessAudio;

            var settingsFile   = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "settings.json");
            var jsonString     = File.ReadAllText(settingsFile);
            var dict           = JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonString);
            var realtimeConfig = RealtimeHostConfig.Deserialize(dict["AudioSettings"]);

            try
            {
                memoryMap  = MemoryMappedFile.OpenExisting("Global\\IRWorkshopMap");
                mmAccessor = memoryMap.CreateViewAccessor();
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("Failed to open memory map");
                Environment.Exit(1);


                // for testing only

                /*
                 * this.memoryMap = MemoryMappedFile.CreateNew("Global\\IRWorkshopMap", 65536);
                 * this.mmAccessor = memoryMap.CreateViewAccessor();
                 * var state = new SharedMemoryState { Gain = 1.0f, Id = 1, IrLeft = new[] { 1.0f, 0.0f }, IrRight = new[] { 1.0f, 0.0f }, IrLength = 2, SelectedInputLeft = 0, SelectedInputRight = 0, SelectedOutputLeft = 0, SelectedOutputRight = 0 };
                 * state.Write(mmAccessor);
                 */
            }

            LoadAudioConfig(realtimeConfig);

            while (true)
            {
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 6
0
        private void LoadSettings()
        {
            try
            {
                if (File.Exists(settingsFile))
                {
                    var jsonString = File.ReadAllText(settingsFile);
                    var dict       = JsonConvert.DeserializeObject <Dictionary <string, string> >(jsonString);

                    if (dict.ContainsKey("AudioSettings"))
                    {
                        realtimeConfig = RealtimeHostConfig.Deserialize(dict["AudioSettings"]);
                        GetChannelNames(realtimeConfig);
                    }

                    if (dict.ContainsKey(nameof(SelectedInputL)))
                    {
                        SelectedInputL = int.Parse(dict[nameof(SelectedInputL)]);
                    }

                    if (dict.ContainsKey(nameof(SelectedInputR)))
                    {
                        SelectedInputR = int.Parse(dict[nameof(SelectedInputR)]);
                    }

                    if (dict.ContainsKey(nameof(SelectedOutputL)))
                    {
                        SelectedOutputL = int.Parse(dict[nameof(SelectedOutputL)]);
                    }

                    if (dict.ContainsKey(nameof(SelectedOutputR)))
                    {
                        SelectedOutputR = int.Parse(dict[nameof(SelectedOutputR)]);
                    }

                    if (dict.ContainsKey(nameof(loadSampleDirectory)))
                    {
                        loadSampleDirectory = dict[nameof(loadSampleDirectory)];
                    }

                    if (dict.ContainsKey(nameof(saveSampleDirectory)))
                    {
                        saveSampleDirectory = dict[nameof(saveSampleDirectory)];
                    }

                    if (dict.ContainsKey(nameof(savePresetDirectory)))
                    {
                        savePresetDirectory = dict[nameof(savePresetDirectory)];
                    }

                    if (dict.ContainsKey(nameof(VolumeSlider)))
                    {
                        VolumeSlider = double.Parse(dict[nameof(VolumeSlider)], CultureInfo.InvariantCulture);
                    }
                }
            }
            catch (Exception)
            {
                Logging.ShowMessage("Failed to load user settings, resetting to default", LogType.Warning);
                File.Delete(settingsFile);
            }
        }