RasPBX bad sound quality when using a dongle

I am completely new here, so excuse my silly questions.

I came across RasPBX and installed it (current version is raspbx-10-10-2020) on my RaspberryPi 3. OS (based on Raspbian) includes Asterisk 16.18.0 and FreePBX I am located in Slovenia, Europe.
I am also using Huawei USB dongle and have set up trunk to mobile network via that dongle.

For clients I am using Zoiper 5 (on Linux, iOS and Android).

Another thing. I had problems with UDP - after 30 seconds (of established connection) call has been dropped. I suppose there has been a problem with SIP ALG, I switched it off on my router, but the problem persisted. So I switched to TCP connection and now everything works just great. However, I am not using TLS/SRTP/ZRTP encryption, but my RasPBX device and clients are operating within secure OpenVPN network. BTW - OpenVPN server is located somewhere else (in Slovenia), so VPN connection between OpenVPN server and RaspPBX and other clients is going through the internet.

Now the problem.

I have tested the incoming and outgoing call via USB dongle and first test were quite good. I am able to call from my GSM to RasPBX and the client can answer the call and sound is of a good quality. I can also call from a Zoiper client to the outside number and call quality is good.

So I decided for some more tests.

I have asked a colleague from USA, Ilinois for a test. Call from one Zoiper client to the other (through the VPN) is working very good. Sound quality is really good.

But then I asked a colleague to call my GSM through USB dongle.

In that case call quality was bad, it was really hard to understand what he was talking.

I am not an expert, but have a feeling this is codec related. This is the list of my codecs under Settings - Asterisk SIP Settings:

  • g722
  • alaw
  • ulaw
  • g729
  • gsm
  • g726
  • g723
  • speex

In a logs, I can see lines like this:
2021-10-27 19:50:07] NOTICE[26589][C-0000000b] translate.c: 2604 lost frame(s) 2605/0 ([email protected])->([email protected])
I assume that means g722 is being used, I have also found out Asterisk is internally using slin coded and then performs transcoding, but don’t know why or if this could affect the sound quality.

What is weird to me is that call from one PJSIP extension and the other has great sound quality, but if call goes through USB dongle, sound is much much worse.

Transcoding can be CPU intensive, and CPU bottlenecks can cause audio issues. The RiPi is quite capable little machine, but there is not a lot of CPU overhead to work with. Can you look at your CPU/Memory usage when you are observing the problem? If it is a resource issue, lessening the transcoding (how to do this is unique to how you are using the PBX) will help with that.

That sounds more like you are subject to NAT but haven’t provided your public addresses. In fact, in a mobile phone environment, you may find that they are impracticable to find, as the IP sharing may not be designed to cope with people who need to know how to route back to the phone.

Asterisk will use slin if you have a conference bridge, because it needs the audio in linear form before it can add it up, or if you originate without specifying codec, because when it sets the preferred codec, it does not know anything about the SIP peer or peers on the resulting legs.

For GSM network usage I would prefer gsm over g722 as it should always work on gsm but g722 is carrier specific.

Thank you for your answers. Unfortunately I am not able to test much more, even my friend in USA is very patient…


@comtech - I plan to buy RPi4, which has more powerful CPU. Do you suggest I should buy a RPi with more RAM (there are models with 2, 4 and 8 GB)?

Can you explain more about lessening the transcoding? Basically, I would like to use PBX to be able to call from my SIM when I am abroad. And to receive calls to my SIM card when I am abroad.

@david55 - regarding the NAT. Can you explain what you mean by that? RasPBX and my clients (computer, mobile phone,…) are connected to OpenVPN network, where they all have fixed IP addresses and they can see each other. For instance, my RasPBX has IP This IP is accessible only via VPN network, and not from the outside.

@dicko - so you suggest I move gsm codec on the top? However, I have another question. I always thought, that codecs that are used inside PBX are . Am I wrong?
I mean, if a call comes from GSM network to my USB dongle (dongle have voice capabilities), I assume there it is decoded and then encoded again by PBX and “sent” to the appropriate extension. If that is true, any codec outside my PBX could be used, and will have no influence to codecs inside PBX. I hope I was able to explain what I am thinking.

Anyway, I did a little test - I changed the extension for incoming calls - before, it was on a computer, now it is on iPhone. And the sound is much better. So I assume it is also the problem of microphone. Nevertheless, which would be the best codec if I expect bad network conditions?

I’d need to see a protocol trace and the actual configuration, but the most common reason for calls dropping at 30 seconds is that the ACK never gets through, and the most common cause of that is that contact address in the response is a private address when the call is using public addresses.

I’d assumed the dongle was being used in data mode, but, if correctly set up, so that both sides use GSM as the codec, it will pass through the PABX unmodified, as long as as the call is set up normally, rather than with originate, and it doesn’t go through a conference bridge. Transcoding may be necessary on side paths, e.g. for recording. GSM doesn’t support DTMF, so DTMF should be carried out of band. In band DTMF would also require transcoding.

@david55 - yes, I figured out that ACK didn’t went through, so I decided to switch to TCP protocol and now it works.

Also, I have another question - I have found out that volume on iPhone is very low. Is it possible to increase the volume in Asterisk? I was reading about editing the /etc/asterisk/extensions_custom.conf, but don’t know exactly what should I change.

