EchoCanceller.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // libtgvoip is free and unencumbered public domain software.
  3. // For more information, see http://unlicense.org or the UNLICENSE file
  4. // you should have received with this source code distribution.
  5. //
  6. #ifndef LIBTGVOIP_ECHOCANCELLER_H
  7. #define LIBTGVOIP_ECHOCANCELLER_H
  8. #include "threading.h"
  9. #include "Buffers.h"
  10. #include "BlockingQueue.h"
  11. #include "MediaStreamItf.h"
  12. #include "utils.h"
  13. #ifndef TGVOIP_NO_DSP
  14. #include "api/scoped_refptr.h"
  15. #endif // TGVOIP_NO_DSP
  16. namespace webrtc{
  17. class AudioProcessing;
  18. class AudioFrame;
  19. }
  20. namespace tgvoip{
  21. class EchoCanceller{
  22. public:
  23. TGVOIP_DISALLOW_COPY_AND_ASSIGN(EchoCanceller);
  24. EchoCanceller(bool enableAEC, bool enableNS, bool enableAGC);
  25. virtual ~EchoCanceller();
  26. virtual void Start();
  27. virtual void Stop();
  28. void SpeakerOutCallback(unsigned char* data, size_t len);
  29. void Enable(bool enabled);
  30. void ProcessInput(int16_t* inOut, size_t numSamples, bool& hasVoice);
  31. void SetAECStrength(int strength);
  32. void SetVoiceDetectionEnabled(bool enabled);
  33. private:
  34. bool enableAEC;
  35. bool enableAGC;
  36. bool enableNS;
  37. bool enableVAD=false;
  38. bool isOn;
  39. #ifndef TGVOIP_NO_DSP
  40. rtc::scoped_refptr<webrtc::AudioProcessing> apm;
  41. webrtc::AudioFrame* audioFrame=NULL;
  42. void RunBufferFarendThread();
  43. bool didBufferFarend;
  44. Thread* bufferFarendThread;
  45. BlockingQueue<int16_t*>* farendQueue;
  46. BufferPool* farendBufferPool;
  47. bool running;
  48. #endif
  49. };
  50. namespace effects{
  51. class AudioEffect{
  52. public:
  53. virtual ~AudioEffect()=0;
  54. virtual void Process(int16_t* inOut, size_t numSamples)=0;
  55. virtual void SetPassThrough(bool passThrough);
  56. protected:
  57. bool passThrough=false;
  58. };
  59. class Volume : public AudioEffect{
  60. public:
  61. Volume();
  62. virtual ~Volume();
  63. virtual void Process(int16_t* inOut, size_t numSamples);
  64. /**
  65. * Level is (0.0, 2.0]
  66. */
  67. void SetLevel(float level);
  68. float GetLevel();
  69. private:
  70. float level=1.0f;
  71. float multiplier=1.0f;
  72. };
  73. }
  74. }
  75. #endif //LIBTGVOIP_ECHOCANCELLER_H