Echo cancellation on Linux

So as I blogged about before, Collabora Multimedia has been doing a project with NLnet to improve echo cancellation support under Linux and Pulse Audio. There were and still are a lot of challenges to get it right, but we wanted to try to lay the groundwork for a system wide solution, which is why we decided to try to implement it within Pulse Audio.

For those wondering what echo cancellation actually means, it is a way to resolve the issue that if you record sound from your laptop microphone and at the same time output sound from your speakers, you easily end up with the sound looping, creating an irritating echo effect, which makes doing voice calls on a machine painful and sometimes impossible. Echo cancellation systems basically try to analyse the data coming out of the speakers so that it can filter it out and ignore it when it comes back through the microphone.

The final result is that we have created a virtual device pair which adds echo cancellation, these virtual devices are automatically used by your application if it announces itself as a ‘phone’ application to Pulse Audio. Our Empathy messaging and video conferencing client does this for instance. The bulk of our work is now done and for many use cases things should just work as soon as the output of our effort gets merged into Pulse Audio and packaged by the distributions. There are some open questions left, but we hope that by making this work available and trying to work with people within the ALSA community we will be able to resolve the remaining issues over time. Anyway, let me just give you the small report Wim Taymans wrote to summarize the work and what has been done:

Pulse Audio filter infrastructure

Currently the echo-cancel module is built upon the virtual source and sink examples, which is currently considered to be the Pulse Audio filter infrastructure.

We briefly looked into the ideas for a different generic filter infrastructure for Pulse Audio. Lennart Poetterings first attempts to implement such an infrastructure were put on hold because of the large complexity wrt to latency and rewinds. Because echo-cancellation is not purely a filter (it needs input from both sink and source) we decided to build the echo-cancel module as a virtual source and sink instead.

Echo cancelling for PulseAudio

A new module called ‘module-echo-cancel’ was added to Pulse Audio. The module adds a new echo-cancel source and sink to the existing devices. All samples played to the echo-cancel sink get echo-cancelled from the samples captured from the echo-cancel source.

The module is built so that new echo cancellation algorithms can be plugged in very easily. Two echo cancellers are implemented already, one based on Speex dsp and another based on the code from Andre Adrian.

The echo-cancel source and sink currently proxy the default source and sink in Pulse Audio. This can be changed with the pavucontrol application by changing the source and sink of the virtual streams.

Currently the echo cancellation code can deal with sources and sinks that share a common clock, such as those found on the same sound card.

For devices that don’t share a common clock, we currently don’t have accurate enough timings from pulseaudio yet in order to implement dynamic resampling. Most echo cancelling algorithms are extremely sensitive to drift and fail as soon as resampling is slightly inaccurate. This means that if you record sound using a USB microphone on your webcam for instance, there is a good chance the card will drift and the echo cancellation will cease to work.

Enable echo cancellation in Empathy

Any application can connect to the new echo-cancel source and sink to use the provided echo-cancellation.

The new echo-cancel source and sink are tagged with the ‘phone’ media.role so that the module called ‘module-intended-roles’ will automatically link Empathy to the echo-cancel source and sinks.

Echo Cancellation test application

In the case that echo cancellation doesn’t work on your system there is a good chance it is due to bugs in the audio driver, to make it more easy to test for this and provide useful bug reports we wrote a test application that can be run when echo cancellation doesn’t work. As with all such applications there is of course only a limited range of things we can test for so it will not be able to detect all types of problems, but it should be able to expose some of the more common ones.

Given that the echo canceller has to run on more than just the ALSA API (pulse audio has various backends), we implemented a new Pulse Audio module called ‘module-test’ that will run a set of tests on all existing source and sink devices.

The current tests include measuring the accuracy of the timevalues reported by the internal clock. The accuracy of this clock is one of the most crucial parts in Pulse Audio because it is directly used to estimate when samples will be played or captured. Having an accurate timevalue for when a particular sample was played and recorded is essential to implement echo cancellation.

An application called ‘patest’ is provided that runs the tests and outputs the results on the standard output.

The output of the patest application contains information about the various devices that were tested along with a min/max jitter and drift measured on those devices. The jitter and drift are mostly caused by inaccurate results returned from the ALSA drivers. A normal jitter would be around +-15us, a typical drift would be +-100us.

The module is constructed in such a way that more tests can be added later.

Future plans

We would really like to resolve the issue of using multiple sound cards, ie laptop speakers outputting from the internal sound card and microphone recording using a USB sound card in a webcam. In order to do so will will try to reach out to some of the core ALSA developers and see if we can work together to figure out if something can be done. In some cases the hardware might not be good enough to resolve the problem in software, but we hope that in at last the majority of the cases we will be able to compensate for hardware issues in the driver layer.

