Example #1
0
        internal static void WindowsInterruptTest()
        {
            Console.WriteLine("press any key to play sound");
            bool isPlaying = false;
            var  ad        = Mono.Audio.AudioDevice.CreateDevice("sss");

            var np = new NotePlayer();



            short[] buffer = new short[480];
            while (true)
            {
                if (!isPlaying)
                {
                    Console.ReadKey(false);
                    isPlaying = true;
                }

                if (isPlaying && !Console.KeyAvailable)
                {
                    // ad.PlaySample(buffer, 480);
                    //Thread.Sleep(100);
                    //Task.Factory.StartNew(() => np.PlayNote(440, 1));
                    //Thread t = new Thread(() => np.PlayNote(440,1));
                    //t.Start();
                    //while (!t.IsAlive) ;
                    np.PlayNote(440, 1);
                    Console.Write(".");
                }
                else
                {
                    Console.Write("£");
                    np.Silence();
                    isPlaying = false;
                    Console.ReadKey(true);
                }
            }
        }
Example #2
0
        static void bc_ButtonEvent2(object sender, PiAndBash.ButtonCatcher.ButtonArgs e)
        {
            // play note while down, stop when released

            if (e.ButtonEvent == PiAndBash.ButtonCatcher.ButtonEventType.Down)
            {
                switch (e.Button)
                {
                case PiAndBash.ButtonCatcher.ButtonType.Up:
                    // play A
                    notePlayer.PlayNote(440, 500);
                    break;

                case PiAndBash.ButtonCatcher.ButtonType.Down:
                    // play C
                    notePlayer.PlayNote(523, 500);
                    break;

                case PiAndBash.ButtonCatcher.ButtonType.Enter:
                    // play F
                    notePlayer.PlayNote(349, 500);
                    break;

                default:
                    break;
                }
            }
            else // button released
            {
                // stop all notes
                notePlayer.Silence();
                if (e.Button == PiAndBash.ButtonCatcher.ButtonType.BotSel)
                {
                    Console.WriteLine("Exiting");
                    (sender as PiAndBash.ButtonCatcher).Stop();
                }
            }
        }