Exemplo n.º 1
0
        private void SettingsChanged(object sender, EventArgs e)
        {
            // Setup
            SetSelectedWaveIn();
            SetSelectedWaveOut();

            var output   = new Output(waveOut);
            var input    = new Input(waveIn);
            var waveform = new Waveform(100, WaveformChart);
            var spectrum = new Spectrum(SpectrumChart);

            var baseFrequency = 100;
            var octaves       = 2;
            var milliseconds  = 8000;

            var powFrequency = milliseconds.ToFrequency();
            var volFrequency = powFrequency / 2;
            var powStep      = (2 * Math.PI) / octaves;
            var volStep      = powStep / 2;

            var mixer = new Mixer();

            for (int i = 0; i < octaves; i++)
            {
                var y = i;

                mixer.AddSource
                (
                    Generators.Sine(
                        new Saw(new Constant(powFrequency), 0, octaves, (i * powStep) + Math.PI)
                        .Function(x => Math.Pow(2, x), Math.Pow(2, 0), Math.Pow(2, octaves))
                        .Function(x => x * baseFrequency, baseFrequency, baseFrequency * octaves)
                        )
                    .ToTone()
                    .SendTo(
                        new Volume(
                            Generators.Function
                            (
                                new Triangle(new Constant(volFrequency), 0, 1, volStep * i), x => Math.Abs(x), 0, 1)
                            )
                        )
                );
            }

            mixer.SendTo(spectrum).SendTo(waveform);
            waveform.SendTo(output);

            waveIn.StartRecording();
            waveOut.Play();
        }