| 6 |
| 7 | #ifndef LIBTGVOIP_ECHOCANCELLER_H |
| 8 | #define LIBTGVOIP_ECHOCANCELLER_H |
| 9 |
| 10 | #include "threading.h" |
| 11 | #include "utils.h" |
| 12 | #include "BlockingQueue.h" |
| 13 | #include "Buffers.h" |
| 14 | #include "MediaStreamItf.h" |
| 15 |
| 16 | #include <cstdint> |
| 17 |
| 18 | namespace webrtc |
| 19 | { |
| 20 |
| 21 | class AudioProcessing; |
| 22 | class AudioFrame; |
| 23 |
| 24 | } // namespace webrtc |
| 25 |
| 26 | namespace tgvoip |
| 27 | { |
| 28 |
| 29 | class EchoCanceller |
| 30 | { |
| 31 | public: |
| 32 | TGVOIP_DISALLOW_COPY_AND_ASSIGN(EchoCanceller); |
| 33 | EchoCanceller(bool m_enableAEC, bool m_enableNS, bool m_enableAGC); |
| 34 | virtual ~EchoCanceller(); |
| 35 | virtual void Start(); |
| 36 | virtual void Stop(); |
| 37 | void SpeakerOutCallback(std::uint8_t* data, std::size_t len); |
| 38 | void Enable(bool enabled); |
| 39 | void ProcessInput(std::int16_t* inOut, std::size_t numSamples, bool& hasVoice); |
| 40 | void SetAECStrength(int strength); |
| 41 | void SetVoiceDetectionEnabled(bool enabled); |
| 42 |
| 43 | private: |
| 44 | #ifndef TGVOIP_NO_DSP |
| 45 | BufferPool<960 * 2, 10> m_farendBufferPool; |
| 46 | BlockingQueue<Buffer>* m_farendQueue; |
| 47 | Thread* m_bufferFarendThread; |
| 48 | webrtc::AudioProcessing* m_apm = nullptr; |
| 49 | webrtc::AudioFrame* m_audioFrame = nullptr; |
| 50 | bool m_didBufferFarend; |
| 51 | bool m_running; |
| 52 |
| 53 | void RunBufferFarendThread(); |
| 54 | #endif |
| 55 |
| 56 | bool m_enableAEC; |
| 57 | bool m_enableAGC; |
| 58 | bool m_enableNS; |
| 59 | bool m_enableVAD = false; |
| 60 | bool m_isOn; |
| 61 | }; |
| 62 |
| 63 | namespace effects |
| 64 | { |
| 65 |
| 66 | class AudioEffect |
| 67 | { |
| 68 | public: |
| 69 | virtual ~AudioEffect() = 0; |
| 70 | virtual void Process(std::int16_t* inOut, std::size_t numSamples) const = 0; |
| 71 | virtual void SetPassThrough(bool m_passThrough); |
| 72 |
| 73 | protected: |
| 74 | [[nodiscard]] bool GetPassThrough() const; |
| 75 |
| 76 | private: |
| 77 | bool m_passThrough = false; |
| 78 | }; |
| 79 |
| 80 | class Volume : public AudioEffect |
| 81 | { |
| 82 | public: |
| 83 | Volume(); |
| 84 | ~Volume() override; |
| 85 | void Process(std::int16_t* inOut, std::size_t numSamples) const override; |
| 86 | /** |
| 87 | * Level is (0.0, 2.0] |
| 88 | */ |
| 89 | void SetLevel(float m_level); |
| 90 | [[nodiscard]] float GetLevel() const; |
| 91 |
| 92 | private: |
| 93 | float m_level = 1.0f; |
| 94 | float m_multiplier = 1.0f; |
| 95 | }; |
| 96 |
| 97 | } // namespace effects |
| 98 |
| 99 | } // namespace tgvoip |
| 100 |
| 101 | #endif // LIBTGVOIP_ECHOCANCELLER_H |
| 102 |