Exemple #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;
        }
Exemple #2
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);
        }