private void Initialize() { int samplesPerSecond = int.Parse(AppConfiguration.AudioSamplesPerSecond); int bitsPerSample = int.Parse(AppConfiguration.AudioBitsPerSample); int channels = int.Parse(AppConfiguration.AudioChannels); string waveOutDeviceName = WinSound.GetWaveOutDeviceNames().Count > 0 ? WinSound.GetWaveOutDeviceNames()[0] : null; if (waveOutDeviceName != null) { _player = new WinSoundPlayer(); _player.Open(waveOutDeviceName, samplesPerSecond, bitsPerSample, channels, 1280, SoundBufferCount); } else { MessageBox.Show("本机未找到播放设备!", "提示", 0, MessageBoxIcon.Exclamation); } string waveInDeviceName = WinSound.GetWaveInDeviceNames().Count > 0 ? WinSound.GetWaveInDeviceNames()[0] : null; if (waveInDeviceName != null) { _recorder = new WinSoundRecord(); _recorder.DataRecorded += Recorder_DataRecorded; _recorder.Open(waveInDeviceName, samplesPerSecond, bitsPerSample, channels, 1280, SoundBufferCount); } else { MessageBox.Show("本机未找到录音设备!", "提示", 0, MessageBoxIcon.Exclamation); } OpenRemoteAudio(samplesPerSecond, bitsPerSample, channels); _isRun = true; }
private void Initialize() { _samplesPerSecond = AppConfiguration.AudioSamplesPerSecond; _bitsPerSample = (short)AppConfiguration.AudioBitsPerSample; _channels = (short)AppConfiguration.AudioChannels; _dataBufferSize = 1280; string waveOutDeviceName = WinSound.GetWaveOutDeviceNames().Count > 0 ? WinSound.GetWaveOutDeviceNames()[0] : null; if (waveOutDeviceName != null) { _player = new WinSoundPlayer(); _player.Open(waveOutDeviceName, _samplesPerSecond, _bitsPerSample, _channels, _dataBufferSize, _soundBufferCount); } else { MessageBoxHelper.ShowBoxExclamation("本机未找到播放设备!"); } string waveInDeviceName = WinSound.GetWaveInDeviceNames().Count > 0 ? WinSound.GetWaveInDeviceNames()[0] : null; if (waveInDeviceName != null) { _recorder = new WinSoundRecord(); _recorder.DataRecorded += Recorder_DataRecorded; _recorder.Open(waveInDeviceName, _samplesPerSecond, _bitsPerSample, _channels, _dataBufferSize, _soundBufferCount); } else { MessageBoxHelper.ShowBoxExclamation("本机未找到录音设备!"); } this.AudioAdapterHandler.StartRemoteAudio(_samplesPerSecond, _bitsPerSample, _channels); this._isRun = true; }
private void OpenAudio(int samplesPerSecond, int bitsPerSample, int channels) { int inDeviceOpen = 0; int outDeviceOpen = 0; try { string waveInDeviceName = WinSound.GetWaveInDeviceNames().Count > 0 ? WinSound.GetWaveInDeviceNames()[0] : null; if (waveInDeviceName != null) { _Recorder = new WinSoundRecord(); _Recorder.DataRecorded += Recorder_DataRecorded; _Recorder.Open(waveInDeviceName, samplesPerSecond, bitsPerSample, channels, 1280, 8); } else { inDeviceOpen = 1; } } catch { } try { string waveOutDeviceName = WinSound.GetWaveOutDeviceNames().Count > 0 ? WinSound.GetWaveOutDeviceNames()[0] : null; if (waveOutDeviceName != null) { _Player = new WinSoundPlayer(); _Player.Open(waveOutDeviceName, samplesPerSecond, bitsPerSample, channels, 1280, 8); } else { outDeviceOpen = 1; } } catch { } SendAsyncToServer(MessageHead.C_AUDIO_DEVICE_OPENSTATE, new AudioDeviceStatesPack() { PlayerEnable = outDeviceOpen == 0 ? true : false, RecordEnable = inDeviceOpen == 0 ? true : false }); }