Esempio n. 1
0
 public static void Main(string[] args)
 {
     using (var settings = new Settings())
     {
         // Change this if you don't have pulseaudio or want to change to anything else.
         if (Environment.OSVersion.Platform == PlatformID.Unix)
         {
             settings[ConfigurationKeys.AudioDriver].StringValue = "pulseaudio";
         }
         settings[ConfigurationKeys.SynthAudioChannels].IntValue = 2;
         using (var syn = new Synth(settings))
         {
             foreach (var arg in args)
             {
                 if (SoundFont.IsSoundFont(arg))
                 {
                     syn.LoadSoundFont(arg, true);
                 }
             }
             if (syn.FontCount == 0)
             {
                 syn.LoadSoundFont("/usr/share/sounds/sf2/FluidR3_GM.sf2", true);
             }
             for (int i = 0; i < 16; i++)
             {
                 syn.SoundFontSelect(i, 0);
             }
             var files = args.Where(SoundFont.IsMidiFile);
             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.ProgramChange(0, 1);
                     syn.NoteOn(0, 60, 120);
                     Thread.Sleep(5000);
                     syn.NoteOff(0, 60);
                 }
             }
         }
     }
 }
 public void LoadUnloadSoundFont()
 {
     using (var syn = new Synth (NewAlsaSettings ()))
     using (var audio = new AudioDriver (syn.Settings, syn)) {
         syn.LoadSoundFont ("/usr/share/sounds/sf2/FluidR3_GS.sf2", false);
         Assert.AreEqual (1, syn.FontCount, "FontCount");
         for (int i = 0; i < 16; i++)
             syn.SoundFontSelect (i, 1);
         syn.UnloadSoundFont (1, true);
         Assert.AreEqual (0, syn.FontCount, "FontCount");
     }
 }
Esempio n. 3
0
 public void LoadUnloadSoundFont()
 {
     using (var syn = new Synth(NewAlsaSettings()))
         using (var audio = new AudioDriver(syn.Settings, syn)) {
             syn.LoadSoundFont("/usr/share/sounds/sf2/FluidR3_GS.sf2", false);
             Assert.AreEqual(1, syn.FontCount, "FontCount");
             for (int i = 0; i < 16; i++)
             {
                 syn.SoundFontSelect(i, 1);
             }
             syn.UnloadSoundFont(1, true);
             Assert.AreEqual(0, syn.FontCount, "FontCount");
         }
 }
