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 }
public FluidsynthMidiReceiver(Context context) { #if MIDI_MANAGER access = new FluidsynthMidiAccess (); access.ConfigureSettings = (settings) => { #else var settings = new Settings (); #endif //settings [ConfigurationKeys.AudioDriver].StringValue = "opensles"; //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_stream_loader = new AndroidAssetStreamLoader (context.Assets); asset_sfloader = new SoundFontLoader (syn, asset_stream_loader); syn.AddSoundFontLoader (asset_sfloader); foreach (var sf in sfs) syn.LoadSoundFont (sf, false); adriver = new AudioDriver (syn.Settings, syn); #endif }
public void UpdateSelectedInstrument(SoundFontSelection item) { if (skip_loading) { return; } var prevItem = SelectedSoundItem; SelectedSoundItem = item; if (output != null && item.File != prevItem.File) { output.CloseAsync(); keyon_flags = new bool [128]; } if (prevItem?.File != item.File) { access = new FluidsynthMidiAccess(); if (File.Exists("/dev/snd/seq")) // ALSA { access.ConfigureSettings = s => s [NFluidsynth.ConfigurationKeys.AudioDriver].StringValue = "alsa"; } access.SoundFonts.Add(item.File); output = access.OpenOutputAsync(access.Outputs.First().Id).Result; } int ch = item.Bank >= 128 ? 9 : 0; /* * output.Send (new byte[] {(byte) (MidiEvent.CC + ch), MidiCC.BankSelect, (byte) (item.Bank / 0x80)}, 0, 3, 0); * output.Send (new byte[] {(byte) (MidiEvent.CC + ch), MidiCC.BankSelectLsb, (byte) (item.Bank % 0x80)}, 0, 3, 0); * output.Send (new byte[] {(byte) (MidiEvent.Program + ch), (byte) (item.Instrument % 128)}, 0, 2, 0); * output.Send (new byte[] {(byte) (MidiEvent.CC + ch), MidiCC.Volume, 120}, 0, 3, 0); */ output.Send(new byte[] { (byte)(MidiEvent.CC + ch), MidiCC.BankSelect, (byte)(item.Bank / 0x80) }, 0, 3, 0); output.Send(new byte[] { (byte)(MidiEvent.CC + ch), MidiCC.BankSelectLsb, (byte)(item.Bank % 0x80) }, 0, 3, 0); output.Send(new byte[] { (byte)(MidiEvent.Program + ch), (byte)(item.Patch % 128) }, 0, 2, 0); output.Send(new byte[] { (byte)(MidiEvent.CC + ch), MidiCC.Volume, 127 }, 0, 3, 0); output.Send(new byte[] { (byte)(MidiEvent.CC + ch), MidiCC.Expression, 127 }, 0, 3, 0); }