5

I'm trying to produce low bitrate opus files with L/R stereo. What decides if opusenc will use L/R stereo instead of joint stereo? Is there are flag I can pass? Is it related to bitrate?

opusenc input.wav output.opus //produces L/R stereo
opusenc input.wav output.opus --bitrate 8 //produces joint stereo
Colin Pickard
  • 45,724
  • 13
  • 98
  • 148
  • I was testing this by encoding a file with very high stereo separation and listening to the result. The channels were distinctly separate with the default encoding. – Colin Pickard Apr 04 '14 at 15:09

2 Answers2

2

It looks like it is determined here:

    if (st->force_channels!=OPUS_AUTO && st->channels == 2)
    {
        st->stream_channels = st->force_channels;
    } else {
#ifdef FUZZING
       /* Random mono/stereo decision */
       if (st->channels == 2 && (rand()&0x1F)==0)
          st->stream_channels = 3-st->stream_channels;
#else
       /* Rate-dependent mono-stereo decision */
       if (st->channels == 2)
       {
          opus_int32 stereo_threshold;
          stereo_threshold = stereo_music_threshold + ((voice_est*voice_est*(stereo_voice_threshold-stereo_music_threshold))>>14);
          if (st->stream_channels == 2)
             stereo_threshold -= 4000;
          else
             stereo_threshold += 4000;
          st->stream_channels = (equiv_rate > stereo_threshold) ? 2 : 1;
       } else {
          st->stream_channels = st->channels;
       }
#endif
    }

Just breifly reading through the opusenc source code, it looks like setting force_channels to 2 on the struct OpusEncoder will make it work. However, looking through the opusenc.c source code, no where is that field set. You could easily modify the source however to always force channels to be two. For the future, it looks like opus calls it "dual stereo" rather than "L/R stereo".

Carl Mastrangelo
  • 5,970
  • 1
  • 28
  • 37
  • Messing with the code you pasted above will just change when the encoder decides to downmix to mono internally. The exact stereo mode (L/R vs mid-side vs intensity) is spread between the SILK and CELT code and isn't something you should mess with. I'm not sure what the original post was trying to achieve, but messing with the stereo mode was likely not that. – Jean-Marc Valin May 16 '14 at 17:44
1

Opus by default attempts to make the best decision possible based on the current bitrate. The decision is made on the following table (20 ms frame size):

  • 8-12 kbit/s for NB speech,
  • 16-20 kbit/s for WB speech,
  • 28-40 kbit/s for FB speech,
  • 48-64 kbit/s for FB mono music, and
  • 64-128 kbit/s for FB stereo music.

This is because opus assume that, if the bitrate is too low, it cannot encode stereo with sufficient quality.

Actually the documentation says that it is possible to change the number of channels BUT it doesn't explain how. I'll take a look later anyway on how to do this.

You can find these informations on rfc6716

Antonio E.
  • 4,381
  • 2
  • 25
  • 35