Beispiel #1
0
 public string[] GetDevices()
 {
     return(tuner.GetDevices());
 }
Beispiel #2
0
        void StartListening(int device, double threshold)
        {
            Console.ForegroundColor = CONSOLE_INFO_COLOR;

            string[] devices = tuner.GetDevices();

            tuner.SetDevice(device);

            bool res = tuner.StartListening();

            if (res)
            {
                int recHandle = tuner.Stream;

                int samplerate = tuner.GetSampleRate();

                char[]        loopCharSeq = { '\\', '|', '/', '-' };
                int           curChar     = 0;
                string        emptyLine   = new string(' ', Console.WindowWidth);
                StringBuilder sb          = new StringBuilder();

                bool exitRequired = false;

                // loop until record stream is active and no key is pressed
                while (tuner.IsRecording() && exitRequired == false)
                {
                    double freq = tuner.CurrentFrequency;

                    Console.CursorLeft = CURSOR_LEFT_POSITION;

                    sb.Append("freq: ");
                    sb.Append(freq.ToString("#0.000"));
                    sb.Append(" Hz ");

                    if (freq > 0)
                    {
                        sb.Append(" note: ");

                        string note  = String.Empty;
                        double cents = 0;

                        Utility.FreqToNote(freq, out note, out cents);
                        sb.Append(note);
                        sb.Append(' ');
                        sb.Append(cents);
                        sb.Append(" cents ");
                    }

                    if (Console.KeyAvailable)
                    {
                        ConsoleKey input = Console.ReadKey(true).Key;

                        double tmpthreshold = tuner.Threshold;

                        bool isThresholdCommandRequested = false;

                        switch (input)
                        {
                        case ConsoleKey.Enter:
                            exitRequired = true;
                            break;

                        case ConsoleKey.RightArrow:
                            isThresholdCommandRequested = true;
                            tmpthreshold += STEP_THRESHOLD;
                            if (tmpthreshold <= MAX_THRESHOLD)
                            {
                                tuner.Threshold = tmpthreshold;
                            }
                            break;

                        case ConsoleKey.LeftArrow:
                            isThresholdCommandRequested = true;
                            tmpthreshold -= STEP_THRESHOLD;
                            if (tmpthreshold >= MIN_THRESHOLD)
                            {
                                tuner.Threshold = tmpthreshold;
                            }
                            break;
                        }

                        // set showThresholdValue = false

                        /*
                         * if (isThresholdCommandRequested)
                         * {
                         *  showThresholdValue = true;
                         *  if (timer.Enabled)
                         *      timer.Stop();
                         *  timer.Start();
                         * }
                         * */
                    }

                    sb.Append(loopCharSeq[curChar++ % 4]);

                    Console.Write(emptyLine);
                    Console.CursorTop--;
                    Console.Write(sb.ToString());

                    if (showThresholdValue)
                    {
                        Console.CursorTop += CURSOR_THRESHOLD_DISTANCE;
                        Console.CursorLeft = CURSOR_LEFT_POSITION;
                        Console.Write(emptyLine);
                        Console.CursorTop--;
                        sb.Clear();
                        sb.Append("Threshold: ");
                        sb.Append(tuner.Threshold);
                        Console.Write(sb.ToString());
                        Console.CursorTop -= CURSOR_THRESHOLD_DISTANCE;
                    }

                    sb.Clear();

                    Thread.Sleep(PROCESS_DELAY);
                }
            }
            else
            {
                Console.ForegroundColor = CONSOLE_ERROR_COLOR;
                Console.WriteLine("ERROR: Can't listen to this device");
            }

            tuner.Free();
        }