Example #1
0
        /// <summary>
        /// This function is called in a separate thread, and plays a single note
        /// </summary>
        /// <param name="note">The note value is an integer where 1 = C5, and each increment upwards is a step up on a piano. Ex, 5 = E5</param>
        private void noteThread(int note)
        {
            SineWaveOscillator osc1 = new SineWaveOscillator(44100);

            int note1 = (int)(440.0 * Math.Pow(2.0, ((double)(note + 59) - 69.0) / 12.0));

            osc1.Frequency = note1;

            osc1.Amplitude = 8192;

            WaveOut waveOut1 = new WaveOut();

            waveOut1.Init(osc1);

            waveOut1.Play();

            Thread.Sleep(1000);

            waveOut1.Stop();

            switch (note)
            {
            case 1:
                flag1 = false;
                break;

            case 5:
                flag2 = false;
                break;

            case 8:
                flag3 = false;
                break;

            case 13:
                flag4 = false;
                break;

            case 16:
                flag5 = false;
                break;

            case 19:
                flag6 = false;
                break;

            default:
                break;
            }
        }
Example #2
0
        /// <summary>
        /// This function is called in a separate thread, and plays 3 note forming a major chord
        /// </summary>
        /// <param name="note">The note value is similar to that in noteThread, but with the single note determining the chord.  Ex, 1 = C5 major chord</param>
        private void chordThread(int note)
        {
            SineWaveOscillator osc1 = new SineWaveOscillator(44100);
            SineWaveOscillator osc2 = new SineWaveOscillator(44100);
            SineWaveOscillator osc3 = new SineWaveOscillator(44100);

            int note1 = (int)(440.0 * Math.Pow(2.0, ((double)(note + 59) - 69.0) / 12.0));
            int note2 = (int)(440.0 * Math.Pow(2.0, ((double)(note + 63) - 69.0) / 12.0));
            int note3 = (int)(440.0 * Math.Pow(2.0, ((double)(note + 66) - 69.0) / 12.0));

            osc1.Frequency = note1;
            osc2.Frequency = note2;
            osc3.Frequency = note3;

            osc1.Amplitude = 8192;
            osc2.Amplitude = 8192;
            osc3.Amplitude = 8192;

            WaveOut waveOut1 = new WaveOut();
            WaveOut waveOut2 = new WaveOut();
            WaveOut waveOut3 = new WaveOut();

            waveOut1.Init(osc1);
            waveOut2.Init(osc2);
            waveOut3.Init(osc3);

            waveOut1.Play();
            waveOut2.Play();
            waveOut3.Play();

            Thread.Sleep(1000);

            waveOut1.Stop();
            waveOut2.Stop();
            waveOut3.Stop();

            switch (note)
            {
            case 1:
                flag1 = false;
                break;

            case 8:
                flag2 = false;
                break;

            case 4:
                flag3 = false;
                break;

            case 6:
                flag4 = false;
                break;

            case 11:
                flag5 = false;
                break;

            case 2:
                flag6 = false;
                break;

            default:
                break;
            }
        }