Example #1
0
        private static void OpenInputForDevice()
        {
            PrintInputDeviceList();
            var deviceID = GetDeviceIDFromUser();
            var device   = AudioService.GetAudioInputDevice(deviceID);

            if (device == null)
            {
                Console.WriteLine("Invalid input device ID or error upon retrieving input device.");
                WaitForKey("Press any key to end...");
                return;
            }

            Console.WriteLine("===========================================");
            Console.WriteLine("OPENING INPUT BUFFER - PRESS ANY KEY TO END");
            Console.WriteLine("===========================================");

            var inputBuffer = AudioService.OpenInputBuffer(device);

            while (!Console.KeyAvailable)
            {
                Thread.Sleep(100);
                var retrievedSamples = inputBuffer.RetrieveBufferedSamples();
                Console.WriteLine("{0:T} - Retrieved {1} samples.  Peak = {2}", DateTime.Now, retrievedSamples.Length, retrievedSamples.Length > 0 ? retrievedSamples.Max() : 0);
            }

            AudioService.CloseInputBuffer(inputBuffer);

            Console.WriteLine();
            WaitForKey("Press any key to end...");

            return;
        }