Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / audio_processing / aec / aec_core.h
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10
11 /*
12  * Specifies the interface for the AEC core.
13  */
14
15 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_
16 #define WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_
17
18 #include "webrtc/typedefs.h"
19
20 #define FRAME_LEN 80
21 #define PART_LEN 64               // Length of partition
22 #define PART_LEN1 (PART_LEN + 1)  // Unique fft coefficients
23 #define PART_LEN2 (PART_LEN * 2)  // Length of partition * 2
24
25 typedef float complex_t[2];
26 // For performance reasons, some arrays of complex numbers are replaced by twice
27 // as long arrays of float, all the real parts followed by all the imaginary
28 // ones (complex_t[SIZE] -> float[2][SIZE]). This allows SIMD optimizations and
29 // is better than two arrays (one for the real parts and one for the imaginary
30 // parts) as this other way would require two pointers instead of one and cause
31 // extra register spilling. This also allows the offsets to be calculated at
32 // compile time.
33
34 // Metrics
35 enum {
36   kOffsetLevel = -100
37 };
38
39 typedef struct Stats {
40   float instant;
41   float average;
42   float min;
43   float max;
44   float sum;
45   float hisum;
46   float himean;
47   int counter;
48   int hicounter;
49 } Stats;
50
51 typedef struct AecCore AecCore;
52
53 int WebRtcAec_CreateAec(AecCore** aec);
54 int WebRtcAec_FreeAec(AecCore* aec);
55 int WebRtcAec_InitAec(AecCore* aec, int sampFreq);
56 void WebRtcAec_InitAec_SSE2(void);
57 #if defined(MIPS_FPU_LE)
58 void WebRtcAec_InitAec_mips(void);
59 #endif
60
61 void WebRtcAec_BufferFarendPartition(AecCore* aec, const float* farend);
62 void WebRtcAec_ProcessFrame(AecCore* aec,
63                             const short* nearend,
64                             const short* nearendH,
65                             int knownDelay,
66                             int16_t* out,
67                             int16_t* outH);
68
69 // A helper function to call WebRtc_MoveReadPtr() for all far-end buffers.
70 // Returns the number of elements moved, and adjusts |system_delay| by the
71 // corresponding amount in ms.
72 int WebRtcAec_MoveFarReadPtr(AecCore* aec, int elements);
73
74 // Calculates the median and standard deviation among the delay estimates
75 // collected since the last call to this function.
76 int WebRtcAec_GetDelayMetricsCore(AecCore* self, int* median, int* std);
77
78 // Returns the echo state (1: echo, 0: no echo).
79 int WebRtcAec_echo_state(AecCore* self);
80
81 // Gets statistics of the echo metrics ERL, ERLE, A_NLP.
82 void WebRtcAec_GetEchoStats(AecCore* self,
83                             Stats* erl,
84                             Stats* erle,
85                             Stats* a_nlp);
86 #ifdef WEBRTC_AEC_DEBUG_DUMP
87 void* WebRtcAec_far_time_buf(AecCore* self);
88 #endif
89
90 // Sets local configuration modes.
91 void WebRtcAec_SetConfigCore(AecCore* self,
92                              int nlp_mode,
93                              int metrics_mode,
94                              int delay_logging);
95
96 // Non-zero enables, zero disables.
97 void WebRtcAec_enable_reported_delay(AecCore* self, int enable);
98
99 // Returns non-zero if reported delay is enabled and zero if disabled.
100 int WebRtcAec_reported_delay_enabled(AecCore* self);
101
102 // We now interpret delay correction to mean an extended filter length feature.
103 // We reuse the delay correction infrastructure to avoid changes through to
104 // libjingle. See details along with |DelayCorrection| in
105 // echo_cancellation_impl.h. Non-zero enables, zero disables.
106 void WebRtcAec_enable_delay_correction(AecCore* self, int enable);
107
108 // Returns non-zero if delay correction is enabled and zero if disabled.
109 int WebRtcAec_delay_correction_enabled(AecCore* self);
110
111 // Returns the current |system_delay|, i.e., the buffered difference between
112 // far-end and near-end.
113 int WebRtcAec_system_delay(AecCore* self);
114
115 // Sets the |system_delay| to |value|.  Note that if the value is changed
116 // improperly, there can be a performance regression.  So it should be used with
117 // care.
118 void WebRtcAec_SetSystemDelay(AecCore* self, int delay);
119
120 #endif  // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_