1
/* Copyright (C) 2003 Epic Games
2
Written by Jean-Marc Valin
4
File: speex_preprocess.h
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
11
1. Redistributions of source code must retain the above copyright notice,
12
this list of conditions and the following disclaimer.
14
2. Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in the
16
documentation and/or other materials provided with the distribution.
18
3. The name of the author may not be used to endorse or promote products
19
derived from this software without specific prior written permission.
21
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
POSSIBILITY OF SUCH DAMAGE.
34
#ifndef SPEEX_PREPROCESS_H
35
#define SPEEX_PREPROCESS_H
37
#include "speex/speex_types.h"
45
typedef struct SpeexPreprocessState {
46
int frame_size; /**< Number of samples processed each time */
47
int ps_size; /**< Number of points in the power spectrum */
48
int sampling_rate; /**< Sampling rate of the input/output */
58
float speech_prob_start;
59
float speech_prob_continue;
61
float *frame; /**< Processing frame (2*ps_size) */
62
float *ps; /**< Current power spectrum */
63
float *gain2; /**< Adjusted gains */
64
float *window; /**< Analysis/Synthesis window */
65
float *noise; /**< Noise estimate */
66
float *reverb_estimate; /**< Estimate of reverb energy */
67
float *old_ps; /**< Power spectrum for last frame */
68
float *gain; /**< Ephraim Malah gain */
69
float *prior; /**< A-priori SNR */
70
float *post; /**< A-posteriori SNR */
72
float *S; /**< Smoothed power spectrum */
73
float *Smin; /**< See Cohen paper */
74
float *Stmp; /**< See Cohen paper */
75
float *update_prob; /**< Propability of speech presence for noise update */
77
float *zeta; /**< Smoothed a priori SNR */
81
float *loudness_weight; /**< Perceptual loudness curve */
92
float *inbuf; /**< Input buffer (overlapped analysis) */
93
float *outbuf; /**< Output buffer (for overlap and add) */
97
float loudness; /**< loudness estimate */
98
float loudness2; /**< loudness estimate */
99
int nb_adapt; /**< Number of frames used for adaptation so far */
100
int nb_loudness_adapt; /**< Number of frames used for loudness adaptation so far */
101
int consec_noise; /**< Number of consecutive noise frames */
102
int nb_preprocess; /**< Number of frames processed so far */
103
struct drft_lookup *fft_lookup; /**< Lookup table for the FFT */
105
} SpeexPreprocessState;
107
/** Creates a new preprocessing state */
108
SpeexPreprocessState *speex_preprocess_state_init(int frame_size, int sampling_rate);
110
/** Destroys a denoising state */
111
void speex_preprocess_state_destroy(SpeexPreprocessState *st);
113
/** Preprocess a frame */
114
int speex_preprocess(SpeexPreprocessState *st, spx_int16_t *x, float *echo);
116
/** Preprocess a frame */
117
void speex_preprocess_estimate_update(SpeexPreprocessState *st, spx_int16_t *x, float *echo);
119
/** Used like the ioctl function to control the preprocessor parameters */
120
int speex_preprocess_ctl(SpeexPreprocessState *st, int request, void *ptr);
124
#define SPEEX_PREPROCESS_SET_DENOISE 0
125
#define SPEEX_PREPROCESS_GET_DENOISE 1
127
#define SPEEX_PREPROCESS_SET_AGC 2
128
#define SPEEX_PREPROCESS_GET_AGC 3
130
#define SPEEX_PREPROCESS_SET_VAD 4
131
#define SPEEX_PREPROCESS_GET_VAD 5
133
#define SPEEX_PREPROCESS_SET_AGC_LEVEL 6
134
#define SPEEX_PREPROCESS_GET_AGC_LEVEL 7
136
#define SPEEX_PREPROCESS_SET_DEREVERB 8
137
#define SPEEX_PREPROCESS_GET_DEREVERB 9
139
#define SPEEX_PREPROCESS_SET_DEREVERB_LEVEL 10
140
#define SPEEX_PREPROCESS_GET_DEREVERB_LEVEL 11
142
#define SPEEX_PREPROCESS_SET_DEREVERB_DECAY 12
143
#define SPEEX_PREPROCESS_GET_DEREVERB_DECAY 13
145
#define SPEEX_PREPROCESS_SET_PROB_START 14
146
#define SPEEX_PREPROCESS_GET_PROB_START 15
148
#define SPEEX_PREPROCESS_SET_PROB_CONTINUE 16
149
#define SPEEX_PREPROCESS_GET_PROB_CONTINUE 17