public static void Main(string[] args)
 {
     using (var settings = new Settings ()) {
         if (Environment.OSVersion.Platform == PlatformID.Unix)
             settings [ConfigurationKeys.AudioDriver].StringValue = "alsa";
         using (var syn = new Synth (settings)) {
             foreach (var arg in args)
                 if (Synth.IsSoundFont (arg))
                     syn.LoadSoundFont (arg, true);
             if (syn.FontCount == 0)
                 syn.LoadSoundFont ("/usr/share/sounds/sf2/FluidR3_GM.sf2", true);
             var files = args.Where (a => Synth.IsMidiFile (a));
             if (files.Any ()) {
                 foreach (var arg in files) {
                     using (var player = new Player (syn)) {
                         using (var adriver = new AudioDriver (syn.Settings, syn)) {
                             player.Add (arg);
                             player.Play ();
                             player.Join ();
                         }
                     }
                 }
             } else {
                 using (var adriver = new AudioDriver (syn.Settings, syn)) {
                     syn.NoteOn (0, 60, 100);
                     Thread.Sleep (5000);
                     syn.NoteOff (0, 60);
                 }
             }
         }
     }
 }
 public void Properties()
 {
     var c = new Settings ();
     Assert.AreEqual (16, c [ConfigurationKeys.SynthMidiChannels].IntValue, ConfigurationKeys.SynthMidiChannels);
     Assert.AreEqual (1, c [ConfigurationKeys.SynthAudioChannels].IntValue, ConfigurationKeys.SynthAudioChannels);
     Assert.AreEqual ("alsa_seq", c [ConfigurationKeys.MidiDriver].StringValue, ConfigurationKeys.MidiDriver);
     Assert.AreEqual ("jack", c [ConfigurationKeys.AudioDriver].StringValue, ConfigurationKeys.AudioDriver);
     Assert.AreEqual (0, c [ConfigurationKeys.SynthDeviceId].IntValue, ConfigurationKeys.SynthDeviceId);
     Assert.AreEqual (256, c [ConfigurationKeys.SynthPolyphony].IntValue, ConfigurationKeys.SynthPolyphony);
     c.Dispose ();
 }
        public AudioDriver(Settings settings, AudioHandler handler, byte[] data)
            : base(LibFluidsynth.Audio.new_fluid_audio_driver2 (settings.Handle, (dt, len, nin, inBuffer, nout, outBuffer) => {
				try {
					var bufPtrs = new IntPtr [nout];
					Marshal.Copy (outBuffer, bufPtrs, 0, nout);
					var buf = new float [nout] [];
					for (int i = 0; i < nout; i++)
						Marshal.Copy (bufPtrs [i], buf [i], 0, len);
					handler (dt, buf);
					return 0;
				} catch (Exception) {
					return -1;
				}
				}, data), true)
        {
        }
        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 Synth(Settings settings)
     : base(LibFluidsynth.Synth.new_fluid_synth (settings.Handle), true)
 {
 }
 public MidiRouter(Settings settings, MidiEventHandler handler, byte [] eventHandlerData)
     : base(LibFluidsynth.Midi.new_fluid_midi_router (settings.Handle, (d, e) => handler (d, new MidiEvent (e)), eventHandlerData), true)
 {
 }
 public AudioDriver(Settings settings, Synth synth)
     : base(LibFluidsynth.Audio.new_fluid_audio_driver (settings.Handle, synth.Handle), true)
 {
 }