webrtc.cpp 905 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <string>
  2. #include <iostream>
  3. #include "webrtc.h"
  4. Webrtc::Webrtc()
  5. {
  6. #ifdef AEC_DELAY
  7. apm = webrtc::AudioProcessing::Create();
  8. apm->noise_suppression()->Enable(true);
  9. apm->noise_suppression()->set_level(webrtc::NoiseSuppression::kHigh);
  10. apm->gain_control()->Enable(true);
  11. apm->gain_control()->set_analog_level_limits(0, 255);
  12. apm->gain_control()->set_mode(webrtc::GainControl::kAdaptiveAnalog);
  13. frame = new webrtc::AudioFrame();
  14. #endif
  15. }
  16. Webrtc::~Webrtc()
  17. {
  18. #ifdef AEC_DELAY
  19. delete frame;
  20. delete apm;
  21. #endif
  22. }
  23. #ifdef AEC_DELAY
  24. void Webrtc::SetFrameParam(int rate, int step, int chans)
  25. {
  26. frame->sample_rate_hz_ = rate;
  27. frame->samples_per_channel_ = rate * step / 1000.0;
  28. frame->num_channels_ = chans;
  29. }
  30. void Webrtc::FrameProcess(short *data, int len)
  31. {
  32. memcpy(frame->data_, data, len);
  33. apm->ProcessStream(frame);
  34. memcpy(data, frame->data_, len);
  35. }
  36. #endif