153a5a1b3Sopenharmony_ci/* Copyright (C) 2003 Epic Games
253a5a1b3Sopenharmony_ci   Written by Jean-Marc Valin */
353a5a1b3Sopenharmony_ci/**
453a5a1b3Sopenharmony_ci *  @file speex_preprocess.h
553a5a1b3Sopenharmony_ci *  @brief Speex preprocessor. The preprocess can do noise suppression,
653a5a1b3Sopenharmony_ci * residual echo suppression (after using the echo canceller), automatic
753a5a1b3Sopenharmony_ci * gain control (AGC) and voice activity detection (VAD).
853a5a1b3Sopenharmony_ci*/
953a5a1b3Sopenharmony_ci/*
1053a5a1b3Sopenharmony_ci   Redistribution and use in source and binary forms, with or without
1153a5a1b3Sopenharmony_ci   modification, are permitted provided that the following conditions are
1253a5a1b3Sopenharmony_ci   met:
1353a5a1b3Sopenharmony_ci
1453a5a1b3Sopenharmony_ci   1. Redistributions of source code must retain the above copyright notice,
1553a5a1b3Sopenharmony_ci   this list of conditions and the following disclaimer.
1653a5a1b3Sopenharmony_ci
1753a5a1b3Sopenharmony_ci   2. Redistributions in binary form must reproduce the above copyright
1853a5a1b3Sopenharmony_ci   notice, this list of conditions and the following disclaimer in the
1953a5a1b3Sopenharmony_ci   documentation and/or other materials provided with the distribution.
2053a5a1b3Sopenharmony_ci
2153a5a1b3Sopenharmony_ci   3. The name of the author may not be used to endorse or promote products
2253a5a1b3Sopenharmony_ci   derived from this software without specific prior written permission.
2353a5a1b3Sopenharmony_ci
2453a5a1b3Sopenharmony_ci   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2553a5a1b3Sopenharmony_ci   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2653a5a1b3Sopenharmony_ci   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2753a5a1b3Sopenharmony_ci   DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
2853a5a1b3Sopenharmony_ci   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2953a5a1b3Sopenharmony_ci   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3053a5a1b3Sopenharmony_ci   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3153a5a1b3Sopenharmony_ci   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3253a5a1b3Sopenharmony_ci   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
3353a5a1b3Sopenharmony_ci   ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3453a5a1b3Sopenharmony_ci   POSSIBILITY OF SUCH DAMAGE.
3553a5a1b3Sopenharmony_ci*/
3653a5a1b3Sopenharmony_ci
3753a5a1b3Sopenharmony_ci#ifndef SPEEX_PREPROCESS_H
3853a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_H
3953a5a1b3Sopenharmony_ci/** @defgroup SpeexPreprocessState SpeexPreprocessState: The Speex preprocessor
4053a5a1b3Sopenharmony_ci *  This is the Speex preprocessor. The preprocess can do noise suppression,
4153a5a1b3Sopenharmony_ci * residual echo suppression (after using the echo canceller), automatic
4253a5a1b3Sopenharmony_ci * gain control (AGC) and voice activity detection (VAD).
4353a5a1b3Sopenharmony_ci *  @{
4453a5a1b3Sopenharmony_ci */
4553a5a1b3Sopenharmony_ci
4653a5a1b3Sopenharmony_ci#include "speexdsp_types.h"
4753a5a1b3Sopenharmony_ci
4853a5a1b3Sopenharmony_ci#ifdef __cplusplus
4953a5a1b3Sopenharmony_ciextern "C" {
5053a5a1b3Sopenharmony_ci#endif
5153a5a1b3Sopenharmony_ci
5253a5a1b3Sopenharmony_ci/** State of the preprocessor (one per channel). Should never be accessed directly. */
5353a5a1b3Sopenharmony_cistruct SpeexPreprocessState_;
5453a5a1b3Sopenharmony_ci
5553a5a1b3Sopenharmony_ci/** State of the preprocessor (one per channel). Should never be accessed directly. */
5653a5a1b3Sopenharmony_citypedef struct SpeexPreprocessState_ SpeexPreprocessState;
5753a5a1b3Sopenharmony_ci
5853a5a1b3Sopenharmony_ci
5953a5a1b3Sopenharmony_ci/** Creates a new preprocessing state. You MUST create one state per channel processed.
6053a5a1b3Sopenharmony_ci * @param frame_size Number of samples to process at one time (should correspond to 10-20 ms). Must be
6153a5a1b3Sopenharmony_ci * the same value as that used for the echo canceller for residual echo cancellation to work.
6253a5a1b3Sopenharmony_ci * @param sampling_rate Sampling rate used for the input.
6353a5a1b3Sopenharmony_ci * @return Newly created preprocessor state
6453a5a1b3Sopenharmony_ci*/
6553a5a1b3Sopenharmony_ciSpeexPreprocessState *speex_preprocess_state_init(int frame_size, int sampling_rate);
6653a5a1b3Sopenharmony_ci
6753a5a1b3Sopenharmony_ci/** Destroys a preprocessor state
6853a5a1b3Sopenharmony_ci * @param st Preprocessor state to destroy
6953a5a1b3Sopenharmony_ci*/
7053a5a1b3Sopenharmony_civoid speex_preprocess_state_destroy(SpeexPreprocessState *st);
7153a5a1b3Sopenharmony_ci
7253a5a1b3Sopenharmony_ci/** Preprocess a frame
7353a5a1b3Sopenharmony_ci * @param st Preprocessor state
7453a5a1b3Sopenharmony_ci * @param x Audio sample vector (in and out). Must be same size as specified in speex_preprocess_state_init().
7553a5a1b3Sopenharmony_ci * @return Bool value for voice activity (1 for speech, 0 for noise/silence), ONLY if VAD turned on.
7653a5a1b3Sopenharmony_ci*/
7753a5a1b3Sopenharmony_ciint speex_preprocess_run(SpeexPreprocessState *st, spx_int16_t *x);
7853a5a1b3Sopenharmony_ci
7953a5a1b3Sopenharmony_ci/** Preprocess a frame (deprecated, use speex_preprocess_run() instead)*/
8053a5a1b3Sopenharmony_ciint speex_preprocess(SpeexPreprocessState *st, spx_int16_t *x, spx_int32_t *echo);
8153a5a1b3Sopenharmony_ci
8253a5a1b3Sopenharmony_ci/** Update preprocessor state, but do not compute the output
8353a5a1b3Sopenharmony_ci * @param st Preprocessor state
8453a5a1b3Sopenharmony_ci * @param x Audio sample vector (in only). Must be same size as specified in speex_preprocess_state_init().
8553a5a1b3Sopenharmony_ci*/
8653a5a1b3Sopenharmony_civoid speex_preprocess_estimate_update(SpeexPreprocessState *st, spx_int16_t *x);
8753a5a1b3Sopenharmony_ci
8853a5a1b3Sopenharmony_ci/** Used like the ioctl function to control the preprocessor parameters
8953a5a1b3Sopenharmony_ci * @param st Preprocessor state
9053a5a1b3Sopenharmony_ci * @param request ioctl-type request (one of the SPEEX_PREPROCESS_* macros)
9153a5a1b3Sopenharmony_ci * @param ptr Data exchanged to-from function
9253a5a1b3Sopenharmony_ci * @return 0 if no error, -1 if request in unknown
9353a5a1b3Sopenharmony_ci*/
9453a5a1b3Sopenharmony_ciint speex_preprocess_ctl(SpeexPreprocessState *st, int request, void *ptr);
9553a5a1b3Sopenharmony_ci
9653a5a1b3Sopenharmony_ci
9753a5a1b3Sopenharmony_ci
9853a5a1b3Sopenharmony_ci/** Set preprocessor denoiser state */
9953a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_DENOISE 0
10053a5a1b3Sopenharmony_ci/** Get preprocessor denoiser state */
10153a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_DENOISE 1
10253a5a1b3Sopenharmony_ci
10353a5a1b3Sopenharmony_ci/** Set preprocessor Automatic Gain Control state */
10453a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_AGC 2
10553a5a1b3Sopenharmony_ci/** Get preprocessor Automatic Gain Control state */
10653a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_AGC 3
10753a5a1b3Sopenharmony_ci
10853a5a1b3Sopenharmony_ci/** Set preprocessor Voice Activity Detection state */
10953a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_VAD 4
11053a5a1b3Sopenharmony_ci/** Get preprocessor Voice Activity Detection state */
11153a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_VAD 5
11253a5a1b3Sopenharmony_ci
11353a5a1b3Sopenharmony_ci/** Set preprocessor Automatic Gain Control level (float) */
11453a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_AGC_LEVEL 6
11553a5a1b3Sopenharmony_ci/** Get preprocessor Automatic Gain Control level (float) */
11653a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_AGC_LEVEL 7
11753a5a1b3Sopenharmony_ci
11853a5a1b3Sopenharmony_ci/** Set preprocessor dereverb state */
11953a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_DEREVERB 8
12053a5a1b3Sopenharmony_ci/** Get preprocessor dereverb state */
12153a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_DEREVERB 9
12253a5a1b3Sopenharmony_ci
12353a5a1b3Sopenharmony_ci/** Set preprocessor dereverb level */
12453a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_DEREVERB_LEVEL 10
12553a5a1b3Sopenharmony_ci/** Get preprocessor dereverb level */
12653a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_DEREVERB_LEVEL 11
12753a5a1b3Sopenharmony_ci
12853a5a1b3Sopenharmony_ci/** Set preprocessor dereverb decay */
12953a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_DEREVERB_DECAY 12
13053a5a1b3Sopenharmony_ci/** Get preprocessor dereverb decay */
13153a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_DEREVERB_DECAY 13
13253a5a1b3Sopenharmony_ci
13353a5a1b3Sopenharmony_ci/** Set probability required for the VAD to go from silence to voice */
13453a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_PROB_START 14
13553a5a1b3Sopenharmony_ci/** Get probability required for the VAD to go from silence to voice */
13653a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_PROB_START 15
13753a5a1b3Sopenharmony_ci
13853a5a1b3Sopenharmony_ci/** Set probability required for the VAD to stay in the voice state (integer percent) */
13953a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_PROB_CONTINUE 16
14053a5a1b3Sopenharmony_ci/** Get probability required for the VAD to stay in the voice state (integer percent) */
14153a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_PROB_CONTINUE 17
14253a5a1b3Sopenharmony_ci
14353a5a1b3Sopenharmony_ci/** Set maximum attenuation of the noise in dB (negative number) */
14453a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_NOISE_SUPPRESS 18
14553a5a1b3Sopenharmony_ci/** Get maximum attenuation of the noise in dB (negative number) */
14653a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_NOISE_SUPPRESS 19
14753a5a1b3Sopenharmony_ci
14853a5a1b3Sopenharmony_ci/** Set maximum attenuation of the residual echo in dB (negative number) */
14953a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_ECHO_SUPPRESS 20
15053a5a1b3Sopenharmony_ci/** Get maximum attenuation of the residual echo in dB (negative number) */
15153a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_ECHO_SUPPRESS 21
15253a5a1b3Sopenharmony_ci
15353a5a1b3Sopenharmony_ci/** Set maximum attenuation of the residual echo in dB when near end is active (negative number) */
15453a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_ECHO_SUPPRESS_ACTIVE 22
15553a5a1b3Sopenharmony_ci/** Get maximum attenuation of the residual echo in dB when near end is active (negative number) */
15653a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_ECHO_SUPPRESS_ACTIVE 23
15753a5a1b3Sopenharmony_ci
15853a5a1b3Sopenharmony_ci/** Set the corresponding echo canceller state so that residual echo suppression can be performed (NULL for no residual echo suppression) */
15953a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_ECHO_STATE 24
16053a5a1b3Sopenharmony_ci/** Get the corresponding echo canceller state */
16153a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_ECHO_STATE 25
16253a5a1b3Sopenharmony_ci
16353a5a1b3Sopenharmony_ci/** Set maximal gain increase in dB/second (int32) */
16453a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_AGC_INCREMENT 26
16553a5a1b3Sopenharmony_ci
16653a5a1b3Sopenharmony_ci/** Get maximal gain increase in dB/second (int32) */
16753a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_AGC_INCREMENT 27
16853a5a1b3Sopenharmony_ci
16953a5a1b3Sopenharmony_ci/** Set maximal gain decrease in dB/second (int32) */
17053a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_AGC_DECREMENT 28
17153a5a1b3Sopenharmony_ci
17253a5a1b3Sopenharmony_ci/** Get maximal gain decrease in dB/second (int32) */
17353a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_AGC_DECREMENT 29
17453a5a1b3Sopenharmony_ci
17553a5a1b3Sopenharmony_ci/** Set maximal gain in dB (int32) */
17653a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_AGC_MAX_GAIN 30
17753a5a1b3Sopenharmony_ci
17853a5a1b3Sopenharmony_ci/** Get maximal gain in dB (int32) */
17953a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_AGC_MAX_GAIN 31
18053a5a1b3Sopenharmony_ci
18153a5a1b3Sopenharmony_ci/*  Can't set loudness */
18253a5a1b3Sopenharmony_ci/** Get loudness */
18353a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_AGC_LOUDNESS 33
18453a5a1b3Sopenharmony_ci
18553a5a1b3Sopenharmony_ci/*  Can't set gain */
18653a5a1b3Sopenharmony_ci/** Get current gain (int32 percent) */
18753a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_AGC_GAIN 35
18853a5a1b3Sopenharmony_ci
18953a5a1b3Sopenharmony_ci/*  Can't set spectrum size */
19053a5a1b3Sopenharmony_ci/** Get spectrum size for power spectrum (int32) */
19153a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_PSD_SIZE 37
19253a5a1b3Sopenharmony_ci
19353a5a1b3Sopenharmony_ci/*  Can't set power spectrum */
19453a5a1b3Sopenharmony_ci/** Get power spectrum (int32[] of squared values) */
19553a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_PSD 39
19653a5a1b3Sopenharmony_ci
19753a5a1b3Sopenharmony_ci/*  Can't set noise size */
19853a5a1b3Sopenharmony_ci/** Get spectrum size for noise estimate (int32)  */
19953a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_NOISE_PSD_SIZE 41
20053a5a1b3Sopenharmony_ci
20153a5a1b3Sopenharmony_ci/*  Can't set noise estimate */
20253a5a1b3Sopenharmony_ci/** Get noise estimate (int32[] of squared values) */
20353a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_NOISE_PSD 43
20453a5a1b3Sopenharmony_ci
20553a5a1b3Sopenharmony_ci/* Can't set speech probability */
20653a5a1b3Sopenharmony_ci/** Get speech probability in last frame (int32).  */
20753a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_PROB 45
20853a5a1b3Sopenharmony_ci
20953a5a1b3Sopenharmony_ci/** Set preprocessor Automatic Gain Control level (int32) */
21053a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_SET_AGC_TARGET 46
21153a5a1b3Sopenharmony_ci/** Get preprocessor Automatic Gain Control level (int32) */
21253a5a1b3Sopenharmony_ci#define SPEEX_PREPROCESS_GET_AGC_TARGET 47
21353a5a1b3Sopenharmony_ci
21453a5a1b3Sopenharmony_ci#ifdef __cplusplus
21553a5a1b3Sopenharmony_ci}
21653a5a1b3Sopenharmony_ci#endif
21753a5a1b3Sopenharmony_ci
21853a5a1b3Sopenharmony_ci/** @}*/
21953a5a1b3Sopenharmony_ci#endif
220