示例#1
0
        private void StartRecord()
        {
            waveIn = new WaveInEvent();
            int device   = inputDeviceBox.SelectedIndex;
            int channels = WaveInEvent.GetCapabilities(device).Channels;

            waveIn.DeviceNumber = device;
            waveIn.WaveFormat   = new WaveFormat(48000, channels);
            //waveIn.BufferMilliseconds = 100;
            //waveIn.NumberOfBuffers = 2;

            waveProvider = new BufferedWaveProvider(waveIn.WaveFormat);
            waveProvider.DiscardOnBufferOverflow = true;
            //waveProvider.BufferLength = 44100;
            //waveProvider.BufferDuration = TimeSpan.FromMilliseconds(10000);

            waveOut = new WaveOut();
            waveOut.Init(waveProvider);
            waveOut.DeviceNumber = outputDeviceBox.SelectedIndex;

            waveIn.DataAvailable += (_, e) => {
                waveProvider.AddSamples(e.Buffer, 0, e.BytesRecorded);
            };
            waveIn.RecordingStopped += (_, __) => {
                waveProvider.ClearBuffer();
            };

            waveProvider.ClearBuffer();
            waveIn.StartRecording();
            if (playVoiceCheck.Checked)
            {
                waveOut.Play();
            }
        }
示例#2
0
        public WaveInManagerDevice(string deviceName)
        {
            _running          = false;
            _waveInDeviceName = deviceName;
            int iDeviceNum = 0;

            for (int i = 0; i < WaveInEvent.DeviceCount; i++)
            {
                WaveInCapabilities capabilities = WaveInEvent.GetCapabilities(i);
                if (capabilities.ProductName == _waveInDeviceName)
                {
                    iDeviceNum        = i;
                    _numberOfChannels = capabilities.Channels;
                    break;
                }
            }

            waveIn = new WaveInEvent();
            waveIn.DeviceNumber      = iDeviceNum;
            waveIn.DataAvailable    += waveIn_DataAvailable;
            waveIn.RecordingStopped += waveIn_RecordingStopped;
            waveIn.WaveFormat        = AudioProcessingGlobals.GetWaveFormatForChannels(_numberOfChannels);

            try
            {
                StartIfNeeded();
            }
            catch (Exception ex)
            {
                Common.DebugHelper.WriteExceptionToLog("MultiWaveInProcessor", ex, false, "waveIn.StartRecording();");
                waveIn = null;
            }
        }
示例#3
0
        private WaveInEvent CreateWaveInEvent()
        {
            // 録音デバイスを選びたい場合は、WaveInEvent.DeviceCount、WaveInEvent.GetCapabilities を使って探してください。
            var deviceNumber = 0;

            WaveInEvent waveInEvent = new WaveInEvent();

            waveInEvent.DeviceNumber = deviceNumber;
            waveInEvent.WaveFormat   = new WaveFormat(this.SamplingRate, WaveInEvent.GetCapabilities(deviceNumber).Channels);
            return(waveInEvent);
        }
示例#4
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var i = (ComboBox)sender;

            inputDeviceNo = i.SelectedIndex;

            var p = WaveInEvent.GetCapabilities(inputDeviceNo);

            script.api.DeviceName = p.ProductName;

            SaveConfig();
        }
示例#5
0
        private void InitAvailableAudioSources()
        {
            var deviceList = new Dictionary <int, string>();

            deviceList.Add(-1, "(no sound)");
            for (var i = 0; i < WaveInEvent.DeviceCount; i++)
            {
                var caps = WaveInEvent.GetCapabilities(i);
                if (audioFormats.All(caps.SupportsWaveFormat))
                {
                    deviceList.Add(i, caps.ProductName);
                }
            }
            AvailableAudioSources    = deviceList;
            SelectedAudioSourceIndex = -1;
        }
示例#6
0
        private void InitAvailableAudioSources()
        {
            List <AudioDevice> deviceList = new List <AudioDevice>();

            deviceList.Add(new AudioDevice("(no sound)", -1));

            for (var i = 0; i < WaveInEvent.DeviceCount; i++)
            {
                var caps = WaveInEvent.GetCapabilities(i);
                if (audioFormats.All(caps.SupportsWaveFormat))
                {
                    deviceList.Add(new AudioDevice(caps.ProductName, i));
                }
            }
            this.comboBox_screenAudioDevice.DataSource    = deviceList;
            this.comboBox_screenAudioDevice.DisplayMember = "Name";
            this.comboBox_screenAudioDevice.ValueMember   = "Value";
            this.comboBox_screenAudioDevice.DropDownStyle = ComboBoxStyle.DropDownList;
        }
