[关闭]
@chenlai89 2015-07-17T02:16:33.000000Z 字数 2525 阅读 2438

Webrtc Audio Processing

code


The Audio Processing Module (APM) provides a collection of voice processing
components designed for real-time communications software.

APM operates on two audio streams on a frame-by-frame basis.

  1. Frames of the primary stream, on which all processing is applied, are passed to |ProcessStream()|.
  2. Frames of the reverse direction stream, which are used for analysis by some components, are passed to |AnalyzeReverseStream()|.

  3. On the client-side, this will typically be the near-end (capture) and far-end (render) streams, respectively.

Note: APM should be placed in the signal chain as close to the audio hardware abstraction layer (HAL) as possible.

On the server-side, the reverse stream will normally not be used, with processing occurring on each incoming stream.

Component interfaces

Thread safety

Thread safety is provided with the following assumptions to reduce locking
overhead:
1. The stream getters and setters are called from the same thread as ProcessStream(). More precisely, stream functions are never called concurrently with ProcessStream().
2. Parameter getters are never called concurrently with the corresponding
setter.

Data chunks

Usage example, omitting error checking:

Initialize

  1. AudioProcessing* apm = AudioProcessing::Create(0);
  2. apm->high_pass_filter()->Enable(true);
  3. apm->echo_cancellation()->enable_drift_compensation(false);
  4. apm->echo_cancellation()->Enable(true);
  5. apm->noise_reduction()->set_level(kHighSuppression);
  6. apm->noise_reduction()->Enable(true);
  7. apm->gain_control()->set_analog_level_limits(0, 255);
  8. apm->gain_control()->set_mode(kAdaptiveAnalog);
  9. apm->gain_control()->Enable(true);
  10. apm->voice_detection()->Enable(true);

Data processing

  1. // Start a voice call...
  2. // ... Render frame arrives bound for the audio HAL ...
  3. apm->AnalyzeReverseStream(render_frame);
  4. // ... Capture frame arrives from the audio HAL ...
  5. // Call required set_stream_ functions.
  6. apm->set_stream_delay_ms(delay_ms);
  7. apm->gain_control()->set_stream_analog_level(analog_level);
  8. apm->ProcessStream(capture_frame);
  9. // Call required stream_ functions.
  10. analog_level = apm->gain_control()->stream_analog_level();
  11. has_voice = apm->stream_has_voice();
  12. // Repeate render and capture processing for the duration of the call...
  13. // Start a new call...
  14. apm->Initialize();
  15. // Close the application...
  16. delete apm;
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注