1219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard/* 2219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard ** Copyright 2003-2010, VisualOn, Inc. 3219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard ** 4219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard ** Licensed under the Apache License, Version 2.0 (the "License"); 5219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard ** you may not use this file except in compliance with the License. 6219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard ** You may obtain a copy of the License at 7219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard ** 8219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard ** http://www.apache.org/licenses/LICENSE-2.0 9219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard ** 10219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard ** Unless required by applicable law or agreed to in writing, software 11219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard ** distributed under the License is distributed on an "AS IS" BASIS, 12219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard ** See the License for the specific language governing permissions and 14219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard ** limitations under the License. 15219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard */ 16219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 17219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 18219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard/*-------------------------------------------------------------------* 19219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard * WB_VAD_C.H * 20219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard *-------------------------------------------------------------------* 21219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard * Constants for Voice Activity Detection. * 22219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard *-------------------------------------------------------------------*/ 23219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 24219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#ifndef __WB_VAD_C_H__ 25219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define __WB_VAD_C_H__ 26219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 27219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define FRAME_LEN 256 /* Length (samples) of the input frame */ 28219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define COMPLEN 12 /* Number of sub-bands used by VAD */ 29219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 30219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define UNIRSHFT 7 /* = log2(MAX_16/UNITY), UNITY = 256 */ 31219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define SCALE 128 /* (UNITY*UNITY)/512 */ 32219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 33219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define TONE_THR (Word16)(0.65*MAX_16) /* Threshold for tone detection */ 34219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 35219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard/* constants for speech level estimation */ 36219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define SP_EST_COUNT 80 37219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define SP_ACTIVITY_COUNT 25 38219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define ALPHA_SP_UP (Word16)((1.0 - 0.85)*MAX_16) 39219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define ALPHA_SP_DOWN (Word16)((1.0 - 0.85)*MAX_16) 40219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 41219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define NOM_LEVEL 2050 /* about -26 dBov Q15 */ 42219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define SPEECH_LEVEL_INIT NOM_LEVEL /* initial speech level */ 43219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define MIN_SPEECH_LEVEL1 (Word16)(NOM_LEVEL * 0.063) /* NOM_LEVEL -24 dB */ 44219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define MIN_SPEECH_LEVEL2 (Word16)(NOM_LEVEL * 0.2) /* NOM_LEVEL -14 dB */ 45219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define MIN_SPEECH_SNR 4096 /* 0 dB, lowest SNR estimation, Q12 */ 46219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 47219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard/* Time constants for background spectrum update */ 48219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define ALPHA_UP1 (Word16)((1.0 - 0.95)*MAX_16) /* Normal update, upwards: */ 49219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define ALPHA_DOWN1 (Word16)((1.0 - 0.936)*MAX_16) /* Normal update, downwards */ 50219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define ALPHA_UP2 (Word16)((1.0 - 0.985)*MAX_16) /* Forced update, upwards */ 51219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define ALPHA_DOWN2 (Word16)((1.0 - 0.943)*MAX_16) /* Forced update, downwards */ 52219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define ALPHA3 (Word16)((1.0 - 0.95)*MAX_16) /* Update downwards */ 53219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define ALPHA4 (Word16)((1.0 - 0.9)*MAX_16) /* For stationary estimation */ 54219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define ALPHA5 (Word16)((1.0 - 0.5)*MAX_16) /* For stationary estimation */ 55219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 56219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard/* Constants for VAD threshold */ 57219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define THR_MIN (Word16)(1.6*SCALE) /* Minimum threshold */ 58219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define THR_HIGH (Word16)(6*SCALE) /* Highest threshold */ 59219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define THR_LOW (Word16)(1.7*SCALE) /* Lowest threshold */ 60219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define NO_P1 31744 /* ilog2(1), Noise level for highest threshold */ 61219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define NO_P2 19786 /* ilog2(0.1*MAX_16), Noise level for lowest threshold */ 62219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define NO_SLOPE (Word16)(MAX_16*(float)(THR_LOW-THR_HIGH)/(float)(NO_P2-NO_P1)) 63219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 64219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define SP_CH_MIN (Word16)(-0.75*SCALE) 65219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define SP_CH_MAX (Word16)(0.75*SCALE) 66219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define SP_P1 22527 /* ilog2(NOM_LEVEL/4) */ 67219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define SP_P2 17832 /* ilog2(NOM_LEVEL*4) */ 68219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define SP_SLOPE (Word16)(MAX_16*(float)(SP_CH_MAX-SP_CH_MIN)/(float)(SP_P2-SP_P1)) 69219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 70219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard/* Constants for hangover length */ 71219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define HANG_HIGH 12 /* longest hangover */ 72219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define HANG_LOW 2 /* shortest hangover */ 73219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define HANG_P1 THR_LOW /* threshold for longest hangover */ 74219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define HANG_P2 (Word16)(4*SCALE) /* threshold for shortest hangover */ 75219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define HANG_SLOPE (Word16)(MAX_16*(float)(HANG_LOW-HANG_HIGH)/(float)(HANG_P2-HANG_P1)) 76219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 77219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard/* Constants for burst length */ 78219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define BURST_HIGH 8 /* longest burst length */ 79219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define BURST_LOW 3 /* shortest burst length */ 80219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define BURST_P1 THR_HIGH /* threshold for longest burst */ 81219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define BURST_P2 THR_LOW /* threshold for shortest burst */ 82219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define BURST_SLOPE (Word16)(MAX_16*(float)(BURST_LOW-BURST_HIGH)/(float)(BURST_P2-BURST_P1)) 83219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 84219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard/* Parameters for background spectrum recovery function */ 85219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define STAT_COUNT 20 /* threshold of stationary detection counter */ 86219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 87219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define STAT_THR_LEVEL 184 /* Threshold level for stationarity detection */ 88219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define STAT_THR 1000 /* Threshold for stationarity detection */ 89219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 90219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard/* Limits for background noise estimate */ 91219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define NOISE_MIN 40 /* minimum */ 92219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define NOISE_MAX 20000 /* maximum */ 93219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define NOISE_INIT 150 /* initial */ 94219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 95219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard/* Thresholds for signal power (now calculated on 2 frames) */ 96219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define VAD_POW_LOW (Word32)30000L /* If input power is lower than this, VAD is set to 0 */ 97219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define POW_TONE_THR (Word32)686080L /* If input power is lower,tone detection flag is ignored */ 98219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 99219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard/* Constants for the filter bank */ 100219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define COEFF3 13363 /* coefficient for the 3rd order filter */ 101219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define COEFF5_1 21955 /* 1st coefficient the for 5th order filter */ 102219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define COEFF5_2 6390 /* 2nd coefficient the for 5th order filter */ 103219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define F_5TH_CNT 5 /* number of 5th order filters */ 104219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#define F_3TH_CNT 6 /* number of 3th order filters */ 105219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 106219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard#endif //__WB_VAD_C_H__ 107219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 108219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 109219e2627f1e062c10645664b0d2470d4dfaf5083Mans Rullgard 110