示例#7
0
        private void CheckDevice()
        {
            int count = WaveInEvent.DeviceCount;

            for (int i = 0; i < count; ++i)
            {
                string name = WaveInEvent.GetCapabilities(i).ProductName;
                inputDeviceBox.Items.Add(name);
            }

            count = WaveOut.DeviceCount;
            for (int i = 0; i < count; ++i)
            {
                string name = WaveOut.GetCapabilities(i).ProductName;
                outputDeviceBox.Items.Add(name);
            }
            inputDeviceBox.SelectedIndex  = 0;
            outputDeviceBox.SelectedIndex = 0;
        }
示例#8
0
        private int GetDeviceNumFromName(string deviceName)
        {
            if (string.IsNullOrWhiteSpace(deviceName))
            {
                return(-1);
            }
            int iDeviceNum = -1;

            for (int i = 0; i < WaveInEvent.DeviceCount; i++)
            {
                WaveInCapabilities capabilities = WaveInEvent.GetCapabilities(i);
                if (string.Equals(capabilities.ProductName, deviceName, StringComparison.InvariantCultureIgnoreCase))
                {
                    iDeviceNum = i;
                    break;
                }
            }
            return(iDeviceNum);
        }
示例#9
0
        public int SelectInputDevice()
        {
            int  inputDevice   = 0;
            bool isValidChoice = false;

            do
            {
                Console.Clear();
                Console.WriteLine("Please select input or recording device: ");

                for (int i = 0; i < WaveInEvent.DeviceCount; i++)
                {
                    Console.WriteLine(i + ". " + WaveInEvent.GetCapabilities(i).ProductName);
                }

                Console.WriteLine();

                try
                {
                    if (int.TryParse(Console.ReadLine(), out inputDevice))
                    {
                        isValidChoice = true;
                        Console.WriteLine("You have chosen " + WaveInEvent.GetCapabilities(inputDevice).ProductName + ".\n");
                    }
                    else
                    {
                        isValidChoice = false;
                    }
                }
                catch
                {
                    throw new ArgumentException("Device # chosen is out of range.");
                }
            } while (isValidChoice == false);

            return(inputDevice);
        }
