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(); }
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); } }
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); } }