Beispiel #1
0
        private void MuteCore(IAudioCaptureProvider audioCapture, bool mute)
        {
            if (audioCapture == null)
            {
                throw new ArgumentNullException("audioCapture");
            }

            lock (captures)
            {
                if (mute)
                {
                    mutedCaptures.Add(audioCapture);
                }
                else
                {
                    mutedCaptures.Add(audioCapture);
                }

                var ps = captures.Values.Where(e => e.AudioCapture == audioCapture);

                foreach (var e in ps)
                {
                    e.Muted = mute;
                }
            }
        }
        public AudioCaptureSettingsViewModel()
        {
            CaptureProviders = Modules.Capture;

            IAudioCaptureProvider savedCaptureProvider = Modules.Capture.FirstOrDefault(p => p.GetType().GetSimpleName() == Settings.VoiceProvider);

            if (savedCaptureProvider == null)
            {
                CurrentCaptureProvider = Modules.Capture.FirstOrDefault();
            }
            else
            {
                CurrentCaptureProvider = savedCaptureProvider;

                if (Settings.VoiceDevice != null)
                {
                    var setDevice = CaptureDevices.FirstOrDefault(d => d.Device.Name == Settings.VoiceDevice);
                    if (setDevice != null)
                    {
                        CurrentCaptureDevice = setDevice;
                    }
                }
            }

            VoiceActivationThreshold        = Settings.VoiceActivationLevel;
            VoiceActivationSilenceThreshold = Settings.VoiceActivationContinueThreshold / 100;
            UseVoiceActivation = !Settings.UsePushToTalk;
        }
Beispiel #3
0
        public void Attach(IAudioCaptureProvider audioCapture, AudioSource source, AudioEngineCaptureOptions options)
        {
            if (audioCapture == null)
            {
                throw new ArgumentNullException("audioCapture");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (audioCapture.Device == null)
            {
                audioCapture.Device = audioCapture.DefaultDevice;
            }

            lock (captures)
            {
                audioCapture.SamplesAvailable += OnSamplesAvailable;
                audioCapture.BeginCapture(source.CodecSettings, source.CodecSettings.FrameSize);
                captures[source] = new AudioCaptureEntity(audioCapture, source, options);
                captureToSourceLookup[audioCapture] = source;

                if (this.captureMuted || mutedCaptures.Contains(audioCapture))
                {
                    captures[source].Muted = true;
                }
            }
        }
Beispiel #4
0
 public void TearDown()
 {
     this.provider = null;
     this.source   = null;
     this.receiver = null;
     this.sender   = null;
     this.context  = null;
 }
        /// <summary>
        /// Constructs a new <see cref="SamplesAvailableEventArgs"/>
        /// </summary>
        /// <param name="provider">The provider samples are available from.</param>
        /// <param name="available">The number of available samples.</param>
        public SamplesAvailableEventArgs(IAudioCaptureProvider provider, int available)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            Provider  = provider;
            Available = available;
        }
Beispiel #6
0
        public void Setup()
        {
            this.provider = new MockAudioCaptureProvider();
            this.source   = AudioSourceTests.GetTestSource();

            var c = new MockConnectionProvider(GablarskiProtocol.Instance).GetClientConnection();

            var client = new MockClientContext(c);

            this.context  = client;
            this.sender   = new ClientSourceHandler(client, new ClientSourceManager(client));
            this.receiver = (IAudioReceiver)this.sender;
        }
Beispiel #7
0
        public AudioCaptureEntity(IAudioCaptureProvider audioCapture, AudioSource source, AudioEngineCaptureOptions options)
        {
            this.audioCapture = audioCapture;
            this.source = source;
            this.options = options;

            this.frameLength = (this.source.CodecSettings.FrameSize / source.CodecSettings.SampleRate) * 1000;

            if (options.Mode == AudioEngineCaptureMode.Activated)
            {
                activation = new VoiceActivation (source.CodecSettings, source.CodecSettings.FrameSize, options.StartVolume, options.ContinuationVolume, options.ContinueThreshold);
                //preprocessor = new SpeexPreprocessor (this.source.FrameSize, this.source.Frequency);
            }
        }
Beispiel #8
0
        public AudioCaptureEntity(IAudioCaptureProvider audioCapture, AudioSource source, AudioEngineCaptureOptions options)
        {
            this.audioCapture = audioCapture;
            this.source       = source;
            this.options      = options;

            this.frameLength = (this.source.CodecSettings.FrameSize / source.CodecSettings.SampleRate) * 1000;

            if (options.Mode == AudioEngineCaptureMode.Activated)
            {
                activation = new VoiceActivation(source.CodecSettings, source.CodecSettings.FrameSize, options.StartVolume, options.ContinuationVolume, options.ContinueThreshold);
                //preprocessor = new SpeexPreprocessor (this.source.FrameSize, this.source.Frequency);
            }
        }