示例#10
0
        protected override Task <string> Record(Channel Channel)
        {
            var tcs = new TaskCompletionSource <string>();

            WavSource = new WaveInEvent();
            bool IsEqual = false;

            ProductName = string.Empty;
            List <Guid> AudioDeviceList = null;

            switch (Channel)
            {
            case Channel.Left:
            case Channel.Right:
                AudioDeviceList = ExternalAudioDeviceList;
                break;

            case Channel.AudioJack:
                AudioDeviceList = MachineAudioDeviceList;
                break;

            case Channel.HeadSet:
                AudioDeviceList = DigitalMicDeviceList;
                break;

            case Channel.Fan:
                AudioDeviceList = FanRecordDeviceList;
                break;
            }

            SetupApi.di.Clear();

            for (int n = -1; n < WaveInEvent.DeviceCount; n++)
            {
                var caps = WaveInEvent.GetCapabilities(n);
                Console.WriteLine("Record device {0}: {1}", n, caps.ProductName);
                Console.WriteLine(caps.ManufacturerGuid);
                Trace.WriteLine(caps.ManufacturerGuid);

                foreach (var v in AudioDeviceList)
                {
                    if (caps.ManufacturerGuid.Equals(v))
                    {
                        DeviceNumber = n;
                        ProductName  = caps.ProductName;

                        if (!di.ContainsKey(DeviceNumber))
                        {
                            di.Add(DeviceNumber, ProductName);
                        }

                        SetupApi.GetLocationInformation(DeviceNumber, ProductName);
                        Console.WriteLine("Find");
                    }
                }
            }

            switch (Channel)
            {
            case Channel.Left:
            case Channel.Right:
                IsEqual = ExternalAudioDeviceList.Except(FanRecordDeviceList).Count() == 0;
                if (IsEqual)
                {
                    if (SetupApi.di.Count() < 2 || ProductName.Contains(UsbAudioDeviceName))
                    {
                        throw new Exception("External audio device not found");
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(ProductName) || ProductName.Contains(UsbAudioDeviceName))
                    {
                        throw new Exception("External audio device not found");
                    }
                }

                DeviceNumber = SetupApi.di.OrderBy(e => e.Value).FirstOrDefault().Key;
                //ProductName = SetupApi.di.OrderBy(e => e.Value).FirstOrDefault().Value;
                break;

            case Channel.HeadSet:
                if (string.IsNullOrEmpty(ProductName))
                {
                    throw new Exception("Digital Mic device not found");
                }
                break;

            case Channel.AudioJack:
                ProductName = string.Empty;
                Regex regex = new Regex(RealtekMicrophone);
                foreach (var v in di)
                {
                    if (regex.IsMatch(v.Value))
                    {
                        DeviceNumber = v.Key;
                        ProductName  = v.Value;
                    }
                }

                if (string.IsNullOrEmpty(ProductName))
                {
                    throw new Exception("Audio Jack device not found");
                }
                break;

            case Channel.Fan:
                IsEqual = ExternalAudioDeviceList.Except(FanRecordDeviceList).Count() == 0;
                if (IsEqual)
                {
                    if (SetupApi.di.Count() < 2)
                    {
                        throw new Exception("Fan record device not found");
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(ProductName))
                    {
                        throw new Exception("Fan record device not found");
                    }
                }

                DeviceNumber = SetupApi.di.OrderBy(e => e.Value).LastOrDefault().Key;
                //ProductName = SetupApi.di.OrderBy(e => e.Value).LastOrDefault().Value;
                break;
            }

            WavSource.DeviceNumber = DeviceNumber;
            Console.WriteLine("Record device ###### {0} ######", WaveInEvent.GetCapabilities(DeviceNumber).ProductName);
            foreach (var item in SetupApi.di.OrderBy(e => e.Value))
            {
                Console.WriteLine(item.Key + "   " + item.Value);
            }
            WavSource.WaveFormat     = new WaveFormat(44100, 1);
            WavSource.DataAvailable += (sender, e) =>
            {
                if (WavSourceFile != null)
                {
                    WavSourceFile.Write(e.Buffer, 0, e.BytesRecorded);
                    WavSourceFile.Flush();
                }
            };

            WavSource.RecordingStopped += (sender, e) =>
            {
                if (WavSource != null)
                {
                    WavSource.Dispose();
                    WavSource = null;
                }

                if (WavSourceFile != null)
                {
                    WavSourceFile.Dispose();
                    WavSourceFile = null;
                }

                Thread.Sleep(200);
                tcs.SetResult("Done");
                Console.WriteLine("Record Stopped");
            };

            switch (Channel)
            {
            case Channel.Left:
                WavSourceFile = new WaveFileWriter(LeftRecordFileName, WavSource.WaveFormat);
                break;

            case Channel.Right:
                WavSourceFile = new WaveFileWriter(RightRecordFileName, WavSource.WaveFormat);
                break;

            case Channel.HeadSet:
                WavSourceFile = new WaveFileWriter(InternalRecordFileName, WavSource.WaveFormat);
                break;

            case Channel.AudioJack:
                WavSourceFile = new WaveFileWriter(AudioJackRecordFileName, WavSource.WaveFormat);
                break;

            case Channel.Fan:
                WavSourceFile = new WaveFileWriter(FanRecordFileName, WavSource.WaveFormat);
                break;
            }

            WavSource.StartRecording();
            return(tcs.Task);
        }
