Search code examples
sipvoiplinphoneopuslinphone-sdk

Linphone opus codec sampling rate


I would like to use opus codec in linphone

But I have a few problems using it. If someone with opus codec knowledge could help me out would appreciate it. How I can force audio sampling scheme to 8000 Hz? Currently, it uses 48000 Hz only.

Thanks in advance


Solution

  • If you look at rfc7587 Section 4.1, you can read this:

    Opus supports 5 different audio bandwidths, which can be adjusted
    during a stream.  The RTP timestamp is incremented with a 48000 Hz
    clock rate for all modes of Opus and all sampling rates.  The unit
    for the timestamp is samples per single (mono) channel.  The RTP
    timestamp corresponds to the sample time of the first encoded sample
    in the encoded frame.  For data encoded with sampling rates other
    than 48000 Hz, the sampling rate has to be adjusted to 48000 Hz.
    

    Reading more in the rfc7587, you will find out that, in SDP, you will always see the codec being using "OPUS/48000/2", no matter the real sampling rates.

    No matter the real sampling rate, as explained above, the RTP timestamp will always be incremented with a 48000 Hz clock rate.

    If you wish to control the real sampling rate for the codec (and thus, the bandwidth), you can use the following SDP parameters: maxplaybackrate and maxaveragebitrate are the ones to be used.

    Section 3.1.1 is listing the relation between maxaveragebitrate and the sampling rate:

    3.1.1.  Recommended Bitrate
    
       For a frame size of 20 ms, these are the bitrate "sweet spots" for  Opus in various configurations:
    
       o  8-12 kbit/s for NB speech,
       o  16-20 kbit/s for WB speech,
       o  28-40 kbit/s for FB speech,
       o  48-64 kbit/s for FB mono music, and
       o  64-128 kbit/s for FB stereo music.
    

    Conclusion: to use only 8000Hz in OPUS, you must negotiate with such parameters, where 12kbit/s is the maximum setup for opus in NB speech:

       m=audio 54312 RTP/AVP 101
       a=rtpmap:101 opus/48000/2
       a=fmtp:101 maxplaybackrate=8000; sprop-maxcapturerate=8000; maxaveragebitrate=12000
    

    I don't know if linphone is following all the parameters, but this is the theory!