ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:54:45 2017 +0800
Revision:
47:9e361da97763
?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TMBOY 47:9e361da97763 1 /* Copyright (C) Jean-Marc Valin */
TMBOY 47:9e361da97763 2 /**
TMBOY 47:9e361da97763 3 @file speex_echo.h
TMBOY 47:9e361da97763 4 @brief Echo cancellation
TMBOY 47:9e361da97763 5 */
TMBOY 47:9e361da97763 6 /*
TMBOY 47:9e361da97763 7 Redistribution and use in source and binary forms, with or without
TMBOY 47:9e361da97763 8 modification, are permitted provided that the following conditions are
TMBOY 47:9e361da97763 9 met:
TMBOY 47:9e361da97763 10
TMBOY 47:9e361da97763 11 1. Redistributions of source code must retain the above copyright notice,
TMBOY 47:9e361da97763 12 this list of conditions and the following disclaimer.
TMBOY 47:9e361da97763 13
TMBOY 47:9e361da97763 14 2. Redistributions in binary form must reproduce the above copyright
TMBOY 47:9e361da97763 15 notice, this list of conditions and the following disclaimer in the
TMBOY 47:9e361da97763 16 documentation and/or other materials provided with the distribution.
TMBOY 47:9e361da97763 17
TMBOY 47:9e361da97763 18 3. The name of the author may not be used to endorse or promote products
TMBOY 47:9e361da97763 19 derived from this software without specific prior written permission.
TMBOY 47:9e361da97763 20
TMBOY 47:9e361da97763 21 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
TMBOY 47:9e361da97763 22 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
TMBOY 47:9e361da97763 23 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
TMBOY 47:9e361da97763 24 DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
TMBOY 47:9e361da97763 25 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
TMBOY 47:9e361da97763 26 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
TMBOY 47:9e361da97763 27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
TMBOY 47:9e361da97763 28 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
TMBOY 47:9e361da97763 29 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
TMBOY 47:9e361da97763 30 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
TMBOY 47:9e361da97763 31 POSSIBILITY OF SUCH DAMAGE.
TMBOY 47:9e361da97763 32 */
TMBOY 47:9e361da97763 33
TMBOY 47:9e361da97763 34 #ifndef SPEEX_ECHO_H
TMBOY 47:9e361da97763 35 #define SPEEX_ECHO_H
TMBOY 47:9e361da97763 36 /** @defgroup SpeexEchoState SpeexEchoState: Acoustic echo canceller
TMBOY 47:9e361da97763 37 * This is the acoustic echo canceller module.
TMBOY 47:9e361da97763 38 * @{
TMBOY 47:9e361da97763 39 */
TMBOY 47:9e361da97763 40 #include "speex/speex_types.h"
TMBOY 47:9e361da97763 41
TMBOY 47:9e361da97763 42 #ifdef __cplusplus
TMBOY 47:9e361da97763 43 extern "C" {
TMBOY 47:9e361da97763 44 #endif
TMBOY 47:9e361da97763 45
TMBOY 47:9e361da97763 46 /** Obtain frame size used by the AEC */
TMBOY 47:9e361da97763 47 #define SPEEX_ECHO_GET_FRAME_SIZE 3
TMBOY 47:9e361da97763 48
TMBOY 47:9e361da97763 49 /** Set sampling rate */
TMBOY 47:9e361da97763 50 #define SPEEX_ECHO_SET_SAMPLING_RATE 24
TMBOY 47:9e361da97763 51 /** Get sampling rate */
TMBOY 47:9e361da97763 52 #define SPEEX_ECHO_GET_SAMPLING_RATE 25
TMBOY 47:9e361da97763 53
TMBOY 47:9e361da97763 54 /** Internal echo canceller state. Should never be accessed directly. */
TMBOY 47:9e361da97763 55 struct SpeexEchoState_;
TMBOY 47:9e361da97763 56
TMBOY 47:9e361da97763 57 /** @class SpeexEchoState
TMBOY 47:9e361da97763 58 * This holds the state of the echo canceller. You need one per channel.
TMBOY 47:9e361da97763 59 */
TMBOY 47:9e361da97763 60
TMBOY 47:9e361da97763 61 /** Internal echo canceller state. Should never be accessed directly. */
TMBOY 47:9e361da97763 62 typedef struct SpeexEchoState_ SpeexEchoState;
TMBOY 47:9e361da97763 63
TMBOY 47:9e361da97763 64 /** Creates a new echo canceller state
TMBOY 47:9e361da97763 65 * @param frame_size Number of samples to process at one time (should correspond to 10-20 ms)
TMBOY 47:9e361da97763 66 * @param filter_length Number of samples of echo to cancel (should generally correspond to 100-500 ms)
TMBOY 47:9e361da97763 67 * @return Newly-created echo canceller state
TMBOY 47:9e361da97763 68 */
TMBOY 47:9e361da97763 69 SpeexEchoState *speex_echo_state_init(int frame_size, int filter_length);
TMBOY 47:9e361da97763 70
TMBOY 47:9e361da97763 71 /** Destroys an echo canceller state
TMBOY 47:9e361da97763 72 * @param st Echo canceller state
TMBOY 47:9e361da97763 73 */
TMBOY 47:9e361da97763 74 void speex_echo_state_destroy(SpeexEchoState *st);
TMBOY 47:9e361da97763 75
TMBOY 47:9e361da97763 76 /** Performs echo cancellation a frame, based on the audio sent to the speaker (no delay is added
TMBOY 47:9e361da97763 77 * to playback ni this form)
TMBOY 47:9e361da97763 78 *
TMBOY 47:9e361da97763 79 * @param st Echo canceller state
TMBOY 47:9e361da97763 80 * @param rec signal from the microphone (near end + far end echo)
TMBOY 47:9e361da97763 81 * @param play Signal played to the speaker (received from far end)
TMBOY 47:9e361da97763 82 * @param out Returns near-end signal with echo removed
TMBOY 47:9e361da97763 83 */
TMBOY 47:9e361da97763 84 void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *rec, const spx_int16_t *play, spx_int16_t *out);
TMBOY 47:9e361da97763 85
TMBOY 47:9e361da97763 86 /** Performs echo cancellation a frame (deprecated) */
TMBOY 47:9e361da97763 87 void speex_echo_cancel(SpeexEchoState *st, const spx_int16_t *rec, const spx_int16_t *play, spx_int16_t *out, spx_int32_t *Yout);
TMBOY 47:9e361da97763 88
TMBOY 47:9e361da97763 89 /** Perform echo cancellation using internal playback buffer, which is delayed by two frames
TMBOY 47:9e361da97763 90 * to account for the delay introduced by most soundcards (but it could be off!)
TMBOY 47:9e361da97763 91 * @param st Echo canceller state
TMBOY 47:9e361da97763 92 * @param rec signal from the microphone (near end + far end echo)
TMBOY 47:9e361da97763 93 * @param out Returns near-end signal with echo removed
TMBOY 47:9e361da97763 94 */
TMBOY 47:9e361da97763 95 void speex_echo_capture(SpeexEchoState *st, const spx_int16_t *rec, spx_int16_t *out);
TMBOY 47:9e361da97763 96
TMBOY 47:9e361da97763 97 /** Let the echo canceller know that a frame was just queued to the soundcard
TMBOY 47:9e361da97763 98 * @param st Echo canceller state
TMBOY 47:9e361da97763 99 * @param play Signal played to the speaker (received from far end)
TMBOY 47:9e361da97763 100 */
TMBOY 47:9e361da97763 101 void speex_echo_playback(SpeexEchoState *st, const spx_int16_t *play);
TMBOY 47:9e361da97763 102
TMBOY 47:9e361da97763 103 /** Reset the echo canceller to its original state
TMBOY 47:9e361da97763 104 * @param st Echo canceller state
TMBOY 47:9e361da97763 105 */
TMBOY 47:9e361da97763 106 void speex_echo_state_reset(SpeexEchoState *st);
TMBOY 47:9e361da97763 107
TMBOY 47:9e361da97763 108 /** Used like the ioctl function to control the echo canceller parameters
TMBOY 47:9e361da97763 109 *
TMBOY 47:9e361da97763 110 * @param st Echo canceller state
TMBOY 47:9e361da97763 111 * @param request ioctl-type request (one of the SPEEX_ECHO_* macros)
TMBOY 47:9e361da97763 112 * @param ptr Data exchanged to-from function
TMBOY 47:9e361da97763 113 * @return 0 if no error, -1 if request in unknown
TMBOY 47:9e361da97763 114 */
TMBOY 47:9e361da97763 115 int speex_echo_ctl(SpeexEchoState *st, int request, void *ptr);
TMBOY 47:9e361da97763 116
TMBOY 47:9e361da97763 117 #ifdef __cplusplus
TMBOY 47:9e361da97763 118 }
TMBOY 47:9e361da97763 119 #endif
TMBOY 47:9e361da97763 120
TMBOY 47:9e361da97763 121
TMBOY 47:9e361da97763 122 /** @}*/
TMBOY 47:9e361da97763 123 #endif