示例#11
0
        protected override Task <string> Record(Channel Channel)
        {
            var tcs = new TaskCompletionSource <string>();

            WavSource   = new WaveInEvent();
            ProductName = string.Empty;
            List <Guid> AudioDeviceList = null;

            if (Channel == Channel.HeadSet)
            {
                AudioDeviceList = MachineAudioDeviceList;
            }
            else if (Channel == Channel.Left || Channel == Channel.Right)
            {
                AudioDeviceList = ExternalAudioDeviceList;
            }

            for (int n = -1; n < WaveInEvent.DeviceCount; n++)
            {
                var caps = WaveInEvent.GetCapabilities(n);
                Console.WriteLine("Record device {0}: {1}", n, caps.ProductName);
                Console.WriteLine(caps.ManufacturerGuid);
                Trace.WriteLine(caps.ManufacturerGuid);

                foreach (var v in AudioDeviceList)
                {
                    if (caps.ManufacturerGuid.Equals(v))
                    {
                        DeviceNumber = n;
                        ProductName  = caps.ProductName;
                        Console.WriteLine("Find");
                    }
                }
            }

            if (string.IsNullOrEmpty(ProductName) && Channel == Channel.HeadSet)
            {
                throw new Exception("Machine audio device not found");
            }
            else if (string.IsNullOrEmpty(ProductName) && (Channel == Channel.Left || Channel == Channel.Right))
            {
                throw new Exception("External audio device not found");
            }

            WavSource.DeviceNumber = DeviceNumber;
            Console.WriteLine("Record device {0}", ProductName);
            WavSource.WaveFormat     = new WaveFormat(44100, 2);
            WavSource.DataAvailable += (sender, e) =>
            {
                if (WavSourceFile != null)
                {
                    WavSourceFile.Write(e.Buffer, 0, e.BytesRecorded);
                    WavSourceFile.Flush();
                }
            };

            WavSource.RecordingStopped += (sender, e) =>
            {
                if (WavSource != null)
                {
                    WavSource.Dispose();
                    WavSource = null;
                }

                if (WavSourceFile != null)
                {
                    WavSourceFile.Dispose();
                    WavSourceFile = null;
                }

                Thread.Sleep(200);
                tcs.SetResult("Done");
                Console.WriteLine("Record Stopped");
            };

            if (Channel == Channel.Left)
            {
                WavSourceFile = new WaveFileWriter(LeftRecordFileName, WavSource.WaveFormat);
            }
            else if (Channel == Channel.Right)
            {
                WavSourceFile = new WaveFileWriter(RightRecordFileName, WavSource.WaveFormat);
            }
            else if (Channel == Channel.HeadSet)
            {
                WavSourceFile = new WaveFileWriter(InternalRecordFileName, WavSource.WaveFormat);
            }

            WavSource.StartRecording();
            return(tcs.Task);
        }
示例#12
0
        private void Form1_Load(object sender, EventArgs e)
        {
            this.FormClosed     += Form1_FormClosed;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;

            mainFileWriteThread = new EasyLoopThread(mainFileWriteThreadAction, null, 100);

            script = new Emugen.Script.Script <ConfigScriptAPI>(configFilePath, new ConfigScriptAPI());
            script.Run();
            script.Run();

            if (script.api.OutputDirectoryPath != "")
            {
                targetRootDirectory = textBox1.Text = script.api.OutputDirectoryPath;
            }
            else
            {
                targetRootDirectory = textBox1.Text = System.IO.Directory.GetCurrentDirectory();
            }

            //WaveInEvent.DeviceCount、WaveInEvent.GetCapabilities
            for (var i = 0; i < WaveInEvent.DeviceCount; i++)
            {
                var p = WaveInEvent.GetCapabilities(i);

                comboBox1.Items.Add(p.ProductName);
                if (script.api.DeviceName == p.ProductName)
                {
                    inputDeviceNo = i;
                }
            }
            comboBox1.SelectedIndex = inputDeviceNo;

            checkBox1.Checked = script.api.IsMonaural;

            comboBox2.Items.Add("mp3");
            comboBox2.Items.Add("wav");
            if (script.api.SaveType == "mp3")
            {
                comboBox2.SelectedIndex = 0;
            }
            else
            {
                comboBox2.SelectedIndex = 1;
            }

            {
                var btn = new VoiceRecoder.EmugenWFUI.Button(this, 5, 5, 160, 60, "録音開始", 24);
                btn.Click = () =>
                {
                    if (isStart)
                    {
                        btnStop_Click();
                        isStart  = !isStart;
                        btn.Text = "録音開始";
                    }
                    else
                    {
                        btnStart();
                        isStart  = !isStart;
                        btn.Text = "録音終了";
                    }
                };
            }
            {
                var btn = new VoiceRecoder.EmugenWFUI.Button(this, 5, 70, 160, 40, "フォルダを開く", 14);
                btn.Click = () =>
                {
                    var dir = CreateTargetDirectory();
                    System.Diagnostics.Process.Start(dir);
                };
            }
        }
示例#13
0
 public WindowsWaveInDevice(int index)
 {
     Capabilities = WaveInEvent.GetCapabilities(index);
     _source      = new WindowsWaveInSource(this, index);
 }
示例#14
0
        static void Main(string[] args)
        {
            var songs = new List <Song>();

            songs.AddRange(DeserializeSongs.LoadSongs(args));
            songs.AddRange(DeserializeSongs.LoadSongs(DefaultSongAddress));
            DetectSongs.Initialize(songs);

            var sb = new StringBuilder();

            songs.Select(item => sb.Append($"{item.name}, ")).ToArray();
            Console.WriteLine($"{songs.Count} songs loaded: {sb.ToString()}");

            var deviceCount = WaveInEvent.DeviceCount;

            if (deviceCount == 0)
            {
                Console.WriteLine("No microphone device found.");
                return;
            }

            for (int i = 0; i < deviceCount; i++)
            {
                var deviceInfo = WaveInEvent.GetCapabilities(i);
                Console.WriteLine("Device {0}: {1}, {2} channels",
                                  i, deviceInfo.ProductName, deviceInfo.Channels);
            }

            Console.WriteLine($"Select device from {0} to {deviceCount - 1}");

            int index;

            while (!int.TryParse(Console.ReadLine(), out index))
            {
                Console.WriteLine($"Select device from {0} to {deviceCount - 1}");
            }

            Console.WriteLine("Press escape to finish process.");

            Freq2Note.Init();
            var waveIn = new WaveInEvent()
            {
                DeviceNumber = index
            };

            waveIn.DataAvailable     += AudioDataAvailable;
            waveIn.WaveFormat         = new WaveFormat(SamplingRate, 1);
            waveIn.BufferMilliseconds = (int)((double)BufferSize / (double)SamplingRate * 1000.0);

            bwp = new BufferedWaveProvider(waveIn.WaveFormat)
            {
                BufferLength = BufferSize * 2, DiscardOnBufferOverflow = true
            };

            try
            {
                waveIn.StartRecording();
            }
            catch
            {
                string msg = "Could not record from audio device!\n\n";
                msg += "Is your microphone plugged in?\n";
                msg += "Is it set as your default recording device?";
                Console.WriteLine(msg, "ERROR");
            }

            ThreadPool.QueueUserWorkItem(EscapeLoad, null);
            while (true)
            {
                lock (lockObj)
                {
                    if (keyPressed)
                    {
                        break;
                    }
                }

                var note = Process();
                if (note != null)
                {
                    DetectSongs.NoteStreamLoader(note.Value);
                }

                var song = DetectSongs.FindSong();
                if (song != null)
                {
                    Console.WriteLine($"------------------------------------\nSong detect: {song.Value.name}\n------------------------------------");
                }
            }

            waveIn.StopRecording();
            waveIn.Dispose();
        }
        private void StartAudioCapture()
        {
            // Check if we're already listening.
            lock (this.recordingLock)
            {
                if (this.recording == true)
                {
                    return;
                }
            }

            // Attempt to find the Windows Stereo Mix.
            int deviceNum = -1;

            for (int i = 0; i < WaveInEvent.DeviceCount; i++)
            {
                WaveInCapabilities wc = WaveInEvent.GetCapabilities(i);
                if (wc.ProductName.Contains("Stereo Mix"))
                {
                    deviceNum = i;
                    break;
                }
            }

            if (deviceNum == -1)
            {
                throw new Exception("Unable to find Windows Stereo Mix");
            }

            // Start audio recording.
            lock (this.recordingLock)
            {
                // Quick check if some other thread already started listening.
                if (this.recording == true)
                {
                    return;
                }

                WaveInEvent waveIn = new WaveInEvent();
                waveIn.DeviceNumber = deviceNum;
                waveIn.WaveFormat   = new WaveFormat(this.sampleRate, 1);
                // Set the max buffer milliseconds in the event no data is being streamed we'll keep the pipeline streaming.
                waveIn.BufferMilliseconds = this.maxPacketLen / (this.sampleRate / 1000);
                waveIn.DataAvailable     += new EventHandler <WaveInEventArgs>((object sender, WaveInEventArgs e) =>
                {
                    this.streamBuff.AddSamples(e.Buffer, 0, e.BytesRecorded);
                });

                // Allocate the stream buffer and discard on overflow to keep it responsive.
                BufferedWaveProvider streamBuff = new BufferedWaveProvider(waveIn.WaveFormat);
                streamBuff.BufferLength            = this.maxPacketLen * 2;
                streamBuff.DiscardOnBufferOverflow = true;

                try
                {
                    waveIn.StartRecording();
                    this.waveIn     = waveIn;
                    this.streamBuff = streamBuff;
                    this.recording  = true;

                    // Check if a forwardthread was previously running.
                    if (this.forwardThread == null)
                    {
                        this.forwardThread = new Thread(this.ForwardBuffToListeners);
                        this.forwardThread.Start();
                    }
                }
                catch (Exception e)
                {
                    this.recording = false;
                    this.logger.Error("StartAudioCapture returned error: " + e.ToString());
                    throw new Exception("Unable to start recording audio: " + e.ToString());
                }
            }
        }
示例#16
0
 public void testFunc()
 {
     Console.WriteLine(WaveInEvent.GetCapabilities(0).Channels);
 }