Пример #1
0
        public MicEncoder(AudioEncodeCfg audioCfg, Action <MediaFrame> callback)
        {
            _audioCfg  = audioCfg;
            _channels  = audioCfg.channel;
            _frequency = audioCfg.frequency;
            _capturer  = new MicCapturer(audioCfg.micId, _channels, _frequency, audioCfg.samples, MicCapturer_CallBack);
            if (audioCfg.encodeName.EqIgnoreCase("SPEX"))
            {
                _speex = new Speex(4);
            }
            else if (audioCfg.encodeName.EqIgnoreCase("AAC_"))
            {
                if (audioCfg.Params.ContainsKey("UseLastFaacImp") && FaacImp.LastFaacImp != null)
                {
                    _faacImp = FaacImp.LastFaacImp;
                    _faacImp.Encode(new byte[2048]);
                    _faacImp.Encode(new byte[2048]);
                    _faacImp.Encode(new byte[2048]);
                    _faacImp.Encode(new byte[2048]);
                    _faacImp.Encode(new byte[2048]);
                }
                else
                {
                    _faacImp = new FaacImp(_channels, _frequency, audioCfg.bitrate);
                }
            }

            _callBack = callback;
        }
Пример #2
0
 public void SpeexVAD(int vadProbStart = 80, int vadProbContinue = 65)
 {
     if (_isDisoseing || _isDisosed)
     {
         return;
     }
     Speex.SpeexVAD(pSpx, vadProbStart, vadProbContinue);
 }
Пример #3
0
 public void SpeexDenoise(int noiseSuppress = -25)
 {
     if (_isDisoseing || _isDisosed)
     {
         return;
     }
     Speex.SpeexDenoise(pSpx, noiseSuppress);
 }
Пример #4
0
 public void SpeexAGC(int level = 24000)
 {
     if (_isDisoseing || _isDisosed)
     {
         return;
     }
     Speex.SpeexAGC(pSpx, level);
 }
Пример #5
0
 public Speex(int quality, int samples = 160)
 {
     this.Samples = samples;
     if (quality < 0 || quality > 10)
     {
         throw new Exception("quality value must be between 0 and 10.");
     }
     pSpx = Speex.SpeexOpen(quality);
 }
Пример #6
0
        //解码
        public byte[] Decode(byte[] data)
        {
            if (_isDisoseing || _isDisosed)
            {
                return(null);
            }
            var pData   = FunctionEx.BytesToIntPtr(data);
            var pOut    = Marshal.AllocHGlobal(Samples * 2);
            var decSize = Speex.SpeexDecode(this.pSpx, data.Length, pData, pOut);
            var bytes   = FunctionEx.IntPtrToBytes(pOut, 0, decSize);

            Marshal.FreeHGlobal(pOut);
            Marshal.FreeHGlobal(pData);
            return(bytes);
        }
Пример #7
0
        //编码
        public byte[] Encode(byte[] data)
        {
            if (_isDisoseing || _isDisosed)
            {
                return(null);
            }
            var pData   = FunctionEx.BytesToIntPtr(data);
            var pOut    = Marshal.AllocHGlobal(200);
            var encSize = Speex.SpeexEncode(this.pSpx, pData, pOut);

            byte[] buffer = FunctionEx.IntPtrToBytes(pOut, 0, encSize);
            Marshal.FreeHGlobal(pOut);
            Marshal.FreeHGlobal(pData);
            return(buffer);
        }
Пример #8
0
 public void Dispose()
 {
     _isDisoseing = true;
     try
     {
         Speex.SpeexClose(this.pSpx);
     }
     catch
     {
     }
     finally
     {
         _isDisoseing = false;
         _isDisosed   = true;
     }
 }
Пример #9
0
        public byte[] Cancellation(byte[] play, byte[] mic)
        {
            if (_isDisoseing || _isDisosed)
            {
                return(null);
            }
            var pPlay = FunctionEx.BytesToIntPtr(play);
            var pMic  = FunctionEx.BytesToIntPtr(mic);
            var pOut  = Marshal.AllocHGlobal(mic.Length);

            Speex.SpeexEchoCancellation(pSpx, pPlay, pMic, pOut);
            var data = FunctionEx.IntPtrToBytes(pOut, 0, mic.Length);

            Marshal.FreeHGlobal(pPlay);
            Marshal.FreeHGlobal(pMic);
            Marshal.FreeHGlobal(pOut);
            return(data);
        }