^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * OSLEC - A line echo canceller. This code is being developed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * against and partially complies with G168. Using code from SpanDSP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Written by Steve Underwood <steveu@coppice.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * and David Rowe <david_at_rowetel_dot_com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 2001 Steve Underwood and 2007-2008 David Rowe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #ifndef __OSLEC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define __OSLEC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /* Mask bits for the adaption mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define ECHO_CAN_USE_ADAPTION 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define ECHO_CAN_USE_NLP 0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define ECHO_CAN_USE_CNG 0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define ECHO_CAN_USE_CLIP 0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define ECHO_CAN_USE_TX_HPF 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define ECHO_CAN_USE_RX_HPF 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define ECHO_CAN_DISABLE 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * oslec_state: G.168 echo canceller descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * This defines the working state for a line echo canceller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct oslec_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * oslec_create - Create a voice echo canceller context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * @len: The length of the canceller, in samples.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * @return: The new canceller context, or NULL if the canceller could not be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct oslec_state *oslec_create(int len, int adaption_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * oslec_free - Free a voice echo canceller context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * @ec: The echo canceller context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) void oslec_free(struct oslec_state *ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * oslec_flush - Flush (reinitialise) a voice echo canceller context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * @ec: The echo canceller context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) void oslec_flush(struct oslec_state *ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * oslec_adaption_mode - set the adaption mode of a voice echo canceller context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * @ec The echo canceller context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * @adaption_mode: The mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) void oslec_adaption_mode(struct oslec_state *ec, int adaption_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) void oslec_snapshot(struct oslec_state *ec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * oslec_update: Process a sample through a voice echo canceller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * @ec: The echo canceller context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * @tx: The transmitted audio sample.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * @rx: The received audio sample.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * The return value is the clean (echo cancelled) received sample.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int16_t oslec_update(struct oslec_state *ec, int16_t tx, int16_t rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * oslec_hpf_tx: Process to high pass filter the tx signal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * @ec: The echo canceller context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * @tx: The transmitted auio sample.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * The return value is the HP filtered transmit sample, send this to your D/A.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int16_t oslec_hpf_tx(struct oslec_state *ec, int16_t tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #endif /* __OSLEC_H */