Skip to content

Conversation

gustafullberg
Copy link
Contributor

Fixes an issue in Silk mode causing the codec going into DTX one frame too early.

#72

@jmvalin
Copy link
Member

jmvalin commented Nov 23, 2017

I don't know that one behaviour is better than the other. Is the current code causing issues?

@jmvalin
Copy link
Member

jmvalin commented Nov 23, 2017

Nm, just read your explanation in issue #72

@gustafullberg
Copy link
Contributor Author

Is something holding the merge of this PL back? Is more information needed?
IMHO, this is clearly a bug with a clean (two-character) fix suggested.

@jmvalin
Copy link
Member

jmvalin commented Feb 20, 2018

Sorry for the delay. Looking at this now, do you already have some test code/sample for this or should I build one myself. (your patch looks sane, I just want to make sure I test it properly)

@jmvalin jmvalin closed this Feb 20, 2018
@jmvalin jmvalin reopened this Feb 20, 2018
@gustafullberg
Copy link
Contributor Author

No worries.
I don't think I have a test wired up at the moment. I'm a developer of WebRTC, and discovered the bug when a test didn't show the expected DTX pattern in lower complexity modes (Silk-only mode). I tried to describe the pattern in #72 .
If this turns out to be hard to reproduce I'll try to put something together.

@gustafullberg
Copy link
Contributor Author

gustafullberg commented Feb 21, 2018

I wrote a tiny test that shows the issue. It basically encodes zeros with DTX enabled. Please try it out at different complexity levels with and without my pull request.

#include <stdio.h>
#include <opus/opus.h>

int main(int argc, char **argv)
{
  int error;
  OpusEncoder *enc = opus_encoder_create(24000, 1, OPUS_APPLICATION_VOIP, &error);
  opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(6));
  opus_encoder_ctl(enc, OPUS_SET_DTX(1));

  short audio_frame[480] = { 0 };
  int num_dtx = 0, num_coded = 0;
  for(int i = 0; i < 60; i++) {
    int packet_size = 1024*10;
    unsigned char packet[packet_size];
    int len = opus_encode(enc, audio_frame, 240, packet, packet_size);
    if(len <= 2) {
      // DTX
      num_dtx++;
      if(num_coded > 0) {
        printf("Number of consecutive encoded frames %d\n", num_coded);
        num_coded = 0;
      }
    } else {
      // Encoded
      num_coded++;
      if(num_dtx > 0) {
        printf("Number of consecutive DTX frames %d\n", num_dtx);
        num_dtx = 0;
      }
    }
  }
  return 0;
}

Output at complexity level 7:

Number of consecutive encoded frames 10
Number of consecutive DTX frames 20
Number of consecutive encoded frames 1
Number of consecutive DTX frames 20
Number of consecutive encoded frames 1

Output at complexity level 6 without pull request:

Number of consecutive encoded frames 9
Number of consecutive DTX frames 21
Number of consecutive encoded frames 1
Number of consecutive DTX frames 20
Number of consecutive encoded frames 1

Output at complexity level 6 with pull request

Number of consecutive encoded frames 10
Number of consecutive DTX frames 20
Number of consecutive encoded frames 1
Number of consecutive DTX frames 20
Number of consecutive encoded frames 1

As you can see from the output at complexity level <= 6 without the PL we enter DTX one frame too early and stay in DTX one frame too long.

The intended behavior is pretty clear in the code (from silk/define.h):

/* DTX settings */
#define NB_SPEECH_FRAMES_BEFORE_DTX             10      /* eq 200 ms */
#define MAX_CONSECUTIVE_DTX                     20      /* eq 400 ms */

@jmvalin
Copy link
Member

jmvalin commented Feb 23, 2018

merged

@jmvalin jmvalin closed this Feb 23, 2018
aarongable pushed a commit to chromium/chromium that referenced this pull request Mar 5, 2018
xiph/opus#73

Bug: webrtc:8088
Change-Id: Ie3838e5c8600259af46bdf09680e58dcf55f78a2
Reviewed-on: https://chromium-review.googlesource.com/942317
Reviewed-by: Henrik Andreasson <henrika@chromium.org>
Commit-Queue: Felicia Lim <flim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540976}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants