public Recorder(Rectangle area, bool recordmicro, bool recordaudio, int framerate, int bitrate, string filepath, string filename) { _CaptureRegion = new Rectangle(area.X, area.Y, area.Width, area.Height); _RecordingScreen = true; _RecordingMicrophone = recordmicro; _RecordingAudio = recordaudio; _FrameRate = framerate; _BitRate = bitrate; _FileName = filename; _FilePath = filepath; _CameraDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); _CurrentCameraDevice = GetCameraDevice(0); _CameraSource = new VideoCaptureDevice(_CurrentCameraDevice.MonikerString); _ScreenSource = new ScreenCaptureStream(_CaptureRegion); _AudioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture); _CurrenrAudioDevice = GetAudioDevice(0); _Writer = new VideoFileWriter(); _StartTime = DateTime.MinValue; _ScreenTotalFrames = 0; _AudioTotalFrames = 0; }
private void AudioINcomboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { AudioDeviceInfo wybrane = AudioINcomboBox.SelectedItem as AudioDeviceInfo; microphone = Microphone.GetDevice(wybrane); Mikrofonslider.Value = microphone.Volume * 100; }
public Encoder(EventHandler <NewFrameEventArgs> NewFrame, EventHandler <AudioSourceErrorEventArgs> AudioSourceError) { AudioDeviceCollection audioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture); AudioDeviceInfo INfo = null; foreach (var item in audioDevices) { INfo = item; } // Create capture device this.source = new AudioCaptureDevice(INfo.Guid) { // Listen on 22050 Hz DesiredFrameSize = FRAME_SIZE, SampleRate = SAMPLE_RATE, // We will be reading 16-bit PCM Format = SampleFormat.Format16Bit }; // Wire up some events source.NewFrame += NewFrame; source.AudioSourceError += AudioSourceError; // Create buffer for wavechart control this.current = new float[source.DesiredFrameSize]; // Create stream to store file this.stream = new MemoryStream(); this.encoder = new WaveEncoder(stream); }
private void AudioOUTcomboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { AudioDeviceInfo wybrane = AudioOUTcomboBox.SelectedItem as AudioDeviceInfo; speaker = Speaker.GetDevice(wybrane); Glosnikslider.Value = speaker.Volume * 100; }
private void RepopulateAdditionalOutputDevices(AudioDeviceInfo lastDevice, AudioDeviceInfo newDevice) { if (_repopulatingAdditionalOutputDevices) { return; } listBoxAdditionalOutputDevices.BeginUpdate(); _repopulatingAdditionalOutputDevices = true; // Restore the last used primary device if (lastDevice != null && !listBoxAdditionalOutputDevices.Items.Contains(lastDevice)) { listBoxAdditionalOutputDevices.Items.Insert(Math.Max(Array.IndexOf(_outputDevices, lastDevice), 0), lastDevice); } // Remove the new device so it may not be selected if (newDevice != null && listBoxAdditionalOutputDevices.Items.Contains(newDevice)) { listBoxAdditionalOutputDevices.Items.Remove(newDevice); } listBoxAdditionalOutputDevices.EndUpdate(); listBoxAdditionalOutputDevices.Refresh(); _repopulatingAdditionalOutputDevices = false; }
void Button1Click(object sender, EventArgs e) { AudioDeviceInfo info = comboBox1.SelectedItem as AudioDeviceInfo; if (info == null) { MessageBox.Show("No audio devices available."); return; } source = new AudioCaptureDevice(info.Guid); initializing = true; lbStatus.Text = "Waiting for soundcard..."; source = new AudioCaptureDevice(info.Guid); source.SampleRate = 44100; source.DesiredFrameSize = 5000; source.NewFrame += source_NewFrame; detector = new EnergyBeatDetector(43); detector.Beat += new EventHandler(detector_Beat); sample = new List <ComplexSignal>(); source.Start(); }
/// <summary> /// Starts capturing from the chosen audio input interface /// </summary> /// void btnStart_Click(object sender, EventArgs e) { // Get the device currently selected in the combobox AudioDeviceInfo info = comboBox1.SelectedItem as AudioDeviceInfo; if (info == null) { MessageBox.Show("No audio devices available."); return; } // Create a new audio capture device source = new AudioCaptureDevice(info) { // Capture at 22050 Hz DesiredFrameSize = 2048, SampleRate = 22050 }; // Wire up some notification events source.NewFrame += source_NewFrame; source.AudioSourceError += source_AudioSourceError; // Start it! source.Start(); }
public Recorder() { _CaptureRegion = new Rectangle(0, 0, 480, 360); _isRecording = false; _isPausing = false; _RecordingScreen = false; _RecordingCamera = false; _RecordingMicrophone = false; _RecordingAudio = false; _FrameRate = 60; _BitRate = 1200 * 1000; _FileName = "Video.avi"; _FilePath = "C:\\"; _CameraDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); _CurrentCameraDevice = GetCameraDevice(0); _CameraSource = new VideoCaptureDevice(_CurrentCameraDevice.MonikerString); _ScreenSource = new ScreenCaptureStream(_CaptureRegion); _AudioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture); _CurrenrAudioDevice = GetAudioDevice(0); _Writer = new VideoFileWriter(); _StartTime = DateTime.MinValue; _ScreenTotalFrames = 0; _AudioTotalFrames = 0; }
private void buttonStart_Click(object sender, EventArgs e) { this.Invoke((MethodInvoker) delegate() { AudioDeviceInfo info = comboBoxMicrophoneSource.SelectedItem as AudioDeviceInfo; if (info == null) { MessageBox.Show("No audio devices available."); return; } source = new AudioCaptureDevice(info.Guid); initializing = true; labelAudioStatus.Text = "Audio Status: Waiting for soundcard..."; source = new AudioCaptureDevice(info.Guid); source.SampleRate = 44100; source.DesiredFrameSize = 5000; source.NewFrame += Source_NewFrame; detector = new EnergyBeatDetector(43);//changed from 43 //could change this to make is longer or shorter segments that are analyzed. detector.Beat += new EventHandler(Detector_Beat); source.Start(); }); }
/// <summary> /// 构造器:初始化播放器设备 /// </summary> /// <param name="deviceInfo">设备信息</param> private BassPlayer(AudioDeviceInfo? deviceInfo = null) { this.Initialize(deviceInfo); this.endSyncProc = new SYNCPROC(this.EndCallback); this.autoReleaseProc = new SYNCPROC(this.AutoReleaseCallback); this.playingStatusDict = new Dictionary<int, bool>(); this.referenceDict = new Dictionary<int, GCHandle>(); }
public static AudioDeviceInfo[] EnumerateAudioDevices() { var deviceInfos = new AudioDeviceInfo[10]; var numReturned = InteropEnumerateAudioDevices(deviceInfos, deviceInfos.Length); var result = new AudioDeviceInfo[numReturned]; Array.Copy(deviceInfos, result, result.Length); return(result); }
private void initalizeAudioStuff() { try { AudioSource = new AudioCaptureDevice(); AudioDeviceInfo info = null; var adc = new AudioDeviceCollection(AudioDeviceCategory.Capture); foreach (var ad in adc) { string desc = ad.Description; if (desc.IndexOf("Audio") > -1) { info = ad; } } if (info == null) { AudioSource = new AudioCaptureDevice(); } else { AudioSource = new AudioCaptureDevice(info); } //AudioCaptureDevice source = new AudioCaptureDevice(); AudioSource.DesiredFrameSize = 4096; AudioSource.SampleRate = 44100; //int sampleRate = 44100; //int sampleRate = 22050; AudioSource.NewFrame += AudioSource_NewFrame; // AudioSource.Format = SampleFormat.Format64BitIeeeFloat; AudioSource.AudioSourceError += AudioSource_AudioSourceError; // AudioSource.Start(); int x = 1; } catch { } // Create buffer for wavechart control current = new float[AudioSource.DesiredFrameSize]; // Create stream to store file stream = new MemoryStream(); encoder = new WaveEncoder(stream); frames = 0; samples = 0; // Start AudioSource.Start(); }
private void cbSpeakerDevices_SelectionChanged(object sender, SelectionChangedEventArgs e) { AudioDeviceInfo selected = cbSpeakerDevices.SelectedItem as AudioDeviceInfo; if (selected == null) { return; } bool forceStart = lvPhoneCalls.HasItems; MediaHandlers.ChangeSpeaker(selected); }
public Recorder(int xlocation, int ylocation, int width, int height, AudioDeviceInfo audioDevice) { audioEncoder = new WaveEncoder(@"D:\Projects\test_audio.wav"); audio = new AudioCaptureDevice(audioDevice); captureStream = new ScreenCaptureStream(new System.Drawing.Rectangle(xlocation, ylocation, width, height)); video = new VideoFileWriter(); audio.DesiredFrameSize = 4096; audio.SampleRate = 44100; audio.NewFrame += Audio_NewFrame; captureStream.FrameInterval = 1; captureStream.NewFrame += CaptureStream_NewFrame; }
private AudioCaptureDevice GetProperAudioDevice() { AudioDeviceInfo audioDeviceInfo = null; foreach (AudioDeviceInfo audioCaptureDeviceInfo in audioCaptureDevices) { if (audioCaptureDeviceInfo.Guid != Guid.Empty) { audioDeviceInfo = audioCaptureDeviceInfo; } } return(audioDeviceInfo == null ? new AudioCaptureDevice() : new AudioCaptureDevice(audioDeviceInfo)); }
private void listBoxAdditionalOutputDevices_ItemCheck(object sender, ItemCheckEventArgs e) { AudioDeviceInfo item = listBoxAdditionalOutputDevices.Items[e.Index] as AudioDeviceInfo; // Add or remove the item from the controller if (e.NewValue == CheckState.Checked && !_controller.AdditionalOutputDevices.Contains(item)) { _controller.AdditionalOutputDevices.Add(item); } else { _controller.AdditionalOutputDevices.Remove(item); } }
private void comboPrimaryOutputDevice_SelectedIndexChanged(object sender, EventArgs e) { // Set the controller's primary output device AudioDeviceInfo lastDevice = _controller.PrimaryOutputDevice; AudioDeviceInfo newDevice = comboPrimaryOutputDevice.SelectedIndex != -1 ? (AudioDeviceInfo)comboPrimaryOutputDevice.Items[comboPrimaryOutputDevice.SelectedIndex] : null; _controller.PrimaryOutputDevice = newDevice; // Remove that device from additional output devices _controller.AdditionalOutputDevices.Remove(newDevice); RepopulateAdditionalOutputDevices(lastDevice, newDevice); }
/// <summary> /// Changes the speaker device and sets the volume and muted property of the new device. /// </summary> public void ChangeSpeaker(AudioDeviceInfo deviceInfo) { if (!_initialized) { return; } float prevVolume = 0; bool prevMuted = false; if (Speaker != null) { // backup settings prevVolume = Speaker.Volume; prevMuted = Speaker.Muted; // dispose previous device _audioConnector.Disconnect(_phoneCallAudioReceiver, Speaker); _audioConnector.Disconnect(_ringtonePlayer, Speaker); _audioConnector.Disconnect(_ringbackPlayer, Speaker); _audioConnector.Disconnect(_dtmfPlayer, Speaker); UnsubscribeFromSpeakerEvents(); Speaker.Dispose(); AudioEnhancer.SetEchoSource(null); } // create new microphone Speaker = Speaker.GetDevice(deviceInfo); if (Speaker != null) { SubscribeToSpeakerEvents(); _audioConnector.Connect(_phoneCallAudioReceiver, Speaker); _audioConnector.Connect(_ringtonePlayer, Speaker); _audioConnector.Connect(_ringbackPlayer, Speaker); _audioConnector.Connect(_dtmfPlayer, Speaker); // set prev device settings Speaker.Volume = prevVolume; Speaker.Muted = prevMuted; Speaker.Start(); AudioEnhancer.SetEchoSource(Speaker); } OnPropertyChanged("Speaker"); }
private void butStart_Click(object sender, EventArgs e) { AudioDeviceInfo audioDeviceInfo = this.devicesListBox.SelectedItem as AudioDeviceInfo; if (audioDeviceInfo == null) { throw new ArgumentException("No audio devices available."); } source = new AudioCaptureDevice(audioDeviceInfo) { DesiredFrameSize = 8192, SampleRate = 96000, Channels = 2, }; source.NewFrame += new EventHandler <NewFrameEventArgs>(NewFrame); source.Start(); }
private static bool IsSelectableDevice(AudioDeviceInfo device) { string[] hidenAudioDeviceNames = { "VB-Audio VoiceMeeter", "VB-Audio Virtual Cable", "Primary Sound Device", "Primary Sound Driver", "Primary Sound Capture Driver" }; List <string> hiddenAudioNames = new List <string>(hidenAudioDeviceNames); return(!string.IsNullOrEmpty(device.Description) && !hiddenAudioNames.Any(x => device.Description.Contains(x))); }
/// <summary> /// Changes the microphone device. /// </summary> public void ChangeMicrophone(AudioDeviceInfo deviceInfo) { if (!_initialized) { return; } float prevVolume = 0; bool prevMuted = false; if (Microphone != null) { // same device if (Microphone.DeviceInfo.Equals(deviceInfo)) { return; } // backup settings prevVolume = Microphone.Volume; prevMuted = Microphone.Muted; // dispose previous device _audioConnector.Disconnect(Microphone, AudioEnhancer); UnsubscribeFromMicrophoneEvents(); Microphone.Dispose(); } // create new microphone Microphone = Microphone.GetDevice(deviceInfo); if (Microphone != null) { SubscribeToMicrophoneEvents(); _audioConnector.Connect(Microphone, AudioEnhancer); // set prev device settings Microphone.Volume = prevVolume; Microphone.Muted = prevMuted; Microphone.Start(); } OnPropertyChanged("Microphone"); }
void Button1Click(object sender, EventArgs e) { AudioDeviceInfo info = comboBox1.SelectedItem as AudioDeviceInfo; if (info == null) { MessageBox.Show("No audio devices available."); return; } source = new AudioCaptureDevice(info.Guid); source.DesiredFrameSize = 2048; source.SampleRate = 22050; source.NewFrame += source_NewFrame; source.AudioSourceError += source_AudioSourceError; window = RaisedCosineWindow.Hamming(source.DesiredFrameSize); source.Start(); }
private void init(IntPtr controlHandle, EventHandler <AudioOutputErrorEventArgs> AudioOutputError, EventHandler <PlayFrameEventArgs> FramePlayingStarted, EventHandler <NewFrameRequestedEventArgs> NewFrameRequested, EventHandler Stopped) { AudioDeviceCollection audioDevices = new AudioDeviceCollection(AudioDeviceCategory.Output); AudioDeviceInfo INfo = null; foreach (var item in audioDevices) { INfo = item; } // Here we can create the output audio device that will be playing the recording this.output = new AudioOutputDevice(INfo.Guid, controlHandle, decoder.SampleRate, decoder.Channels); // Wire up some events output.FramePlayingStarted += FramePlayingStarted; output.NewFrameRequested += NewFrameRequested; output.Stopped += Stopped; output.AudioOutputError += AudioOutputError; this.frames = this.decoder.Frames; this.samples = this.decoder.Samples; this.wholeSignal = getWholeSignal(); }
/// <summary> /// 查找设备的序号 /// </summary> /// <param name="device">要查找的设备</param> /// <param name="returnDefault">当找不到设备时,是否返回默认设备的序号</param> private static int FindDevice(AudioDeviceInfo? device, bool returnDefault = false) { int result; if (device.HasValue) { int num = -1; BASS_DEVICEINFO[] devices = Bass.BASS_GetDeviceInfos(); IEnumerable<int> source = from d in devices where d.id != null && d.id == device.Value.ID select Array.IndexOf<BASS_DEVICEINFO>(devices, d); if (source.Count<int>() == 1) { num = source.First<int>(); } if (num == -1) { source = from d in devices where d.name == device.Value.Name select Array.IndexOf<BASS_DEVICEINFO>(devices, d); if (source.Count<int>() == 1) { num = source.First<int>(); } } if (num == -1) { source = from d in devices where d.driver == device.Value.Driver select Array.IndexOf<BASS_DEVICEINFO>(devices, d); if (source.Count<int>() == 1) { num = source.First<int>(); } } if (num == -1 && returnDefault) { result = BassPlayer.FindDefaultDevice(); } else { if (num == -1) { throw new Exception("找不到此设备:" + device.Value.Name); } result = num; } } else { result = BassPlayer.FindDefaultDevice(); } return result; }
private bool testKinectPresence() { try { Microsoft.Research.Kinect.Audio.AudioDeviceInfo info = new AudioDeviceInfo(); tbxStatus.Text = String.Format("a kinect sensor is detected", info.DeviceName); return true; } catch (Exception) { tbxStatus.Text = "please connect a kinect sensor"; return false; } }
/// <summary> /// 初始化BassEngine /// </summary> private void Initialize(AudioDeviceInfo? device = null) { try { IntPtr win = IntPtr.Zero; int i = BassPlayer.FindDevice(device, true); if (!Bass.BASS_Init(i, this.sampleFrequency, BASSInit.BASS_DEVICE_DEFAULT, win)) { BASSError code = Bass.BASS_ErrorGetCode(); int num = Bass.BASS_GetDeviceCount(); for (i = -1; i < num; i++) { if (i != 0 && Bass.BASS_Init(i, this.sampleFrequency, BASSInit.BASS_DEVICE_DEFAULT, win)) { break; } } if (i == num) { throw new Exception(); } } if (!device.HasValue && i == BassPlayer.FindDefaultDevice()) { this.Device = null; } else { BASS_DEVICEINFO bASS_DEVICEINFO = Bass.BASS_GetDeviceInfo(Bass.BASS_GetDevice()); this.Device = new AudioDeviceInfo?(new AudioDeviceInfo { Driver = bASS_DEVICEINFO.driver, Name = bASS_DEVICEINFO.name, ID = bASS_DEVICEINFO.id }); } Bass.LoadMe(); } catch (Exception exp) { throw new Exception(exp.Message); } }