Пример #1
0
        /// <summary>
        /// availableSFXThemes에서 name이 일치하는 음악 테마를 찾아 반환합니다.
        /// 만약 찾지 못하면, Name이 null이고 Instruments가 빈 SFXTheme이 반환됩니다.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static SFXTheme FindSFXTheme(string name)
        {
            SFXTheme empty = new SFXTheme(null, null, ChordTransitionType.SomewhatHappy, null, null, null);

            if (!IsReady || name == null)
            {
                return(empty);
            }

            foreach (SFXTheme t in availableSFXThemes)
            {
                if (name.Equals(t.Name))
                {
                    return(t);
                }
            }
            return(empty);
        }
Пример #2
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");
             *  }
             *
             * });
             */
        }