summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@collabora.co.uk>2010-08-31 18:04:33 +0200
committerArun Raghavan <arun.raghavan@collabora.co.uk>2011-03-28 14:40:59 +0530
commitb30bf121d20dd2bacf4577f52f9bae4ff86bc2c8 (patch)
treebf986aff31fd66d7c7a1aaadd97385ac88a79f7e
parent1c2669452b325eb59ebfdfb955c187a2b7e8a7f0 (diff)
echo-cancel: keep frame_size a power of 2
The speex echo canceler prefers a power of 2 for the frame size. Round down the ideal frame_size to the nearest power of two. This makes sure we don't create more than the requested frame_size_ms latency while still providing a power of 2 to the speex echo canceller.
-rw-r--r--src/modules/module-echo-cancel.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/modules/module-echo-cancel.c b/src/modules/module-echo-cancel.c
index 4d44bf73..d6c2ca14 100644
--- a/src/modules/module-echo-cancel.c
+++ b/src/modules/module-echo-cancel.c
@@ -1269,7 +1269,7 @@ int pa__init(pa_module*m) {
pa_source_new_data source_data;
pa_sink_new_data sink_data;
pa_memchunk silence;
- int framelen, rate;
+ int framelen, rate, y;
uint32_t frame_size_ms, filter_size_ms;
uint32_t adjust_time_sec;
@@ -1323,6 +1323,13 @@ int pa__init(pa_module*m) {
u->frame_size_ms = frame_size_ms;
rate = ss.rate;
framelen = (rate * frame_size_ms) / 1000;
+
+ /* framelen should be a power of 2, round down to nearest power of two */
+ y = 1 << ((8 * sizeof (int)) - 2);
+ while (y > framelen)
+ y >>= 1;
+ framelen = y;
+
u->blocksize = framelen * pa_frame_size (&ss);
pa_log_debug ("Using framelen %d, blocksize %lld, channels %d, rate %d", framelen, (long long) u->blocksize,
ss.channels, ss.rate);