Beispiel #1
0
        /// <summary>
        /// 解压Speex音频数据流
        /// </summary>
        /// <param name="input">需要解压的数据流</param>
        /// <returns>解压后的正常音频数据</returns>
        public byte[] DecodeBase(byte[] input)
        {
            SpeexBitsApi.Speex_bits_reset(ref _decodeSpeexBits);
            SpeexBitsApi.Speex_bits_read_from(ref _decodeSpeexBits, input, input.Length);
            //int i = SpeexBitsApi.Speex_bits_nbytes(ref _decodeSpeexBits);
            short[] buffer = new short[160];
            int     len    = SpeexDecodeApi.Speex_decode_int(_decodeStateIntptr, ref _decodeSpeexBits, buffer);

            return(SpeexHelper.ShortsToBytes(buffer));
        }
        /// <summary>
        /// 执行预处理
        /// </summary>
        /// <returns>预处理后的音频数据</returns>
        public byte[] Run(byte[] input)
        {
            if (input == null || input.Length > _frameSize * 2)
            {
                throw new Exception($"值不能为空且每次压缩的数据大小不能超过{_frameSize * 2}个字节");
            }
            input = SpeexHelper.PadArr(input, _frameSize * 2);
            short[] sShort = SpeexHelper.BytesToShorts(input);
            int     result = SpeexPreprocessApi.Speex_preprocess_run(preprocessMemAddress, sShort);

            byte[] output = SpeexHelper.ShortsToBytes(sShort);
            return(output);
        }