Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use Opus 1.5 DRED? #376

Open
sayakasama opened this issue Oct 31, 2024 · 2 comments
Open

how to use Opus 1.5 DRED? #376

sayakasama opened this issue Oct 31, 2024 · 2 comments

Comments

@sayakasama
Copy link

sayakasama commented Oct 31, 2024

I tried to use the DRED of opus 1.5 in my real-time intercom software, and used the way in the demo to simulate the packet loss.
I observed the log and found that when I started to speak, and there was packet loss, the normal call [opus_dred_parse], its return value has always been 0, so the decoder will only call [opus_decode].
However when I stop talking, the [opus_dred_parse] will return a positive number, and then use [opus_ decoder_dred_decode] to decode the packet, I don't understand why, is this the right situation? thanks!

 lost = (packet_loss_perc>0) && (rand()%100 < packet_loss_perc);
        }
        if (len == 0) lost = 1;
        if (lost)
        {
           lost_count++;
           run_decoder = 0;
        } else {
           run_decoder= 1;
        }
        if (run_decoder)
            run_decoder += lost_count;
        if (!lost && lost_count > 0) {
            opus_int32 output_samples=0;
            opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&output_samples));
            dred_input = lost_count*output_samples;
            /* Only decode the amount we need to fill in the gap. */
            ret = opus_dred_parse(dred_dec, dred, data, len, IMIN(48000, IMAX(0, dred_input)), sampling_rate, &dred_end, 0);
            dred_input = ret > 0 ? ret : 0;
        }
        /* FIXME: Figure out how to trigger the decoder when the last packet of the file is lost. */
        for (fr=0;fr<run_decoder;fr++) {
            opus_int32 output_samples=0;
            if (fr == lost_count-1 && opus_packet_has_lbrr(data, len)) {
               opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&output_samples));
               output_samples = opus_decode(dec, data, len, out, output_samples, 1);
            } else if (fr < lost_count) {
               opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&output_samples));
               if (dred_input > 0)
                  output_samples = opus_decoder_dred_decode(dec, dred, (lost_count-fr)*output_samples, out, output_samples);
               else
                  output_samples = opus_decode(dec, NULL, 0, out, output_samples, 0);
            } else {
               output_samples = max_frame_size;
               output_samples = opus_decode(dec, data, len, out, output_samples, 0);
            }
@sayakasama sayakasama changed the title Opus 1.5 DRED and inbandFEC how to use Opus 1.5 DRED? Nov 1, 2024
@LigangSun
Copy link

I try to use it in my project, but it is really easy.
To let opus encode dred data, I disabled the FEC and set bitrates to 32000, then opus can encode two chunks.
Then follow the sample code, I can decode the DRED data, but the voice quality seems not as I expected.
I am still woking on it, hoping a good result.

@sayakasama
Copy link
Author

I try to use it in my project, but it is really easy. To let opus encode dred data, I disabled the FEC and set bitrates to 32000, then opus can encode two chunks. Then follow the sample code, I can decode the DRED data, but the voice quality seems not as I expected. I am still woking on it, hoping a good result.

Thank u for your reply.
I think i have the same doubts as you.I feel like I've enabled dred, but the audio quality isn't what I expected, so I wonder if I'm using it wrong.

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

No branches or pull requests

2 participants