Esempio n. 4
0
        /// <summary>
        /// Renders the currently applied settings to a MIDI file (in memory) and then sets up a player
        /// </summary>
        bool setupPlayerForPlayback()
        {
            if (drv != null)
            {
                drv.Dispose();
            }
            if (player != null)
            {
                player.Dispose();
            }
            if (syn != null)
            {
                syn.Dispose();
            }
            var soundfontFile = @"Soundbanks\ExtractedSoundbank_" + (NLSTChoice + 10).ToString("X2") + ".dls";

            if (!File.Exists(soundfontFile))
            {
                MessageBox.Show("A required soundbank file is missing - Please see the Github on how to extract soundbanks from your ROM.");
                return(false);
            }
            var settings = new Settings();

            settings[ConfigurationKeys.SynthAudioChannels].IntValue = 2;
            syn      = new Synth(settings);
            syn.Gain = 0.5f;
            syn.LoadSoundFont(soundfontFile, true);
            for (int i = 0; i < 16; i++)
            {
                syn.SoundFontSelect(i, 1);
            }

            player = new Player(syn);
            var mid = exportMIDBytes();

            player.AddMem(mid, 0, mid.Length);
            drv = new AudioDriver(settings, syn);
            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// 음악 출력 장치와 타이머를 초기화하고, 현재 음악 테마를 SFXThemeName으로 설정합니다.
        /// </summary>
        /// <param name="SFXThemeName">설정할 음악 테마 이름</param>
        /// <param name="noteResolution">단위 리듬</param>
        /// <param name="timerTickDelegates">타이머의 틱마다 추가로 실행할 메서드의 대리자 목록</param>
        public static void Initialize(string SFXThemeName, int noteResolution, Timer.TickDelegate[] timerTickDelegates = null)
        {
            IsReady  = false;
            HasStart = false;

            //outDevice = new OutputDevice(0);
            settings = new Settings();
            settings[ConfigurationKeys.SynthAudioChannels].IntValue = 2;

            syn = new Synth(settings);
            try
            {
                syn.LoadSoundFont("FluidR3_GM.sf2", true);
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.StackTrace);
                return;
            }
            for (int i = 0; i < 16; i++)
            {
                syn.SoundFontSelect(i, 0);
            }

            adriver = new AudioDriver(syn.Settings, syn);

            /*
             * WaveInEvent recorder = new WaveInEvent
             * {
             *  WaveFormat = new WaveFormat(44100, 2)
             * };
             * BufferedWaveProvider sound = new BufferedWaveProvider(recorder.WaveFormat);
             * recorder.DataAvailable += (object sender, WaveInEventArgs e) =>
             * {
             *  sound.AddSamples(e.Buffer, 0, e.BytesRecorded);
             * };
             * recorder.StartRecording();
             * //sound.Read();
             */
            //playback = new WaveOutEvent();
            //playback.Init(sound);
            //playback.Play();

            /*
             * sound = new BufferedWaveProvider(new WaveFormat(44100, 2));
             * buffer = new byte[44100 * 4];
             * stream = new MemoryStream();
             * Task.Run(() => {
             *  soundStream = new RawSourceWaveStream(stream, new WaveFormat(44100, 2));
             *  reverb = new DmoEffectWaveProvider<DmoWavesReverb, DmoWavesReverb.Params>(soundStream);
             *  outputDevice = new WasapiOut();
             *
             *  outputDevice.Init(reverb);
             *  outputDevice.Play();
             * });
             */
            SFXTheme.CurrentSFXTheme = SFXTheme.FindSFXTheme(SFXThemeName);
            //Console.WriteLine(SFXThemeName + " " + SFXTheme.CurrentSFXTheme.Name);
            NoteResolution = noteResolution;
            Accompaniment.Initialize();

            tickDelegate += Tick;
            if (timerTickDelegates != null)
            {
                foreach (Timer.TickDelegate t in timerTickDelegates)
                {
                    tickDelegate += t;
                }
            }

            mgmt = new PowerManagement();
            mgmt.InitPowerEvents();
            mgmt.OnPowerSuspend += Suspend;
            mgmt.OnPowerResume  += Resume;

            syncPlayBuffer       = new List <Note>();
            syncTransitionBuffer = false;
            playPitchEventBuffer = new List <int>();

            accompanimentTickNumber = new Dictionary <int, int>();
            accompanimentPlayNumber = new Dictionary <int, int>();
            accompanimentTickNumber.Add(7, 0);
            accompanimentTickNumber.Add(8, 0);
            accompanimentPlayNumber.Add(7, 0);
            accompanimentPlayNumber.Add(8, 0);

            IsReady = true;

            /*
             * Task.Run(() =>
             * {
             *  var capture = new WasapiLoopbackCapture();
             *  var effectProvider = new DmoEffectWaveProvider<DmoWavesReverb, DmoWavesReverb.Params>(new WaveInProvider(capture));
             *
             *  PlayEffectorSound(capture, effectProvider);
             *  using (var outputDevice = new WasapiOut())
             *  {
             *      outputDevice.Init(effectProvider);
             *      capture.StartRecording();
             *      outputDevice.Play();
             *      while (capture.CaptureState != NAudio.CoreAudioApi.CaptureState.Stopped)
             *      {
             *          Thread.Sleep(500);
             *          if (!IsReady) capture.StopRecording();
             *      }
             *      Console.WriteLine("Effector stopped");
             *  }
             *
             * });
             */
        }