15 Replies Latest reply on May 24, 2015 5:58 PM by 0d0a

    PJSIP/PJSUA with Wolfson audio card

    joacim

      I am trying to get a SIP client running on my PI with Wolfson audio card.

       

      I can use aplay and arecord, work great but when I set up a call with PJSUA I get the following errors:

       

      07:14:34.698pjsua_app.c  ..Turning sound device ON
      07:14:34.698pjsua_aud.c  ..Opening sound device PCM@16000/1/20ms
      07:14:34.707 alsa_dev.c  ...ALSA lib pcm_hw.c:326:(snd_pcm_hw_hw_params) SNDRV_PCM_IOCTL_HW_PARAMS failed (-22): Invalid argument
      07:14:34.707pjsua_app.c  ..Turning sound device ON
      07:14:34.707pjsua_aud.c  ..Opening sound device PCM@44100/1/20ms
      07:14:35.292ec0x14005a8  ...Echo suppressor created, clock_rate=44100, channel=1, samples per frame=882, tail length=200 ms, latency=100 ms

      07:14:35.293  pjsua_media.c  .Call 0: initializing media..

      07:14:35.297 alsa_dev.c  ALSA lib pcm_hw.c:587:(snd_pcm_hw_start) SNDRV_PCM_IOCTL_START failed (-12): Cannot allocate memory

       

      Anyone that can guide me in the right direction on how to get this running?

       

      Best Regards

        • Re: PJSIP/PJSUA with Wolfson audio card
          shabaz

          I wonder if it is a bitrate issue. A google for that error suggests it might be, but it was unclear.

          16000 is possibly unusual (I'm no expert). 8000 is often more likely. You could check your SIP software config file to see if you can set the bitrates used to something else.

          I could be completely wrong, but it is worth a try.

            • Re: PJSIP/PJSUA with Wolfson audio card
              joacim

              Hi, thank you for the response. I could not configre this so I had to do some hard-coding. Given that I wrote the code correctly it did unfortunately not help.

               

              08:34:18.298    pjsua_app.c !.Turning sound device ON

              08:34:18.303    pjsua_aud.c !.Opening sound device PCM@8000/1/20ms

              08:34:18.311     alsa_dev.c  ..ALSA lib pcm_hw.c:326:(snd_pcm_hw_hw_params) SNDRV_PCM_IOCTL_HW_PARAMS failed (-22): Invalid argument

            • Re: PJSIP/PJSUA with Wolfson audio card
              honi-pi

              Same situation for me. I have a voice app which normally runs in 8k mode. The app supports the rates 8k, 16k and 48k, but only 48k works. There is no advantage for the voice processing from using 48k, but it unnecessarily increases the CPU load.

               

              It would be nice to get some feedback from Wolfson what sampling rates will be supported by future driver releases (on the analogue line in/out connectors).

              • Re: PJSIP/PJSUA with Wolfson audio card
                jwhyte

                Thanks for your post on the sample rate support for the ADC and DAC paths (specifically the analogue input and output paths).

                 

                I can confirm your observation on the sample rate limitation. From our perspective it wasn’t the intention to limit the audio ADC and DAC sample rates to above 32k.

                 

                At the moment we are investigating an update to the drivers which will allow full 8k to 192k support for the analogue inputs and outputs.

                We will keep you posted on progress.

                 

                Thanks.

                • Re: PJSIP/PJSUA with Wolfson audio card
                  ragnar.jensen

                  I too have been bitten by the sample rate bug...

                  I have modified my ~/.asoundrc quite a bit in order to be able to record 1-channel at 8kHz and 16kHz.

                  I'm using ALSA's built-in re-sampling capabilities.

                   

                  This is not for those who like to enjoy HD audio! The sound card operates at 48kHz/16bit at all times.

                  Everything is re-sampled and converted up or down as needed.

                  --

                  Ragnar

                   

                  #######################################################################
                  #
                  # Use libsamplerate instead of internal resampler.
                  # You might have to: sudo apt-get install libasound2-plugins
                  # Or just comment out the next line if the internal one is good enough for your needs.
                  defaults.pcm.rate_converter "samplerate"
                  
                  ######################################################################
                  #
                  # Wolfson Audio Card for Raspberry Pi
                  #
                  pcm.wolfson_pi_soundcard {
                      type hw
                      card sndrpiwsp
                      device 0
                  }
                  # Create a Master volume control
                  pcm.softvol {
                      type            softvol
                      slave {
                          pcm         "pduplex"
                      }
                      control {
                          name        "Master"
                          card        0
                      }
                  }
                  
                  pcm.!default  {
                      type           asym
                      playback.pcm   "plug:softvol"
                      capture.pcm    "pduplex"
                  }
                  
                  #####################################################################
                  #
                  # Mixing and resampling goodness :-)
                  #
                  # Several clients can record and play back simultaneously.
                  # The dmix and dsnoop plugins operate at 48kHz by default, i.e. the sound card will be kept at 48kHz at all times.
                  # All playback streams are converted to 2 channels/48kHz/16bit.
                  # All recording streams are converted from the card's 2 channels/48kHz/16bit
                  # to the requested number of channels, sample rate and bit depth.
                  
                  # We define one pcm device called "playmixer" for playback.
                  pcm.playmixer {
                          ipc_key 140324  # Any number will do, as long as it's unique in the system.
                          ipc_key_add_uid true
                          type dmix
                          slave.pcm "wolfson_pi_soundcard"
                  }
                  
                  # Define another one called "recmixer" for capture.
                  # The sound card will run at 48kHz and input is resampled to the requested rate.
                  pcm.recmixer {
                          ipc_key 140325
                          ipc_key_add_uid true
                          type dsnoop
                          slave.pcm "wolfson_pi_soundcard"
                  }
                  
                  # Define a duplex device, with both in- and outputs.
                  pcm.duplex {
                          type asym
                          playback.pcm "playmixer"
                          capture.pcm "recmixer"
                  }
                  
                  # Add a "plug" plugin for the above "duplex" device.
                  # This is where all the converting takes place.
                  # Sample rate, number of channels, bit depth.
                  # By the way, who thought that "plug" was a good name for a plugin?
                  #
                  # Use this device for all your playback and recording resampling needs.
                  pcm.pduplex {
                          type plug
                          slave.pcm "duplex"
                  }
                  
                  # A ctl device to keep xmms happy
                  ctl.pduplex {
                          type hw
                          card 0
                  }
                  
                  # A DSP to keep the alsa-oss layer happy:
                  pcm.dsp0 {
                          type plug
                          slave.pcm "duplex"
                  }
                  
                  ctl.mixer0 {
                          type hw
                          card 0
                  }
                  
                  
                  
                    • Re: PJSIP/PJSUA with Wolfson audio card
                      lcop

                      HI Ragnar

                       

                      I use your .asoundrc, and the wolfson PI Card works, but I Can't reproduce the files this is the error

                       

                      root@raspberrypi:/home/pi/pjproject-2.2.1/pjsip-apps/bin# aplay PJSYSTEST_TESTREC.WAV               Playing WAVE 'PJSYSTEST_TESTREC.WAV' : Signed 16 bit Little Endian, Rate 8000 Hz, Mono

                      aplay: set_params:1145: Unable to install hw params:

                      ACCESS:  RW_INTERLEAVED

                      FORMAT:  S16_LE

                      SUBFORMAT:  STD

                      SAMPLE_BITS: 16

                      FRAME_BITS: 16

                      CHANNELS: 1

                      RATE: 8000

                      PERIOD_TIME: 125000

                      PERIOD_SIZE: 1000

                      PERIOD_BYTES: 2000

                      PERIODS: 4

                      BUFFER_TIME: 500000

                      BUFFER_SIZE: 4000

                      BUFFER_BYTES: 8000

                      TICK_TIME: 0

                       

                      Can the Wolfson PI Audio Card play files with 8000hz, this is a critical point in the asterisk communication because the principal audio codecs run to 8000hz. do you know?

                       

                      I'm graceful with your answer

                        • Re: PJSIP/PJSUA with Wolfson audio card
                          ragnar.jensen

                          The card itself (or rather its drivers) cannot record or play back at 8 kHz.

                          Using my .asoundrc you should be able to record and play back at any sample rate and bit depth.

                           

                          ragnar@ob3:~/tmp$ arecord -d 10 -f S16_LE -v testing16.wav

                          Recording WAVE 'testing16.wav' : Signed 16 bit Little Endian, Rate 8000 Hz, Mono

                          Plug PCM: Rate conversion PCM (48000, sformat=S16_LE)

                          Converter: libsamplerate

                          Protocol version: 10002

                          Its setup is:

                            stream : CAPTURE

                            access : RW_INTERLEAVED

                            format : S16_LE

                            subformat : STD

                            channels : 1

                            rate : 8000

                            exact rate : 8000 (8000/1)

                            msbits : 16

                            buffer_size : 3000

                            period_size : 1000

                            period_time : 125000

                            tstamp_mode : NONE

                            period_step : 1

                            avail_min : 1000

                            period_event : 0

                            start_threshold : 1

                            stop_threshold : 3000

                            silence_threshold: 0

                            silence_size : 0

                            boundary : 196608000

                          Slave: Route conversion PCM (sformat=S16_LE)

                            Transformation table:

                            0 <- 0*0.5 + 1*0.5

                          Its setup is:

                            stream : CAPTURE

                            access : MMAP_INTERLEAVED

                            format : S16_LE

                            subformat : STD

                            channels : 1

                            rate : 48000

                            exact rate : 48000 (48000/1)

                            msbits : 16

                            buffer_size : 18000

                            period_size : 6000

                            period_time : 125000

                            tstamp_mode : NONE

                            period_step : 1

                            avail_min : 6000

                            period_event : 0

                            start_threshold : 6

                            stop_threshold : 18000

                            silence_threshold: 0

                            silence_size : 0

                            boundary : 1179648000

                          Slave: Direct Snoop PCM

                          Its setup is:

                            stream : CAPTURE

                            access : MMAP_INTERLEAVED

                            format : S16_LE

                            subformat : STD

                            channels : 2

                            rate : 48000

                            exact rate : 48000 (48000/1)

                            msbits : 16

                            buffer_size : 18000

                            period_size : 6000

                            period_time : 125000

                            tstamp_mode : NONE

                            period_step : 1

                            avail_min : 6000

                            period_event : 0

                            start_threshold : 6

                            stop_threshold : 18000

                            silence_threshold: 0

                            silence_size : 0

                            boundary : 1179648000

                          Hardware PCM card 0 'snd_rpi_wsp' device 0 subdevice 0

                          Its setup is:

                            stream : CAPTURE

                            access : MMAP_INTERLEAVED

                            format : S16_LE

                            subformat : STD

                            channels : 2

                            rate : 48000

                            exact rate : 48000 (48000/1)

                            msbits : 16

                            buffer_size : 18000

                            period_size : 6000

                            period_time : 125000

                            tstamp_mode : ENABLE

                            period_step : 1

                            avail_min : 6000

                            period_event : 0

                            start_threshold : 1

                            stop_threshold : 1179648000

                            silence_threshold: 0

                            silence_size : 0

                            boundary : 1179648000

                            appl_ptr : 0

                            hw_ptr : 0

                           

                           

                           

                          ragnar@ob3:~/tmp$ file testing16.wav

                          testing16.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz

                           

                           

                           

                          ragnar@ob3:~/tmp$ aplay -v testing16.wav

                          Playing WAVE 'testing16.wav' : Signed 16 bit Little Endian, Rate 8000 Hz, Mono

                          Plug PCM: Soft volume PCM

                          Control: Master

                          min_dB: -51

                          max_dB: 0

                          resolution: 256

                          Its setup is:

                            stream : PLAYBACK

                            access : RW_INTERLEAVED

                            format : S16_LE

                            subformat : STD

                            channels : 1

                            rate : 8000

                            exact rate : 8000 (8000/1)

                            msbits : 16

                            buffer_size : 3000

                            period_size : 1000

                            period_time : 125000

                            tstamp_mode : NONE

                            period_step : 1

                            avail_min : 1000

                            period_event : 0

                            start_threshold : 3000

                            stop_threshold : 3000

                            silence_threshold: 0

                            silence_size : 0

                            boundary : 196608000

                          Slave: Plug PCM: Rate conversion PCM (48000, sformat=S16_LE)

                          Converter: libsamplerate

                          Protocol version: 10002

                          Its setup is:

                            stream : PLAYBACK

                            access : MMAP_INTERLEAVED

                            format : S16_LE

                            subformat : STD

                            channels : 1

                            rate : 8000

                            exact rate : 8000 (8000/1)

                            msbits : 16

                            buffer_size : 3000

                            period_size : 1000

                            period_time : 125000

                            tstamp_mode : NONE

                            period_step : 1

                            avail_min : 1000

                            period_event : 0

                            start_threshold : 3000

                            stop_threshold : 3000

                            silence_threshold: 0

                            silence_size : 0

                            boundary : 196608000

                          Slave: Route conversion PCM (sformat=S16_LE)

                            Transformation table:

                            0 <- 0

                            1 <- 0

                          Its setup is:

                            stream : PLAYBACK

                            access : MMAP_INTERLEAVED

                            format : S16_LE

                            subformat : STD

                            channels : 1

                            rate : 48000

                            exact rate : 48000 (48000/1)

                            msbits : 16

                            buffer_size : 18000

                            period_size : 6000

                            period_time : 125000

                            tstamp_mode : NONE

                            period_step : 1

                            avail_min : 6000

                            period_event : 0

                            start_threshold : 18000

                            stop_threshold : 18000

                            silence_threshold: 0

                            silence_size : 0

                            boundary : 1179648000

                          Slave: Direct Stream Mixing PCM

                          Its setup is:

                            stream : PLAYBACK

                            access : MMAP_INTERLEAVED

                            format : S16_LE

                            subformat : STD

                            channels : 2

                            rate : 48000

                            exact rate : 48000 (48000/1)

                            msbits : 16

                            buffer_size : 18000

                            period_size : 6000

                            period_time : 125000

                            tstamp_mode : NONE

                            period_step : 1

                            avail_min : 6000

                            period_event : 0

                            start_threshold : 18000

                            stop_threshold : 18000

                            silence_threshold: 0

                            silence_size : 0

                            boundary : 1179648000

                          Hardware PCM card 0 'snd_rpi_wsp' device 0 subdevice 0

                          Its setup is:

                            stream : PLAYBACK

                            access : MMAP_INTERLEAVED

                            format : S16_LE

                            subformat : STD

                            channels : 2

                            rate : 48000

                            exact rate : 48000 (48000/1)

                            msbits : 16

                            buffer_size : 18000

                            period_size : 6000

                            period_time : 125000

                            tstamp_mode : ENABLE

                            period_step : 1

                            avail_min : 6000

                            period_event : 0

                            start_threshold : 1

                            stop_threshold : 1179648000

                            silence_threshold: 0

                            silence_size : 1179648000

                            boundary : 1179648000

                            appl_ptr : 0

                            hw_ptr : 0

                          ragnar@ob3:~/tmp$

                           

                           

                          I notice that you are running aplay as root in your example.

                          Have you put a copy of .asoundrc in root's home directory too? Every user needs its own copy.

                          Or install a global one: Asoundrc - AlsaProject

                          --

                          Ragnar

                        • Re: PJSIP/PJSUA with Wolfson audio card
                          nuntipat

                          Hi Ragnar,

                           

                          I'm using your ~/.asoundrc file above and get this error

                           

                          ALSA lib pcm_direct.c:877:(snd1_pcm_direct_initialize_slave) slave plugin does not support mmap interleaved or mmap noninterleaved access

                          ALSA lib pcm_dmix.c:1030:(snd_pcm_dmix_open) unable to initialize slave

                          aplay: main:682: audio open error: Invalid argument

                           

                          Any help would be really appreciate.

                           

                          Thank you,

                          Palm

                        • Re: PJSIP/PJSUA with Wolfson audio card
                          mrglasspoole

                          How is the CPU usage compared to a USB sound card?