Home | History | Annotate | Download | only in aec
      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 <stddef.h>
     19 
     20 #include "webrtc/typedefs.h"
     21 
     22 #define FRAME_LEN 80
     23 #define PART_LEN 64               // Length of partition
     24 #define PART_LEN1 (PART_LEN + 1)  // Unique fft coefficients
     25 #define PART_LEN2 (PART_LEN * 2)  // Length of partition * 2
     26 #define NUM_HIGH_BANDS_MAX  2     // Max number of high bands
     27 
     28 typedef float complex_t[2];
     29 // For performance reasons, some arrays of complex numbers are replaced by twice
     30 // as long arrays of float, all the real parts followed by all the imaginary
     31 // ones (complex_t[SIZE] -> float[2][SIZE]). This allows SIMD optimizations and
     32 // is better than two arrays (one for the real parts and one for the imaginary
     33 // parts) as this other way would require two pointers instead of one and cause
     34 // extra register spilling. This also allows the offsets to be calculated at
     35 // compile time.
     36 
     37 // Metrics
     38 enum {
     39   kOffsetLevel = -100
     40 };
     41 
     42 typedef struct Stats {
     43   float instant;
     44   float average;
     45   float min;
     46   float max;
     47   float sum;
     48   float hisum;
     49   float himean;
     50   int counter;
     51   int hicounter;
     52 } Stats;
     53 
     54 typedef struct AecCore AecCore;
     55 
     56 AecCore* WebRtcAec_CreateAec();  // Returns NULL on error.
     57 void WebRtcAec_FreeAec(AecCore* aec);
     58 int WebRtcAec_InitAec(AecCore* aec, int sampFreq);
     59 void WebRtcAec_InitAec_SSE2(void);
     60 #if defined(MIPS_FPU_LE)
     61 void WebRtcAec_InitAec_mips(void);
     62 #endif
     63 #if defined(WEBRTC_DETECT_NEON) || defined(WEBRTC_HAS_NEON)
     64 void WebRtcAec_InitAec_neon(void);
     65 #endif
     66 
     67 void WebRtcAec_BufferFarendPartition(AecCore* aec, const float* farend);
     68 void WebRtcAec_ProcessFrames(AecCore* aec,
     69                              const float* const* nearend,
     70                              size_t num_bands,
     71                              size_t num_samples,
     72                              int knownDelay,
     73                              float* const* out);
     74 
     75 // A helper function to call WebRtc_MoveReadPtr() for all far-end buffers.
     76 // Returns the number of elements moved, and adjusts |system_delay| by the
     77 // corresponding amount in ms.
     78 int WebRtcAec_MoveFarReadPtr(AecCore* aec, int elements);
     79 
     80 // Calculates the median, standard deviation and amount of poor values among the
     81 // delay estimates aggregated up to the first call to the function. After that
     82 // first call the metrics are aggregated and updated every second. With poor
     83 // values we mean values that most likely will cause the AEC to perform poorly.
     84 // TODO(bjornv): Consider changing tests and tools to handle constant
     85 // constant aggregation window throughout the session instead.
     86 int WebRtcAec_GetDelayMetricsCore(AecCore* self, int* median, int* std,
     87                                   float* fraction_poor_delays);
     88 
     89 // Returns the echo state (1: echo, 0: no echo).
     90 int WebRtcAec_echo_state(AecCore* self);
     91 
     92 // Gets statistics of the echo metrics ERL, ERLE, A_NLP.
     93 void WebRtcAec_GetEchoStats(AecCore* self,
     94                             Stats* erl,
     95                             Stats* erle,
     96                             Stats* a_nlp);
     97 #ifdef WEBRTC_AEC_DEBUG_DUMP
     98 void* WebRtcAec_far_time_buf(AecCore* self);
     99 #endif
    100 
    101 // Sets local configuration modes.
    102 void WebRtcAec_SetConfigCore(AecCore* self,
    103                              int nlp_mode,
    104                              int metrics_mode,
    105                              int delay_logging);
    106 
    107 // Non-zero enables, zero disables.
    108 void WebRtcAec_enable_delay_agnostic(AecCore* self, int enable);
    109 
    110 // Returns non-zero if delay agnostic (i.e., signal based delay estimation) is
    111 // enabled and zero if disabled.
    112 int WebRtcAec_delay_agnostic_enabled(AecCore* self);
    113 
    114 // Enables or disables extended filter mode. Non-zero enables, zero disables.
    115 void WebRtcAec_enable_extended_filter(AecCore* self, int enable);
    116 
    117 // Returns non-zero if extended filter mode is enabled and zero if disabled.
    118 int WebRtcAec_extended_filter_enabled(AecCore* self);
    119 
    120 // Returns the current |system_delay|, i.e., the buffered difference between
    121 // far-end and near-end.
    122 int WebRtcAec_system_delay(AecCore* self);
    123 
    124 // Sets the |system_delay| to |value|.  Note that if the value is changed
    125 // improperly, there can be a performance regression.  So it should be used with
    126 // care.
    127 void WebRtcAec_SetSystemDelay(AecCore* self, int delay);
    128 
    129 #endif  // WEBRTC_MODULES_AUDIO_PROCESSING_AEC_AEC_CORE_H_
    130