public void TestGetVolume() { var devices = AudioUtilities.GetAllActiveSpeakers(); var speakers = AudioUtilities.GetCurrentSpeakers(); Assert.IsNotNull(speakers); string id; Assert.IsTrue(speakers.GetId(out id) == 0); Assert.IsFalse(string.IsNullOrWhiteSpace(id)); IAudioEndpointVolume endpointVolume = AudioUtilities.GetAudioEndpointVolume(speakers); var device = AudioUtilities.CreateDevice(speakers); Assert.IsNotNull(device); float level; endpointVolume.GetMasterVolumeLevelScalar(out level); Assert.AreNotEqual(0, level); endpointVolume.SetMasterVolumeLevelScalar(level * 1.5f, Guid.NewGuid()); Playback.SetDefaultPlaybackDevice(devices.First(d => d.Id != id).Id); }
static void Main(string[] args) { AudioUtilities.SetMasterVolume(75f); System.Console.WriteLine($"This is system audio {AudioUtilities.GetMasterVolume()}"); System.Threading.Thread.Sleep(5000); AudioUtilities.SetMasterVolume(50f); System.Console.WriteLine($"This is system audio {AudioUtilities.GetMasterVolume()}"); System.Threading.Thread.Sleep(5000); Console.WriteLine("Friendly names:"); List <AudioDevice> soundDevices = new List <AudioDevice>(); foreach (AudioDevice device in AudioUtilities.GetAllDevices()) { Console.WriteLine(device.FriendlyName); soundDevices.Add(device); } // dump all audio sessions List <Process> audioSess = new List <Process>(); Console.WriteLine("Process names:"); foreach (AudioSession session in AudioUtilities.GetAllSessions()) { if (session.Process != null) { // only the one associated with a defined process audioSess.Add(session.Process); } } AudioUtilities.SetApplicationVolume(audioSess[0].Id, 50); System.Threading.Thread.Sleep(5000); AudioUtilities.SetApplicationVolume(audioSess[0].Id, 100); }
public void TestGetAllActiveSpeakers() { var devices = AudioUtilities.GetAllActiveSpeakers(); Assert.IsNotNull(devices); Assert.IsTrue(devices.Count > 0); }
public static void deviceToSpeaker() { AudioDevice defaulDevice = AudioUtilities.GetSpeakersDevice(); speakersList = new LinkedList <Speaker>(); foreach (AudioDevice device in program.audioDeviceList) { if (device.State.ToString().Equals("Active")) { if (device.EnumeratorName.Equals("HDAUDIO")) { Speaker speakertemp = new Speaker(); if (device.Id == defaulDevice.Id) { speakertemp.isDefault = true; } else { speakertemp.isDefault = false; } speakertemp.name = device.Description; speakertemp.id = device.Id; speakersList.AddLast(speakertemp); } } } }
private void SetVolume(float volume) { IMMDevice speakers = AudioUtilities.GetCurrentSpeakers(); IAudioEndpointVolume currentEndpointVolume = AudioUtilities.GetAudioEndpointVolume(speakers); //as we work with volume as a value between 0-100 we need to convert back to a value between 0-1. //MasterVolumeLevelScalar capped at 100, any value above 100 is treated as 100. currentEndpointVolume.SetMasterVolumeLevelScalar(volume > 0 ? volume / 100 : 0, Guid.NewGuid()); }
private AudioDeviceList GetAudioDeviceList() { string id; IMMDevice speakers = AudioUtilities.GetCurrentSpeakers(); speakers.GetId(out id); //get active playback devices, make sure we mark which one is the current default playback device return(new AudioDeviceList(AudioUtilities.GetAllActiveSpeakers().Select(d => new AudioDevice(d, d.Id == id)))); }
public void TestGetCurrentSpeakers() { var speakers = AudioUtilities.GetCurrentSpeakers(); Assert.IsNotNull(speakers); string id; Assert.IsTrue(speakers.GetId(out id) == 0); Assert.IsFalse(string.IsNullOrWhiteSpace(id)); }
void Awake() { instance = this; backgroundAudio = AudioUtilities.GetResourcesClips("background_loops"); ouchAudio = AudioUtilities.GetResourcesClips("character_hurt"); jumpAudio = AudioUtilities.GetResourcesClips("character_jump"); landOnEnemyAudio = AudioUtilities.GetResourcesClips("character_land_on_enemy"); landOnGroundAudio = AudioUtilities.GetResourcesClips("character_land_on_ground"); respawnAudio = AudioUtilities.GetResourcesClips("character_respawn"); walkAudio = AudioUtilities.GetResourcesClips("character_walk"); pickupCollectableAudio = AudioUtilities.GetResourcesClips("pickup_collectable"); }
private float GetCurrentVolume() { IMMDevice speakers = AudioUtilities.GetCurrentSpeakers(); IAudioEndpointVolume currentEndpointVolume = AudioUtilities.GetAudioEndpointVolume(speakers); float volume; currentEndpointVolume.GetMasterVolumeLevelScalar(out volume); //volume comes out as value between 0-1 but we want the value as 0-100 return(volume * 100); }
/** * Mutes/Unmutes Spotify. * * i: 0 = unmute, 1 = mute, 2 = toggle **/ private void Mute(int i) { if (i == 2) // Toggle mute { if (muted) { i = 0; } else { i = 1; } } if (i == 1) { muted = true; } else if (i == 0) { muted = false; } else { muted = !muted; } System.Diagnostics.Process process = new System.Diagnostics.Process(); // http://stackoverflow.com/questions/1469764/run-command-prompt-commands System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "cmd.exe"; if (spotifyMute) { AudioUtilities.SetApplicationMute("spotify", muted); /*startInfo.Arguments = "/C nircmd muteappvolume Spotify.exe " + i.ToString(); * process.StartInfo = startInfo; * process.Start(); * // Run again for some users * startInfo.Arguments = "/C nircmd muteappvolume spotify.exe " + i.ToString(); * process.StartInfo = startInfo; * process.Start();*/ } else { startInfo.Arguments = "/C nircmd mutesysvolume " + i.ToString(); process.StartInfo = startInfo; process.Start(); } }
// renders the given node to the internal ElementData dictionary. If the given node is // not a element, will recursively descend until we render its elements. protected override void RenderNode(ElementNode node) { if (!AudioUtilities.AudioLoaded) { return; } foreach (ElementNode elementNode in node.GetLeafEnumerator()) { // this is probably always going to be a single element for the given node, as // we have iterated down to leaf nodes in RenderNode() above. May as well do // it this way, though, in case something changes in future. if (elementNode == null || elementNode.Element == null) { continue; } bool discreteColors = ColorModule.isElementNodeDiscreteColored(elementNode); for (int i = 0; i < (int)((TimeSpan.TotalMilliseconds / Spacing) - 1); i++) { double gradientPosition1 = (AudioUtilities.VolumeAtTime(i * Spacing) + Data.Range) / Data.Range; double gradientPosition2 = (AudioUtilities.VolumeAtTime((i + 1) * Spacing) + Data.Range) / Data.Range; if (gradientPosition1 <= 0) { gradientPosition1 = 0; } if (gradientPosition1 >= 1) { gradientPosition1 = 1; } //Some odd corner cases if (gradientPosition2 <= 0) { gradientPosition2 = 0; } if (gradientPosition2 >= 1) { gradientPosition2 = 1; } TimeSpan startTime = TimeSpan.FromMilliseconds(i * Spacing); ElementData.Add(GenerateEffectIntents(elementNode, WorkingGradient, MeterIntensityCurve, gradientPosition1, gradientPosition2, TimeSpan.FromMilliseconds(Spacing), startTime, discreteColors)); } } }
// renders the given node to the internal ElementData dictionary. If the given node is // not a element, will recursively descend until we render its elements. protected override void RenderNode(ElementNode node) { if (!AudioUtilities.AudioLoaded) { return; } int currentElement = 0; var nodeCount = 0; if (Inverted) { nodeCount = node.GetLeafEnumerator().Count(); } foreach (ElementNode elementNode in node.GetLeafEnumerator()) { // this is probably always going to be a single element for the given node, as // we have iterated down to leaf nodes in RenderNode() above. May as well do // it this way, though, in case something changes in future. if (elementNode == null || elementNode.Element == null) { continue; } bool discreteColors = ColorModule.isElementNodeDiscreteColored(elementNode); for (int i = 1; i < (int)(TimeSpan.TotalMilliseconds / Spacing); i++) { int startAudioTime; int endAudioTime; if (Inverted) { startAudioTime = i * Spacing - (nodeCount - currentElement) * ((WaveformData)Data).ScrollSpeed + 1; endAudioTime = (i + 1) * Spacing - (nodeCount - currentElement) * ((WaveformData)Data).ScrollSpeed; } else { startAudioTime = i * Spacing - currentElement * ((WaveformData)Data).ScrollSpeed + 1; endAudioTime = (i + 1) * Spacing - currentElement * ((WaveformData)Data).ScrollSpeed; } TimeSpan startTime = TimeSpan.FromMilliseconds(i * Spacing); if (startAudioTime > 0 && startAudioTime < TimeSpan.TotalMilliseconds && endAudioTime > 0 && endAudioTime < TimeSpan.TotalMilliseconds) { double gradientPosition1 = (AudioUtilities.VolumeAtTime(startAudioTime) + Data.Range) / Data.Range; double gradientPosition2 = (AudioUtilities.VolumeAtTime(endAudioTime) + Data.Range) / Data.Range; //Some odd corner cases if (gradientPosition1 <= 0) { gradientPosition1 = 0; } if (gradientPosition1 >= 1) { gradientPosition1 = 1; } //Some odd corner cases if (gradientPosition2 <= 0) { gradientPosition2 = 0; } if (gradientPosition2 >= 1) { gradientPosition2 = 1; } ElementData.Add(GenerateEffectIntents(elementNode, WorkingGradient, MeterIntensityCurve, gradientPosition1, gradientPosition2, TimeSpan.FromMilliseconds(Spacing), startTime, discreteColors)); } } currentElement++; } }
public AudioOutputPreview GetAudioPreview(SourceAudioTrack inputTrack, AudioEncodingViewModel audioVM) { HBAudioEncoder encoder = audioVM.HBAudioEncoder; var outputPreviewTrack = new AudioOutputPreview { Name = inputTrack.Description, Encoder = encoder.DisplayName }; if (encoder.IsPassthrough) { // For passthrough encodes, we need to make sure the input track is of the right type if (!HandBrakeEncoderHelpers.AudioEncoderIsCompatible(inputTrack.Codec, encoder) && encoder.ShortName != "copy") { return(null); } } if (encoder.ShortName == "copy") { if (this.copyMaskChoices.Items.Any( choice => { if (!choice.Enabled) { return(false); } return((HandBrakeEncoderHelpers.GetAudioEncoder("copy:" + choice.Codec).Id & inputTrack.Codec) > 0); })) { return(outputPreviewTrack); } if (this.Profile.AudioEncoderFallback == null) { encoder = HandBrakeEncoderHelpers.AudioEncoders.First(a => !a.IsPassthrough); } else { // The fallback is explicitly set to "None", so drop the track. if (this.Profile.AudioEncoderFallback == "none") { return(null); } encoder = HandBrakeEncoderHelpers.GetAudioEncoder(this.Profile.AudioEncoderFallback); } // Get the default output values for the input track and encoder var defaultSettings = AudioUtilities.GetDefaultSettings(inputTrack, encoder); // Apply the output values to the preview object UpdateAudioPreviewTrack(outputPreviewTrack, defaultSettings); } else { HBMixdown previewMixdown; previewMixdown = HandBrakeEncoderHelpers.SanitizeMixdown(audioVM.SelectedMixdown.Mixdown, encoder, (ulong)inputTrack.ChannelLayout); int previewSampleRate = audioVM.SampleRate; if (previewSampleRate == 0) { previewSampleRate = inputTrack.SampleRate; } // Collect the output values in the AudioTrack object var outputTrack = new OutputAudioTrackInfo { Encoder = encoder, Mixdown = previewMixdown, SampleRate = HandBrakeEncoderHelpers.SanitizeSampleRate(encoder, previewSampleRate), EncodeRateType = audioVM.EncodeRateType }; if (audioVM.EncodeRateType == AudioEncodeRateType.Bitrate) { int previewBitrate = audioVM.SelectedBitrate.Bitrate; if (previewBitrate == 0) { previewBitrate = HandBrakeEncoderHelpers.GetDefaultBitrate(encoder, previewSampleRate, previewMixdown); } else { previewBitrate = HandBrakeEncoderHelpers.SanitizeAudioBitrate(previewBitrate, encoder, previewSampleRate, previewMixdown); } outputTrack.Bitrate = previewBitrate; } else { outputTrack.Quality = audioVM.AudioQuality; } outputTrack.Gain = audioVM.Gain; outputTrack.Drc = audioVM.Drc; // Apply the output values to the preview object UpdateAudioPreviewTrack(outputPreviewTrack, outputTrack); } return(outputPreviewTrack); }
protected AudioPluginBase() { _audioUtilities = new AudioUtilities(); }
public Fireworks() { _data = new FireworksData(); _audioUtilities = new AudioUtilities(); }
private AudioDevice GetCurrentDevice() { return(new AudioDevice(AudioUtilities.CreateDevice(AudioUtilities.GetCurrentSpeakers()))); }
// renders the given node to the internal ElementData dictionary. If the given node is // not a element, will recursively descend until we render its elements. protected override void RenderNode(ElementNode node) { int currentElement = 0; int elementCount = node.GetLeafEnumerator().Count(); foreach (ElementNode elementNode in node.GetLeafEnumerator()) { // this is probably always going to be a single element for the given node, as // we have iterated down to leaf nodes in RenderNode() above. May as well do // it this way, though, in case something changes in future. if (elementNode == null || elementNode.Element == null) { continue; } if (!AudioUtilities.AudioLoaded) { return; } bool discreteColors = ColorModule.isElementNodeDiscreteColored(elementNode); var lastTime = TimeSpan.FromMilliseconds(0); double gradientPosition = (double)(currentElement) / elementCount; //Audio max is at 0db. The threshold gets shifted from 0 to 1 to -1 to 0 and then scaled. double threshold; if (!((VerticalMeterData)Data).Inverted) { threshold = (((double)(elementCount - currentElement)) / elementCount - 1) * Data.Range; gradientPosition = 1 - gradientPosition; } else { threshold = (((double)currentElement) / elementCount - 1) * Data.Range; } var lastValue = AudioUtilities.VolumeAtTime(0) >= threshold; TimeSpan start; for (int i = 1; i < (int)(TimeSpan.TotalMilliseconds / Spacing); i++) { //Current time in ms = i*spacing var currentValue = AudioUtilities.VolumeAtTime(i * Spacing) >= threshold; if (currentValue != lastValue) { start = lastTime; if (lastValue) { var effectIntents = GenerateEffectIntents(elementNode, WorkingGradient, MeterIntensityCurve, gradientPosition, gradientPosition, TimeSpan.FromMilliseconds(i * Spacing) - lastTime, start, discreteColors); ElementData.Add(effectIntents); } lastTime = TimeSpan.FromMilliseconds(i * Spacing); lastValue = currentValue; } } if (lastValue) { start = lastTime; var effectIntents = GenerateEffectIntents(elementNode, WorkingGradient, MeterIntensityCurve, gradientPosition, gradientPosition, TimeSpan - lastTime, start, discreteColors); ElementData.Add(effectIntents); } currentElement++; } }