[pulseaudio-commits] 3 commits - src/modules

Tanu Kaskinen tanuk at kemper.freedesktop.org
Thu Dec 20 01:00:52 PST 2012


 src/modules/echo-cancel/module-echo-cancel.c |   45 ++++++++++++++++-----------
 1 file changed, 27 insertions(+), 18 deletions(-)

New commits:
commit 84e45843220af6479c3e250d0dcfc6904fad007f
Author: Stefan Huber <s.huber at bct-electronic.com>
Date:   Tue Dec 18 13:52:32 2012 +0100

    echo-cancel: Fix calc_diff for asymmetric sample specs
    
    In case that source and sink use different sample specs (e.g., different
    number of channels) the computation of the latency difference fails.
    To fix this, we obtain the corresponding latencies in terms of time using
    the respective sample specs instead of buffer sizes.
    
    Signed-off-by: Stefan Huber <s.huber at bct-electronic.com>
    Acked-by: Peter Meerwald <p.meerwald at bct-electronic.com>

diff --git a/src/modules/echo-cancel/module-echo-cancel.c b/src/modules/echo-cancel/module-echo-cancel.c
index 5c639ae..103aef0 100644
--- a/src/modules/echo-cancel/module-echo-cancel.c
+++ b/src/modules/echo-cancel/module-echo-cancel.c
@@ -294,34 +294,38 @@ enum {
 };
 
 static int64_t calc_diff(struct userdata *u, struct snapshot *snapshot) {
-    int64_t buffer, diff_time, buffer_latency;
-
-    /* get the number of samples between capture and playback */
-    if (snapshot->plen > snapshot->rlen)
-        buffer = snapshot->plen - snapshot->rlen;
+    int64_t diff_time, buffer_latency;
+    pa_usec_t plen, rlen, source_delay, sink_delay, recv_counter, send_counter;
+
+    /* get latency difference between playback and record */
+    plen = pa_bytes_to_usec(snapshot->plen, &u->sink_input->sample_spec);
+    rlen = pa_bytes_to_usec(snapshot->rlen, &u->source_output->sample_spec);
+    if (plen > rlen)
+        buffer_latency = plen - rlen;
     else
-        buffer = 0;
+        buffer_latency = 0;
 
-    buffer += snapshot->source_delay + snapshot->sink_delay;
+    source_delay = pa_bytes_to_usec(snapshot->source_delay, &u->source_output->sample_spec);
+    sink_delay = pa_bytes_to_usec(snapshot->sink_delay, &u->sink_input->sample_spec);
+    buffer_latency += source_delay + sink_delay;
 
-    /* add the amount of samples not yet transferred to the source context */
-    if (snapshot->recv_counter <= snapshot->send_counter)
-        buffer += (int64_t) (snapshot->send_counter - snapshot->recv_counter);
+    /* add the latency difference due to samples not yet transferred */
+    send_counter = pa_bytes_to_usec(snapshot->send_counter, &u->sink_input->sample_spec);
+    recv_counter = pa_bytes_to_usec(snapshot->recv_counter, &u->source_output->sample_spec);
+    if (recv_counter <= send_counter)
+        buffer_latency += (int64_t) (send_counter - recv_counter);
     else
-        buffer += PA_CLIP_SUB(buffer, (int64_t) (snapshot->recv_counter - snapshot->send_counter));
-
-    /* convert to time */
-    buffer_latency = pa_bytes_to_usec(buffer, &u->source_output->sample_spec);
+        buffer_latency += PA_CLIP_SUB(buffer_latency, (int64_t) (recv_counter - send_counter));
 
-    /* capture and playback samples are perfectly aligned when diff_time is 0 */
+    /* capture and playback are perfectly aligned when diff_time is 0 */
     diff_time = (snapshot->sink_now + snapshot->sink_latency - buffer_latency) -
           (snapshot->source_now - snapshot->source_latency);
 
     pa_log_debug("Diff %lld (%lld - %lld + %lld) %lld %lld %lld %lld", (long long) diff_time,
         (long long) snapshot->sink_latency,
         (long long) buffer_latency, (long long) snapshot->source_latency,
-        (long long) snapshot->source_delay, (long long) snapshot->sink_delay,
-        (long long) (snapshot->send_counter - snapshot->recv_counter),
+        (long long) source_delay, (long long) sink_delay,
+        (long long) (send_counter - recv_counter),
         (long long) (snapshot->sink_now - snapshot->source_now));
 
     return diff_time;

commit fc9ad93bb4b2a150766f9a4431949fc4ff4a69eb
Author: Stefan Huber <s.huber at bct-electronic.com>
Date:   Tue Dec 18 13:52:31 2012 +0100

    echo-cancel: Fix missing setup of sink_ss in echo-cancel-test.
    
    In main() of echo-cancel-test it is wrongly assumed that the EC
    implementation's init() function properly initializes sink_ss. In
    contrast, pa__init() sets sink_ss by default to
    sink_master->sample_spec. Fix this by setting sink_ss to default
    parameters and let EC implementation's init() override these settings.
    
    Signed-off-by: Stefan Huber <s.huber at bct-electronic.com>
    Acked-by: Peter Meerwald <p.meerwald at bct-electronic.com>

diff --git a/src/modules/echo-cancel/module-echo-cancel.c b/src/modules/echo-cancel/module-echo-cancel.c
index f7c7276..5c639ae 100644
--- a/src/modules/echo-cancel/module-echo-cancel.c
+++ b/src/modules/echo-cancel/module-echo-cancel.c
@@ -2104,6 +2104,11 @@ int main(int argc, char* argv[]) {
     source_ss.channels = DEFAULT_CHANNELS;
     pa_channel_map_init_auto(&source_map, source_ss.channels, PA_CHANNEL_MAP_DEFAULT);
 
+    sink_ss.format = PA_SAMPLE_S16LE;
+    sink_ss.rate = DEFAULT_RATE;
+    sink_ss.channels = DEFAULT_CHANNELS;
+    pa_channel_map_init_auto(&sink_map, sink_ss.channels, PA_CHANNEL_MAP_DEFAULT);
+
     if (init_common(ma, &u, &source_ss, &source_map) < 0)
         goto fail;
 

commit a99e31fb6ba8c1c04f307e11ecf66efbd4cda4b9
Author: Stefan Huber <s.huber at bct-electronic.com>
Date:   Tue Dec 18 13:52:30 2012 +0100

    echo-cancel: Fix echo-cancel-test's argument number checking
    
    Argument argv[5] is accessed when argc>4, which leads to an invalid
    access for argc==5. Fix this.
    
    Signed-off-by: Stefan Huber <s.huber at bct-electronic.com>
    Acked-by: Peter Meerwald <p.meerwald at bct-electronic.com>

diff --git a/src/modules/echo-cancel/module-echo-cancel.c b/src/modules/echo-cancel/module-echo-cancel.c
index 26ac30b..f7c7276 100644
--- a/src/modules/echo-cancel/module-echo-cancel.c
+++ b/src/modules/echo-cancel/module-echo-cancel.c
@@ -2108,7 +2108,7 @@ int main(int argc, char* argv[]) {
         goto fail;
 
     if (!u.ec->init(u.core, u.ec, &source_ss, &source_map, &sink_ss, &sink_map, &u.blocksize,
-                     (argc > 4) ? argv[5] : NULL )) {
+                     (argc > 5) ? argv[5] : NULL )) {
         pa_log("Failed to init AEC engine");
         goto fail;
     }



More information about the pulseaudio-commits mailing list