mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-05 13:29:57 -05:00
echo-cancel: Hook up WebRTC analog gain control
This commit is contained in:
parent
3d2f2424eb
commit
fb02d50fe3
2 changed files with 25 additions and 7 deletions
|
|
@ -58,6 +58,7 @@ struct pa_echo_canceller_params {
|
||||||
void *apm;
|
void *apm;
|
||||||
uint32_t blocksize;
|
uint32_t blocksize;
|
||||||
pa_sample_spec sample_spec;
|
pa_sample_spec sample_spec;
|
||||||
|
pa_bool_t agc;
|
||||||
} webrtc;
|
} webrtc;
|
||||||
#endif
|
#endif
|
||||||
/* each canceller-specific structure goes here */
|
/* each canceller-specific structure goes here */
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ pa_bool_t pa_webrtc_ec_init(pa_core *c, pa_echo_canceller *ec,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
dgc = DEFAULT_DIGITAL_GAIN_CONTROL;
|
dgc = agc ? FALSE : DEFAULT_DIGITAL_GAIN_CONTROL;
|
||||||
if (pa_modargs_get_value_boolean(ma, "digital_gain_control", &dgc) < 0) {
|
if (pa_modargs_get_value_boolean(ma, "digital_gain_control", &dgc) < 0) {
|
||||||
pa_log("Failed to parse digital_gain_control value");
|
pa_log("Failed to parse digital_gain_control value");
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
@ -193,15 +193,20 @@ pa_bool_t pa_webrtc_ec_init(pa_core *c, pa_echo_canceller *ec,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (agc || dgc) {
|
if (agc || dgc) {
|
||||||
if (mobile && rm <= webrtc::EchoControlMobile::kEarpiece)
|
if (mobile && rm <= webrtc::EchoControlMobile::kEarpiece) {
|
||||||
/* Maybe this should be a knob, but we've got a lot of knobs already */
|
/* Maybe this should be a knob, but we've got a lot of knobs already */
|
||||||
apm->gain_control()->set_mode(webrtc::GainControl::kFixedDigital);
|
apm->gain_control()->set_mode(webrtc::GainControl::kFixedDigital);
|
||||||
else if (dgc)
|
ec->params.priv.webrtc.agc = FALSE;
|
||||||
apm->gain_control()->set_mode(webrtc::GainControl::kAdaptiveDigital);
|
} else if (dgc) {
|
||||||
else {
|
|
||||||
/* FIXME: Hook up for analog AGC */
|
|
||||||
pa_log("Analog gain control isn't implemented yet -- using ditital gain control.");
|
|
||||||
apm->gain_control()->set_mode(webrtc::GainControl::kAdaptiveDigital);
|
apm->gain_control()->set_mode(webrtc::GainControl::kAdaptiveDigital);
|
||||||
|
ec->params.priv.webrtc.agc = FALSE;
|
||||||
|
} else {
|
||||||
|
apm->gain_control()->set_mode(webrtc::GainControl::kAdaptiveAnalog);
|
||||||
|
if (apm->gain_control()->set_analog_level_limits(0, PA_VOLUME_NORM-1) != apm->kNoError) {
|
||||||
|
pa_log("Failed to initialise AGC");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
ec->params.priv.webrtc.agc = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
apm->gain_control()->Enable(true);
|
apm->gain_control()->Enable(true);
|
||||||
|
|
@ -242,15 +247,27 @@ void pa_webrtc_ec_record(pa_echo_canceller *ec, const uint8_t *rec, uint8_t *out
|
||||||
webrtc::AudioProcessing *apm = (webrtc::AudioProcessing*)ec->params.priv.webrtc.apm;
|
webrtc::AudioProcessing *apm = (webrtc::AudioProcessing*)ec->params.priv.webrtc.apm;
|
||||||
webrtc::AudioFrame out_frame;
|
webrtc::AudioFrame out_frame;
|
||||||
const pa_sample_spec *ss = &ec->params.priv.webrtc.sample_spec;
|
const pa_sample_spec *ss = &ec->params.priv.webrtc.sample_spec;
|
||||||
|
pa_cvolume v;
|
||||||
|
|
||||||
out_frame._audioChannel = ss->channels;
|
out_frame._audioChannel = ss->channels;
|
||||||
out_frame._frequencyInHz = ss->rate;
|
out_frame._frequencyInHz = ss->rate;
|
||||||
out_frame._payloadDataLengthInSamples = ec->params.priv.webrtc.blocksize / pa_frame_size(ss);
|
out_frame._payloadDataLengthInSamples = ec->params.priv.webrtc.blocksize / pa_frame_size(ss);
|
||||||
memcpy(out_frame._payloadData, rec, ec->params.priv.webrtc.blocksize);
|
memcpy(out_frame._payloadData, rec, ec->params.priv.webrtc.blocksize);
|
||||||
|
|
||||||
|
if (ec->params.priv.webrtc.agc) {
|
||||||
|
pa_cvolume_init(&v);
|
||||||
|
pa_echo_canceller_get_capture_volume(ec, &v);
|
||||||
|
apm->gain_control()->set_stream_analog_level(pa_cvolume_avg(&v));
|
||||||
|
}
|
||||||
|
|
||||||
apm->set_stream_delay_ms(0);
|
apm->set_stream_delay_ms(0);
|
||||||
apm->ProcessStream(&out_frame);
|
apm->ProcessStream(&out_frame);
|
||||||
|
|
||||||
|
if (ec->params.priv.webrtc.agc) {
|
||||||
|
pa_cvolume_set(&v, ss->channels, apm->gain_control()->stream_analog_level());
|
||||||
|
pa_echo_canceller_set_capture_volume(ec, &v);
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(out, out_frame._payloadData, ec->params.priv.webrtc.blocksize);
|
memcpy(out, out_frame._payloadData, ec->params.priv.webrtc.blocksize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue