Asterisk VoIP: February 2008 Archives

Georgia on my mind - Asterisk plays music!

| | Comments (0) | TrackBacks (0)
While surfing on wikipedia, I found a nice article about the georgia anthem "Georgia on my mind". There is also an OGG file included of the Georgia chorus sung by the Air National Guard Band of the Southwest.

As I will use this file as a fine example and in fact it is licensed with a Creative Commons License, Attribution 2.5. I state: "This was performed as an exhibition by the Air National Guard Band of the Southwest, at the Moorpark College Jazz Festival on May 12, 2007. The vocals are sung by a woman."

For the fastest: Dial 1-678-954-8235 and you'll hear that chorus.

Back to Asterisk.
As I like the state of Georgia I tried to put that chorus on my asterisk server so I could ring it to hear it (ok I won't do it too often but I wanted to have some kind of reason to tell my fiancée that I am sitting again in front of that terminal...).

In the United States, digital voice communications in telephone systems are normally done with the ulaw format using 8000 samples per seconds, 8-bit wide each. It includes a dynamic compression, originally each sample is 16 bits wide. The ulaw algorithm makes a 8 bit sample out of it. Sampling accuracy is high at nearly silent tones and mediocre for louder sounds.
In Europe a similar technique is used, but we call it alaw here, in fact it does the same, it compresses 16 bits to 8. It is very simple to convert ulaw digital data to alaw and vice versa, just use a 255-value-table of compound alaw/ulaw sample pairs.

The first thing to do is to convert the ogg sound file to ulaw (and alaw). I'll use the swiss army knife of sound converters, sox.

sox ANGB_Georgia.ogg -r 8000 -U -c 1 -t raw georgia.ulaw resample -ql

and

sox ANGB_Georgia.ogg -r 8000 -A -c 1 -t raw georgia.alaw resample -ql

The "-c 1" downmixes the stereo output samples of the ogg file to mono (stereo on a phone system wouldn't really not make any sense), "-r 8000" tells sox to create a 8000 samples/sec output file. "-U" is the selector for ulaw, "-A" for alaw.

After copying these files to /var/lib/asterisk/sounds/pascal, I have been able to define this:

exten => 16789548235,1,Answer(1000)
exten => 16789548235,n,Playback(pascal/georgia)
exten => 16789548235,n,Hangup


So whenever a call comes in to 1-678-954-8235, you will hear the chorus, as Asterisk answers the phone first, then plays back the file and then hang up the line.

As you can see, Playback uses files relative to /var/lib/asterisk/sounds, (if you installed Asterisk in its standard locations). The file extension ".ulaw" is added automatically. Asterisk uses the ulaw file because it is an american phone line.

To have a usage for my alaw file, I just put it on one of my numbers of my ISDN line in Germany, using alaw. In that asterisk box, I had to define that:

exten => 3614219,1,Answer(1000)
exten => 3614219,n,Playback(pascal/georgia)
exten => 3614219,n,Hangup


Not really exciting, is it? The sole difference between the above US example and this one is the fact it will use the alaw file - German ISDN's voice transmissions are in alaw format.

So for the next days, you will be able to hear that chorus on

1-678-954-8235  (USA) and
(011)-49-7531-3614219   (German ISDN)

Enjoy :)
In case you did not know it, you can define outgoing MSNs in asterisk and misdn (Linux). It is even possible to tie a specific local telephone to another outbound channel:

[outbound]
exten => _X.,1,Set(OUTBOUNDMETHOD="mISDN/1/${EXTEN}");
exten => _X.,n,ExecIf($[ "${CALLERID(num)}" = "*1"],Set,CALLERID(num)=3614217)
exten => _X.,n,ExecIf($[ "${CALLERID(num)}" = "*2"],Set,CALLERID(num)=3614218)
exten => _X.,n,ExecIf($[ "${CALLERID(num)}" = "*6"],Set,
  OUTBOUNDMETHOD="SIP/${EXTEN}@sipPASCAL")
exten => _X.,n,Dial(${OUTBOUNDMETHOD})


In this case, the local phones *1 and *2 will send 3614217 or 3614218 respectively as local number on outgoing calls. *6 will allways use the sip provider defined as "sipPASCAL" in sip.conf.

Since many isdn providers list charges by msn in their invoices this is neat.


*1 and *6 are lines defined on my Cisco 7960 phone at my desk so I may choose myself which line I will use for callout.
my_7960.jpgFinally I got my Skinny Cisco 7960 phone working with my Asterisk server at home.

I am using chan-sccp-b, and I built it:

sassandra:/home/pascal/chan_sccp-20071213 $ make
sh ./create_config.sh "/usr/include"
Now compiling .... chan_sccp.c          1855 lines
Now compiling .... sccp_actions.c       1643 lines
Now compiling .... sccp_channel.c       1155 lines
Now compiling .... sccp_device.c        927 lines
Now compiling .... sccp_line.c          117 lines
Now compiling .... sccp_utils.c         1703 lines
Now compiling .... sccp_pbx.c           1004 lines
Now compiling .... sccp_cli.c           819 lines
Now compiling .... sccp_softkeys.c      558 lines
Now compiling .... sccp_socket.c        394 lines
Now compiling .... sccp_indicate.c      329 lines
Linking chan_sccp.so

The resulting .so-File has to be copied in the asterisk modules directory (/usr/lib/asterisk/modules if you have installed asterisk in standard locations).

Insert these lines in your modules.conf (/etc/asterisk/modules.conf):

noload => chan_skinny.so
load => chan_sccp.so

A sample sccp.conf:

[general]
keepalive = 30              
context = default
dateFormat = D.M.Y            ; date format         
bindaddr = 0.0.0.0            ; interface to bind to
port = 2000                   ; port to bind to (2000 = skinny)
debug = 4
accountcode=skinny            ; recordname appearing in cdr
callwaiting_tone = 0x2d       ; turn off callwaiting tone == 0
language=en
echocancel = on
silencesuppression = off
cfwdall = on                  ; turn on call forward button
cfwdbusy = on                 ; turn on call forward when busy button
dnd = on                      ; turn on "do not disturb"
mwioncall = on                ; lit message waiting light when new messages are
                              ; in voicemailbox
digittimeoutchat = #          ; type hash to stop dialing timeout
disallow = all
allow = alaw
allow = ulaw                  ; european isdn is alaw, so i use alaw as first preference

[devices]
type        = 7960            ; my phone is a 7960
description = Pascal          ; name appearing in the upper right
tzoffset    = 0
autologin   = *1,*6           ; we have exten *1 and *6
speeddial   = 1234567890,Important Number 1
speeddial   = 0987654321,Important Number 2
speeddial   = 0015552522631,Fake Number
speeddial   = 0310,Test
device => SEP000CCE3A88CA     ; This is the device Name (SEP+Mac)

[lines]
id            = *1            ; Extension
label         = 3614217       ; label on line button
description   = Pascal       
context       = default       ; incoming call context
callwaiting   = 1
incominglimit = 3             ; max 3 incoming calls
mailbox       = 1@default     ; corresponding voicemail box
vmnum         = *9            ; extension to dial to access VoiceMailMain()
cid_name      = Pascal Gienger
cid_num       = *1
line => *1

id            = *6
label         = 584298
description   = Pascal
context       = default
callwaiting   = 1
incominglimit = 3
cid_name      = Pascal Gienger
cid_num       = *6
line => *6

Extensions *1 and *6 are listed as line buttons on my 7960 screen, the second arguments of the speeddial-Commands are Strings which are displayed on the 7960's screen. If you omit them, the numbers will be shown.

In your dhcp server setting for the phone, don't forget to define option 150 (I am using ISC dhcp):

option cisco-tftp code 150 = array of ip-address;

subnet 192.168.100.0 netmask 255.255.255.0 {
        range 192.168.100.128 192.168.100.200;
        default-lease-time 86400;
        max-lease-time 172800;
        option domain-name-servers 192.168.100.2;
        option routers 192.168.100.1;
}


Then you may define the phone entry:

host phone1 {
        hardware ethernet 00:0c:ce:3a:88:ca;
        fixed-address 192.168.100.100;
        option cisco-tftp 192.168.100.2;
}

In my configuration on the asterisk host (192.168.100.2) a tftp server is running and there the phone should at least find 1 file:

  • SEPxxxxxxxxxxxx.cnf.xml (xxxxxxxxxxxx = MAC of your phone, uppercase!)
You do NOT need an "XMLDefaults.cnf.xml"-File unless you want to include also unknown devices (without a proper SEPxxxx-File)!

My SEP-file has the name SEP000CCE3A88CA.cnf.xml and looks like this:

<device>
 <devicePool>
  <callManagerGroup>
   <members>
    <member  priority="0">
     <callManager>
      <ports>
       <ethernetPhonePort>2000</ethernetPhonePort>
      </ports>
      <processNodeName>192.168.100.2</processNodeName>
     </callManager>
    </member>
   </members>
  </callManagerGroup>
 </devicePool>
 <versionStamp>{Jan 28 2008 19:01:00}</versionStamp>
 <loadInformation></loadInformation>
 <userLocale>
  <name>French_France</name>
  <langCode>de</langCode>
 </userLocale>
 <networkLocale>United_Kingdom</networkLocale>
 <idleTimeout>0</idleTimeout>
 <authenticationURL></authenticationURL>
 <directoryURL></directoryURL>
 <idleURL></idleURL>
 <informationURL></informationURL>
 <messagesURL></messagesURL>
 <proxyServerURL></proxyServerURL>
 <servicesURL></servicesURL>
</device>

The most important part are the lines

      <processNodeName>192.168.100.2</processNodeName>

and

       <ethernetPhonePort>2000</ethernetPhonePort>

as they define the address and port of your Asterisk server!
I wanted my phone to display all messages in french but my dialtone like in the united kingdom (i like that sound). I copied the needed messages from a cisco call manager to my tftp server. Due to copyright issues I can't post them here.

To make your phone reload any changes you made in this file you have to set up

 <versionStamp>{Jan 28 2008 19:01:00}</versionStamp>

as the phone compares this date to know that you want the configuration to be updated.

Even if your phone does not find  these files, it will still work - using the locale ist loaded the last time successfully - on new phones this will be English/United States.


After these steps the 7960 works in my asterisk environments. I can call out on ISDN and SIP lines and still have an SCCP (Skinny) phone on the desk.

The Dial() device parameter in extensions.conf  is "SCCP", so you may write:

exten => *1,Dial(SCCP/*1)

or

exten => 3614217,Dial(SCCP/*1)

to map an external ISDN number (in my case) to the local line *1 on the Cisco phone.