Android移植Speex回声消除

最近弄了很久的Android回声消除,今天终于有电成效,顺便拿来分享分享,希望对大家有帮助


Speex不用介绍了,这里介绍了如何使用Speex进行回声消除,下面直接上代码

speex_jni.cpp

//
// Created by jiaokx on 2015/11/30.
//

#include "com_example_speex1_Speex.h"
#include <string.h>
#include <unistd.h>

//#include <speex/speex.h>
//#include <speex/speex_echo.h>

/*start*/
#include <fcntl.h>
#include <speex/speex.h>
#include <speex/speex_echo.h>
#include <speex/speex_preprocess.h>
#include <speex/speex_bits.h>
#include <speex/speex_buffer.h>
#include <speex/speex_header.h>
#include <speex/speex_types.h>

// the header length of the RTP frame (must skip when en/decoding)
static const int rtp_header = 0;

int codec_status = 0;

const int CODEC_OPENED = 1;
const int CODEC_CLOSED = 0;

int aec_status = 0;

const int AEC_OPENED = 1;
const int AEC_CLOSED = 0;

SpeexEchoState *echoState;
SpeexPreprocessState *den;
int sampleRate = 8000;
/*end*/

static int codec_open = 0;

static int dec_frame_size;
static int enc_frame_size;

static SpeexBits ebits, dbits;
void *enc_state;
void *dec_state;

static JavaVM *gJavaVM;

extern "C" jint  Java_com_example_speex1_Speex_open(
        JNIEnv *env, jobject obj, jint compression) {
    int tmp = 0;
    if (codec_open++ != 0)
        return (jint) 0;

    speex_bits_init(&ebits);
    speex_bits_init(&dbits);

    enc_state = speex_encoder_init(&speex_nb_mode);
    dec_state = speex_decoder_init(&speex_nb_mode);

    tmp = compression;
    speex_encoder_ctl(enc_state, SPEEX_SET_QUALITY, &tmp);
    speex_encoder_ctl(enc_state, SPEEX_GET_FRAME_SIZE, &enc_frame_size);
    speex_decoder_ctl(dec_state, SPEEX_GET_FRAME_SIZE, &dec_frame_size);

    SpeexPreprocessState * m_st;
    m_st = speex_preprocess_state_init(enc_frame_size, sampleRate);
    int denoise = 1;
    int noiseSuppress = -25;
    speex_preprocess_ctl(m_st, SPEEX_PREPROCESS_SET_DENOISE, &denoise);
  speex_preprocess_ctl(m_st, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS,&noiseSuppress);
 int agc = 1;
        float q=24000;
        //actually default is 8000(0,32768),here make it louder for voice is not loudy enough by default. 8000
        speex_preprocess_ctl(m_st, SPEEX_PREPROCESS_SET_AGC, &agc);//增益
        speex_preprocess_ctl(m_st, SPEEX_PREPROCESS_SET_AGC_LEVEL,&q);

        int vad = 1;
        int vadProbStart = 80;
        
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值