Example #1
0
        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);
            }
        }
Example #2
0
        //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);
            }
        }
Example #3
0
        //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);
            }
        }
Example #4
0
        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);
            }
        }