Building an Embedded Asterisk PBX Part 2

Here is the next installment in my adventures of building an embedded IP-PBX around the Blackfin-Asterisk. The big news is that we now have a working 4-port embedded IP-PBX and low cost hardware for sale!

DTMF Fixed Point Port

I spent a few days converting the Asterisk floating point DTMF detection code (dsp.c) to fixed point. You see the Blackfin doesn’t have a FPU so any significant floating point work (like DSP) needs to run in fixed point. This work brought the MIPs per channel down from about 200 to 5 (The Blackfin has about 500 MIPs available). It could run much faster if I ported the inner loop code to assembler however I think it’s fast enough for now.

To test the Asterisk DTMF detector I used Steve Underwood’s dtmf_rx_tests.c program from his very well written spandsp library. I moved from floating point to fixed point in a series of very small steps. After each step I ran Steve’s unit test to make sure I hadn’t screwed anything up. This is really the only way to test DSP code, you can’t just hack real time code then push a few buttons on the phone and hope it dials OK!

Here is some typical output from the unit test:
Test 4: Acceptable amplitude ratio (twist)
1 normal twist = 8.00dB
1 reverse twist = 4.20dB
5 normal twist = 8.40dB
5 reverse twist = 4.60dB
9 normal twist = 8.40dB
9 reverse twist = 4.60dB
D normal twist = 8.70dB
D reverse twist = 4.30dB
Test 5: Dynamic range
Dynamic range = 41dB
Test 6: Guard time
Guard time = 25ms
Test 7: Acceptable signal to noise ratio
Acceptable S/N ratio is 10dB
Test: Dial tone tolerance.
Acceptable signal to dial tone ratio is 15dB

Note the last test failed. This test also fails on the floating point code (i.e. running on a PC, before I ported it to the Blackfin). I am not sure why. Could be a switch I forgot to turn on or a bug in the dsp.c code. Need to look into that some day.

Echo Canceller Optimisation

I also spent some time looking at the mec2.h echo canceller in the zaptel package with a view to speeding up code execution. You see if we are running 4-8 analog channels we need to make sure the echo canceller is fairly efficient. In fact, the echo canceller is likely to dominate the CPU load of the PBX; Asterisk and the other DSP code uses a relatively small amount of MIPs in comparison.

