[pulseaudio-discuss] [PATCH v2 21/25] echo-cancel: webrtc canceller supports different in/out channel counts

arun at accosted.net arun at accosted.net
Tue Dec 15 19:50:16 PST 2015


From: Arun Raghavan <git at arunraghavan.net>

Needed for upcoming beamforming code.
---
 src/modules/echo-cancel/echo-cancel.h |  2 +-
 src/modules/echo-cancel/webrtc.cc     | 14 ++++++++------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/modules/echo-cancel/echo-cancel.h b/src/modules/echo-cancel/echo-cancel.h
index 4693516..613f7e3 100644
--- a/src/modules/echo-cancel/echo-cancel.h
+++ b/src/modules/echo-cancel/echo-cancel.h
@@ -65,7 +65,7 @@ struct pa_echo_canceller_params {
              * to C++ linkage. apm is a pointer to an AudioProcessing object */
             void *apm;
             int32_t blocksize; /* in frames */
-            pa_sample_spec rec_ss, play_ss;
+            pa_sample_spec rec_ss, play_ss, out_ss;
             bool agc;
             bool trace;
             bool first;
diff --git a/src/modules/echo-cancel/webrtc.cc b/src/modules/echo-cancel/webrtc.cc
index 5741f45..5f00286 100644
--- a/src/modules/echo-cancel/webrtc.cc
+++ b/src/modules/echo-cancel/webrtc.cc
@@ -333,6 +333,7 @@ bool pa_webrtc_ec_init(pa_core *c, pa_echo_canceller *ec,
     ec->params.webrtc.apm = apm;
     ec->params.webrtc.rec_ss = *rec_ss;
     ec->params.webrtc.play_ss = *play_ss;
+    ec->params.webrtc.out_ss = *out_ss;
     ec->params.webrtc.blocksize =
         (uint64_t) (pa_bytes_per_second(out_ss) / pa_frame_size(out_ss)) * BLOCK_SIZE_US / PA_USEC_PER_SEC;
     *nframes = ec->params.webrtc.blocksize;
@@ -372,17 +373,18 @@ void pa_webrtc_ec_play(pa_echo_canceller *ec, const uint8_t *play) {
 void pa_webrtc_ec_record(pa_echo_canceller *ec, const uint8_t *rec, uint8_t *out) {
     webrtc::AudioProcessing *apm = (webrtc::AudioProcessing*)ec->params.webrtc.apm;
     webrtc::AudioFrame out_frame;
-    const pa_sample_spec *ss = &ec->params.webrtc.rec_ss;
+    const pa_sample_spec *rec_ss = &ec->params.webrtc.rec_ss;
+    const pa_sample_spec *out_ss = &ec->params.webrtc.out_ss;
     pa_cvolume v;
     int old_volume, new_volume;
 
-    out_frame.num_channels_ = ss->channels;
-    out_frame.sample_rate_hz_ = ss->rate;
+    out_frame.num_channels_ = rec_ss->channels;
+    out_frame.sample_rate_hz_ = rec_ss->rate;
     out_frame.interleaved_ = true;
     out_frame.samples_per_channel_ = ec->params.webrtc.blocksize;
 
     pa_assert(out_frame.samples_per_channel_ <= webrtc::AudioFrame::kMaxDataSizeSamples);
-    memcpy(out_frame.data_, rec, ec->params.webrtc.blocksize * pa_frame_size(ss));
+    memcpy(out_frame.data_, rec, ec->params.webrtc.blocksize * pa_frame_size(rec_ss));
 
     if (ec->params.webrtc.agc) {
         pa_cvolume_init(&v);
@@ -408,12 +410,12 @@ void pa_webrtc_ec_record(pa_echo_canceller *ec, const uint8_t *rec, uint8_t *out
         }
 
         if (old_volume != new_volume) {
-            pa_cvolume_set(&v, ss->channels, webrtc_volume_to_pa(new_volume));
+            pa_cvolume_set(&v, rec_ss->channels, webrtc_volume_to_pa(new_volume));
             pa_echo_canceller_set_capture_volume(ec, &v);
         }
     }
 
-    memcpy(out, out_frame.data_, ec->params.webrtc.blocksize * pa_frame_size(ss));
+    memcpy(out, out_frame.data_, ec->params.webrtc.blocksize * pa_frame_size(out_ss));
 }
 
 void pa_webrtc_ec_set_drift(pa_echo_canceller *ec, float drift) {
-- 
2.5.0



More information about the pulseaudio-discuss mailing list