Beispiel #9
0
        public bool Detach(IAudioCaptureProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            bool removed = false;

            lock (captures)
            {
                foreach (var entity in captures.Values.Where(e => e.AudioCapture == provider).ToList())
                {
                    captures.Remove(entity.Source);
                    captureToSourceLookup.Remove(provider);
                    removed = true;
                }

                mutedCaptures.Remove(provider);
            }

            return(removed);
        }
Beispiel #10
0
		private void SetupVoiceCapture ()
		{
			DisableVoiceCapture();

			if (!this.gablarski.IsConnected)
				return;

			try
			{
				if (Settings.VoiceProvider == null)
					throw new Exception ("Capture provider is not set");

				this.voiceCapture = (IAudioCaptureProvider)Activator.CreateInstance (Type.GetType (Settings.VoiceProvider));

				if (String.IsNullOrEmpty (Settings.VoiceDevice) || Settings.VoiceDevice == "Default")
					this.voiceCapture.Device = this.voiceCapture.DefaultDevice;
				else
				{
					this.voiceCapture.Device = this.voiceCapture.GetDevices().FirstOrDefault (d => d.Name == Settings.VoiceDevice) ??
					                           this.voiceCapture.DefaultDevice;
				}

				if (this.voiceSource != null)
				{
					gablarski.Audio.Attach (this.voiceCapture, this.voiceSource, new AudioEngineCaptureOptions
					{
						StartVolume = Settings.VoiceActivationLevel,
						ContinuationVolume = Settings.VoiceActivationLevel / 2,
						ContinueThreshold = TimeSpan.FromMilliseconds (Settings.VoiceActivationContinueThreshold),
						Mode = (!Settings.UsePushToTalk) ? AudioEngineCaptureMode.Activated : AudioEngineCaptureMode.Explicit
					});
				}

				BeginInvoke ((Action)(() =>
				{
					if (btnMute.Checked && !this.captureDisabled)
						return;

					btnMuteMic.Image = Resources.CaptureMuteImage;
					btnMuteMic.Checked = false;
					btnMuteMic.Enabled = true;
					btnMuteMic.ToolTipText = "Mute Microphone";
					this.captureDisabled = false;
				}));
			}
			catch (Exception ex)
			{
				Program.Raygun.Send (ex, new[] { "capture-init" }, Settings.CurrentSettings);

				if (this.voiceCapture != null)
					this.voiceCapture.Dispose();

				this.voiceCapture = null;

				BeginInvoke ((Action) (() =>
				{
					this.captureDisabled = true;
					btnMuteMic.Image = Resources.CaptureMuteImage.ToErrorIcon();
					btnMuteMic.Checked = true;
					btnMuteMic.Enabled = false;
					btnMuteMic.ToolTipText = "Capture Initialization error: " + ex.Message;
				}));
			}
		}
Beispiel #11
0
        private void SetupVoiceCapture()
        {
            DisableVoiceCapture();

            if (!this.gablarski.IsConnected)
            {
                return;
            }

            try
            {
                if (Settings.VoiceProvider == null)
                {
                    throw new Exception("Capture provider is not set");
                }

                this.voiceCapture = (IAudioCaptureProvider)Activator.CreateInstance(Type.GetType(Settings.VoiceProvider));

                if (String.IsNullOrEmpty(Settings.VoiceDevice) || Settings.VoiceDevice == "Default")
                {
                    this.voiceCapture.Device = this.voiceCapture.DefaultDevice;
                }
                else
                {
                    this.voiceCapture.Device = this.voiceCapture.GetDevices().FirstOrDefault(d => d.Name == Settings.VoiceDevice) ??
                                               this.voiceCapture.DefaultDevice;
                }

                if (this.voiceSource != null)
                {
                    gablarski.Audio.Attach(this.voiceCapture, this.voiceSource, new AudioEngineCaptureOptions
                    {
                        StartVolume        = Settings.VoiceActivationLevel,
                        ContinuationVolume = Settings.VoiceActivationLevel / 2,
                        ContinueThreshold  = TimeSpan.FromMilliseconds(Settings.VoiceActivationContinueThreshold),
                        Mode = (!Settings.UsePushToTalk) ? AudioEngineCaptureMode.Activated : AudioEngineCaptureMode.Explicit
                    });
                }

                BeginInvoke((Action)(() =>
                {
                    if (btnMute.Checked && !this.captureDisabled)
                    {
                        return;
                    }

                    btnMuteMic.Image = Resources.CaptureMuteImage;
                    btnMuteMic.Checked = false;
                    btnMuteMic.Enabled = true;
                    btnMuteMic.ToolTipText = "Mute Microphone";
                    this.captureDisabled = false;
                }));
            }
            catch (Exception ex)
            {
                Program.Raygun.Send(ex, new[] { "capture-init" }, Settings.CurrentSettings);

                if (this.voiceCapture != null)
                {
                    this.voiceCapture.Dispose();
                }

                this.voiceCapture = null;

                BeginInvoke((Action)(() =>
                {
                    this.captureDisabled = true;
                    btnMuteMic.Image = Resources.CaptureMuteImage.ToErrorIcon();
                    btnMuteMic.Checked = true;
                    btnMuteMic.Enabled = false;
                    btnMuteMic.ToolTipText = "Capture Initialization error: " + ex.Message;
                }));
            }
        }
