Exemplo n.º 1
0
        void SetupMidiAccess(Context context)
        {
#if TEST_MIDI_API_BASED_ACCESS
            acc = new Commons.Music.Midi.AndroidMidiAccess.MidiAccess(this);
#else
            var acc = new FluidsynthMidiAccess();
            this.acc = acc;
            acc.ConfigureSettings += settings => {
                settings [ConfigurationKeys.AudioSampleFormat].StringValue = "16bits";                 // float or 16bits

                var manager = context.GetSystemService(Context.AudioService).JavaCast <AudioManager> ();

                // Note that SynthSampleRate 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;
                settings [ConfigurationKeys.SynthThreadSafeApi].IntValue = 0;
                settings [ConfigurationKeys.AudioDriver].StringValue     = "oboe";
                acc.SoundFontLoaderFactories.Add(syn => new AndroidNativeAssetSoundFontLoader(settings, context.Assets));
            };
            SynthAndroidExtensions.GetSoundFonts(acc.SoundFonts, context, predefined_temp_path);
#endif
        }
        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
        }