/// <summary> /// Plays the recorded audio stream. /// 播放录制的音频流。 /// </summary> /// private void BtnPlay_Click(object sender, EventArgs e) { // First, we rewind the stream //【1】首先,我们拨回初始值 stream.Seek(0, SeekOrigin.Begin); // Then we create a decoder for it //【2】然后我们为它创建一个解码器 decoder = new WaveDecoder(stream); /*Configure the track bar so the cursorcan show the proper current position *【3】 配置跟踪条,使光标可以显示正确的当前位置 */ if (trackBar1.Value < decoder.Frames) { decoder.Seek(trackBar1.Value); } trackBar1.Maximum = decoder.Samples; // Here we can create the output audio device that will be playing the recording //【4】在这里我们可以创建将播放录音的输出音频设备 output = new AudioOutputDevice(this.Handle, decoder.SampleRate, decoder.Channels); // 【5】Wire up some events 注册一些事件 //【5.1】指示帧块已开始执行事件。 output.FramePlayingStarted += output_FramePlayingStarted; output.NewFrameRequested += output_NewFrameRequested; output.Stopped += output_PlayingFinished; // Start playing! output.Play(); updateButtons(); }
public void OnDeviceVolumeChanged(float volume, AudioOutputDevice audioOutputDevice) { if (slider != null && AudioOutputDevice.id == audioOutputDevice.id) { slider.value = volume; } }
private void InitAudioOutputDevice(Signal probingInput) { audioOutputDevice = new AudioOutputDevice(audioOutputDeviceOwnerHandle, probingInput.SampleRate, probingInput.Channels); audioOutputDevice.FramePlayingStarted += AudioOutputDeviceFramePlayingStarted; audioOutputDevice.NewFrameRequested += AudioOutputDeviceNewFrameRequested; audioOutputDevice.Stopped += AudioOutputDevicePlayingFinished; }
public AudioOutputDevice[] AudioOutputDevices(string audioOutputName) { return(MarshalUtils.Retrieve(() => Native.LibVLCAudioOutputDeviceListGet(NativeReference, audioOutputName), Marshal.PtrToStructure <AudioOutputDevice.Internal>, s => AudioOutputDevice.__CreateInstance(s), device => device.Next, Native.LibVLCAudioOutputDeviceListRelease)); }
public void InitializeUI(AudioStreamType[] audioStreamTypes, AudioOutputDevice[] audioOutputDevices) { if (!initialized) { Initialize(); } float y = -Y_SPACING; int length = audioStreamTypes.Length; for (int i = 0; i < length; i++) { AudioStreamType audioStreamType = audioStreamTypes[i]; SystemVolumeItem volumeItem = CreateSystemVolumeItem(); volumeItem.InitUI(audioStreamType); volumeItem.RectTransform.anchoredPosition = new Vector2(0, y); y -= volumeItem.RectTransform.rect.height; y -= Y_SPACING; } length = audioOutputDevices.Length; for (int i = 0; i < length; i++) { AudioOutputDevice audioOutputDevice = audioOutputDevices[i]; DeviceVolumeItem volumeItem = CreateDeviceVolumeItem(); volumeItem.InitUI(audioOutputDevice); volumeItem.RectTransform.anchoredPosition = new Vector2(0, y); y -= volumeItem.RectTransform.rect.height; y -= Y_SPACING; } scrollRect.content.sizeDelta = new Vector2(0, Mathf.Abs(y)); }
public void OnDeviceVolumeMuteChanged(bool muted, AudioOutputDevice audioOutputDevice) { if (AudioOutputDevice.id == audioOutputDevice.id) { this.muted = muted; UpdateMuteSprite(); } }
public void InitUI(AudioOutputDevice audioOutputDevice) { AudioOutputDevice = audioOutputDevice; slider.value = NativeSystemVolumeManager.GetDeviceVolume(audioOutputDevice); UpdateTitleLabel(audioOutputDevice.name); NativeSystemVolumeManager.AddDeviceVolumeChangedListener(OnDeviceVolumeChanged); NativeSystemVolumeManager.AddDeviceVolumeMuteChangedListener(OnDeviceVolumeMuteChanged); muted = NativeSystemVolumeManager.IsDeviceVolumeMuted(audioOutputDevice); UpdateMuteSprite(); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); output = new AudioOutputDevice(Handle, 8000, 1); output.FramePlayingStarted += output_Started; output.Stopped += output_Stopped; input = new float[2][]; input[0] = getSignal("Resources/mic1.wav"); input[1] = getSignal("Resources/mic2.wav"); }
public void PatchPluginToAudioOutput(Guid guid, AudioOutputDevice device, int latency) { var plugin = GetPluginByGuid(guid); try { _vstHost.PatchPluginToAudioOutput(plugin, device, latency); } catch (Exception e) { throw GetFaultException <GenericFault>(e); } }
public MMDevice GetAudioEndpoint(AudioOutputDevice device) { if (device.DefaultDevice) { return(_enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia)); } foreach (var dev in _enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active)) { if (dev.ID == device.Id) { return(dev); } } return(null); }
public static void BeginAudioPlayback(string filePath, AudioOutputDevice audioOutputDevice, float volume, double beginTime, double endTime) { try { AudioFileReader audioFileReader = new AudioFileReader(filePath); // Configure mixer MixingSampleProvider mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(audioFileReader.WaveFormat.SampleRate, 2)); // Force audio to stereo 2-channel MultiplexingWaveProvider waveProvider = new MultiplexingWaveProvider(new IWaveProvider[] { audioFileReader.ToWaveProvider() }, audioFileReader.WaveFormat.Channels > 1 ? 2 : 1); // Apply volume preferences VolumeSampleProvider volumeSampleProvider = new VolumeSampleProvider(waveProvider.ToSampleProvider()) { Volume = volume }; // Force sample rate ISampleProvider convertedSampleProvider = ConvertToMixerSampleRate(mixer, ConvertToMixerChannelCount(mixer, volumeSampleProvider)); // Seek OffsetSampleProvider offsetSampleProvider = new OffsetSampleProvider(convertedSampleProvider); offsetSampleProvider.SkipOver = TimeSpan.FromSeconds(beginTime); offsetSampleProvider.Take = TimeSpan.FromSeconds(endTime) - offsetSampleProvider.SkipOver; // Configure mixer mixer.AddMixerInput(offsetSampleProvider); audioOutputDevice.InitializeAndPlay(mixer); audioOutputDevice.PlaybackStopped += (sender, e) => { //audioFileReader.Close(); audioFileReader.Dispose(); }; } catch (Exception ex) { ApplicationLogger.Log(ex.Message, ex.StackTrace); } }
public void PatchPluginToAudioOutput(RemoteVstPlugin plugin, AudioOutputDevice device, int latency) { var audioService = new AudioService(); var ep = audioService.GetAudioEndpoint(device); if (ep == null) { throw new Exception( $"Unable to open audio device {device.Name} because the device (currently) doesn't exist"); } UnpatchPluginFromAudioOutput(); _outputDevice = new WasapiOut(ep, AudioClientShareMode.Shared, true, latency); _vstWaveProvider = new VSTStream(); _vstWaveProvider.pluginContext = plugin.PluginContext; _vstWaveProvider.SetWaveFormat(_outputDevice.OutputWaveFormat.SampleRate, _outputDevice.OutputWaveFormat.Channels); _outputDevice.Init(_vstWaveProvider); _outputDevice.Play(); }
public async Task <string> SetAudioOutputDevice(string audioOutputDeviceName) { try { if (_mediaPlayer != null) { AudioOutputDevice defaultAudioOutputDevice = _mediaPlayer.AudioOutputDeviceEnum.FirstOrDefault(a => a.Description == "Default"); if (audioOutputDeviceName.ToLower() == "default") { _mediaPlayer.SetOutputDevice(defaultAudioOutputDevice.DeviceIdentifier); return($"Successfully defaulted the song request media player's audio output device"); } AudioOutputDevice audioOutputDevice = _mediaPlayer.AudioOutputDeviceEnum.FirstOrDefault(a => a.Description == audioOutputDeviceName); if (audioOutputDevice.Description != audioOutputDeviceName) { _mediaPlayer.SetOutputDevice(defaultAudioOutputDevice.DeviceIdentifier); return("Cannot set the requested audio output device for the song request media player. " + $"Setting it to \"{defaultAudioOutputDevice.Description}\""); } else { _mediaPlayer.SetOutputDevice(audioOutputDevice.DeviceIdentifier); return($"Successfully set the song request media player's audio output device to \"{audioOutputDeviceName}\""); } } } catch (Exception ex) { await _errHndlrInstance.LogError(ex, "LibVLCSharpPlayer", "SetAudioOutputDevice(string)", false); } return("I cannot find the song request media player"); }
public void PatchPluginToAudioOutput(AudioOutputDevice device, int latency) { _remoteVstService.PatchPluginToAudioOutput(_guid, device, latency); }
public void PatchPluginToAudioOutput(Guid guid, AudioOutputDevice device, int latency) { }
public VlcAudioDevice(AudioOutputDevice device) { _device = device; }
private string GetAudioDevice(string description) { var audioDevicesAoutNames = new string[] { "directsound", "directx" }; var vlcObj = _wrapper.ExpandedLibVLCNew(null); var audioDevicePtr = _wrapper.ExpandedAudioOutputListGet(vlcObj); var audioDevicesPtr = IntPtr.Zero; var audioDeviceName = string.Empty; var audioDevice = new AudioDescription { NextDescription = audioDevicePtr, Description = null, Name = null }; while (audioDevice.NextDescription != IntPtr.Zero) { audioDevice = (AudioDescription)Marshal.PtrToStructure(audioDevice.NextDescription, typeof(AudioDescription)); for (int i = 0; i < audioDevicesAoutNames.Length; i += 2) { if (audioDevice.Name.Contains(audioDevicesAoutNames[i])) { audioDevicesPtr = _wrapper.ExpandedAudioOutputDeviceListGet(vlcObj, audioDevicesAoutNames[i + 1]); break; } } } if (audioDevicesPtr == IntPtr.Zero) { Debug.Log("GetAudioDevice: Can't get audio output device list for " + audioDevice.Name); return(audioDeviceName); } AudioOutputDevice outputDevice = new AudioOutputDevice { NextDevice = audioDevicesPtr, Description = null, Device = null }; try { while (outputDevice.NextDevice != IntPtr.Zero) { outputDevice = (AudioOutputDevice)Marshal.PtrToStructure(outputDevice.NextDevice, typeof(AudioOutputDevice)); if (outputDevice.Description.Contains(description)) { Debug.Log("GetAudioDevice: New audio output device \n" + "Device: " + outputDevice.Device + "\n" + "Description: " + outputDevice.Description); audioDeviceName = outputDevice.Device; } } } finally { if (audioDevicePtr != IntPtr.Zero) { _wrapper.ExpandedAudioOutputListRelease(audioDevicePtr); } if (audioDevicesPtr != IntPtr.Zero) { _wrapper.ExpandedAudioOutputDeviceListRelease(audioDevicesPtr); } _wrapper.ExpandedLibVLCRelease(vlcObj); } if (string.IsNullOrEmpty(audioDeviceName)) { Debug.Log("GetAudioDevice: Can't find audio output device - switched to Default"); } return(audioDeviceName); }