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.
41
typedef struct SpeexPreprocessState {
42
int frame_size; /**< Number of samples processed each time */
43
int ps_size; /**< Number of points in the power spectrum */
44
int sampling_rate; /**< Sampling rate of the input/output */
52
float *frame; /**< Processing frame (2*ps_size) */
53
float *ps; /**< Current power spectrum */
54
float *gain2; /**< Adjusted gains */
55
float *window; /**< Analysis/Synthesis window */
56
float *noise; /**< Noise estimate */
57
float *old_ps; /**< Power spectrum for last frame */
58
float *gain; /**< Ephraim Malah gain */
59
float *prior; /**< A-priori SNR */
60
float *post; /**< A-posteriori SNR */
62
float *S; /**< Smoothed power spectrum */
63
float *Smin; /**< See Cohen paper */
64
float *Stmp; /**< See Cohen paper */
65
float *update_prob; /**< Propability of speech presence for noise update */
67
float *zeta; /**< Smoothed a priori SNR */
71
float *loudness_weight; /**< Perceptual loudness curve */
82
float *inbuf; /**< Input buffer (overlapped analysis) */
83
float *outbuf; /**< Output buffer (for overlap and add) */
87
float loudness; /**< loudness estimate */
88
float loudness2; /**< loudness estimate */
89
int nb_adapt; /**< Number of frames used for adaptation so far */
90
int nb_loudness_adapt; /**< Number of frames used for loudness adaptation so far */
91
int consec_noise; /**< Number of consecutive noise frames */
92
int nb_preprocess; /**< Number of frames processed so far */
93
struct drft_lookup *fft_lookup; /**< Lookup table for the FFT */
95
} SpeexPreprocessState;
97
/** Creates a new preprocessing state */
98
SpeexPreprocessState *speex_preprocess_state_init(int frame_size, int sampling_rate);
100
/** Destroys a denoising state */
101
void speex_preprocess_state_destroy(SpeexPreprocessState *st);
103
/** Preprocess a frame */
104
int speex_preprocess(SpeexPreprocessState *st, short *x, float *noise);
106
/** Preprocess a frame */
107
void speex_preprocess_estimate_update(SpeexPreprocessState *st, short *x, float *noise);
109
/** Used like the ioctl function to control the preprocessor parameters */
110
int speex_preprocess_ctl(SpeexPreprocessState *st, int request, void *ptr);
114
#define SPEEX_PREPROCESS_SET_DENOISE 0
115
#define SPEEX_PREPROCESS_GET_DENOISE 1
117
#define SPEEX_PREPROCESS_SET_AGC 2
118
#define SPEEX_PREPROCESS_GET_AGC 3
120
#define SPEEX_PREPROCESS_SET_VAD 4
121
#define SPEEX_PREPROCESS_GET_VAD 5
123
#define SPEEX_PREPROCESS_SET_AGC_LEVEL 6
124
#define SPEEX_PREPROCESS_GET_AGC_LEVEL 7