Пример #1
0
        public void Interpret(string s)
        {
            var notes = Parse(s);
            int i     = 0;

            watch = new Stopwatch();

            Synth synth = new Synth();

            SynthRecorder recorer = new SynthRecorder(new List <ISampleProvider> {
                synth.sineWave.ToSampleProvider(), synth.sawWave.ToSampleProvider(), synth.squareWave.ToSampleProvider(), synth.triangleWave.ToSampleProvider()
            });

            synth.SetRecorder(recorer);
            synth.InitWaves();

            synth.SetSynthType(WaveType.saw);
            foreach (var n in notes)
            {
                watch.Start();
                watch.Reset();
                Console.WriteLine("{0} - {1} - {2}", n.Pitch, n.Ocatve, n.GetFrequency());
                synth.PlayWave(n.GetFrequency());
                if (i % 4 == 0)
                {
                    AudioPlaybackEngine.Instance.PlaySound(kick);
                }
                i++;

                watch.Stop();
                if ((int)watch.ElapsedMilliseconds > 100)
                {
                    Debugger.Break();
                }

                int waitTime = 100 - (int)watch.ElapsedMilliseconds;

                Thread.Sleep(waitTime);
                synth.StopWave();
            }
        }
Пример #2
0
 public void SetRecorder(SynthRecorder recorder)
 {
     this.recorder = recorder;
 }