@chenlai89
2015-07-17T02:16:33.000000Z
字数 2525
阅读 2438
code
The Audio Processing Module (APM) provides a collection of voice processing
components designed for real-time communications software.
|ProcessStream()|
. Frames of the reverse direction stream, which are used for analysis by some components, are passed to |AnalyzeReverseStream()|
.
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 follow a similar pattern and are accessed through corresponding getters
in APM.
All components are disabled
at create-time, with default settings that are recommended for most situations.
New settings can be applied without enabling a component.
Enabling a component triggers memory allocation and initialization to allow it to start processing the streams.
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.
APM accepts only linear PCM audio data in chunks of 10 ms.
The int16 interfaces use interleaved data, while the float interfaces use deinterleaved data.
AudioProcessing* apm = AudioProcessing::Create(0);
apm->high_pass_filter()->Enable(true);
apm->echo_cancellation()->enable_drift_compensation(false);
apm->echo_cancellation()->Enable(true);
apm->noise_reduction()->set_level(kHighSuppression);
apm->noise_reduction()->Enable(true);
apm->gain_control()->set_analog_level_limits(0, 255);
apm->gain_control()->set_mode(kAdaptiveAnalog);
apm->gain_control()->Enable(true);
apm->voice_detection()->Enable(true);
// Start a voice call...
// ... Render frame arrives bound for the audio HAL ...
apm->AnalyzeReverseStream(render_frame);
// ... Capture frame arrives from the audio HAL ...
// Call required set_stream_ functions.
apm->set_stream_delay_ms(delay_ms);
apm->gain_control()->set_stream_analog_level(analog_level);
apm->ProcessStream(capture_frame);
// Call required stream_ functions.
analog_level = apm->gain_control()->stream_analog_level();
has_voice = apm->stream_has_voice();
// Repeate render and capture processing for the duration of the call...
// Start a new call...
apm->Initialize();
// Close the application...
delete apm;