Another thing we hope to see is that with this infrastructure in place that maybe some commercial entities decide to open source their echo cancellation algorithms, enabling us to plug in new ones that are more robust in terms of handling clock drifting for instance. Another possibility is that academic projects working on echo cancellation can now find it easy to put their algorithms into a production system easily, so we can see some innovation in this field happen in the open source space.

GStreamer Conference 2010 approaching fast

So we are now just about a Month away from kicking of the worlds first GStreamer Conference. On the 26th of October, in Cambridge, UK we will host a long list of great presenters and talks on GStreamer and related topics. There are also some great GStreamer talks at the CE Linux Europe conference which happens on the 27th and 28th of October, like Benjamin Gaignard presenting on GStreamer and Android.

So check out the program and register for the conference or you risk missing the chance to meet members from the global GStreamer community.

Hope to see you all in Cambridge!

GStreamer Conference 2010 Update

So the preparations for this year GStreamer Conference 2010 is progressing at a healthy pace. Today I put the list of speakers and abstracts online, which combined with the conference timetable should let you plan the event pretty well.

I recommend everyone to look over the list of speakers and abstracts, because I am sure there will be things there everyone will find interesting.

I would also like to remind everyone that we got some great talks happening as part of CE Linux as well like Benjamin Gaignard of ST Ericsson talking about Android and GStreamer, Stefan Kost of Nokia talking about Meego and GStreamer and finally Arun Raghavan from Collabora Multimedia speaking about Pulse Audio. So make sure not to miss the CE Linux days.

You find registration information on the main conference website and be sure to register early as space is limited, so if you wait to long you might not be able to register at all.

Respect to the web developers

I been working on a web page for my wedding in November. This has turned out to be quite a lot more painful
than I expected and I have to admit my respect for web developers have increased a lot due to it. Getting a webpage to look nice across all browsers seems to be a really painful job.

Currently the only browser in which my page works perfectly is Firefox, Opera also does a mostly fine job, while Chrome fails on handling a dynamic SVG image I embedded in the page, and IE8, well lets not talk about what horrendous results it gives :)

Collabora Multimedia at GUADEC

The full Collabora Multimedia crew is in The Hague this week for GUADEC and our annual get together. It is the first time all 12 of us are together and its nice to spend some time face to face to get to know each other beyond IRC.

Currently doing a little hackfest at our hotel, pushing forward some cool stuff like echo cancellation, PiTiVi and more.

GStreamer Conference 2010

The preparations for the GStreamer 2010 conference is moving ahead at full speed. Today I was able to put the speakers list and program online showing out strong lineup of presenters and topics.

The actual GStreamer conference website is here for those of you who missed it the first time.

So be sure to mark 26th of October in your calendar so you can attend.
There are some great GStreamer related talks that will happen as part of
the CE Linux conference too, but I will wait until that program has been announced before letting you know more about those :)

OpenOffice and GStreamer

Was happy to see this OpenOffice and GStreamer blog entry today about how OpenOffice has chosen GStreamer to power the multimedia support in OpenOffice going forward. While users of OpenOffice on Linux have been able to enjoy GStreamer support for quite some time thanks to the efforts of Novell, it is still good to see that the upstream project is also coming around to officially supporting this. Currently only enabled by default for Unix/Linux systems I hope we will see it used on Windows and on MacOS X eventually. A big welcome to the OpenOffice community into the GStreamer community :)

One man against the elements

Every once in a while a man is faced with what seems like an insurmountable obstacle, at that point he has two choices, give up and despair or tackle the challenge head on. Yesterday I was faced with such an obstacle and in honour of my mountain dwelling ancestors I did the right thing and of course took on the challenge.

So what peril came across my path you ask? What challenge lead me to having to reach for new heights in ingenuity and problem solving? Well I will tell you. It all started in those days that Cambridge was bathed in blue skies and sunlight for over a week, it being such a rare occasion I felt a special tribute to the sun needed to be built and with no one else stepping up to the plate it was left to me to take on this Herculean and potentially dangerous task. The first component of my sun altar came from a land far away, known for its huge amounts of sunlight and its skimpy bikinis. This crucial building block was called the Amazonas Paradiso Terracotta Hammock and yesterday morning it was delivered to my humble abode.

However standing there with my new hammock I realized all was not well in the land, my garden only got one tree in it. And while others might have looked to the sky and screamed ‘why me?’ I instead decided to take matters into my own hands. So after a quick trip to B&Q I had gathered the materials I needed to create my own tree, my frankentree one could say. After a lot of digging, hammering, drilling and rope cutting, my act of creation was done, and a wonder had appeared in my humble garden.

And thus it had happened, against all odds and mother nature herself fighting against me, I had endured and in the end succeeded in my mission.

So now I can spend the rest of the summer relaxing in my wondrous hammock, enjoying Pax Romana