📄 mus_dtct.c
字号:
/* ITU-T G.729 Annex C+ - Reference C code for floating point implementation of G.729 Annex C+ (integration of Annexes B, D and E) Version 2.1 of October 1999*//* ----------------------------------------------------------------- *//* MUSIC DETECTION MODULE *//* *//* *//* (C) Copyright 1999 : Conexant Systems *//* *//* ----------------------------------------------------------------- *//* File : MUS_DTCT.C*/#include <stdio.h>#include <stdlib.h>#include <math.h>#include "typedef.h"#include "ld8k.h"#include "tab_ld8k.h"#include "ld8cp.h"#include "vad.h"#define sqr(a) ((a)*(a))void init_musdetect(struct musdet_state_t *state){ state->count_music = 0; state->Mcount_music = (F)0.0; state->count_consc = 0; state->MeanPgain = (F)0.5; state->count_pflag = 0; state->Mcount_pflag = (F)0.0; state->count_consc_pflag = 0; state->count_consc_rflag = 0; set_zero(state->mrc, 10); state->MeanSE = (F)0.0;}void musdetect( struct musdet_state_t *state, int rate, FLOAT Energy, FLOAT *rc, int *lags, FLOAT *pgains, int stat_flg, int frm_count, int prev_vad, int *Vad, FLOAT LLenergy){ int i; FLOAT sum1, sum2,std; short PFLAG1, PFLAG2, PFLAG; FLOAT pderr, Lenergy , SD, tmp_vec[10]; FLOAT Thres; pderr =(F)1.0; for (i=0; i< 4; i++) pderr *= ((F)1.0 - rc[i]*rc[i]); dvsub(state->mrc, rc, tmp_vec, 10); SD = dvdot(tmp_vec, tmp_vec, 10); Lenergy = (F)10.0*(FLOAT)log10(pderr*Energy/(F)240.0 +EPSI); if( *Vad == NOISE ){ dvwadd(state->mrc, (F)0.9, rc, (F)0.1, state->mrc, 10); state->MeanSE = (F)0.9 * state->MeanSE + (F)0.1 * Lenergy; } sum1 =(F)0.0; sum2 =(F)0.0; for(i=0; i<5; i++){ sum1 += (FLOAT) lags[i]; sum2 += pgains[i]; } sum1 = sum1/(F)5.0; sum2 = sum2/(F)5.0; std =(F)0.0; for(i=0; i<5; i++) std += sqr(((FLOAT) lags[i] - sum1)); std = (FLOAT)sqrt(std/(F)4.0); state->MeanPgain = (F)0.8 * state->MeanPgain + (F)0.2*sum2; if (rate == G729D) Thres = (F)0.73; else Thres = (F)0.63; if (state->MeanPgain > Thres) PFLAG2 =1; else PFLAG2 =0; if (std < (F)1.30 && state->MeanPgain > (F)0.45) PFLAG1 =1; else PFLAG1 =0; PFLAG= (INT16)( ((INT16)prev_vad & (INT16)(PFLAG1 | PFLAG2))| (INT16)(PFLAG2)); if(rc[1] <= (F)0.45 && rc[1] >= (F)0.0 && state->MeanPgain < (F)0.5) state->count_consc_rflag++; else state->count_consc_rflag = 0; if (stat_flg == 1 && (*Vad == VOICE)) state->count_music++; if ((frm_count%64) == 0 ){ if( frm_count == 64) state->Mcount_music = (FLOAT)state->count_music; else state->Mcount_music = (F)0.9 * state->Mcount_music + (F)0.1 * (FLOAT)state->count_music; } if (state->count_music == 0) state->count_consc++; else state->count_consc = 0; if(state->count_consc > 500 || state->count_consc_rflag > 150) state->Mcount_music = (F)0.0; if ((frm_count%64) == 0) state->count_music = 0; if (PFLAG == 1 ) state->count_pflag++; if ((frm_count%64) == 0){ if (frm_count == 64) state->Mcount_pflag = (FLOAT)state->count_pflag; else { if (state->count_pflag > 25) state->Mcount_pflag = (F)0.98 * state->Mcount_pflag + (F)0.02*(FLOAT)state->count_pflag; else if (state->count_pflag > 20) state->Mcount_pflag = (F)0.95 * state->Mcount_pflag + (F)0.05*(FLOAT)state->count_pflag; else state->Mcount_pflag = (F)0.90 * state->Mcount_pflag + (F)0.10*(FLOAT)state->count_pflag; } } if (state->count_pflag == 0) state->count_consc_pflag++; else state->count_consc_pflag = 0; if (state->count_consc_pflag > 100 || state->count_consc_rflag > 150) state->Mcount_pflag = (F)0.0; if ((frm_count%64) == 0) state->count_pflag = 0; if (rate == G729E){ if (SD > (F)0.15 && (Lenergy - state->MeanSE) > (F)4.0 && (LLenergy > 50.0)) *Vad = VOICE; else if ((SD > (F)0.38 || (Lenergy - state->MeanSE)> (F)4.0) && (LLenergy > 50.0)) *Vad = VOICE; else if ((state->Mcount_pflag >= (F)10.0 || state->Mcount_music >= (F)5.0 || frm_count < 64) && (LLenergy > 7.0)) *Vad = VOICE; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -