Inheritance: NFluidsynth.FluidsynthObject
コード例 #1
0
 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);
                 }
             }
         }
     }
 }
コード例 #2
0
        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
        }