public Task OpenAsync() { if (synth != null) { throw new InvalidOperationException("The MIDI output is already open."); } settings = new Settings(); if (midi_access.ConfigureSettings != null) { midi_access.ConfigureSettings(settings); } synth = new Synth(settings); synth.HandleError = midi_access.HandleNativeError; foreach (var factory in midi_access.SoundFontLoaderFactories) { synth.AddSoundFontLoader(factory(synth)); } foreach (var sf in midi_access.SoundFonts) { synth.LoadSoundFont(sf, false); } adriver = new AudioDriver(synth.Settings, synth); return(Task.FromResult(true)); }
public FluidsynthMidiReceiver(Context context) { #if MIDI_MANAGER access = new FluidsynthMidiAccess(); access.ConfigureSettings = (settings) => { #else var settings = new Settings(); #endif settings [ConfigurationKeys.AudioDriver].StringValue = "oboe"; //settings [ConfigurationKeys.SynthParallelRender].IntValue = 0; //settings [ConfigurationKeys.SynthThreadsafeApi].IntValue = 0; //settings [ConfigurationKeys.AudioPeriods].IntValue = 16; //settings [ConfigurationKeys.AudioPeriods].IntValue = 64; settings [ConfigurationKeys.AudioSampleFormat].StringValue = "16bits"; // float or 16bits var manager = context.GetSystemService(Context.AudioService).JavaCast <AudioManager> (); // Note that it is NOT audio sample rate but *synthesizing* sample rate. // So it is kind of wrong assumption that AudioManager.PropertyOutputSampleRate would give the best outcome... //var sr = double.Parse (manager.GetProperty (AudioManager.PropertyOutputSampleRate)); //settings [ConfigurationKeys.SynthSampleRate].DoubleValue = sr; settings [ConfigurationKeys.SynthSampleRate].DoubleValue = 11025; var fpb = double.Parse(manager.GetProperty(AudioManager.PropertyOutputFramesPerBuffer)); settings [ConfigurationKeys.AudioPeriodSize].IntValue = (int)fpb; #if MIDI_MANAGER }; SynthAndroidExtensions.GetSoundFonts(access.SoundFonts, context, predefined_temp_path); output = access.OpenOutputAsync(access.Outputs.First().Id).Result; #else syn = new Synth(settings); var sfs = new List <string> (); SynthAndroidExtensions.GetSoundFonts(sfs, context, predefined_temp_path); asset_sfloader = new AndroidNativeAssetSoundFontLoader(settings, context.Assets); syn.AddSoundFontLoader(asset_sfloader); foreach (var sf in sfs) { syn.LoadSoundFont(sf, false); } adriver = new AudioDriver(syn.Settings, syn); #endif }