Summary:ASTERISK-02495: [patch] Adjustabe Speex Codec
Reporter:Anthony Minessale (anthm)Labels:
Date Opened:2004-09-28 17:46:06Date Closed:2008-01-15 15:08:35.000-0600
Versions:Frequency of
Environment:Attachments:( 0) codecs.conf
( 1) speex.diff
Description:This patch makes it possible to control the quality of the speex codec from a configuration file [codecs.conf]

quality => 3
complexity => 4
; true / false
enhancement => true
; true / false
vad => false
; true / false
vbr => false
abr_quality => 5
; true / false
abr => false
vbr_quality => 5
; true / false
dtx => false


If you find use in any of the asterisk features I
have made, Go Ahead! Send me some money at paypal anthmct@yahoo.com

Comments:By: Brian West (bkw918) 2004-09-28 18:45:06

quality = 2
complexity = 3

great also.


By: fgravato (fgravato) 2004-09-28 21:27:07

quality = 1
quality = 1

Less overhead but doesn't sound to bad.. do able in harsh situations

By: Brian West (bkw918) 2004-09-28 22:21:13

fyi try 0/0

By: arkadi (arkadi) 2004-09-29 08:12:23

What is about implementing 4-5 most reasonable presets like speex4, speex8vbr that could be used as independent codecs with all the benefits of fine-graned configuration? Only codec init function should be replicated.
Additionally a preset itself could be tuned in codecs.conf, but only allowing to modify parameters that do not influence ability of the peer to correctly decode the stream without implementing same configuration changes on peer's side.
If you are still on Speex thing, there is a problem with chan_h323 and Speex. Gnomemeeting can do Speex too, but its expectation is different from what Asterisk sends. Both agree to use Speex but the result is garbage instead of normal audio. Asterisk implementation of Speex capabilities somehow could be synced to interoperate with H.323.

By: Brian West (bkw918) 2004-09-29 09:09:44

we do not have the namespace for that.

By: stevekstevek (stevekstevek) 2004-09-29 09:17:50

I've done some testing in this area, w.r.t speex quality vs bitrate, and also with speex speed vs bitrate.

Asterisk uses the speex shared library, I think, so the compile-time options I used in testing would need to be applied to the speex compilation.

Also note, that speex 1.1 will be a bunch faster than 1.0 and totally compatible.

Here's some results for just compression/decompression, on an athlon XP 1700+, 1.45Ghz:

Reference times:
GSM encode: 146x
GSM Decode: 280x

Speex Std Encode: 12.2x
Speex Std Decode: 168x

iLBC -O2:
Encode/Decode = 38.3X/112.2X

iLBC -O3 -ffast-math -funroll-all-loops -march=pentium3 -fprefetch-loop-arrays
Encode/Decode = 48.8X/183.8X

Speex options and compile options:
8kbps complexity 1:
Encoding/Decoding 29.2x / 168x realtime.

6.5kbps complexity 1:
Encode/Decode = 31.9x / 17.4x realtime

8kbps complexity 1, with compilation flags "-O3 -ffast-math -funroll-all-loops
-march=pentium3 -fprefetch-loop-arrays -fsingle-precision-constant"
Encode/Decode = 53.4x / 361x realtime

8kbps complexity 1, with compilation flags -O3 -msse
Encode/Decode = 65x/386x

Default settings, with compilation flags -O3 -msse
Encode/Decode = 28x/409x

So, in summary, with optimized compilation [including using the sse code in there), speex can perform very well.

Also, I'd look at the "ABR" modes it supports;  (average bit rates); this is a VBR mode with bandwidth constraints:  it will keep the average bit rate at the set point, but will use more or less bandwidth as the speech requires.

By: Anthony Minessale (anthm) 2004-09-29 20:21:00

Updated to let you control abr too

abr => true
abr_quality => 5

By: zoa (zoa) 2004-09-30 01:45:56

what will happen if im using speex with one setting at one server and try to negotiate with a speex with a different setting on another server ?

By: Brian West (bkw918) 2004-09-30 09:03:55


it just works.

By: zoa (zoa) 2004-09-30 10:54:48

But what will it negotiate to ?

And cant we have some kind of aliases in codec.conf that we can use in for example sip.conf ? Even if we cannot include this alias into the stuff we send to the other side for negotiating.

That way we can set it per peer, as that will be needed if you have a lot of customers.

By: stevekstevek (stevekstevek) 2004-09-30 11:01:54

" But what will it negotiate to ?"

OK, maybe I can clarify:

1) The speex settings are set on the encode side:  speex decoders can decode any valid speex bit-stream:  This is just like mp3 encoders:  You can encode with whatever encoder and settings you want, and any decoder can decode them.

2) These settings, in particular, will tell asterisk how to encode speex.  So, if you set these settings on server (A), it will affect all outgoing speex streams.  It will _not_ affect how other servers using speex send things to you.  They'll use either the default settings, or whatever they're configured to send.


Why would you want to change the remote side?  To save incoming bandwidth?

A future idea I have, for iax2, is to have receiver reports.  Using these, (as well as RTCP reciever reports), one could do stuff like automatically switch to lower-bandwidth codecs (or codec settings) if you detect packet loss, etc..

By: Mark Spencer (markster) 2004-09-30 23:16:45

Cleaned up and added to CVS

By: Russell Bryant (russell) 2004-10-01 17:49:02

new feature - not included in the 1.0 branch

By: Digium Subversion (svnbot) 2008-01-15 15:08:35.000-0600

Repository: asterisk
Revision: 3868

U   trunk/codecs/codec_speex.c
A   trunk/configs/codecs.conf.sample

r3868 | markster | 2008-01-15 15:08:35 -0600 (Tue, 15 Jan 2008) | 2 lines

Add configurable options to Speex (from anthm) (bug ASTERISK-2495)