$ cd ~ $ wget http://www.rowetel.com/ucasterisk/downloads/oslec-0.1.tar.gz $ tar xvzf oslec-0.1.tar.gz $ cd oslec-0.1 $ make $ insmod kernel/oslec.ko
Open Source Line Echo Canceller (OSLEC)IntroductionOslec is an open source high performance line echo canceller. When used with Asterisk it works well on lines where the built-in Zaptel echo canceller fails. No tweaks like rxgain/txgain or fxotrain are required. Oslec is supplied as GPL licensed C source code and is free as in speech. Oslec partially complies with the G168 standard and runs in real time on x86 and Blackfin platforms. Patches exist to allow any Zaptel compatible hardware to use Oslec. It has been successfully tested on analog and PRI x86 hardware (e.g. TDM400, X100P, Sangoma A104 etc) and on the IP04 embedded Asterisk platform. There is also a project underway to use OSLEC with mISDN. Oslec is included in many distributions, including Debian, Gentoo, Trixbox, Elastix, and Callweaver. TestimonialsSo how good is Oslec?
Thanks for OSLEC, it's so much better than my hacked KB1 which is called MG2 :-)
Author of the Zaptel MG2 echo canceller — Michael Gernoth Once I managed to get OSLEC installed (it was a big job for me, because I was missing many of the dependancies and knowledge), it immediately fixed the echo problems I had been unable to get rid of to date despite lots and lots of tweeks, tests and fiddling. Even more suprisingly, it appears to converge almost immediately from my initial test. This code is the best since thing since, well, Asterisk !!!
— David Gottschalk
Short version: KB1 < MG2 < OSLEC < HPEC In the open source line echo canceller category, OSLEC is so far the best I've seen. It converges reasonably fast, and thanks to it's dual-path approach, will converge, albeit a bit slowly, on nasty echo paths where cancellers like KB1 and MG2 will fail entirely. The nonlinear processor and comfort noise generator provide for a far more pleasant listening experience than KB1/MG2. It's not quite up to the grade of ADT's G.168 canceller used in Digiums HPEC product in terms of convergence speed or tail coverage.
Head Of Engineering; Vadacom Ltd — Nic Bellamy Since I installed the first version of OSLEC I was hooked…. It's been several months now since the alpha version was released; after using OSLEC Mark and I agreed that we had to have OSLEC as the main echo cancellation in the Astfin distribution.
Astfin.org — Pawel Pastuszak I've been working with Oslec since March of 2007. Oslec has had some problems, but, thanks to David, they are solved. Now, I can say Oslec is time-tested. The best, I can note - it is still under development (with feed-back). Thank you David for your good deed. BTW: comparison to Intel IPP's echo canceler have shown, Oslec is very good :-)
Parabel Ltd — Pavel Selivano Oslec News
HowTo - Run OSLEC with Asterisk/ZaptelNotes:
1/ Download, build and install oslec: $ cd ~ $ wget http://www.rowetel.com/ucasterisk/downloads/oslec-0.1.tar.gz $ tar xvzf oslec-0.1.tar.gz $ cd oslec-0.1 $ make $ insmod kernel/oslec.ko Optional: If you want the latest and greatest, replace the "wget" step with: $ svn co http://svn.astfin.org/software/oslec/trunk/ oslec
2/ Build, patch and install Zaptel. First obtain zaptel-1.2.13.tar.gz and: $ tar xvzf zaptel-1.2.13.tar.gz $ cd zaptel-1.2.13 $ ./configure $ patch < ../oslec-0.1/kernel/zaptel-1.2.13.patch (see note 1 below) $ cp ../oslec-0.1/kernel/dir/Module.symvers . (see note 2 below) $ make $ insmod zaptel.ko $ insmod wctdm.ko $ ./ztcfg $ asterisk
3/ These options in zapata.conf are important: echocancel=yes
echocancelwhenbridged=no
;echotraining=400
The echocancelwhenbridged=no allows faxes to pass from FXS to FXO ports without interference from the echo canceller. This option is important for fax signals. Make sure echotraining is disabled when using Oslec - this is not supported and if enabled will cause the channel to be silent (i.e. no audio will pass through). PBX in a Flash InstallJD Austin has documented an Oslec install procedure for PBX in a Flash. Thanks JD. Rhino PRI cardsThe rhino-2.2.6 driver for Rhino PRI cards has software echo cancellation disabled by default. This means there is no echo cancellation unless you opt for the Rhino hardware echo cancellation module. However the driver is easy to hack to enable software echo cancellation, and hence Oslec. In the rhino-2.2.6 driver, file r1t1_base.c, r1t1_receiveprep function, around line 800: static void r1t1_receiveprep(struct r1t1 *rh, int nextbuf)
{
/*
int x;
for (x=0;x<rh->span.channels;x++) {
zt_ec_chunk(&rh->chans[x], rh->chans[x].readchunk, rh->ec_chunk2[x]);
memcpy(rh->ec_chunk2[x],rh->ec_chunk1[x],ZT_CHUNKSIZE);
memcpy(rh->ec_chunk1[x],rh->chans[x].writechunk,ZT_CHUNKSIZE);
}
*/
zt_receive(&rh->span);
}
Solution 1: Simply un-comment the code and rebuild the driver: static void r1t1_receiveprep(struct r1t1 *rh, int nextbuf)
{
int x;
for (x=0;x<rh->span.channels;x++) {
zt_ec_chunk(&rh->chans[x], rh->chans[x].readchunk, rh->ec_chunk2[x]);
memcpy(rh->ec_chunk2[x],rh->ec_chunk1[x],ZT_CHUNKSIZE);
memcpy(rh->ec_chunk1[x],rh->chans[x].writechunk,ZT_CHUNKSIZE);
}
zt_receive(&rh->span);
}
Solution 2: Bob Conklin from Rhino has suggested this fix that they have in SVN trunk: static void r1t1_receiveprep(struct r1t1 *rh, int nextbuf)
{
if (!rh->dsp_up)
zt_ec_span(&rh->span);
zt_receive(&rh->span);
}
This version automatically falls back to software echo cancellation if the DSP-based hardware echo cancellation is not present. Thanks Bob! StatusCurrent status is considered Stable. As of 3 January 2008:
DirectoriesThe Oslec SVN repository combines several projects (mainly spandsp) used to develop, test, and run oslec. spandsp : A subset of spandsp to support testing and development of Oslec. The echo canceller and G168 test suite source code live in here. user….: User mode apps, e.g. sampling of echo signals and a unit test for measuring the execution speed of Oslec. kernel..: Builds Oslec into a kernel module. Also contains patches for Zaptel to allow the use of Oslec. Run Time InformationSet up a call that uses an analog port, then check out /proc/oslec for real-time stats: [root@homework kernel]# cat /proc/oslec/info channels....: 1 mode........: [13] |ADAPTION|NLP|CNG| Ltx.........: 0 Lrx.........: 211 Lclean......: 211 Lclean_bg...: 211 shift.......: 0 Double Talk.: 1 MIPs (last)....: 1 MIPs (worst)...: 7 MIPs (avergage): 1 You can turn the various mode switches off and on, for example: echo 9 > /proc/oslec/mode turns off comfort noise, but keeps ADAPT and NLP on. The mode switches are listed in the echo.h header file (#define ECHO_CAN_USE_*). The /proc interface only monitors the first Zaptel call you bring up, see oslec_wrap.c for more information. There is a GUI for run-time control of Oslec, called the Oslec Control Panel. For example you can Enable and Disable the echo canceller in real time, as you are speaking. If you Reset the echo canceller you can hear how long it takes to converge again.
$ cd kernel $ ./oslec-ctrl-panel.sh
Execution Speed and OptimisationIn the user directory there is a speedtest.c program that measures how many MIPs the echo canceller consumes and estimates how many cancellers can run in real time. The current x86 code is vanilla C and could be greatly improved with MMX or SSE optimisations, some of which are already coded in spandsp. There is also much that can be done to improve execution speed on the Blackfin. Steve's spandsp code includes some support for MMX and SSE2 optimisation. Define USE_MMX or USE_SSE2 in the Makefile to use this option. At this stage only the fir.h filter code is optimised, oslec would run much faster if lms_adapt_bg() in echo.c was also ported to MMX/SSE2. With USE_MMX defined, the speedtest.c program dropped from 33 MIPs to 20 MIPs per channel for 256 taps/32ms. If using MMX in the kernel (e.g. with zaptel) make sure you compile zaptel with CONFIG_ZAPTEL_MMX to ensure the FPU state is saved in the right places. Thanks Nic Bellamy for help in testing MMX. Some notes on further optimisation: 1/ How do lots of MIPs in ISR affect total system performance? For example if we are using 25% of MIP in ISR does * still run OK? Find the CPU load knee different for user versus kernel mode cycles consumption. 2/ Estimated Oslec MIPs are 5(N)(Fs), N is the filter size (number of taps), Fs=8000 is the sampling rate. Factor of 5 is comprised of 1 for each FIR filter (forgeround and background), 2 for LMS, 1 for overhead. This suggests that when optimised around 10 MIPs for a 32ms tail. 3/ There are some more notes on optimisation for the Blackfin in echo.c. Background and CreditsOslec started life as a prototype echo canceller and G168 test framework from Steve Underwood's Spandsp library. Steve wrote much of the DSP code used in Asterisk, and the Zaptel echo cancellation code is heavily based on his work. Using the Spandsp G168 test framework, a high performance echo canceller has been developed and carefully tested. Working together with alpha testers the performance has been brought to a beta state. More. Thanks to Steve Underwood, Jean-Marc Valin, and Ramakrishnan Muthukrishnan for their suggestions and email discussions. Thanks also to those people who collected echo samples for me such as Mark, Pawel, and Pavel. Thanks Nic Bellamy for help with testing, explanation of long path issues, and MMX support. Thanks Tzafrir for testing and patches/enhancements and Dmitry for help with multithreaded and locking issues. Thanks Vieri for finding a circuit with a tail > 32ms, and Patrick for submitting a Zaptel 1.2.18 patch. Thanks Dave Fullerton and Carlton O'Riley for Zaptel 1.4.3/1.4.4 patches. Thanks Bill Salibrici for finding a memory leak. Thanks Michael E. Kromer for submitting a Zaptel 1.4.7.1 patch, and Tzafrir for the Zaptel 1.4.8 patch. Thanks Russ Price for the Zaptel 1.2.24 patch. Thanks Chris Notley for the 1.4.11 patch. Thanks to Peter Schlaile for porting Oslec to mISDN. Thanks also to Kristijan Vrban for sending me some ISDN hardware so I can help with the ISDN/Oslec testing! Thanks to Tzafrir and Faidon for helping debug the muted audio problems on 64 bit systems. Sampling Zaptel EchoIntroductionI have developed a system for sampling echo on running Zaptel/Asterisk systems. If you do experience any echo with Oslec, please use this system to sample the echo, then email the sample files to me. See the Part 1 blog post for more information on sampling echo. The nice thing about is that it doesn't interfere with your running Asterisk system. If you hear echo at any time you can fire up a console and run "sample" to capture real-time data from the Zaptel port. There are other ways to capture audio from a running Asterisk system, for example using the built in Asterisk play and record applications. However this system is designed to capture exactly the signals being fed to & from the echo canceller - preserving the exact timing of the signals and with no intermediate buffering. This is very important for echo cancellation work - the algorithms depend on an exact timing relationship between the transmit and receive signals. The system simultaneously captures the receive signal both before and after the echo canceller - something that is difficult to do with the built in Asterisk functions due to the location of the echo canceller deep in the Zaptel driver. If you would like to help further develop Oslec, please send me your echo samples! I would welcome any samples of your echo signals, for example where the echo canceller isn't working well, and also cases where it does work well. By comparing the two cases we can learn a lot about the strengths and weaknesses of the algorithm. Installing1/ Install Oslec ("HowTo - Run OSLEC with Asterisk/Zaptel" section above). 2/ If you would like to use zaptap without oslec change the selected echo canceller in zconfig.c and rebuild/install zaptel. 3/ Compile sample.c: # cd user # make 4/ Create a device node. I used major number 33 as it was free on my PC: # mknod -m 666 /dev/sample c 33 0 If 33 is not free choose a free major number and change the #define SAMPLE_MAJOR in zaptel.c and recompile. Note it is important to "insmod zaptel.o" from inside the zaptel directory and don't forget the ".o" (.ko for Linux 2.6). Otherwise insmod will use the previously installed version of zaptel and "sample" won't work. 5/ Make the call to the Zaptel port you wish to sample. Run sample while talking: # ./sample test 1 5 this will create test_tx.raw, test_rx.raw & test_ec.raw. There will be a few messages on the console as the driver does it's thing, you can check these with dmesg. 6/ You can check your samples by playing them back through your sound card, for example: # play -f s -r 8000 -s w test_ec.raw 7/ To convert the raw files to wave files (this is more convenient for playing and processing with the Oslec simulation): # sox -t raw -r 8000 -s -w -c 1 test_ec.raw test_ec.wav # play test_ec.wav 8/ There is an Octave script pl.m to help plot the samples: # cp /your/test/samples ~/oslec/user
# cd ~/oslec/user
# octave
octave:1> pl("test")
Configuration
signalling=fxs_ks
echocancel=yes
;echocancelwhenbridged=yes
;echotraining=400
group=2;
conext=incoming
channel =>4
Note echo training is switched off, although this didn't make much difference to the FXO Port when using the built-in Zaptel echo cancellers. (helped the the FXS port though). Oslec does not support echo training. SupportOpen IssuesI would really appreciate some help with these issues! I am mainly a DSP/hardware guy so could use some help in the kernel mode module area:
Further WorkHere are some ideas for further work. 1/ Make info screen on control panel update each second automatically. 2/ When e/c is reset during a call it converges faster than at start of calls. This suggests e/c is wandering off into dumb states before the call is connected. Perhaps disabling adaption until the call is connected would help with faster convergence 3/ Preserving the state of the e/c between calls is also a very good idea, current zaptel design destroys the e/c at the end of a call. 4/ Switch on and test SSE and MMX filter code for x86. Code LMS update for x86 in SSE or MMX. 5/ Add a feature to /proc/oslec to extract the current estimated impulse response. Use gnuplot or Octave to plot it in real time. 6/ Attempt to speed convergence. 7/ Set up test scripts for greater coverage of G168 tests. 8/ If necessary develop a sparse approach to handle 128ms tails. HowTo - OSLEC G168 SimulationThe simulation form of Oslec is useful for Oslec development. It is much easier to develop using a non-real time, user mode program than saying 'Hello,…1,…2,….3" down a telephone line. The simulation dumps internal states while it is running, which can be plotted and analysed using Octave.
Further Reading
There are several blog posts documenting the development of Oslec:
Some useful links:
|