1c55a96383497a772a307b346368133960b02ad03Eric Laurent/*
2c55a96383497a772a307b346368133960b02ad03Eric Laurent *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3c55a96383497a772a307b346368133960b02ad03Eric Laurent *
4c55a96383497a772a307b346368133960b02ad03Eric Laurent *  Use of this source code is governed by a BSD-style license
5c55a96383497a772a307b346368133960b02ad03Eric Laurent *  that can be found in the LICENSE file in the root of the source
6c55a96383497a772a307b346368133960b02ad03Eric Laurent *  tree. An additional intellectual property rights grant can be found
7c55a96383497a772a307b346368133960b02ad03Eric Laurent *  in the file PATENTS.  All contributing project authors may
8c55a96383497a772a307b346368133960b02ad03Eric Laurent *  be found in the AUTHORS file in the root of the source tree.
9c55a96383497a772a307b346368133960b02ad03Eric Laurent */
10c55a96383497a772a307b346368133960b02ad03Eric Laurent
11c55a96383497a772a307b346368133960b02ad03Eric Laurent// Performs delay estimation on block by block basis.
12c55a96383497a772a307b346368133960b02ad03Eric Laurent// The return value is  0 - OK and -1 - Error, unless otherwise stated.
13c55a96383497a772a307b346368133960b02ad03Eric Laurent
14c55a96383497a772a307b346368133960b02ad03Eric Laurent#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_DELAY_ESTIMATOR_WRAPPER_H_
15c55a96383497a772a307b346368133960b02ad03Eric Laurent#define WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_DELAY_ESTIMATOR_WRAPPER_H_
16c55a96383497a772a307b346368133960b02ad03Eric Laurent
17c55a96383497a772a307b346368133960b02ad03Eric Laurent#include "typedefs.h"
18c55a96383497a772a307b346368133960b02ad03Eric Laurent
19c55a96383497a772a307b346368133960b02ad03Eric Laurent// Releases the memory allocated by WebRtc_CreateDelayEstimator(...)
20c55a96383497a772a307b346368133960b02ad03Eric Laurent// Input:
21c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - handle        : Pointer to the delay estimation instance.
22c55a96383497a772a307b346368133960b02ad03Eric Laurent//
23c55a96383497a772a307b346368133960b02ad03Eric Laurentint WebRtc_FreeDelayEstimator(void* handle);
24c55a96383497a772a307b346368133960b02ad03Eric Laurent
25c55a96383497a772a307b346368133960b02ad03Eric Laurent// Allocates the memory needed by the delay estimation. The memory needs to be
26c55a96383497a772a307b346368133960b02ad03Eric Laurent// initialized separately through WebRtc_InitDelayEstimator(...).
27c55a96383497a772a307b346368133960b02ad03Eric Laurent//
28c55a96383497a772a307b346368133960b02ad03Eric Laurent// Inputs:
29c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - handle        : Instance that should be created.
30c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - spectrum_size : Size of the spectrum used both in far-end and
31c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        near-end. Used to allocate memory for spectrum
32c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        specific buffers.
33c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - max_delay     : The maximum delay which can be estimated. Needed to
34c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        allocate memory for history buffers.
35c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - lookahead     : Amount of non-causal lookahead to use. This can
36c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        detect cases in which a near-end signal occurs before
37c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        the corresponding far-end signal. It will delay the
38c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        estimate for the current block by an equal amount,
39c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        and the returned values will be offset by it.
40c55a96383497a772a307b346368133960b02ad03Eric Laurent//
41c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        A value of zero is the typical no-lookahead case.
42c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        This also represents the minimum delay which can be
43c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        estimated.
44c55a96383497a772a307b346368133960b02ad03Eric Laurent//
45c55a96383497a772a307b346368133960b02ad03Eric Laurent// Output:
46c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - handle        : Created instance.
47c55a96383497a772a307b346368133960b02ad03Eric Laurent//
48c55a96383497a772a307b346368133960b02ad03Eric Laurentint WebRtc_CreateDelayEstimator(void** handle,
49c55a96383497a772a307b346368133960b02ad03Eric Laurent                                int spectrum_size,
50c55a96383497a772a307b346368133960b02ad03Eric Laurent                                int max_delay,
51c55a96383497a772a307b346368133960b02ad03Eric Laurent                                int lookahead);
52c55a96383497a772a307b346368133960b02ad03Eric Laurent
53c55a96383497a772a307b346368133960b02ad03Eric Laurent// Initializes the delay estimation instance created with
54c55a96383497a772a307b346368133960b02ad03Eric Laurent// WebRtc_CreateDelayEstimator(...)
55c55a96383497a772a307b346368133960b02ad03Eric Laurent// Input:
56c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - handle        : Pointer to the delay estimation instance.
57c55a96383497a772a307b346368133960b02ad03Eric Laurent//
58c55a96383497a772a307b346368133960b02ad03Eric Laurent// Output:
59c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - handle        : Initialized instance.
60c55a96383497a772a307b346368133960b02ad03Eric Laurent//
61c55a96383497a772a307b346368133960b02ad03Eric Laurentint WebRtc_InitDelayEstimator(void* handle);
62c55a96383497a772a307b346368133960b02ad03Eric Laurent
63c55a96383497a772a307b346368133960b02ad03Eric Laurent// Estimates and returns the delay between the far-end and near-end blocks. The
64c55a96383497a772a307b346368133960b02ad03Eric Laurent// value will be offset by the lookahead (i.e. the lookahead should be
65c55a96383497a772a307b346368133960b02ad03Eric Laurent// subtracted from the returned value).
66c55a96383497a772a307b346368133960b02ad03Eric Laurent// Inputs:
67c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - handle        : Pointer to the delay estimation instance.
68c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - far_spectrum  : Pointer to the far-end spectrum data.
69c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - near_spectrum : Pointer to the near-end spectrum data of the current
70c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        block.
71c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - spectrum_size : The size of the data arrays (same for both far- and
72c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        near-end).
73c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - far_q         : The Q-domain of the far-end data.
74c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - near_q        : The Q-domain of the near-end data.
75c55a96383497a772a307b346368133960b02ad03Eric Laurent//
76c55a96383497a772a307b346368133960b02ad03Eric Laurent// Output:
77c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - handle        : Updated instance.
78c55a96383497a772a307b346368133960b02ad03Eric Laurent//
79c55a96383497a772a307b346368133960b02ad03Eric Laurent// Return value:
80c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - delay         :  >= 0 - Calculated delay value.
81c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        -1    - Error.
82c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        -2    - Insufficient data for estimation.
83c55a96383497a772a307b346368133960b02ad03Eric Laurent//
84c55a96383497a772a307b346368133960b02ad03Eric Laurentint WebRtc_DelayEstimatorProcessFix(void* handle,
85c55a96383497a772a307b346368133960b02ad03Eric Laurent                                    uint16_t* far_spectrum,
86c55a96383497a772a307b346368133960b02ad03Eric Laurent                                    uint16_t* near_spectrum,
87c55a96383497a772a307b346368133960b02ad03Eric Laurent                                    int spectrum_size,
88c55a96383497a772a307b346368133960b02ad03Eric Laurent                                    int far_q,
89c55a96383497a772a307b346368133960b02ad03Eric Laurent                                    int near_q);
90c55a96383497a772a307b346368133960b02ad03Eric Laurent
91c55a96383497a772a307b346368133960b02ad03Eric Laurent// See WebRtc_DelayEstimatorProcessFix() for description.
92c55a96383497a772a307b346368133960b02ad03Eric Laurentint WebRtc_DelayEstimatorProcessFloat(void* handle,
93c55a96383497a772a307b346368133960b02ad03Eric Laurent                                      float* far_spectrum,
94c55a96383497a772a307b346368133960b02ad03Eric Laurent                                      float* near_spectrum,
95c55a96383497a772a307b346368133960b02ad03Eric Laurent                                      int spectrum_size);
96c55a96383497a772a307b346368133960b02ad03Eric Laurent
97c55a96383497a772a307b346368133960b02ad03Eric Laurent// Returns the last calculated delay updated by the function
98c55a96383497a772a307b346368133960b02ad03Eric Laurent// WebRtc_DelayEstimatorProcess(...).
99c55a96383497a772a307b346368133960b02ad03Eric Laurent//
100c55a96383497a772a307b346368133960b02ad03Eric Laurent// Input:
101c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - handle        : Pointer to the delay estimation instance.
102c55a96383497a772a307b346368133960b02ad03Eric Laurent//
103c55a96383497a772a307b346368133960b02ad03Eric Laurent// Return value:
104c55a96383497a772a307b346368133960b02ad03Eric Laurent//      - delay         :  >= 0 - Last calculated delay value.
105c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        -1    - Error.
106c55a96383497a772a307b346368133960b02ad03Eric Laurent//                        -2    - Insufficient data for estimation.
107c55a96383497a772a307b346368133960b02ad03Eric Laurent//
108c55a96383497a772a307b346368133960b02ad03Eric Laurentint WebRtc_last_delay(void* handle);
109c55a96383497a772a307b346368133960b02ad03Eric Laurent
110c55a96383497a772a307b346368133960b02ad03Eric Laurent#endif  // WEBRTC_MODULES_AUDIO_PROCESSING_UTILITY_DELAY_ESTIMATOR_WRAPPER_H_
111