I have identified a few areas where mec2.h could be optimised. One example is in the tap update code:
for (k=0; k<ec->N_d; k ) {
grad2 = CONVOLVE2(yada yada);
ec->a_i[k] = grad2 / two_beta_i;
ec->a_s[k] = ec->a_i[k] >> 16;

BTW I have deleted a lot of code for clarity. On the Blackfin the divide is a function call which is a no-no for real time DSP code. In fact divides are generally a bad idea for real time DSP, you want everything to be expressed in terms of multiplies and adds.

However, we are in luck. As we are dividing by a constant the divide can be pulled out of the inner loop:
inv_two_beta_i = 1/two_beta_i;
for (k=0; k<ec->N_d; k ) {
grad2 = CONVOLVE2(yada yada);
ec->a_i[k] = grad2 * inv_two_beta_i;
ec->a_s[k] = ec->a_i[k] >> 16;

There are also several other places where the echo canceller could be optimised. This would also help performance on x86 platforms, for example there is no reason why much larger tails (or larger spans) couldn’t be handled on a PC with a little more optimisation.

Multiple Analog Ports

Once I had the DSP code moving along nicely it was time to port the driver to handle multiple analog ports. Here is the output from the driver as it boots and auto detects 4 modules:
root:/var/tmp> insmod wcfxs.ko debug=1
Using wcfxs.ko

Registered Span 1 ('WCTDM/0') with 8 channels
Span ('WCTDM/0') is new master
iRxBuffer1 = 0xff803e58
iTxBuffer1 = 0xff803ed8
ISR installed OK
port: 1 port_type: O
port: 2 port_type: O
port: 3 port_type: S
port: 4 port_type: S
port: 5 port_type: -
port: 6 port_type: -
port: 7 port_type: -
port: 8 port_type: -

O means an FXO port was detected, S means an FXS port. In this case just four ports are loaded, out of a possible 8. You know I really should have added the letters “FX” in front of those strings. Hmmmmm. Maybe when I finish this blog post.

Here is what it all looks like when configured for four ports:

A pretty red light means an FXO port, green means FXS. The whole thing isn’t very big, about the size of a phone handset:

Want more than 4 ports? No problem. Just stack another board on top:

In this example I didn’t populate all the ports as I hadn’t soldered up enough modules at the time. Can you guess from the lights how each port is configured?

It might be useful to introduce a few terms:

  1. The mother board is the Blackfin STAMP card on the bottom. These are made by Analog Devices and are available off the shelf for about $200. They run uClinux and also support way-fast DSP work.
  2. On top of that I plug in a daughter board (why are boards always girls?). This puppy holds some glue logic and sockets for the modules and SD card.
  3. The modules are the little boards that plug into the daughter board. There are two types of modules, FXS and FXO. The daughter board holds four modules.

So the whole thing is very similar to the Digium TDM400 design (and other companies who use modular approaches I guess), except that here the mother board is an embedded system and the daughter board uses a serial bus rather than PCI.

Stack Overflow

I am pretty happy with the hardware stacking architecture, here are some other cool things it can do:

  1. Although I haven’t tried it you might be able to stack more boards on top, to give a total of 12, 16 ports etc.
  2. It would be easy to design a daughter card with sockets for 8 or even 12 modules, that way you wouldn’t have to stack it so high. You could then make an IP-PBX in the shape of a channel-bank.
  3. It’s possible to combine analog and other interfaces in one stack. For example you could combine analog ports and say BRI-ISDN using the fourfin board.
  4. If the Blackfin DSP starts to glow cherry red we can always add a DSP daughter card to handle say echo cancellation.


So how well does it work? Well it’s early days but so far so good:

  1. It works (really) and stays up until I bring it down, i.e. as far as I can tell it’s stable.
  2. I can make calls between ports and have run calls on 3 out of 4 ports at the same time. I ran out of phones and phone lines at that point!
  3. I can play the “Congratulations, you have successfully installed….” demo and even call Digium via the IAX2 demo.
  4. It makes and receives IAX2 & SIP calls OK.

Getting Involved

There are still plenty of things to do. If you would like to work on a leading-edge project with open hardware and software, you are very welcome to join our community and get involved.

Corporate sponsorship is welcome, however please don’t ask me to close the hardware designs (I get a lot of that). Some thoughts on the business and social possibilities are here. Some ways to contribute are engineering time, donation of test equipment, and direct financial support. In return you get high quality, well tested, open hardware designs and quality open DSP software.

We already have people working on software, hardware, and some companies donating test equipment and engineering time.

Next Steps

  1. Lots of testing. I would like to give the platform a good hammering using automated tests, for example have FXS ports call FXO ports continually and pass a few tones back and forth while measuring signal quality automatically.
  2. I would like to improve the echo canceller algorithm. I have a bunch of ideas and a “brains trust” of strong DSP guys who I am in email contact with to help on this one. I don’t see any reason why an open echo canceller can’t be made just as good at the proprietary echo cancellers being used in “hardware” echo cancellers today. After all, they are just software running on DSP chip. I am not saying it is a trivial problem (echo cancellation is tough DSP voodoo), but I am saying is is do-able. Any echo cancellation gurus out there – please email me if you would like to help with effort or even just advice.
  3. Implement booting via the SD-card.
  4. Complete the port to a late model Asterisk.
  5. Compliance Testing. I have booked the first set of compliance tests and will be aiming at approvals for the US, Canada, Australia and New Zealand. Once testing is complete you will be able to build and deploy real world products that are approved for connection to the telephone networks in these countries.
  6. The ultimate test. I will install one at my Mums house. If she can’t break it no one can. She is death to anything with IT in it. She doesn’t need a GUI, rather a RPI (rotary phone interface).

Hardware for Sale

I have started manufacture of 20 Beta units, they are due to ship in mid October. The price for a kit consisting of 1 daughter card and a total of 4 FXS/FXO modules (see photo below) is US$299 plus shipping (McDonalds ruler not included unless you really want one).

Combined with a US$226 BF537 STAMP card from Digikey (enter ADDS-BF537-STAMP-ND in the search box) you can start experimenting with your very own embedded Asterisk PBX with 4 analog ports for around US$500. Please email me if you are interested.

Buy purchasing my products you directly support open telephony hardware development.


  • Building an Embedded Asterisk PBX Part 1
  • Building an Embedded Asterisk PBX Part 3
  • loan 13 payday 19 online arizona6 city payday 4 central loan6 advance 4 loan payday paydayadvance6 8 loan payday vapayday loan bad credit 8direct consolidation 9 loancredit loans personal bad 90 daytax for loans abandoment purposes Mappornos bondagesubmission bondage pornsites porn bondeprone porn bonebonnie british pornstar porn bonniefucking boob porngame boob porn Mapporn pimp 50centsoldr 6and porn95991 tattoo closet artists pornmag a3 pornadept porn aaslincoln porn abeabuelas y porn sexo madresporn accept creditporn accion enny porn accord Map

    21 thoughts on “Building an Embedded Asterisk PBX Part 2”

    1. Hi !
      Before 4 years I’m working on DTMF decoder code for mcu MSP430 (TI). And I found on TI site source code for DTMF decoder with integers. It was nice code, very efficient (1-2 mips) using digital filters. I converted this code in VB6 code for testing. In VB6 I finished app for different simulation (DTMF generator with lo/hi frq. level attenuation, adding noise …). All results was good. Code is efficient, small, and robust.

    2. This is so awsome! Will you also be selling just the FXO and FXS modules to experiment with? Perhaps for a super small home system, hint hint 😉

    3. Hi Bryan,

      Thanks for your kind words. Sure it’s possible, however you would also need a clock oscillator and without the extra storage in the SD-card you can only boot via tftp. What might be nicer is a 2-port system with a small Blackfin system on board, ie a custom single-board hardware design.

      – David

    4. Oh so you will have that one ready when? 😉 That is what I was thinking actually, although I am no designer nor a great programmer but am willing to try most anything and believe this would be of use to others, so willing to put in some time where I can.

      Now a question from an extremely novice person, as I said, could the modules be make to work with a USB Port? IE the header thru circuitry converted and then plugged into a USB header or external port? Where I ma going with that is other SBCs have USB on them and have the timing and memory I use one as a 3 port router firewall and works very nicely, this would be real nice to add to the board as options to give a full home solution.

    5. He He – no plans to build it just yet, but if anyone would like to try a really low cost/low density implementation all the pieces are there (for example schematic and PCB designs for all the components).

      Re USB yes it is possible. One issue with USB is the latency of the tx and rx audio streams, I don’t know much about that. You might also need some fancy glue logic to implement the interface between the USB chip and the modules. Also your SBC may not have the horsepower for the DSP required, however for one or two channels it may be possible. My gut feel is it’s probably cheaper and a lower chip count to do it with the Blackfin.

    6. Hi

      I find the BOM of the 4fx.pcb.output_bom.txt is a little diffrence with 4fx-0.3.3.pdf. Could you tell me which is
      correct ?

      Best Regards

      Wang Xiang

    7. hi david
      I want to buy the fx kit . so how can i buy one!would you please mail me about how to buy one ! thanks!!

    8. Good Day!
      I have great interest in mounting a station as the described one above and would like to know as I make to obtain the archives in tango of the confection of the plates, the archives of software and the list of components used in the construction dess NetPBX

    9. David,

      I really enjoyed speaking with you at Astricon. I’d like to go ahead and purchase one of your ‘developer kits’, if you still have any available. I’d even consider assembing it myself, if it saves you the effort – and if I can get a pre-made board to mount the components on. Send me an email or reply in the thread when you get a chance.

      Keep up the good work!

      Chris Happel

    10. Hi, where could i find more resources to this subject… porting threaded apps to uClinux? You have more things, articles, etc? thnks

    11. sorry , could you tell me how to moved from floating point to fixed point steps ???
      I found the embedded asterisk detect dtmf(Inband) when used g711
      it will very delay……
      I play an ivr sound , default wait 3 seconds then play again.
      but if one channel used g711 become need to wait 10~20 seconds.
      if uper 2 channel used g711 , i wait long time then can not play again , and the all registed CPE will fail …..
      thank you very much…..
      Mail :

    12. Jackie – there is a patch for the float to fixed point conversion of the Asterisk dsp.c DTFM detector in

    13. David ,
      thanks a lot for your help
      that is a very nice code
      now , i can use 3 inband channels.
      But , i found another problem about the sip trunk register.
      i use asterisk register to a sip proxy, that is a public ip.
      my asterisk and 2 CPE used private ip at the same hub.
      if my hub’s uplink do not connection to router.
      sometime the 2 CPE can not make call.
      i found the asterisk retry register to sip trunk and every thing will lock…
      when it show timeout then it will unlock
      anyone find this problem???
      or my configs need to add some setting???

    14. Hi David,

      Thank you for this very nice peace of work! Wishing your goals helping developing countries come true.

      I’d like to buy the kit (Daughter board and FXS/FXO Modules. I don’t think I’ll use the Mc ruler :) ). Please write to me for details.


    15. I am interested in this project is it still alive … I am trying to build something similar using Raspberry pi … as a personal project but interested to build it up as a business as well..
      I would appreciate your feedback


    Comments are closed.