Currently it contains:

exten => sms,1,Verbose(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})})
exten => sms,n,System(echo "To: [email protected]\nSubject: Incoming SMS from ${CALLERID(num)}\n\n${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${CALLERID(num)}: " > /tmp/sms.txt)
exten => sms,n,Set(FILE(/tmp/sms.txt,,,a)=${BASE64_DECODE(${SMS_BASE64})})
exten => sms,n,System(sendmail -t < /tmp/sms.txt)
exten => sms,n,Hangup()
exten => _.,1,Set(CALLERID(name)=${CALLERID(num)})
exten => _.,n,Goto(from-trunk,${EXTEN},1)

I have tried to add:
exten => X.,1,Set(VOLUME(TX)=7)
exten => X.,n,Set(VOLUME(RX)=7)
…but it seems there is no effect on increased volume. The extension on iPhone is 3000.

One thing to note is that the G.722 used for HD Voice on mobile networks, is not the the g722 understood by Asterisk. It is G.722.2, but Asterisk only understands plain G.722, which is actually a different technology, with only really the audio bandwidth in common. G,722.2 is or was patented, and I don’t believe there is any Asterisk transcoder for it, so if taking audio from mobile phone voice channels, you need to use GSM if you want to avoid something being forced to transcode it.


To change the SIP volume in FreePBX you need to edit extensions.conf and admin/modules/core/functions.inc.php (from which extensions_additional.conf is generated)

To set the incoming (and internal) volume search for macro-dial in extensions.conf

It should look like

exten => s,1,GotoIf("${MOHCLASS}" = “”?dial)
exten => s,n,SetMusicOnHold(${MOHCLASS})

You need to edit it to look like this, the volume (TX) and (RX) are the transmit and receive levels, they can be any integer between 0 and 10 although you’re unlikely to use more than 4.

exten => s,1,Set(VOLUME(TX)=4)
exten => s,n,Set(VOLUME(RX)=4)
exten => s,n,GotoIf("${MOHCLASS}" = “”?dial)
exten => s,n,SetMusicOnHold(${MOHCLASS})

To set outgoing volume search for macro-dialout-trunk in /var/www/html/admin/modules/core/functions.inc.php (or where ever your FreePBX install is located)

It should look like

$context = ‘macro-dialout-trunk’;
$exten = ‘s’;
$ext->add($context, $exten, ‘’, new ext_set(‘DIAL_TRUNK’, ‘${ARG1}’));

You need edit it to look like this, again setting the volume levels

$context = ‘macro-dialout-trunk’;
$exten = ‘s’;
$ext->add($context, $exten, ‘’, new ext_set(‘VOLUME(TX)’, ‘4’));
$ext->add($context, $exten, ‘’, new ext_set(‘VOLUME(RX)’, ‘4’));
$ext->add($context, $exten, ‘’, new ext_set(‘DIAL_TRUNK’, ‘${ARG1}’));

Reload FreePBX and you should notice your calls are now much louder!

Changing volume is another thing that will force transcoding to slin*

Thank you.

However, if I open the file /etc/asterisk/extensions.conf
it says:

; Do NOT edit this file as it is auto-generated by FreePBX. All modifications to ;
; this file must be done via the web gui. There are alternative files to make    ;
; custom modifications.                                                          ;

Any idea how to make this modification via web GUI? Or is it safe to change the settings, i. e. will not be overwritten by FreePBX sometime later?

Another problem… /etc/asterisk/extensions.conf contains this:

; macro-dial has been converted into a function.
; see core/functions.inc/macro-dial.php

But I cannot find file macro-dial.php.


Is a way to override any context in extensions.conf.

OK, so if I understand correctly:

  • outgoing volume is set in /var/www/html/admin/modules/core/functions.inc.php
  • incoming (and internal) volume is set in extensions.conf

(In my case I have a problems with incoming volume).

However, since I should not be using extensions.conf, I should edit /etc/asterisk/extensions_override.conf instead.
My question is - how?

Should I add only this into this file (currently this file is empty)?
$ext->add($context, $exten, ‘’, new ext_set(‘VOLUME(TX)’, ‘4’));
$ext->add($context, $exten, ‘’, new ext_set(‘VOLUME(RX)’, ‘4’));

This is for overriding (replacing what extensions_additional has) a context, according to the linked instructions above, for incoming, you need to adjust the [macro-dial] context.

In the override file I would add:
exten => s,1,Set(VOLUME(TX)=4)
exten => s,n,Set(VOLUME(RX)=4)
exten => s,n,GotoIf("${MOHCLASS}" = “”?dial)
exten => s,n,SetMusicOnHold(${MOHCLASS})

I would look at the original [macro-dial] context so that you bring over all the existing lines that are in play on your PBX, then just add your additional VOLUME lines.

EDIT: As Lorne mentions below, the downside to this approach is that [macro-dial] will remain in a permanently overrode state. This means if the FreePBX project modifies [macro-dial] in extensions_additional, your overrride file would continue to use your older context. Now will the [macro-dial] context change greatly in the short-term, probably not, and you’d likely be fine in this instance, but Lorne’s approach is the better practice.

As a “proof of concept” editing the override file is okay, but as a supportable way to fix this, its FAR better to use a dialplan hook: Hooking for fun and income

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.