Beispiel #12
0
 public void Mute(IAudioCaptureProvider audioCapture)
 {
     MuteCore(audioCapture, true);
 }
Beispiel #13
0
 public void Unmute(IAudioCaptureProvider audioCapture)
 {
     MuteCore (audioCapture, false);
 }
Beispiel #14
0
        private void MuteCore(IAudioCaptureProvider audioCapture, bool mute)
        {
            if (audioCapture == null)
                throw new ArgumentNullException ("audioCapture");

            lock (captures)
            {
                if (mute)
                    mutedCaptures.Add (audioCapture);
                else
                    mutedCaptures.Add (audioCapture);

                var ps = captures.Values.Where (e => e.AudioCapture == audioCapture);

                foreach (var e in ps)
                    e.Muted = mute;
            }
        }
Beispiel #15
0
 public void Mute(IAudioCaptureProvider audioCapture)
 {
     MuteCore (audioCapture, true);
 }
Beispiel #16
0
        public bool Detach(IAudioCaptureProvider provider)
        {
            if (provider == null)
                throw new ArgumentNullException ("provider");

            bool removed = false;

            lock (captures)
            {
                foreach (var entity in captures.Values.Where (e => e.AudioCapture == provider).ToList())
                {
                    captures.Remove (entity.Source);
                    captureToSourceLookup.Remove (provider);
                    removed = true;
                }

                mutedCaptures.Remove (provider);
            }

            return removed;
        }
Beispiel #17
0
 public void Unmute(IAudioCaptureProvider audioCapture)
 {
     MuteCore(audioCapture, false);
 }
Beispiel #18
0
        public void Setup()
        {
            this.provider = new MockAudioCaptureProvider();
            this.source = AudioSourceTests.GetTestSource();

            var c = new MockConnectionProvider (GablarskiProtocol.Instance).GetClientConnection();

            var client = new MockClientContext (c);
            this.context = client;
            this.sender = new ClientSourceHandler (client, new ClientSourceManager (client));
            this.receiver = (IAudioReceiver)this.sender;
        }
        /// <summary>
        /// Constructs a new <see cref="SamplesAvailableEventArgs"/>
        /// </summary>
        /// <param name="provider">The provider samples are available from.</param>
        /// <param name="available">The number of available samples.</param>
        public SamplesAvailableEventArgs(IAudioCaptureProvider provider, int available)
        {
            if (provider == null)
                throw new ArgumentNullException ("provider");

            Provider = provider;
            Available = available;
        }
Beispiel #20
0
 public void TearDown()
 {
     this.provider = null;
     this.source = null;
     this.receiver = null;
     this.sender = null;
     this.context = null;
 }
Beispiel #21
0
        public void Attach(IAudioCaptureProvider audioCapture, AudioSource source, AudioEngineCaptureOptions options)
        {
            if (audioCapture == null)
                throw new ArgumentNullException ("audioCapture");
            if (source == null)
                throw new ArgumentNullException ("source");
            if (options == null)
                throw new ArgumentNullException ("options");

            if (audioCapture.Device == null)
                audioCapture.Device = audioCapture.DefaultDevice;

            lock (captures)
            {
                audioCapture.SamplesAvailable += OnSamplesAvailable;
                audioCapture.BeginCapture (source.CodecSettings, source.CodecSettings.FrameSize);
                captures[source] = new AudioCaptureEntity (audioCapture, source, options);
                captureToSourceLookup[audioCapture] = source;

                if (this.captureMuted || mutedCaptures.Contains (audioCapture))
                    captures[source].Muted = true;
            }
        }