コード例 #1
0
        public VoiceToolstripButton(VoiceService voices)
        {
            Voices = voices;

            ToolTipText = "Voice Chat";

            Paint += new PaintEventHandler(VoiceToolstripButton_Paint);

            ButtonClick += new EventHandler(VoiceToolstripButton_ButtonClick);
            MouseDown += new MouseEventHandler(VoiceToolstripButton_MouseDown);
            MouseUp += new MouseEventHandler(VoiceToolstripButton_MouseUp);
            OffButton = new ToolStripMenuItem("Off", Res.VoiceRes.VoiceOff, OffButton_Clicked);
            VoiceActivatedButton = new ToolStripMenuItem("Voice Activated", Res.VoiceRes.VoiceVAD, VoiceActivatedButton_Clicked);
            PushtoTalkButton = new ToolStripMenuItem("Push to Talk", Res.VoiceRes.VoicePTT, PushtoTalkButton_Clicked);
            MuteButton = new ToolStripMenuItem("Mute", Res.VoiceRes.VoiceMute, MuteButton_Clicked);
            SettingsButton = new ToolStripMenuItem("Settings", Res.VoiceRes.VoiceSettings, SettingsButton_Clicked);

            DropDownItems.Add(OffButton);
            DropDownItems.Add(VoiceActivatedButton);
            DropDownItems.Add(PushtoTalkButton);
            DropDownItems.Add(MuteButton);
            DropDownItems.Add(SettingsButton);

            WindowID = Voices.Core.RndGen.Next();

            Voices.RegisterWindow(WindowID, new VolumeUpdateHandler(VoiceService_VolumeUpdate));

            OffButton.PerformClick();
        }
コード例 #2
0
ファイル: VoiceSettings.cs プロジェクト: RoelofSol/DeOps
        public VoiceSettings(VoiceService voices)
        {
            InitializeComponent();

            Voices = voices;

            // recording
            for (int i = 0; i < WinMM.waveInGetNumDevs(); i++)
            {
                WinMM.WaveInCaps device = new WinMM.WaveInCaps();

                WinMM.ErrorCheck(WinMM.waveInGetDevCaps(i, ref device, Marshal.SizeOf(device)));

                DeviceInCombo.Items.Add(device.szPname);
            }

            DeviceInCombo.SelectedIndex = 0;

            // playback
            for (int i = 0; i < WinMM.waveOutGetNumDevs(); i++)
            {
                WinMM.WaveOutCaps device = new WinMM.WaveOutCaps();

                WinMM.ErrorCheck(WinMM.waveOutGetDevCaps(i, ref device, Marshal.SizeOf(device)));

                DeviceOutCombo.Items.Add(device.szPname);

            }

            DeviceOutCombo.SelectedIndex = 0;
        }
コード例 #3
0
ファイル: PlayAudio.cs プロジェクト: RoelofSol/DeOps
        public PlayAudio(VoiceService voices, int frameSize, RemoteVoice user)
        {
            Voices = voices;
            User = user;

            CallbackHandler = new WinMM.WaveDelegate(WaveCallback);

            FrameSize = frameSize;
            int sampleRate = 0;

            // if 20ms, at high quality (16khz) is 320 samples at 2 bytes each
            if (FrameSize == 320)
            {
                sampleRate = 16000;
                BufferSize = 320 * 2 * 2; // 2 bytes each frame, 2 channels
                SpeexMode = Speex.SPEEX_MODEID_WB;
            }
            else if(FrameSize == 160)
            {
                sampleRate = 8000;
                BufferSize = 160 * 2 * 2;
                SpeexMode = Speex.SPEEX_MODEID_NB;
            }
            else
            {
                Dispose();
                return;
            }

            try
            {
                // init speex
                Speex.speex_bits_init(ref DecodeBits);
                IntPtr modePtr = Speex.speex_lib_get_mode(SpeexMode);
                SpeexDecoder = Speex.speex_decoder_init(modePtr);

                int tmp = 1;
                Speex.speex_decoder_ctl(SpeexDecoder, Speex.SPEEX_SET_ENH, ref tmp);

                // init wave
                Format = new WinMM.WaveFormat(sampleRate, 16, 2);
                WinMM.ErrorCheck(WinMM.waveOutOpen(out WaveHandle, Voices.PlaybackDevice, Format, CallbackHandler, 0, WinMM.CALLBACK_FUNCTION));

                for (int i = 0; i < BufferCount; i++)
                    Buffers[i] = new PlayBuffer(i, WaveHandle, BufferSize);
            }
            catch (Exception ex)
            {
                Dispose();
                Voices.Core.Network.UpdateLog("Voice", "Error starting playing: " + ex.Message);
            }
        }
コード例 #4
0
ファイル: RecordAudio.cs プロジェクト: RoelofSol/DeOps
        //public IntPtr EchoState;
        public RecordAudio(VoiceService voices)
        {
            Voices = voices;

            CallbackHandler = new WinMM.WaveDelegate(WaveCallback);

            // if 20ms, at high quality (16khz) is 320 samples at 2 bytes each
            if (HighQuality)
            {
                SampleRate = 16000;
                BufferSize = 320 * 2;
                SpeexMode = Speex.SPEEX_MODEID_WB;
            }
            else
            {
                SampleRate = 8000;
                BufferSize = 160 * 2;
                SpeexMode = Speex.SPEEX_MODEID_NB;
            }

            //LastBuffer = new byte[BufferSize];

            try
            {
                InitSpeexEncoder();

                Format = new WinMM.WaveFormat(SampleRate, 16, 1);
                WinMM.ErrorCheck(WinMM.waveInOpen(out WaveHandle, Voices.RecordingDevice, Format, CallbackHandler, 0, WinMM.CALLBACK_FUNCTION));

                for (int i = 0; i < BufferCount; i++)
                    Buffers[i] = new RecordBuffer(i, WaveHandle, BufferSize);

                WinMM.ErrorCheck(WinMM.waveInStart(WaveHandle));
            }
            catch (Exception ex)
            {
                Dispose();
                Voices.Core.Network.UpdateLog("Voice", "Error starting recording: " + ex.Message);
            }
        }